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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.bsumbit {
  color: red;
  border-radius: 5px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid ;
  padding:5px;
}
</style>
</head>
<body>

<h3>ΚΑΤΑΧΩΡΗΣΗ ΑΠΟΥΣΙΩΝ ΓΙΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑ/ΕΚΔΡΟΜΗ </h3>
<?php
require "dbconnect.php";
$name=$_SESSION['n'];
$usr=$_SESSION['pmp'];
$dt=$_SESSION['dt'];

$s=$dbcon->prepare("select mitroo,period from apousies where dateout=? and teacher=?");
$s->execute([$dt,$usr]);  
$stuin=array();
$i=1;
while($row=$s->fetch(PDO::FETCH_ASSOC))
{
	$stuin[$i]=$row['mitroo'];
	$i++;
}
echo "ΟΝΟΜΑ ΥΠΕΥΘΥΝΟΥ :"."<b>" .$name."</b>"."<br>";
?>
<form  method="post" >
<?php
echo "<br>"."Ημερομηνία: <input type='date' name='date' value='$dt' > ";
echo "Από περίοδο: <input type='text' name='papo' value='$papo' size='3' required> ";
echo "Μέχρι περίοδο: <input type='text' name='pm' value='$pm' size='3' required>";
?>
&nbsp;&nbsp;&nbsp <input type="submit" name="ddkekd" value="Υποβολή Επιλογών" class="bsumbit">
</form> 
<?php

if (isset($_POST['ddkekd']))
{
	$date=$_POST['date'];
	$papo=$_POST['papo'];
	$pm=$_POST['pm'];
$sql = "SELECT mitroo,tmima,eponimo,onoma  FROM allstudentinfo order by tmima ASC ";
$result = $dbcon->prepare($sql);
$result->execute(); 
echo "<BR >";

?>
<form  method="post" name ="epilogi" action = "ekdapousia.php">
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:520px; height: 650px">
<?php

echo "<table style='width:500px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>ΜΗΤΡΩΟ</th>
<th>ΤΜΗΜΑ</th>
<th>ΟΝΟΜΑΤΕΠΩΝΥΜΟ</th>
<th></th>
<th>ΕΠΙΛΟΓΗ</th>
</tr>";

$i=1;
while ($row =$result->fetch(PDO::FETCH_ASSOC)) 
  { 
    $am[$i]=$row['mitroo'];
	$per=$row['period'];
	if(in_array($am[$i],$stuin) AND ($per >= $papo AND $per <= $pm) )
	{
	   $checked = "checked";
	}
	else
	{
		$checked = "";
    }
	$tm1[$i]=$row['tmima'];
	$namet[$i]=$row['eponimo']." ".$row['onoma'];;
	echo "<tr>";
	echo "<td>".$am[$i]."</td>";
	echo "<td>".$tm1[$i]."</td>";
	echo "<td>".$namet[$i]."</td>";
	echo "<td>"." "."</td>";
    echo "<td ALIGN=center>"."<input type='checkbox' name='mitr[]' value='$am[$i]'  {$checked} >"."</td>";
	echo "</tr>";
    $i++;
}
    echo "<input type='hidden' name='tmep' value='$tm1'>";
	echo "<input type='hidden' name='papo' value='$papo'>";
	echo "<input type='hidden' name='pm' value='$pm'>";
	echo "<input type='hidden' name='date' value='$date'>";
	echo "</table>";
?>
</div>
<br>
<input type="Submit" name="exit1" value="ΤΕΛΟΣ ΕΠΙΛΟΓΗΣ" class="bsumbit">

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