<?php
session_start();$menu=$_SESSION['menu'];include $menu;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11pt; }
<p style="font-size:11px;"></p>
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=700, height=600, top='+top+', left='+left);
}
</script>
</head>

<body>

<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];
$ac=$_SESSION['access'];
$go='true';
if ($ac==1) 
{
   $sql = mysqli_query($con,"SELECT Class_id  FROM voithos  where yt='$usr' ");
   if (mysqli_num_rows($sql) > 0) 
   {
	 $row=mysqli_fetch_array($sql);
	 $tmima=$row['Class_id'];
	 $sql1 = "SELECT *  FROM allstudentinfo  where tmima='$tmima' ORDER BY eponimo,onoma ASC";
     $result = mysqli_query($con,$sql1);
   }
   else
   { echo " ΔΕΝ ΕΧΕΤΕ ΥΠΕΥΘΥΝΟΤΗΤΑ ΤΜΗΜΑΤΟΣ";
     $go='false';
	 }
}
else
{
    $sql = "SELECT *  FROM allstudentinfo  ORDER BY tmima ASC";
    $result = mysqli_query($con,$sql);
}
if ($go=='true')
{
$datedisp= date('d-m-Y', strtotime($dt));
?>
<h3> ΑΠΟΥΣΙΕΣ ΜΕΧΡΙ: <?php echo $datedisp; ?> ΓΙΑ ΤΟ ΤΜΗΜΑ: <?php echo $tmima; ?> </h3>
<?php
$sqla = mysqli_query($con,"SELECT datexar FROM apousiesabakio " );
$rowa = mysqli_fetch_array($sqla);
$dx=$rowa['datexar'];
$datexar=date('d-m-Y', strtotime($dx));
echo "<p>"."ΟΙ ΑΠΟΥΣΙΕΣ ΕΙΝΑΙ ΧΑΡΑΚΤΗΡΙΣΜΕΝΕΣ ΜΕΧΡΙ : ".date('d-m-Y', strtotime($rowa['datexar']))."</p>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>A/A</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΜΑΘΗΤΗΣ / ΤΡΙΑ</th>
<th>ΑΠ.ΑΒΑΚΙΟ ΜΕΧΡΙ  (".$datexar.") </th>
<th>ΑΠΟΥΣΙΕΣ ΣΥΣΤ ΑΠΟ (".$datexar.") </th>
<th>ΑΠΟΥΣΙΕΣ ΟΛΙΚΟ</th>
<th>ΑΠΟΥΣΙΕΣ Β ΤΕΤΡ</th>";
$sql = mysqli_query($con,"SELECT a.mitroo,a.apousiestotal,a.apousiesbtotal,a.datexar,b.onoma,b.eponimo 
FROM apousiesabakio as a, allstudentinfo as b WHERE b.tmima='$tmima' and a.mitroo=b.mitroo ORDER by b.eponimo,b.onoma" );
$row = mysqli_fetch_array($sql);
$totap=array();
$k=1;
while($row = mysqli_fetch_array($sql))
{	
  $ap=0;
  $mitroo=$row['mitroo'];
  echo "<tr>";
  echo "<td>".$k. "</td>"; 
  echo "<td>";
  ?>
  <a href="#" onClick="popupCenter('apousiesm.php?data=<?php echo $mitroo; ?>')"><?php echo $mitroo; ?></a> 
  <?php
  echo "</td>";
  echo "<td>".$row['eponimo']." ".$row['onoma']."</td>"; 
  $sqlx = mysqli_query($con,"SELECT count(apousia) as apcx FROM apousies 
			WHERE mitroo='$mitroo' and ((apousia=1 and kath IS NULL) and dateout > '$dx') group by mitroo " );
  $rowx = mysqli_fetch_array($sqlx);
  echo "<td>".$row['apousiestotal']."</td>";
  echo "<td>".$rowx['apcx']."</td>";
  $apt=$rowx['apcx']+$row['apousiestotal'];
  echo "<td>".$apt."</td>";
  $sqlx = mysqli_query($con,"SELECT count(apousia) as apcx FROM apousies 
			WHERE mitroo='$mitroo' and ((apousia=1 and kath IS NULL) and dateout > '2020-01-10') group by mitroo " );
  $rowx = mysqli_fetch_array($sqlx);
  echo "<td>".$rowx['apcx']."</td>";
  echo "</tr>";
  $k++;  
}
	 
echo "</table>";	
}


 ?>
<br /><br />
<a  href=<?php echo $menu; ?>  style="color:blue "  > <button>  Επιστροφή στο Μενού  </a>
</body>
</html>