<?php
session_start(); // start up your PHP session! 
include "logo.php";
$menu=$_SESSION['menu'];
?>
<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";

if (isset($_POST['nameid'])){
    $am=$_POST['nameid'];
	
    $tm1=$_POST['tmimaid'];
	
	$date=$_POST['date'];
	$sql = "SELECT mitroo,eponimo,onoma  FROM allstudentinfo WHERE mitroo='$am'";
    $result = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($result);
	$nm=$row['eponimo']." ".$row['onoma'];
	echo  $nm. " , ( ".$tm1." )" ;
	echo "<br>"."<br>";
	
	$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
	for ($i=1;$i<=5;$i++){
       for ($per=1;$per<=7;$per++){
         $day=$dayf[$i].$per;
         
	 $lesson="";
	 $taxi=mb_substr($tm1, 0, 1, 'utf-8');
	 $tm3a=mb_substr($tm1, 0, 1, 'utf-8');
	 $tm3b=mb_substr($tm1, 2, 1, 'utf-8');
	 $tm3=$tm3a.$tm3b;
	 
	 $sql = "SELECT id,Teacher,($day)  FROM timetable WHERE ($day)='$tm1' OR (($day) LIKE '%$tm3%' AND ($day) LIKE 'Α%') ";
	 $result = mysqli_query($con,$sql);
	 $c=mysqli_num_rows($result);
	 
	 if ($c > 0 ) {
		$row = mysqli_fetch_array($result);
		$name=$row['Teacher'];
		//echo "in".$per."cc".$name."cc".$row["day"];
		$id=$row['id'];$nid=$id+1;
	    $res1 = mysqli_query($con,"SELECT * FROM timetable WHERE id='$nid'  " ); 
        $row3 = mysqli_fetch_array($res1); 
	    $room= $row3["$day"];
		if ($c == 2 AND $name==$oldname AND $taxi=='Α') {
		   $row = mysqli_fetch_array($result);
		   $name=$row['Teacher'];
		   $id=$row['id']; $nid=$id+1;
	       $res1 = mysqli_query($con,"SELECT * FROM timetable WHERE id='$nid'  " ); 
           $row3 = mysqli_fetch_array($res1); 
	       $room= $row3["$day"];	
		}
	 }
     else
	 {
	   
	   $sql = "SELECT synd,kathigitis  FROM syndidaskalies WHERE pmp='$am'";
       $result = mysqli_query($con,$sql);
	   while ($row = mysqli_fetch_array($result)) 
       {
	      $name=$row['kathigitis'];
	      $less=$row['synd'];
          $less=rtrim(ltrim($less));
	     // echo $less."zz";
		  $res = mysqli_query($con,"SELECT * FROM timetable WHERE Teacher='$name' AND ($day)='$less' " ); 
          $c=mysqli_num_rows($res);
		  if ($c > 0) {
			//echo $day."xx".$name."xx".$less;
		    $row2 = mysqli_fetch_array($res);
            $id=$row2["id"]; $nid=$id+1;
	        $res1 = mysqli_query($con,"SELECT * FROM timetable WHERE id='$nid'  " ); 
            $row3 = mysqli_fetch_array($res1); 
	        $room= $row3["$day"];
			break 1;
	   	    }
	     }
					 
	}//else
	 
	 $math1[$i][$per]=$name;
	 //$room1[$i][$per]= trim(strrev(strstr(strrev((strstr($room, '/'))), '(')), '/(');
	 $arr = explode("/", $room);
     $room1[$i][$per] = $arr[1];
	 $oldname=$name; 
  }
 } //for loops

$_SESSION['room1']=$room1;

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<=7;$per++){
	echo "<tr>";
	echo "<td>".$per."</td>";
	for ($k=1;$k<=5;$k++){
		$math=$math1[$k][$per];
		$s1=$room1[$k][$per];
		echo "<td>" . $s1."  (".$math.") ". "</td>";
		}
		echo "</tr>";
}
echo "</table>";

}
//<a  href="locate.php" style="color:blue "  >  Επανάληψη Εντοπισμού  </a>
 ?>
<br /><br />

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