<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:14pt; }
<p style="font-size:14px;"></p>
</style>
</head>

<body>
<h3> ΕΒΔΟΜΑΔΙΑΙΟ ΠΡΟΓΡΑΜΜΑ ΜΑΘΗΤΗ/ΤΡΙΑΣ </h3>
<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$mitroo=$_SESSION['usr'];
$dd=date('D', strtotime($dt));
if (isset($_POST['nameid']))
{
  $mitroo=$_POST['nameid'];
}


	$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
	$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma,tmima  FROM allstudentinfo WHERE mitroo='$mitroo'");
    $row = mysqli_fetch_array($result);
	$nm=$row['eponimo']." ".$row['onoma'];
	$tmima=$row['tmima'];
	echo  $nm. " , ( ".$tmima." )" ;
	echo "<br>"."<br>";
	$resultx = mysqli_query($con,"SELECT * FROM stutimetable WHERE mitroo='$mitroo' ");
	$c=mysqli_num_rows($resultx);
	$rowx = mysqli_fetch_array($resultx);
	$id=$rowx['id'];
	$nid=$id+1;
	$res1 = mysqli_query($con,"SELECT * FROM stutimetable WHERE id='$nid'  " ); 
	$rows1 = mysqli_fetch_array($res1); 
	
	for ($x=1;$x<=5;$x++){
		for ($per=1;$per<=$gym;$per++)
		{
			$day1=$dayf[$x].$per;
			$day=$dayf[$x];
			$math[$x][$per]=$rowx["$day1"];
			$srow= $rows1["$day1"];
			$sall=explode("/",$srow);
			$room =$sall[0];
			$less = $sall[1];
			$teach= $sall[2];
			$rest = mysqli_query($con,"SELECT Name FROM teachers WHERE PMP='$teach'  " ); 
			$rowrest = mysqli_fetch_array($rest);
			$teacher= $rowrest['Name'];
			$disp[$x][$per] = $room."/".$less."/".$teacher;
		}
	}
$_SESSION['room1']=$disp;

//*************************************
$apal=mysqli_query($con,"select * from apallages where mitroo='$mitroo' ");
while($rapal=mysqli_fetch_array($apal))
{
	$dayout=$rapal['dayout'];
	$key = array_search($dayout, $dayf);
	$perout=$rapal['perout'];
	$teachin=$rapal['teachin'];
	$d=$dayout.$perout;
	$sqa=mysqli_query($con,"select ".$d.",t.id,te.Name from timetable as t, teachers as te 
	      where t.Teacher=te.Name and te.PMP='$teachin'");
	 $rowa=mysqli_fetch_array($sqa);
     $id1=$rowa['id']+1;
	 $nam=$rowa['Name'];
     $sqa=mysqli_query($con,"select ".$d." from timetable where id='$id1'");
	 $rowa=mysqli_fetch_array($sqa);
     $mathx=$rowa["$d"]; 
	 //$ar=explode("/",$mathx);
	 $disp[$key][$perout]=$mathx;
	 $math[$key] [$perout]=$nam;
}		   
		//*************************
echo "<table class='myTable' >
<tr style='border:2px solid black;font-size:14px'  >
<tr>
<th>Περ.</th>
<th>Δευτερα</th>
<th>Τρίτη</th>
<th>Τετάρτη</th>
<th>Πέμπτη</th>
<th>Παρασκευή</th>
</tr>";
for ($per=1;$per<=$gym;$per++){
	echo "<tr>";
	echo "<td>".$per."</td>";
	for ($k=1;$k<=5;$k++){
		$mathx=$math[$k][$per];
		$s1=$disp[$k][$per];
		
		echo "<td>" . $s1."  (".$mathx.") ". "</td>";
		}
		echo "</tr>";
}
echo "</table>";

 ?>
<br /><br />

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