<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
include "logo.php";
$menu = $_SESSION['menu'];
$dt=$_SESSION['dt'];
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:13px; }
<p style="font-size:12px;"></p>
</style>
<body>
<h3> ΚΑΤΑΣΤΑΣΗ ΑΝΑΠΛΗΡΩΣΕΩΝ ΜΕΧΡΙ <?php echo $dt;?> </h3>
<?php
require "dbconnect.php"; 
$gym=$_SESSION['gym'];
$result = mysqli_query($con,"select max(ct) as mct from ((SELECT count(a.teacher) as ct FROM anaplirosi as a,timetable as t 
where (a.teacher > 0 and a.period <> '$gym' and t.pmp=a.teacher and t.id <> a.aponid and t.id % 2=1)  group by a.teacher))as nt");
$row = mysqli_fetch_array($result);
$max=$row['mct'];

$result = mysqli_query($con,"SELECT a.*,t.Name,t.totanapl FROM anaplirosi as a,teachers as t 
          where a.teacher=t.PMP and (t.access=5 or t.access=1) and a.period <> '$gym' order by t.Name,a.date");
$row = mysqli_fetch_array($result);
$dates=array();
// emfanise ton pinaka 
echo "<table class='myTable' >
<tr style='border:1px solid black'  >
<th>A/A</th>
<th>ΠΜΠ</th>
<th>ΕΚΠΑΙΔΕΥΤΙΚΟΣ</th>";
for ($i=1;$i<=$max;$i++)
{
	$titep="Αναπλ".$i;
	echo "<th>".$titep."</th>";
}
echo "<th>ΣΥΝΟΛΟ</th>";
echo "<th>ΥΠΟΛΟΙΠΟ</th>";
echo "</tr>";
$i=1;
while (!empty($row))
{
  $pmp=$row['teacher'];
  $kath = $row['Name'];
  $tot = $row['totanapl'];
  echo "<tr>";
  echo "<td>".$i."</td>";
  echo "<td>";
  ?>
	<a href="#" onClick="window.open('editanaplirosi.php?data=<?php echo $pmp; ?>',' ','width=900,height=700')"><?php echo $pmp; ?></a>
  <?php
  echo "</td>";
  echo "<td>".$kath."</td>";
    
  $c=0;
  while ($pmp == $row['teacher'])
  {
    $dates = $row['date'];
	echo "<td>".$dates."</td>";
	$c++;
	$row = mysqli_fetch_array($result);
  }
   $n=$max-$c;
   for($k=1;$k<=$n;$k++){echo "<td>"." "."</td>";}
   $ypo = $tot - $c;
   echo "<td>".$c."</td>"; 
   echo "<td>".$ypo."</td>";
  $i++;
}

echo "</table>";
echo "<br>"."<br>";

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