<?php
session_start();
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:4px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>

<body>
<h2> ΠΡΟΓΡΑΜΜΑ  ΕΚΠΑΙΔΕΥΤΙΚΟΥ </h2>
<?php
  require "dbconnect.php"; 
  $gym=$_SESSION['gym'];
  $gym=7;
  $dt=$_SESSION['dt'];
  $day=date('D');
   $i=1;
   while ($i<=$gym) {
   $field[$i]=$day.$i;
   $i++;
   }

   echo "ΗΜΕΡΟΜΗΝΙΑ:".$dt ;
   echo "<br>"."<br>";  
   $result = mysqli_query($con,"SELECT Teacher,($field[1]),($field[2]),($field[3]),($field[4]),($field[5]),($field[6]),($field[7]) FROM timetable " ); 
echo "<br>"."<br>";  
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#FFFF80' >
<th>Περίοδος 1</th>
<th>Περίοδος 2</th>
<th>Περίοδος 3</th>
<th>Περίοδος 4</th>
<th>Περίοδος 5</th>
<th>Περίοδος 6</th>
<th>Περίοδος 7</th>
</tr>";  

  while ($row = mysqli_fetch_array($result)){
   $id=$row["id"];
   $teach=$row['Teacher'];
   
   $sqlteach=mysqli_query($con,"SELECT Name FROM teachers WHERE Name='$teach'");
   $c=mysqli_num_rows($sqlteach);
    
	$fl=0;
   for ($i=1;$i<=$gym;$i++){
     $in=$field[$i];
     $l=$row["$in"];
     $lesson[$i]= rtrim(ltrim($l));
	 if ($lesson[$i] == "---" ){$fl++;}
   }
   
   if ($teach <> NULL AND $c >0 AND $fl < 7){
    echo "<tr>"; 
     for ($i=1;$i<=$gym;$i++){
     $in=$field[$i];
     $l=$row["$in"];
     $lesson[$i]= rtrim(ltrim($l));
	 if ($lesson[$i] <> NULL ){
	   $array[1] = $i;
       $array[2] = $teach;
       $str = serialize($array);
       $strenc = urlencode($str);
	   echo "<td>" . "<a href=\"newmath2.php?data=".$strenc."\">".$lesson[$i]."/".$teach. "</a>". "</td>";}
	 else {	echo "<td>". "</td>";}
	 }
 echo "</tr>";
   }
  }
echo "</table>";
?>
</body>
</html>