<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</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>
<body>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
if (isset($_POST['Submitallages'])) {
	$kathigitis=$_POST['kathigr'];
	$fromperiod=$_POST['fromp'];
	$toperiod=$_POST['top'];
	$room=$_POST['room'];
	$miso=$_POST['miso'];
	$chwith=$_POST['chwith'];
	$last=$_POST['last'];
	
	//gia room
	$kid=$_POST['kathig'];
	$period=$_POST['period'];
	$seroom=$_POST['seroom'];
	$aporoom=$_POST['aporoom'];
	//...........................
	
$result = mysqli_query($con,"SELECT id FROM allages WHERE date='$dt' ");
$crow1=mysqli_num_rows($result);

if ($crow1>0)
 {	
     mysqli_query($con,"DELETE FROM allages WHERE date='$dt'");
 }
 
$nk=count($kathigitis);echo $nk;
for ($i=0;$i<$nk;$i++)  
{
 if ($kathigitis[$i]>0)// delete oles tis allages pou den exoun kathigiti
 {
    $chwi=$chwith[$i];
	if (empty($chwith[$i])) $chwi=0;
	$sql="INSERT INTO allages (date, idteacher,fromper,toper,room,miso,chwith,last)	VALUES 
	('$dt','$kathigitis[$i]','$fromperiod[$i]','$toperiod[$i]','$room[$i]','$miso[$i]','$chwi','$last[$i]') ";
    if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con)); } 
 }
}

////////// allagi aithousas
$result = mysqli_query($con,"SELECT id FROM allagiroom WHERE date='$dt' ");
$crow1=mysqli_num_rows($result);

if ($crow1>0)
 {	
  mysqli_query($con,"DELETE FROM allagiroom WHERE date='$dt'");
 }


$n=1;$k=0;
while($period[$n]<> 0)  {
 $sql="INSERT INTO allagiroom (idteacher,period,seroom,aporoom,date) VALUES ('$kid[$k]','$period[$n]','$seroom[$n]','$aporoom[$n]','$dt' ) ";

        if (!mysqli_query($con,$sql))
        {
         die('Error: ' . mysqli_error($con));
         } 
	
	$n++;$k++;
}
$n--;
//////////
//echo "ΚΑΤΑΧΩΡΗΘΗΚΑΝ ΜΕ ΕΠΙΤΥΧΙΑ ".$al1." ΑΛΛΑΓΕΣ  "."<br>";

//**************************************
include "anapliroseis1.php";
//**************************************
}
?>	
<br><br>
<a  href=<?php echo $menu;?> style="color:blue "> <button>Επιστροφή στο Μενού</button></a>
<?php echo "&nbsp&nbsp&nbsp";?> 
<input type="button" style="color:blue " onClick="document.location.href='allagesnew1.php'" value="Αρχική Αναπληρώσεων" />
</body>
</html>