<?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:11px; }
<p style="font-size:09px;"></p>
</style>
<body>

<h3>ΑΠΑΛΛΑΓΕΣ ΜΑΘΗΜΑΤΩΝ </h3>
<?php
date_default_timezone_set("Europe/Athens");
require "dbconnect.php";
$usr=$_SESSION['usr'];
$date=date('Y-m-d');
echo "<br>"."<br>";
$dayn=array('Mon'=>'Δευτέρα','Tue' => 'Τρίτη' ,'Wed'=>'Τετάρτη','Thu'=>'Πέμπτη','Fri'=>'Παρασκευή');

//*********************** add apallages ston katalogo
$apal=mysqli_query($con,"select ap.*,a.eponimo,a.onoma,a.tmima from apallages as ap,allstudentinfo as a 
                   where a.mitroo=ap.mitroo order by a.tmima,ap.mitroo ASC");
$c=mysqli_num_rows($apal);
if ($c==0){echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΚΑΤΑΧΩΡΗΜΕΝΕΣ ΑΠΑΛΛΑΓΕΣ";}
else
{
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>A/Α</th>
<th>Μητρώο</th>
<th>Τμήμα</th>
<th>Μαθητής/τρια</th>
<th>Ημέρα</th>
<th>Περ.</th>
<th>Απαλλαγή από</th>
<th>Μπαίνει σε</th>
</tr>";	
$i=1;
while($rapal=mysqli_fetch_array($apal))
{
    echo "<tr>";
    echo "<td>" .  "<a href=\"?data=".$i."\">"."<b>".$i."</b>". "</a>". "</td>";
    echo "<td>" .$rapal['mitroo']. "</td>";
	echo "<td>" . $rapal['tmima']. "</td>";
	$epo=$rapal['eponimo']." ".$rapal['onoma'];
	echo "<td>" .$epo. "</td>";
	$dayout=$rapal['dayout'];
	$key = array_search($dayout, $dayn);
	echo $key;
	echo "<td>" . $dayn[$dayout]. "</td>";
	echo "<td>" . $rapal['perout']. "</td>";
	$perout=$rapal['perout'];
	$teachout=$rapal['teachout'];
	$teachin=$rapal['teachin'];
	$d=$dayout.$perout;
	$sqa=mysqli_query($con,"select ".$d.",t.id from timetable as t, teachers as te 
	      where t.Teacher=te.Name and te.PMP='$teachout'");
	 $rowa=mysqli_fetch_array($sqa);
     $id1=$rowa['id']+1;
     $sqa=mysqli_query($con,"select ".$d." from timetable where id='$id1'");
	 $rowa=mysqli_fetch_array($sqa);
     $mathx=$rowa["$d"]; 
     $ar=explode("/",$mathx);
	 echo "<td>" . $ar[1]. "</td>";
	 $sqa=mysqli_query($con,"select ".$d.",t.id 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;
     $sqa=mysqli_query($con,"select ".$d." from timetable where id='$id1'");
	 $rowa=mysqli_fetch_array($sqa);
     $mathx=$rowa["$d"]; 
     echo "<td>" . $mathx. "</td>";
	 echo "</tr>"; 
	 
	 $i++;	
	//.............................................
}
echo "</table>";
echo "<br>"."<br>";
}
 ?>
 <br /> <br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>