<?php
include "scrinit.php";
include $menu;
?>

<head>
<title>ΕΚΤΑΚΤΗ ΑΝΑΠΛΗΡΩΣΗ</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<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>

<body>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$usr = $_SESSION['usr'];
$gym=$_SESSION['gym'];
$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
$day = date('D', strtotime($dt));
$daytext = $daymap[date('w', strtotime($dt))];
echo "ΗΜΕΡΟΜΗΝΙΑ:".$datedisp;


if ($day=="Sat" or $day=="Sun")
{
    echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΜΑΤΑ ΣΗΜΕΡΑ"."<br>";
}
else 
{ 
$res1 = $dbcon->prepare("SELECT * FROM anaplirosi where date=? and teacher=? ");
$res1->execute([$dt,$usr]);
?>
<form method="POST"  >
<?php
if ($res1->rowcount() > 0)
{
	echo '<p style="color: blue; ">
      ΕΧΕΤΕ ΗΔΗ ΚΑΤΑΧΩΡΗΜΕΝΕΣ ΑΝΑΠΛΗΡΩΣΕΙΣ  </p>';
	  
	echo "<table class='myTable' >
	<tr style='border:1px solid black' bgcolor='#d6ff73'  >
	<th>Ημέρa</th>
	<th>Ημερομηνία</th>
	<th>Περίοδος</th>
	<th>Αναπλήρωση για</th>
	<th>Τμήμα</th>
	<th>ΔΙΑΓΡΑΦΗ</th></tr>";

   while($row=$res1->fetch(PDO::FETCH_ASSOC))
   {
	   $apon=$row['pmpapon'];
	   $per=$row['period'];
	   $ida=$row['id'];
	   $tm=$row['mathima'];
	   $res2 = $dbcon->prepare("SELECT Teacher FROM dailytab where pmp=?");
	   $res2->execute([$apon]);
	   $row2=$res2->fetch(PDO::FETCH_ASSOC);
	   $teachapon=$row2['Teacher'];
	   echo "<tr>";
	   echo "<td>".$daytext."</td>";
	   echo "<td>".$dt."</td>";
	   echo "<td>".$per."</td>";
	   echo "<td>".$teachapon."</td>";
	   echo "<td>".$tm."</td>";
	   $x=$apon."/".$per;
	   echo "<td>". "<input type='checkbox' name='delt' value='$x' >" ."</td>";	
	   echo "</tr>";
   }
   echo "</table>";
}

$sql = "SELECT pmp,Teacher FROM dailytab where id & 1 order by Teacher ASC";
$result = $dbcon->prepare($sql);
$result->execute();
echo '<p style="color: blue; ">
      ΑΛΛΑΓΗ / ΠΡΟΣΘΗΚΗ ΑΝΑΠΛΗΡΩΣΗΣ  </p>';
?>

<b>ΠΕΡΙΟΔΟΣ ΑΝΑΠΛΗΡΩΣΗΣ: </b>
<select name="ora">
<?php
for ($i=1;$i<=$gym;$i++)
{
	echo "<option ".$sel." value=".$i.">".$i."</option>";
}
?>
</select>

&nbsp;&nbsp;&nbsp<b> ΚΑΘΗΓΗΤΗΣ/ΤΡΙΑ ΠΟΥ ΘΑ ΑΝΑΠΛΗΡΩΣΕΤΕ: </b>
<select name='kathigitis' >
<?php
$kathig="";
$kath="xx/0";
echo "<option value ='".$kath."'>".$kathig."</option>";
while ($row = $result->fetch(PDO::FETCH_ASSOC)) 
{
	$kathig=$row['Teacher'];
	$pmpapon=$row['pmp'];
	$kath=$kathig."/".$pmpapon;
	echo "<option value ='".$kath."'>".$kathig."</option>";
}
?>
</select>
<br><br><br><br>
<input type="Submit" name="anaplb" value="Επιβεβαίωση Επιλογών" >
</form>
<br><br>
<?php
if (isset($_POST['delt']))
{
	$t=$_POST['delt'];
	$ar=explode("/",$t);
	$per=$ar[1];
	$apon=$ar[0];
	$resd = $dbcon->prepare("DELETE FROM anaplirosi where date=? and pmpapon=? and period=?");
	$resd->execute([$dt,$apon,$per]);	  
}
if (isset($_POST['kathigitis']))
{
   $ora=$_POST['ora'];
   $p=$_POST['kathigitis'];
   $arr = explode("/", $p);
   $teachapon = $arr[0];
   $pmpapon=$arr[1];
   $pmpaponx=$arr[1];
   $anapl=1;  
	if (!empty($pmpapon))
	{
		ob_end_clean();
		include $menu;
		include "newmath.php";
	}
	else
	{
		header("Refresh:0");
	}
}
}
?>
<br />
</body>
</html>