<?php
include "scrinit.php";
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:3px;font-size:12px; }

</style>
</head>

<body>

<?php
require "dbconnect.php";
$usr=$_SESSION['pmp'];
$dt=$_SESSION['dt'];

$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ");
   
?>
ΗΜΕΡΟΜΗΝΙΑ:  <?php echo $dt; ?> 
<form method='post'> 

<br><h4> ΕΠΙΛΟΓΗ  ΤΜΗΜΑΤΟΣ</h4><br />

    <label>Τμήμα:</label><select name='tmimaid' id='tmimaid'>
     
    <?php
	echo "<option value='---'>select</option>";
    while($row2 = mysqli_fetch_array($sql2) ) 
	{
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
    }
    ?>
    </select>

<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>
<br><br>
<?php
if (isset($_POST['submit1']))
{
	$tmima=$_POST['tmimaid'];
	$gym=$_SESSION['gym'];
	$daymap = array(' ','Mon', 'Tue', 'Wed', 'Thu', 'Fri');
	for ($i=1;$i<=$gym;$i++)
	{
	   for ($j=1;$j<=5;$j++)
	   {
		  $x=($i-1)*$gym+$j;
		  $dd[$x]=$daymap[$j].$j; 
	   }
	}  

$result = $dbcon->prepare("SELECT * FROM timetable where MOD(id,2)<>0 ");
$result->execute();
$result1 = $dbcon->prepare("SELECT * FROM timetable where MOD(id,2)= 0 ");
$result1->execute();
$tprog=$room=array();

while ($row=$result->fetch(PDO::FETCH_ASSOC))
{
   $id=$row['id'];
  
   $row1=$result1->fetch(PDO::FETCH_ASSOC);
   for ($i=1;$i<=5;$i++)
	{
	   for ($j=1;$j<=$gym;$j++)
	   {
          $dd=$daymap[$i].$j;
		  if ($tmima==$row["$dd"])
		  {
             $tprog[$i][$j]=$row["$dd"];
			 $room[$i][$j]=$row1["$dd"];
			 $teach[$i][$j]=$row['Teacher'];
		  }
		  
       }
	}
}
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#ffcc00'  > 
<th>Περ.</th>
<th>Δευτερα</th>
<th>Τρίτη</th>
<th>Τετάρτη</th>
<th>Πέμπτη</th>
<th>Παρασκευή</th>";
for ($per=1;$per<=$gym;$per++){
	echo "<tr>";
	echo "<td>".$per."</td>";
	for ($k=1;$k<=5;$k++)
	{
		$mathx=$tprog[$k][$per];
		$s1=$room[$k][$per];
		$t=$teach[$k][$per];
		if (!empty($mathx))
		{
		echo "<td>" .$mathx."  [".$s1."] ".$t. "</td>";
		}
		else
		{
			echo "<td>" ." Συνδ.". "</td>";
		}
	}
		echo "</tr>";
}
echo "</table>";
}	
?>
<a  href=<?php echo $menu; ?>  style="color:blue "  >  Επιστροφή στο Μενού  </a>
</body>
</html>