<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
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; }
.divider{
    width:10px;
    height:auto;
    display:inline-block;
}
.clickMe {
    -moz-appearance: button;
    -ms-appearance: button;
    -o-appearance: button;
    -webkit-appearance: button;
    appearance: button;
    text-decoration: none;
    color: #0047b3;
    padding: 0.2em 0.4em;
}​
</style>

<p style="font-size:14px;"></p>
</style>
</head>

<body>
<?php
require "dbconnect.php";
$date=$_SESSION['dt'];
$gym=$_session['gym'];
if (isset($_POST['nameid']))
{
    $per=$_POST['ora']; 
    $am=$_POST['nameid'];
    $tm1=$_POST['tmimaid'];
	include "allagiprog.php";
	echo "ΗΜΕΡΟΜΗΝΙΑ :".$date;
	$day = date('D', strtotime($date));
	if ($day=="Sat" or $day=="Sun")
       {
           echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΜΑΤΑ ΣΗΜΕΡΑ"."<br>";
       }
    else 
    { 
	$lesson="";
	$day = date('D', strtotime($date)).$per;
	$dayx="day".$per;echo $dayx;
	$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'];
	
	$sql = "SELECT id,Teacher,($dayx)  FROM dailytab WHERE ($dayx)='$tm1' ";
	$result = mysqli_query($con,$sql);
	$c=mysqli_num_rows($result);
	if ($c > 0 ) {
		$row = mysqli_fetch_array($result);
		$name=$row['Teacher'];$id=$row['id'];
		$nid=$id+1;
	    $res1 = mysqli_query($con,"SELECT * FROM dailytab WHERE id='$nid'  " ); 
        $row3 = mysqli_fetch_array($res1); 
	    $room= $row3["$dayx"];
		}
	else
	{
	$sql = "SELECT synd,kathigitis  FROM syndidaskalies WHERE pmp='$am'";
    $result = mysqli_query($con,$sql);
	
   while ($row = mysqli_fetch_array($result)) 
   {
	$name=rtrim(ltrim($row['kathigitis']));
	echo $name;
	$lesson=$row['synd'];
   
	$res = mysqli_query($con,"SELECT * FROM dailytab WHERE Teacher='$name' " ); 
    $row2 = mysqli_fetch_array($res);
    $id=$row2['id'];
	$lesson=$row2["$dayx"];
	$lesson=rtrim(ltrim($lesson));
	echo $lesson;
	if ((rtrim(ltrim($row['synd']))==$lesson) OR ($lesson==$tm1))
	  {
        $nid=$id+1;
	    $res1 = mysqli_query($con,"SELECT * FROM dailytab WHERE id='$nid'  " ); 
        $row3 = mysqli_fetch_array($res1); 
	    $room= $row3["$dayx"];
	   
	    break ;
	  }
	}
	}
	 

echo "<table class='myTable' >
<tr style='border:1px solid black' >
<th>Περίοδος</th>
<th>Τμήμα/Συνδιδασκαλια</th>
<th>Α.Μ</th>
<th>Όνοματεπώνυμο</th>
<th>Τμήμα</th>
<th>Αίθουσα</th>
<th> Καθηγητής / Ύλη</th>
</tr>";

		 echo "<tr >";
		 echo "<td>".$per. "</td>";
	     echo "<td>". $lesson.  "</td>";
		 echo "<td>".$am. "</td>";
	     echo "<td>". $nm. "</td>";
	     echo "<td>". $tm1. "</td>";
	     echo "<td>". $room. "</td>";
		 echo "<td>". $name . "</td>";
	     echo "</tr>"; 
echo "</table>";	 
}
}
 ?>
<br /><br />
<a class="clickme" href="locate.php" >Επανάληψη Εντοπισμού</a>
<a class="clickme" href="locate.php" >Επιστροφή στο Μενού</a>

</body>
</html>