<?php
include "scrinit.php";
include "logo.php";

?>

<head>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:12px; }
<p style="font-size:12px;"></p>
</style>
</head>

<body>

<?php
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
require "dbconnect.php";

$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
$daytext = $daymap[date('w', strtotime($dt))];
$day = date('D', strtotime($dt));
$dayper=$day.$gym;
?>
<h3>ΑΝΑΠΛΗΡΩΣΕΙΣ / ΑΛΛΑΓΕΣ - <?php echo $daytext." ( ".$datedisp." )"; ?> </h3>
<?php
//**************************** display efimerevontes
$sqlv=mysqli_query($con, "SELECT e.pmp,t.Name  FROM efimeries as e,teachers as t  WHERE e.pmp=t.PMP and dayper='$dayper' ");
$rowv=mysqli_fetch_array($sqlv);
$vdname=$rowv['Name'];
echo "<table  class='myTable' >
<tr style='border:1px solid black' bgcolor='#66CC99' >
<th>ΕΦΗΜΕΡΕΥΩΝ ΒΟΗΘΟΣ</th> </tr>";
echo "<tr>";
echo "<td>"."<b>"."<p style='font-size:16px;'>".$vdname."</p>";"</b>"."</td>";
echo "</tr>"."</table>";
//*********************************

if (isset($_POST['Submitanapl'])) 
{
$lesson1=$kath1=$anaplir1=array();
$anaplir1 = $_POST['anaplir'];//anaplirotes ! den apousiazoun
$lesson1 = $_POST['lesson1'];// mathima
$kath = $_POST['kath'];// kathigitis pou apousiazei
$kath1=$_POST['kathn'];
$ka=$_POST['ka1'];//arithmos aponton
$ebdomi=$_POST['ebdomi']; //mathima/tmima ebdomis
$apone=$_POST['apone']; 
$evdfrom=$_POST['evdfrom'];//poia periodos metafertike stin 7h
$anaplire=$_POST['anaplire']; //poios anaplironei
$rme=$_POST['rme']; //se poia ethousa
///////////////////////////////////////////////********************************
echo "<br>";
echo "<br>"."<b>"."ΚΑΘΗΓΗΤΕΣ/ΤΡΙΕΣ ΠΟΥ ΑΠΟΥΣΙΑΖΟΥΝ - ΑΝΑΠΛΗΡΩΤΕΣ/ΤΡΙΕΣ"."</b>"."<br>";
//echo "<br>";
echo "<table style='width:800px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#66CC99' >
<th>Α/Α</th>
<th>Εκπαιδευτικός</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περίοδος ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";

 
for ($ka=1;$ka<$tk;$ka++)
{
 echo "<tr>";
 echo "<td>".$r. "</td>";
 $kathapon=$kath1[$ka];
 
 $sql=mysqli_query($con, "SELECT PMP  FROM teachers WHERE Name='$kathapon' ");
 $row=mysqli_fetch_array($sql);
 $pmpapon=$row['PMP'];
 $sql=mysqli_query($con, "SELECT id FROM timetable WHERE Teacher='$kathapon' ");
 $row=mysqli_fetch_array($sql);
 $aponid=$row['id'];
 echo "<td>"."<font face='arial' size='2pt'>".$kathapon." (".$aponid.")"."</td>";
 for ($i=1;$i<=$gym;$i++)
 {
	    echo "<td>" ."<font face='arial' size='2pt'>". $lesson1[$ka][$i]. "</td>";	 
 }     
		 
 echo "</tr>"; echo "<tr>"; echo "<td>". "   " . "</td>"; echo "<td>". "   " . "</td>";
 for ($i=1;$i<=$gym;$i++)
     {
		 $tid=$anaplir1[$ka][$i];
		 $sql=mysqli_query($con, "SELECT Teacher FROM timetable  WHERE id='$tid' ");
	     $row=mysqli_fetch_array($sql);
		 $teachname=$row['Teacher'];
		 if ($tid > 0 and $tid < 999 )
		 {
		   echo "<td>"."<b>"."<font face='arial' size='2pt'>".$teachname."</b>"."</td>"; 
		 }
		 elseif ($tid==999)
		 {
		    echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΣΤΟ ΤΜΗΜΑ ΤΟΥΣ"."</b>"."</td>";
		 }
		 elseif ($tid=="!")
		 {
			echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΠΑΡΩΝ/ΟΥΣΑ"."</b>"."</td>"; 
		 }
		 elseif ($tid=="ΔΔΚ")
		 {
			echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΕΚΔΗΛΩΣΗ"."</b>"."</td>"; 
		 }
		 else
		 {
		   echo "<td>"."<b>"."<font face='arial' size='2pt'>"." "."</b>"."</td>"; 	 
		 }
		 
	 } 
 
 echo "</tr>"; 
 
  $ka++;
  $r++;  
  }
echo "</table>";
//.................................. insert anaplirosi gia 7h
$fe=count($ebdomi);
for ($i=1;$i<=$fe;$i++)
{
 $aponid=$apone[$i];
 
 $sql=mysqli_query($con, "SELECT t.Teacher,s.PMP FROM timetable as t,teachers as s WHERE t.Teacher=s.Name AND t.id='$aponid' ");
 $row=mysqli_fetch_array($sql);
 $pmpapon=$row['PMP'];
 $teachname=$row['Teacher'];
 $per=$gym;
 $perevd=$evdfrom[$i];
 //
 $tid=$anaplire[$i];
 $sql=mysqli_query($con, "SELECT t.Teacher,s.PMP FROM timetable as t,teachers as s WHERE t.Teacher=s.Name AND t.id='$tid' ");
 $row=mysqli_fetch_array($sql);
 $pmp=$row['PMP'];
 $teachname=$row['Teacher'];
 $ebd=$ebdomi[$i]." (".$rme[$i].")";
 if ($pmp > 0)
 {
 mysqli_query($con,"INSERT INTO anaplirosi (id,teacher,tid,date,period,aponevd,pmpapon,aponid,mathima) VALUES (NULL,'$pmp','$tid','$dt','$per','$perevd','$pmpapon','$aponid','$ebd')");	
 }
}
}
include "readdailytab.php";
include "ensoanaplir.php";
include "katahorisi.php";
//************* emfanise anapliroseis kai allages
include "anaplirosiday.php";
?>	
<br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>
</body>
</html>