<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
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:2px;font-size:9pt; }
<p style="font-size:9px;"></p>
</style>

</head>
<body>
<h2> ΑΝΑΦΟΡA ΗΜΕΡIΣΙΩΝ ΑΠΟΥΣΙΩΝ</h2>

<?php 

require("dbconnect.php");
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];

echo "<br>"."ΗΜΕΡΟΜΗΝΙΑ: ".$dt."<br>";
$day = date('D', strtotime($dt));
$_SESSION['day']=$day;

if ($day=="Sat" or $day=="Sun"){
    echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΜΑΤΑ ΣΗΜΕΡΑ"."<br>";
	}
else 
{
 	
 $sql = mysqli_query($con,"select al.eponimo,al.onoma,al.tmima,a.*,s.* 
 from stiriksi as s,apousies as a,allstudentinfo as al where s.mitroo=a.mitroo
 and s.mitroo=al.mitroo and a.apousia=1 and s.period=a.period and a.dateout > '2016-10-01' order by s.mitroo");	

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  > 
<th>ΜΗΤΡΩΟ</th>
<th>ΌΝΟΝΑΤΕΠΩΝΥΜΟ ΜΑΘΗΤΗ / ΤΡΙΑΣ</th>
<th>ΤΜΗΜΑ</th>
<th>ΑΠΟ ΜΑΘΗΜΑ</th>
<th>ΣΤΗΡΙΞΗ</th>
<th>ΑΝΤΙΚΕΙΜΕΝΟ</th>
<th>ΔΙΔΑΣΚΩΝ/ΟΥΣΑ</th>
<th>ΗΜΕΡΟΜΗΝΙΑ</th>
<th>ΠΕΡΙΟΔΟΣ</th>

</tr>";
 $i=1;
 while ($row = mysqli_fetch_array($sql)) {
	  $date=$row['dateout'];
	  $d=date('D', strtotime($date));
	  $day=$row['day'];
	  if($d==$day)
	  {
	  $name=$row['eponimo']." ".$row['onoma'];
	  $mitroo=$row['mitroo'];
      
	  $tmima=$row['tmima'];
	  $lesson=$row['lessonout'];
	  
	  $per=$row['period'];
	  $pmpt=$row['teacher'];//pou ebale apousia
	  $sqx=mysqli_query($con,"select Name from teachers where PMP='$pmpt'");
	  $rowx=mysqli_fetch_array($sqx);
	  $tname=rtrim(ltrim($rowx['Name']));
	  
	  $day=$row['day'].$per;
	  $sqx=mysqli_query($con,"select ".$day.",id from timetable where rtrim(ltrim(Teacher))='$tname'");
	  $rowx=mysqli_fetch_array($sqx);
	  $tmimas=$rowx["$day"];
	  $id=$rowx['id']+1;
	  $sqx=mysqli_query($con,"select ".$day." from timetable where id='$id'");
	  $rowx=mysqli_fetch_array($sqx);
	  $mathima=$rowx["$day"];
	  
      echo "<tr>";
	  echo "<td>". $mitroo."</td>";
	  echo "<td>". $name."</td>";
	  echo "<td>". $tmima."</td>";
	  echo "<td>". $lesson."</td>";
	  echo "<td>". $tmimas."</td>";
	  echo "<td>". $mathima."</td>";
	  echo "<td>". $tname."</td>";
	  echo "<td>". $date."</td>";
	  echo "<td>". $per."</td>";
	  echo "</tr>";
	  }
}
echo "</table>";	 
}
?>

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