<?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));
 
$sql= mysqli_query($con,"SELECT * FROM timetable  " );
$c=mysqli_num_rows($sql); 

$i=1;
while($row = mysqli_fetch_array($sql))
{
	$teacher=$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) {
		$teach1[$i]=$teacher;
		$i++;
	}
	$row = mysqli_fetch_array($sql);
}
$limit=$i-1;
//................... new part
$day = date('D', strtotime($dt));
$_SESSION['day']=$day;
for ($x=1;$x<=$limit;$x++)
{
	$teach=$teach1[$x];
	//echo $teach;
	require "newmathsub.php";
	//print_r($lesson);echo "<br>";
	for ($y=1;$y<=7;$y++)
	{
		$lesson1[$x][$y]=$lesson[$y];
	}
	//print_r($lesson1);
}

//..................
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>A/A</th>
<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 ($j=1; $j<=$limit; $j++)
    { 
	 echo "<tr>";
	 echo "<td>".$j."</td>";
	 echo "<td>".$teach1[$j]."</td>";
	 $ts=mysqli_query($con,"SELECT PMP FROM teachers WHERE Name='$teach1[$j]'");
	 $tr=mysqli_fetch_array($ts);
	 $tpmp=$tr['PMP'];
	  for ($k=1; $k<=7; $k++) 
	  { 
			$ls=$lesson1[$j][$k];
			if ($ls==" "){
				echo "<td>".$ls."</td>";}
			else
			{
				$result=mysqli_query($con,"SELECT t.Name  
FROM apousies as a, teachers as t WHERE t.PMP=a.teacher AND a.dateout='$dt' AND a.mathima='$ls' AND a.period='$k'  " );
$crow1=mysqli_num_rows($result);
			if($crow1 > 0) {
				$pas=$ls."/".$k."/".$tpmp; 
				   echo "<td bgcolor='#330099'> ";	   	 
	               echo "<a href=\"newmath2.php?pas=".$pas."\" style='color: #CCFFFF'>".$ls. "</a>". "</td>";
				   }
			else
				{$pas=$ls."/".$k."/".$tpmp; 
				echo "<td > ";
				echo "<a href=\"newmath2.php?pas=".$pas."\" style='color: #CC0000'>".$ls. "</a>". "</td>";
				}
	         }
	  }
	 echo "</tr>";
	}
echo "</table>";
?>
</body>
</html>