<?php
include "scrinit.php";
include "logo.php";
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$daytext = $daymap[date('w', strtotime($dt))];
?>
<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> ΑΝΑΔΟΜΗΜΕΝΟ ΗΜΕΡΙΣΙΟ ΠΡΟΓΡΑΜΜΑ <?php echo "( ".$daytext."  ".date('d-m-Y', strtotime($dt))." )";?></h4>
<?php
$gym=$_SESSION['gym'];
//****************************** 
include "allagiprog.php";
//.........................
for ($i=1;$i<=$gym;$i++)
{
	$dd[$i]="day".$i;
}
if ($day=="Sat" or $day=="Sun")
{
    echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΜΑΤΑ ΣΗΜΕΡΑ"."<br>";
}
else 
{ 
$fields = implode(",", $dd);

$result = $dbcon->prepare("SELECT pmp,id,Teacher,".$fields." FROM dailytab ");
$result->execute();
$tprog=$teach=$tpmp=$room=array();
$j=0;
$d=$gym+1;
while ($row=$result->fetch(PDO::FETCH_ASSOC))
{
   $id=$row['id'];
   $teach[$id]=$row['Teacher'];
   $tpmp[$id]=$row['pmp'];
   for ($i=1;$i<=$d;$i++) 
   {
      $in="day".$i;
      $tprog[$id][$i]=$row["$in"];
   }
}


//........................
$limit=count($teach);
$i=1;
for ($x=1;$x<=$limit;$x += 2)
{
	$teacher=$teach[$x];
	$teachpmp=$tpmp[$x];
    $flg=0;
	for ($j=1;$j<=$gym;$j++) 
	{	
	    if (!empty($tprog[$x][$j])) 
		{
		   $flg=1;
	       $lesson[$i][$j]=$tprog[$x][$j];
		   $ar=explode("/",$tprog[$x+1][$j]);
		   $subj[$i][$j]=$ar[1];
		}
		 else
		{ 
	       $lesson[$i][$j]="";
		   $subj[$i][$j]="";
		}
	}
	if ($flg == 1) 
	{
		$teach1[$i]=$teacher;
		$tpmp1[$i]=$teachpmp;
		$i++;
	}
}

$limit=$i-1;
//..................
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#04B486'  >
<th>A/A</th>
<th>Teacher</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="ΠΕΡΙΟΔΟΣ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";


for ($j=1; $j<=$limit; $j++)
    { 
	 echo "<tr>";
	 echo "<td>".$j."</td>";
	 echo "<td>".$teach1[$j]."</td>";
	 $tpmp=$tpmp1[$j];
	 for ($k=1; $k<=$gym; $k++) 
	  { 
			$ls=$lesson[$j][$k];
			$sb=$subj[$j][$k];
			if ($ls==""){
				echo "<td>".$ls."</td>";}
			else
			{
				$result=$dbcon->prepare("SELECT teacher FROM apousies WHERE dateout=? AND mathima=? AND period=?  " );
                $result->execute([$dt,$ls,$k]);
                $crow1=$result->rowCount();
				if($crow1 > 0) 
				{
				   $pas=$ls."/".$sb."/".$k."/".$tpmp; 
				   echo "<td bgcolor='#330099'> ";			   	 
	               echo "<a href=\"newmath2.php?pas=".$pas."\" style='color: #CCFFFF'>".$ls. "</a>". "</td>";
				}
			    else
				{
					$pas=$ls."/".$sb."/".$k."/".$tpmp;
					echo "<td > ";
					echo "<a href=\"newmath2.php?pas=".$pas."\" style='color: #CC0000'>".$ls. "</a>". "</td>";			    
				}
	         }
	  }
	 echo "</tr>";
	
	}
echo "</table>";
}
?>
<br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </button></a>
</body>
</html>