<?php
include "scrinit.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:1px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</script>
<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=900, height=300, top='+top+', left='+left);
}
</script>

</head>
<body>

<?php 

require("dbconnect.php");
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
echo "Date:".$dt;

$day="day";
$d1="day"."1";$d2=$day."2";$d3=$day."3";$d4=$day."4";$d5=$day."5";$d6=$day."6";$d7=$day."7";$d8=$day."8";$d9=$day."9";
$result = mysqli_query($con,"SELECT id,Teacher,".$d1.",".$d2.",".$d3.",".$d4.",".$d5.",".$d6.",".$d7.",".$d8.",".$d9." FROM dailytab ");

$tprog=array();$teach=array();$room=array();
$j=0;
while ($row = mysqli_fetch_array($result))
{
   $id=$row['id'];
   $teach[$id]=$row['Teacher'];
   for ($i=1;$i<=$gym;$i++) 
   {
      $in=$day.$i;
      $tprog[$id][$i]=$row["$in"];
	  if($row["$in"] <>"" AND !($id & 1)){
	  	  $ar=explode("/",$row["$in"]);
		  $j++;
		  $room[$j]=$ar[0];
		  }
   }
}
$room=array_unique($room);sort($room);
$n=count($room);
$t=$id;
////////
for ($i=1;$i<=$t;$i++) 
{
  for ($j=1;$j<=$gym;$j++) 
  {
        if( !($i & 1))
		{
		  if($tprog[$i][$j] <>"" )
		  {
	  	  $ar=explode("/",$tprog[$i][$j]);
		  $r=$ar[0];//room
		  $roomin[$r][$j]=$teach[$i-1];
		  }
		  
		}
  }		  
}
ksort($roomin);
	   
echo "<table style='width:900px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#FFAF80'  >
<th>ΑΙΘΟΥΣΑ</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";

foreach($room as $rin) 
   {
      echo "<tr>";
	  echo "<td>". $rin . "</td>";
	  for ($k=1;$k<=$gym;$k++) 
         {
           echo "<td>". $roomin[$rin][$k] . "</td>";
         }
      echo "</tr>";
   }  
echo "</table>";	

?>


</body>
</html>