<?php
include "scrinit.php";
?>
<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:1px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>

<?php 
require("dbconnect.php");
$gym=$_SESSION['gym'];
$gymx=$_SESSION['gymx'];

$day = date('D', strtotime($dt));

mysqli_query($con,'TRUNCATE TABLE dailytab;');
$ta="";
$cols="id,pmp,Teacher,";
for ($i=1;$i<=$gymx;$i++){$ta.="day".$i.',';}
$cols=$cols.$ta;
$cols = " (".rtrim($cols, ',').") ";
$ta="";	
$all="id,pmp,Teacher,";
for ($i=1;$i<=$gymx;$i++){$t=$day.$i;$ta.=$t.',';}
$all=$all.$ta;
$all = rtrim($all, ',');

mysqli_query($con,"INSERT INTO dailytab ".$cols. " SELECT ".$all." FROM timetable");
//
include "readdailytab.php";
////////////////////////////// allages gia ddk - ekdilosi sxoliou
$sql=$dbcon->prepare("select * from offperiods where datefrom=? ") ;
$sql->execute([$dt]);
$c=$sql->rowCount();
if ($c > 0)
{
  $class=$classin=array();
  while($row=$sql->fetch(PDO::FETCH_ASSOC))
  {
  $perapo=$row['perapo'];
  $permexri=$row['permexri'];
  $tmf=$row['tmimafrom'];
  $tmt=$row['tmimamexri'];
  
  $sql1=$dbcon->prepare("select v.Class_id,t.Name from voithos as v,teachers as t where v.yt=t.PMP") ;
  $sql1->execute();
  $nt=$sql1->rowCount();
  $ct=0;
  while($row1=$sql1->fetch(PDO::FETCH_ASSOC))
   {
      $cl=$row1['Class_id'];
	  if($cl >= $tmf and $cl <= $tmt)
	  {
		$classin[$cl]=$row1['Name']; 
        $ct++;		
	  }
   }
   if ($ct==$nt) //ola ta tmimata tou sxoleiou
   {
	 $n=count($teach);  
     for ($i=1;$i<=$n;$i++) 
     {
	   for ($k=$perapo;$k<=$permexri;$k++)//empty all classes
	   {
			$tprog[$i][$k]="";
	   }
     }
     $n=count($teach);
	 for ($i=1;$i<=$n;$i+=2)  
     {
	   if (in_array($teach[$i],$classin))
	   {
		  $tmima=array_search($teach[$i],$classin);
		  for ($k=$perapo;$k<=$permexri;$k++)
			 {
		        $tprog[$i][$k]=$tmima;
			    $v=$i+1;
			    $tprog[$v][$k]="YT/Δ.Δ.Κ";
			 } 
       }
     }
   }
  }
   include "katahorisi.php";
  
   //////////////////////////////////   
}

include "amivread.php";
include "ensomatosi.php";
include "katahorisi.php";
include "ensoanaplir.php";
include "katahorisi.php";

?>
</body>
</html>