<?php
session_start(); // start up your PHP session! 
$menu=$_SESSION['menu'];

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Εντοπισμός Μαθητή/τριας</title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
<p style="font-size:14px;"></p>
</style>
</head>

<body>
<?php
require "dbconnect.php";
$date=$_SESSION['dt'];
if (isset($_POST['nameid']))
{
	include $menu;
	echo "<br>"."<br>"." ΣΤΟΙΧΕΙΑ ΑΠΟΥΣΙΑΣ"."<br>"."<br>";
    $per=$_POST['ora']; 
    $mitroo=$_POST['nameid'];
    $tmima=$_POST['tmimaid'];
	$date=$_SESSION['dt'];

	$sql = mysqli_query($con,"SELECT a.mitroo,a.id,t.Name,a.mathima,a.period,al.eponimo,al.onoma,al.tmima  FROM allstudentinfo as al,apousies as a,teachers as t 
	       WHERE a.mitroo='$mitroo' AND a.mitroo=al.mitroo AND a.apousia=1 AND a.dateout='$date' AND t.PMP=a.teacher AND a.period='$per' 
		   AND (a.mitroo not in (select mitroo from apousies where kath > 0 and dateout='$date' and period='$per'))");
}
else
{
	$sql = mysqli_query($con,"SELECT a.mitroo,a.id,t.Name,a.mathima,a.period,al.eponimo,al.onoma,al.tmima  FROM allstudentinfo as al,apousies as a,teachers as t 
	       WHERE a.mitroo=al.mitroo AND a.apousia=1 AND a.dateout='$date' AND t.PMP=a.teacher AND (a.mitroo not in (select mitroo from apousies where kath > 0 and dateout='$date')) ORDER BY al.tmima,al.mitroo ASC");	
}
	if (!$sql) {die('Error: ' . mysqli_error($con));   }
    $c=mysqli_num_rows($sql);
	
if ($c==0){
	
	echo "<br>"."<br>"."<br>"." ΔΕΝ ΥΠΑΡΧΟΥΝ ΑΠΟΥΣΙΕΣ";}
else
{
?>
<form  method="post" action="deleteapou2.php">
<?php
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:9px'  >
<tr>
<th>Κωδικός</th>
<th>Μητρώο</th>
<th>Τμήμα</th>
<th>Μαθητής/τρια</th>
<th>Περίοδ.</th>
<th>Μάθημα</th>
<th>Καθηγητής</th>
<th>Διαγραφή</th>
</tr>";	
$code=$mitroo1=$tmima1=$teacher=$mathima=$stname=$per=ARRAY();
$i=1;
while ($row = mysqli_fetch_array($sql)) 
{
	$code[$i]=$row['id'];
    $mitroo1[$i]=$row['mitroo'];
	$tmima1[$i]=$row['tmima'];
	$teacher[$i]=$row['Name'];
	$mathima[$i]=$row['mathima'];
	$stname[$i]=$row['eponimo']." ".$row['onoma'];
	$per[$i]=$row['period'];
    
echo "<tr>";
echo "<td>" . $code[$i]."</td>";
echo "<td>" . $mitroo1[$i]. "</td>";
echo "<td>" . $tmima1[$i]. "</td>";
echo "<td>" . $stname[$i]. "</td>";
echo "<td>" . $per[$i]. "</td>";
echo "<td>" . $mathima[$i]. "</td>";
echo "<td>" . $teacher[$i]. "</td>";
echo "<td>". "<input type='checkbox' value='$code[$i]' name='coded[]' >" ."</td>";
echo "</tr>"; 
}
echo "</table>";

?>
<br /><br />
<input type="submit" name="delete2" value="Διαγραφή Άπουσίας" > 
</form>
<?php
}
?>
 <br /> <br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>