<meta charset="utf-8">
<link href="../../css/templatemo_style.css" rel="stylesheet" type="text/css" />
<?php
session_start();
if (isset($_GET['s'])) {
    $s = $_GET['s'];
    $_SESSION['GROUPOFUSE'] = $s;
}


if ($_SESSION['GROUPOFUSE'] == 1) {
    $pagetitle = "1oυ Γραφείου!!!";
    include('../../divs/header.php');
    require_once('../../mysqli_connect.php');
} else {
    require_once('../../login/login_functions.inc.php');
    $url = absolute_url('../../login/login.php');
    header("Location: $url");
    exit();
}
?>


<!--  MENU  -->

 <!-- end of templatemo_menu -->

<div id="templatemo_main"> <span class="tm_bottom"></span>

 <style> #templatemo_main table{
	   font-weight:bold;
	   color:#000000;
	   }
            #templatemo_main tr{
	   font-weight:500;
	   color:#000000;
	   }
       #templatemo_main h1{
	   text-align:center;
	   color:#FC0;
	   }
	   #templatemo_main h2{
	   text-align:center;
	   color:#CC9;
	   }
       </style>
    <?php
    if ($_POST['submitted']) {
        $errors = array();

        if (empty($_POST['name'])) {
            $errors[] = 'Δεν επιλέξατε στέλεχος';
        } else {
            $name = mysqli_real_escape_string($dbc, trim($_POST['name']));
            $data = explode(' ', $name);
            $id = $data[3];
        }

        if (empty($errors)) {

            $q = "SELECT  concat_ws(' ',r.rankname,s.surname,s.name) as stelexos
          from stelexi s, ranks r,oplo o where r.rankid=s.rankid and s.oploid=o.oploid 
          and s.id=$id ";

            $r = mysqli_query($dbc, $q);



            if ($r) {


                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

                    echo '<h1>Ατομικά έγγραφα του Στελέχους : ' . $row['stelexos'] . ' !</h1>';
                }
            } else {
                echo 'Δεν κατέστη δυνατή η ανάκτηση των ατομικών εγγράφων του ανωτέρω στελέχους!';
            }
            $q = "SELECT  concat(s.name,' ',s.middlename,' ',s.surname) as name,s.id as am,
                  r.rankname as rank,o.oploname as oplo,k.kathikname as kath
                  from stelexi s, ranks r,oplo o,kathikonta k
                  where r.rankid=s.rankid and s.oploid=o.oploid and k.kathikid=s.kathikontaid and 
                  s.id=$id ";

            $r = mysqli_query($dbc, $q);
            if ($r) {


                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>AM</a></b></td>
             <td align="left"><b>Βαθμός</b></td>
             <td align="left"><b>Ονοματεπώνυμο</b></td>
             <td align="left"><b>Όπλο/Σώμα</b></td>
             <td align="left"><b>Καθήκοντα</b></td>
               </tr>
          ';
                $bg = '#eeeeee';
                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['am'] . '</td>
            <td align="left">' . $row['rank'] . '</td>
            <td align="left">' . $row['name'] . '</td>
            <td align="left">' . $row['oplo'] . '</td>
            <td align="left">' . $row['kath'] . '</td>
			
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            } 
            $q = "SELECT  p.eidos as poinh,p.diarkeia as meres, date_format(p.date,'%d %M %y') as date
                  ,p.aitia as aitia from stelexi s, poines p
                  where s.id=p.stid and s.id=$id ";

            $r = mysqli_query($dbc, $q);
            if ($r) {

                echo'</br><h2>Πίνακας Ποινών</h2>';
                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>Ημερομηνία Επιβολής</a></b></td>
             <td align="left"><b>Είδος</b></td>
             <td align="left"><b>Διάρκεια</b></td>
             <td align="left"><b>Αιτιολογία</b></td>
            </tr>
          ';
                $bg = '#eeeeee';
                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['date'] . '</td>
            <td align="left">' . $row['poinh'] . '</td>
            <td align="left">' . $row['meres'] . '</td>
            <td align="left">' . $row['aitia'] . '</td>    
            	
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            }
            $cury=date('Y');
            $q = "SELECT  a.eidos as adeia,a.diarkeia as meres, date_format(a.date,'%d %M %y') 
                  as date
                  from stelexi s, adeies a
                  where s.id=a.stid and s.id=$id and a.date like '$cury%'";
           // echo $q; 
            $r = mysqli_query($dbc, $q);
            if ($r) {

                echo'</br><h2>Πίνακας Aδειών Τρέχοντος Έτους</h2>';
                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>Ημερομηνία Επιβολής</a></b></td>
             <td align="left"><b>Είδος</b></td>
             <td align="left"><b>Διάρκεια</b></td>
           
            </tr>
          ';
                $bg = '#eeeeee';
                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['date'] . '</td>
            <td align="left">' . $row['adeia'] . '</td>
            <td align="left">' . $row['meres'] . '</td>
              
            	
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            }
            $q = "SELECT  m.eidos as met, date_format(m.date,'%d %M %y') as date
                  from stelexi s, metavoles m
                  where s.id=m.stid and s.id=$id ";

            $r = mysqli_query($dbc, $q);
            if ($r) {

                echo'</br><h2>Πίνακας Μεταβολών</h2>';
                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>Ημερομηνία Μεταβολής</a></b></td>
             <td align="left"><b>Μεταβολή</b></td>
             <td align="left"><b>Παρατηρήσεις</b></td>
            
            </tr>
          ';
                $bg = '#eeeeee';
                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['date'] . '</td>
            <td align="left">' . $row['met'] . '</td>
            
            	
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            }
             $q = "SELECT  p.proagogh as proa,p.edyethaproagoghs as edyetha, date_format(p.date,'%d %M %y') as date
                  from stelexi s, proagoges p
                  where s.id=p.stid and s.id=$id ";

            $r = mysqli_query($dbc, $q);
            if ($r) {

                echo'</br><h2>Πίνακας Προαγωγών</h2>';
                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>Ημερομηνία Προαγωγής</a></b></td>
             <td align="left"><b>Προαγωγή</b></td>
             <td align="left"><b>ΕΔΥΕΘΑ</b></td>
            
            </tr>
          ';
                $bg = '#eeeeee';
                while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['date'] . '</td>
            <td align="left">' . $row['proa'] . '</td>
            <td align="left">' . $row['edyetha'] . '</td>
           
            	
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            }
        } else {
            echo '<p class="error">The following error(s) occurred:<br />';

            foreach ($errors as $msg) { // Print each error.
                echo " - $msg<br />\n";
            }
        }
             $q = "SELECT  v.vathmos as va,concat(s.name,' ',s.middlename,' ',s.surname) as name 
                 from stelexi s, vathmologia v
                  where s.id=v.stid and v.stid=$id ";

            $r = mysqli_query($dbc, $q);
             $q1 = "SELECT  v.vathmos as va,concat(s.name,' ',s.middlename,' ',s.surname) as name 
                 from stelexi s, vathmologia v
                  where s.id=v.idaxiologoynta and v.stid=$id ";

            $r1 = mysqli_query($dbc, $q1);
             $q2 = "SELECT  v.vathmos as va,concat(s.name,' ',s.middlename,' ',s.surname) as name 
                 from stelexi s, vathmologia v
                  where s.id=v.idgnomateyontos and v.stid=$id ";

            $r2 = mysqli_query($dbc, $q2);
            if ($r and $r2 and $r1 ) {

                echo'</br><h2>Πίνακας Βαθμολογίας</h2>';
                echo '<table align="center"  bgcolor="#FFFF99"  bordercolor="#FF3300" border="2" cellspacing="3" cellpadding="3" width="100%">
          <tr>
             <td align="left"><b>Γενικός Βαθμός</a></b></td>
             <td align="left"><b>Αξιολογών</b></td>
             <td align="left"><b>Γνωματεύων</b></td>
            
            </tr>
          ';
                $bg = '#eeeeee';
                while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC) and $row1 = mysqli_fetch_array($r1, MYSQLI_ASSOC) and $row2 = mysqli_fetch_array($r2, MYSQLI_ASSOC) ) {
                    $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
                    echo '<tr bgcolor="' . $bg . '">
            <td align="left">' . $row['va'] . '</td>
            <td align="left">' . $row1['name'] . '</td>
            <td align="left">' . $row2['name'] . '</td>
           
            	
              </tr>
              ';
                }
                echo '</table>';
            } else {
                echo 'Παρακαλώ προσπαθείστε ξανά';
            }
    } else {
        echo'the page has been acceded in error';
    }
    ?>






    <div class="cleaner"></div>
</div> 




<?php
include('../../divs/footer.php');
?>