<?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: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>
<h4> ΕΒΔΟΜΑΔΙΑΙΟ ΠΡΟΓΡΑΜΜΑ ΑΙΘΟΥΣΑΣ </h4>
<?php 

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

$sql = mysqli_query($con,"SELECT roomnum FROM room ");

?>
<form  method='post'> 
<label>Επέλεξε Αίθουσα:</label>
<select name='roomid' >
<?php
echo "<option value='---'>select</option>";
while($row = mysqli_fetch_array($sql) ) 
{
   
   echo "<option value='$row[roomnum]'>$row[roomnum]  $row[perigrafi]</option>";
}
?>
</select>
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>
<?php
if (isset($_POST['submit1']) )
{
	$roomar=array();
	$rm=$_POST['roomid'];
	$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
	$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
	for ($x=1;$x<=5;$x++)
	{
	   $per=1;
       while ($per<=$gym)
	   {
         $day1=$dayf[$x].$per;
         $day=$dayf[$x];
		 
         $resultx = mysqli_query($con,"SELECT id,Teacher,($day1)  FROM timetable ");
	     
		 while ($rowx = mysqli_fetch_array($resultx))
		 {
	       $teach=rtrim(ltrim($rowx['Teacher']));
	       $less=rtrim(ltrim($rowx["$day1"]));
	       $id=$rowx['id'];
		   $nid=$id+1;
	       $res1 = mysqli_query($con,"SELECT ($day1) FROM timetable WHERE id='$nid'  " ); 
           $row3 = mysqli_fetch_array($res1); 
	       $ar=explode("/",$row3["$day1"]);
		   $room=$ar[0];
		   if ($room==$rm)
		   {
			  $roomar[$x][$per] = $teach."/".$less; 
		   }
		 }
	       $per++;
        }
    } //for loops

echo "<br>";
echo "<table style='width:900px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#FFAF80'  >
<th>Περ.</th>";
for ($i=1;$i<=5;$i++)
{
	$titep=$daymap[$i];
	echo "<th>".$titep."</th>";
}
echo "</tr>";

for ($i=1;$i<=$gym;$i++) 
{
	  echo "<td>". $i. "</td>";
	  for ($k=1;$k<=5;$k++) 
         {
           echo "<td>". $roomar[$k][$i] . "</td>";
         }
      echo "</tr>";
}  
echo "</table>";	
}
?>


</body>
</html>