<?php
include "scrinit.php";
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>
</head>

<body>

<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$stname=$_SESSION['stname'];

if(isset($_POST['nameid']))
{
  $mitr=$_POST['nameid'];
  $tmimaid=$_POST['tmimaid'];
}
$sql1 = $dbcon->prepare("SELECT * FROM parameters " );
$sql1->execute();
$row1=$sql1->fetch(PDO::FETCH_ASSOC);
$btetrs=$row1['btetrs'];
	
$sql = $dbcon->prepare("SELECT eponimo,onoma FROM allstudentinfo WHERE mitroo= ? ");
$sql->execute([$mitr]);
$row = $sql->fetch(PDO::FETCH_ASSOC);
$stname=$row['eponimo']." ".$row['onoma'];
echo "<br>";
echo "<b>". $stname."  (".$tmimaid."-".$mitr." )"."</b>";
echo "<br>";

$sql = $dbcon->prepare("SELECT a.dateout, a.period,a.mitroo FROM apousies as a WHERE a.mitroo= ? AND a.apousia=1 
 ORDER BY dateout,period " );
$sql->execute([$mitr]);
$row = $sql->fetch(PDO::FETCH_ASSOC);
	
// Print out result
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Ημερομηνία</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
$apa=$apb=0;
$in=0;
$totapa=$totapb=array();
while(!empty($row)) 
{
      $per1=array();
	  $dat=$row['dateout'];
	  if ($dat >= $btetrs and $in<>1)
	  {
		echo '<tr bgcolor="#e6e6ff">';
		echo "<td>"." ΣΥΝΟΛΟ A ". "</td>";
		$i=1;    
		while($i<=$gym)
		{
			echo "<td>". $totapa[$i] . "</td>";
			$i++;
		}
		echo "</tr>"; 
		$in=1;		
	  }
	  echo "<td>". $dat . "</td>"; 	 
	  while ($dat==$row['dateout'])
	  {
	     $per1[$row['period']]="XXXX";
	     
		 if ($dat >= $btetrs)
		 {
			$totapb[$row['period']]++;
			$apb++;
		 }
		 else
		 {
			$totapa[$row['period']]++;
			$apa++;	 
		 }
	     $row = $sql->fetch(PDO::FETCH_ASSOC);
	  }
    

     $i=1;    
     while($i<=$gym){
		 echo "<td>". $per1[$i] . "</td>";$i++;}
     echo "</tr>"; 
}

echo "</tr>"; 
echo '<tr bgcolor="#e6e6ff">';
echo "<td>"." ΣΥΝΟΛΟ Β ". "</td>";
$i=1;    
while($i<=$gym)
{
	echo "<td>". $totapb[$i] . "</td>";$i++;
}
echo "</tr>";
echo "</table>";	
echo "<br>"."<br>";
echo "<b>"."ΣΥΝΟΛΟ ΜΗ ΧΑΡΑΚΤΗΡΙΣΜΕΝΩΝ ΑΠΟΥΣΙΩΝ Α: ".$apa."</b>";
echo "<br>"."<b>"."ΣΥΝΟΛΟ ΜΗ ΧΑΡΑΚΤΗΡΙΣΜΕΝΩΝ ΑΠΟΥΣΙΩΝ B: ".$apb."</b>";
$s=$apa+$apb;
echo "<br>"."<b>"."ΣΥΝΟΛΟ : ".$s."</b>";
 ?>
<br /><br />
<a  href="apmathiti.php" style="color:blue "  > <button> Επανάληψη Αναφοράς  </a>
<a  href=<?php echo $menu; ?>  style="color:blue "  > <button>  Επιστροφή στο Μενού  </a>
</body>
</html>