<?php
session_start();
ob_implicit_flush (true);

date_default_timezone_set("Europe/Athens");
if ($_SESSION['islogin']=='' ) 
{ 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
}
$menu = $_SESSION['menu'];

include "logo.php";
?>
<head>
<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>

</head>
<body>
<!-- Progress bar holder -->
<br><br><br>
<h2>ΕΝΑΡΞΗ ΔΙΑΔΙΚΑΣΙΑΣ - ΠΑΡΑΚΑΛΩ ΠΕΡΙΜΕΝΕΤΕ</h2>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
<?php
require "dbconnect.php";

$dt=$_SESSION['dt'];
$gym=$_SESSION['gym']; echo $gym;
mysqli_query($con,'TRUNCATE TABLE stutimetable');
$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
$ta="";
$cols="mitroo,";
$gym=8;
for ($k=1;$k<=5;$k++)
{
   for ($i=1;$i<=7;$i++)
   {$ta.=$dayf[$k].$i.',';}
}
$cols=$cols.$ta;
$cols = " (".rtrim($cols, ',').") ";

$result = mysqli_query($con,"SELECT mitroo,tmima FROM allstudentinfo order by tmima,mitroo");
$total=mysqli_num_rows($result);	
$m=1;
while($row = mysqli_fetch_array($result))
{
  $percent = intval($m/$total * 100)."%";
  echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$m.' μαθητές-τριες διεκπεραιώθηκαν.";
    </script>';
  flush(); ob_flush();
  $mitroo=$row['mitroo'];
  $tmima=$row['tmima'];
  $vlf1="'".$mitroo."'".",";
  $vl1=" "; 
  $vlf2="NULL,";
  $vl2=" "; 
  for ($x=1;$x<=5;$x++)
  {
	for ($per=1;$per<=7;$per++)
	{
         $day1=$dayf[$x].$per;
		//****************************
           include "mathitisprog.php";
		//***************************** 
		 $room=$room."/".$pmpx;
		 $vl1.="'".ltrim(rtrim($less))."'".",";
		 $vl2.="'".ltrim(rtrim($room))."'".",";		 
     }
   } 
	$vlf1=$vlf1.$vl1;
	$vlf1 = " (".rtrim($vlf1, ',')." )";
	$vlf2=$vlf2.$vl2;
	$vlf2 = " (".rtrim($vlf2, ',')." ) ";
	$sql1="INSERT INTO stutimetable {$cols} values {$vlf1} ";
	if(!mysqli_query($con, $sql1))
				{
					echo "ERROR: Could not execute $sql1. " . mysqli_error($con);
				}
	$sql2="INSERT INTO stutimetable {$cols} values {$vlf2} ";
	if(!mysqli_query($con, $sql2))
				{
					echo "ERROR: Could not execute $sql2. " . mysqli_error($con);
				}	
	
	$m++;

}

// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Ο ΠΙΝΑΚΑΣ ΔΗΜΙΟΥΡΓΗΘΗΚΕ ΜΕ ΕΠΙΤΥΧΙΑ"</script>';
 ?>
<br /><br />

<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>