<?php
session_start();

?>

<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:1px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>

<body>
<h4> ΑΝΑΠΛΗΡΩΣΕΙΣ </h4>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
echo "ΗΜΕΡΟΜΗΝΙΑ:".$dt;

$day = date('D', strtotime($dt));
echo $day."<br>";
 
echo " ΕΚΠΑΙΔΕΥΤΙΚΟΣ ΠΟΥ ΑΠΟΥΣΙΑΖΕΙ:";
$sql = "SELECT name FROM teachers ORDER BY Name ";
$result = mysqli_query($con,$sql);
?>
<form method="POST"  >
<select name='kathigitis'>
<?php
while ($row = mysqli_fetch_array($result)) 
{
	$kathigitis=$row['name'];
   	echo "<option value ='".$kathigitis."'>".$kathigitis."</option>";
}
echo "</select>";

?>
<br />	<br />
<input type="Submit" name="anaplb" value="Επιβεβαίωση Επιλογών" >
</form>
<?php

if (isset($_POST['kathigitis']))
{ 
 $apon=$_POST['kathigitis'];

	
$sql= mysqli_query($con,"SELECT * FROM timetable where Teacher='$apon' " );
$row = mysqli_fetch_array($sql);

echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>Teacher </th>
<th>ΠΕΡΙΟΔΟΣ 1</th>
<th>ΠΕΡΙΟΔΟΣ 2</th>
<th>ΠΕΡΙΟΔΟΣ 3</th>
<th>ΠΕΡΙΟΔΟΣ 4</th>
<th>ΠΕΡΙΟΔΟΣ 5</th>
<th>ΠΕΡΙΟΔΟΣ 6</th>
<th>ΠΕΡΙΟΔΟΣ 7</th>
</tr>";
$i=1;
 echo "<tr>";
     $apont[$i]=$row['Teacher'];
	 echo "<td>".$apont[$i]."</td>";

for ($j=1; $j<=7; $j++)
    { 
	$d=$day.$j;
	$aponmath[$i][$j]=$row["$d"];
	
	$array[1] = $apont[$i];
    $array[2] = $j;
	$str = serialize($array);
    $strenc = urlencode($str);
	echo "<td>" . "<a href=\"anaplikath2.php?data=".$strenc."\">".$aponmath[$i][$j]. "</a>". "</td>";
	} 
	echo "</tr>";
	
echo "</table>";

//.........................................................  
echo "<br>";
if($aponmath[$i][7] <> " ") {
	echo "Το τμήμα ".$aponmath[$i][7]. " σχολάνει 7η περίοδο"; }
echo "<br>";


$sql= mysqli_query($con,"SELECT * FROM timetable  " );
$c=mysqli_num_rows($sql); 

$i=1;
while($row = mysqli_fetch_array($sql))
{
	$teachr=$row['Teacher'];
	
	$flg=0;
	for ($j=1;$j<=7;$j++) {
	    $d=$day.$j;	
	    if ($row["$d"] <> NULL ) {
		   $flg=1;
	       $lesson[$i][$j]=$row["$d"];}
		 else
		{ $lesson[$i][$j]=" ";}
	}
	if ($flg == 1) {
		$teach[$i]=$teachr;
		$i++;
	}
	$row = mysqli_fetch_array($sql);
}
$limit=$i;


echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>Teacher</th>
<th>ΠΕΡΙΟΔΟΣ 1</th>
<th>ΠΕΡΙΟΔΟΣ 2</th>
<th>ΠΕΡΙΟΔΟΣ 3</th>
<th>ΠΕΡΙΟΔΟΣ 4</th>
<th>ΠΕΡΙΟΔΟΣ 5</th>
<th>ΠΕΡΙΟΔΟΣ 6</th>
<th>ΠΕΡΙΟΔΟΣ 7</th>
</tr>";

for ($l=1; $l<=6; $l++){
	$ap=$aponmath[1][$l];
$sql= mysqli_query($con,"SELECT * FROM allstudentinfo WHERE tmima='$ap' " ); 
$c=mysqli_num_rows($sql);
if ($c > 0) {
$aponm[$l] = $aponmath[1][$l];
}
else
{$aponm[$l] ="";}
}
$cl[1]='red';
$cl[2]='yellow';
$cl[3]='brown';
$cl[4]='blue';
$cl[5]='maroon';
$cl[6]='cyan';

for ($j=1; $j<=$limit; $j++)
    { 
	
	 echo "<tr>";
	 if ($teach[$j] == $apont[1]){
			   echo "<td bgcolor='#330099'> ";
			   echo "<font color='red'> $teach[$j] </font>";
	           echo "</td>"; }
	 else {
	 echo "<td>".$teach[$j]."</td>";}
	  
	  for ($k=1; $k<=7; $k++) 
	  { 
	  
	    	$ls=$lesson[$j][$k];
			
			if (in_array($ls,$aponm ,TRUE))
			{
			   $key=array_search($ls,$aponm);
			   echo $key. "xx ".$j." ..";
			   if ($teach[$j] == $apont[1])
			    {
			      echo "<td bgcolor='#99FFFF'> ";
			      echo "<font color='". $cl[$key]."'  > $ls </font>";
	              echo "</td>"; 
				}
			   else
			   {
			      echo "<td bgcolor='#FFFFFF'> ";
			       echo "<font color='". $cl[$key]."'  > $ls </font>";
	              echo "</td>"; 
			   }}
			else  {echo "<td>".$ls."</td>";}
			
	   }
	 echo "</tr>";
	}
	
echo "</table>";

}

//<br />
//<a  href="index.php" style="color:blue "  >  Επιστροφή στο Μενού  </a>


?>


</body>
</html>