<?php
include "scrinit.php";
include "logo.php";
?>
<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'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];

$mitr=$_GET['data'];

$sql = mysqli_query($con,"SELECT eponimo,onoma,tmima FROM allstudentinfo WHERE mitroo='$mitr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
echo "<br>";
echo $stname." ".$tmimaid." ".$mitr;
echo "<br>";
$sql = mysqli_query($con,"SELECT dateout, period FROM apousies WHERE mitroo='$mitr' AND apousia=1  ORDER BY dateout,period " );
$row = mysqli_fetch_array($sql);
	
// 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>";	
$ap=0;
$totap=array();
while(!empty($row)) {
      $per1=array();
	  $dt=$row['dateout'];
	  echo "<td>". $dt . "</td>"; 	 
	  while ($dt==$row['dateout'])
	  {
	     $per1[$row['period']]="<b>"."?"."</b>";
	     $ap++;
		 $totap[$row['period']]++;
	     $row = mysqli_fetch_array($sql);
	  }
    

     $i=1;    
     while($i<=7){
		 echo "<td>". $per1[$i] . "</td>";$i++;}
     echo "</tr>"; 
}
echo "<td>"." ΣΥΝΟΛΟ ". "</td>";
$i=1;    
     while($i<=7){
		 echo "<td>". $totap[$i] . "</td>";$i++;}
     echo "</tr>"; 
echo "</table>";	
echo "<br>"."<br>";
echo "ΣΥΝΟΛΟ ΜΗ ΧΑΡΑΚΤΗΡΙΣΜΕΝΩΝ ΑΠΟΥΣΙΩΝ : ".$ap;
echo "<br>"."<br>";
//**************************** synola kata mathima
$sql = mysqli_query($con,"SELECT dateout, period, tetramino FROM apousies WHERE mitroo='$mitr' AND apousia=1  ORDER BY dateout,period " );
$dayper=$tetr=$math=$mathc=array();
$i=1;
while($row = mysqli_fetch_array($sql)) 
{    
	  $day = date('D', strtotime($row['dateout']));
	  $dayper[$i]=$day.$row['period']; 
	  $tetr[$i]=$row[tetramino];
	  $sqla = mysqli_query($con,"SELECT id FROM stutimetable WHERE mitroo='$mitr' " );
	  $rowa = mysqli_fetch_array($sqla);
	  $idx=$rowa['id']+1;
	  $sqla = mysqli_query($con,"SELECT ".$dayper[$i]." FROM stutimetable WHERE id='$idx' " );
	  $rowa = mysqli_fetch_array($sqla);
	  $m=$rowa["$dayper[$i]"];
	  $ar=explode("/",$m);
	  $math[$i]=$ar[1];
	  $i++;
}
$math=array_filter($math);
$mathtm=array_unique($math);

foreach($mathtm as $les)
{
	$mathc[$les]=0;
}

foreach ($math as $mt)
{
	$mathc[$mt]++;
}

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>A/A</th>
<th>ΜΗΤΡΩΟ</th>";
foreach($mathtm as $les)
{
	echo "<th>".$les."</th>";
}
echo "</tr>";
echo "<tr>";
echo "<td>"." "."</td>";
echo "<td>".$mitr."</td>";
foreach ($mathc as $c)
{
	echo "<td>".$c."</td>";
}
echo "</tr>";
echo "</table>";

 ?>
<br /><br />
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</body>
</html>