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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style>
.fieldset
{
    width:400px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
</style>
<body>

<h3>ΕΠΙΛΟΓΗ ΜΑΘΗΤΩΝ ΓΙΑ ΔΙΚΑΙΟΛΟΓΗΣΗ</h3>
<?php
$name=$_SESSION['n'];
$usr=$_SESSION['pmp'];
$date=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$timefrom=date("H:i:s",time());
$timeto=date("H:i:s",time());
require "dbconnect.php";

$sql = "SELECT mitroo,tmima,eponimo,onoma  FROM allstudentinfo order by tmima ASC ";
$result = mysqli_query($con,$sql);

echo "<b>"."Για πολλαπλή επιλογή κρατήστε πατημένο το CTRL κάνοντας κλικ στον μαθητή. Πατήστε 'ΤΕΛΟΣ ΕΠΙΛΟΓΗΣ' για καταχώρηση";
echo "<BR >";
$time=date("H:i:s");
 
?> 
<br> 
<form  name='xx' method='post'>
<fieldset fieldset class="fieldset" style="width:500px">
ΔΙΚΑΙΟΛΟΓΗΣΗ ΜΑΘΗΤΗ/ΤΡΙΑΣ
<p>&nbsp&nbsp&nbspΗμερμηνία:<input type='date' name='date' value = '<?php echo $date; ?>' /></p>
<p>Ώρα Έναρξης:<input  type='time' name='timefrom' value='<?php echo $timefrom;?>' />
&nbsp&nbsp&nbsp&nbsp&nbspΏρα λήξης:<input type='time'  name='timeto' value='<?php echo $timeto; ?>'/></p>
ΕΠΙΛΟΓΗ ΜΑΘΗΤΗ/ΤΡΙΑΣ:<br>
<?php
$i=1;
echo "<select name='pmp1[]'  size='25' multiple>";
while ($row = mysqli_fetch_array($result)) 
{
	$am=$row['mitroo'];
	$tm1=$row['tmima'];
	$nm=$row['onoma'];
	$epo=$row['eponimo'];
   	echo "<option value ='".$am."'>".$tm1."&nbsp;&nbsp;&nbsp;".$am."&nbsp;&nbsp;&nbsp;".$epo." ".$nm."</option>";
	$i++;
}
    echo "<input type='hidden' name='tmep' value='$tm1'>";
echo "</select>";

?>

<br><br>
<input type="hidden" name="tmima" value="<?php echo $tm1; ?>" >
<input type="submit" name="submit1" value="Τέλος Επιλογής " >
</fieldset>
</form>

<?php
if (isset($_POST['submit1']))
{
	$mitr = $_POST['pmp1'];
	$tmima= $_POST['tmima'];
    $timef=$_POST['timefrom'];
	$timet=$_POST['timeto'];
	$t1= date('H:i',strtotime($timef) );
	$t2=date('H:i',strtotime($timet) );
	$ekd="ΣΥΜΒΟΥΛΟΣ ΑΠΟ:".$t1." ΜΕΧΡΙ: ".$t2;
	
    if ($t1 < '08:15') {$papo=1;}
    elseif ( $t1 > '08:15' and $t1 < '09:00' ){$papo=2;}
       elseif ( $t1 > '09:00' and $t1 < '10:05' ){$papo=3;}
	     elseif ($t1 > '10:05' and $t1 < '10:50'){$papo=4;}
		   elseif ($t1 > '10:50' and $t1 < '11:55' ){$papo=5;}
		     elseif ($t1 > '11:55' and $t1 < '12:40'){$papo=6;}
			   else {$papo=7;} 
			   
	if ($t2 < '08:15') {$pm=1;}
    elseif ( $t2 < '09:00' ){$pm=2;}
       elseif ( $t2 < '10:05' ){$pm=3;}
	     elseif ($t2 < '10:50'){$pm=4;}
		   elseif ($t2 < '11:55' ){$pm=5;}
		     elseif ( $t2 < '12:40'){$pm=6;}
			   else {$pm=7;}		   

	if (count($mitr) > 0) 
   {
	   
    $sql="INSERT INTO ekdilosi (onoma,date,teacher,perapo,permexri) VALUES ('$ekd','$date','$usr','$papo','$pm' )";
    if (!mysqli_query($con,$sql)) die('Error: ' . mysqli_error($con));
		$sql = "SELECT code FROM ekdilosi WHERE onoma = '$ekd' ";
    $result = mysqli_query($con,$sql);
    $row = mysqli_fetch_array($result);
    $code=$row['code'];
	
   foreach ($mitr as $a)
   {
   $pp="";
   $ppp="";
   for ($k=1;$k<=$gym;$k++)
		  {
			$pp=$pp.'p'.$k.',';
			if ($k >= $papo and $k <= $pm)
			{$ppp=$ppp.'1,';}
			else{$ppp=$ppp.'0,';}
			
		  }
		  $pp=trim($pp,',');
		  $ppp=trim($ppp,',');
		  mysqli_query($con,"insert into ekdilosistu (code,tmima,pmp,".$pp.") values('$code','$tmima','$a',".$ppp.")");

   if (!mysqli_query($con,$sql)) die('Error: ' . mysqli_error($con));

   }
   }
   echo "ΤΟ ΑΡΧΕΙΟ ΕΝΗΜΕΡΩΘΗΚΕ  ΜΕ ΕΠΙΤΥΧΙΑ";
}

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

</body>
</html>