<?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">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>
<h3>ΣΤΟΛΗ ΕΜΦΑΝΙΣΗ </h3>
<body>
<?php
require("dbconnect.php");
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];

$sql = mysqli_query($con,"SELECT a.dateout, a.mitroo, a.period,a.teacher,al.tmima,al.onoma,al.eponimo,t.Name
 FROM apousies as a,allstudentinfo as al, teachers as t 
 WHERE a.stoli=1 AND a.dateout='$dt' AND a.mitroo=al.mitroo and t.PMP=a.teacher 
 ORDER BY al.tmima,a.dateout,a.mitroo,a.period " );
	
$c=mysqli_num_rows($sql);
if ($c >0)
{
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr>
<th>Αρ.M</th>
<th>Τμήμα</th>
<th>Όνομα</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
while($row = mysqli_fetch_array($sql)) 
{
	  $mitr[$row['mitroo']]=$row['mitroo'];
	  $per[$row['mitroo']][$row['period']]=1;
	  $tmima[$row['mitroo']]=$row['tmima'];
	  $name[$row['mitroo']]=$row['eponimo']." ".$row['onoma'];
	  $tname[$row['mitroo']][$row['period']]=$row['Name'];
}
$day = date('D', strtotime($dt));
foreach($mitr as $mitrx)
{
	
	echo "<tr>";
	echo "<td>". $mitrx . "</td>";
	echo "<td>". $tmima[$mitrx] . "</td>";
	echo "<td>". $name[$mitrx]. "</td>";
	for ($i=1;$i<=$gym;$i++)
	{
		$getf=$day.$i;
		$sql = mysqli_query($con,"SELECT ".$getf." FROM stutimetable WHERE id IN (SELECT ID+1 FROM stutimetable WHERE mitroo='$mitrx')");
		$row = mysqli_fetch_array($sql);
		$x=explode("/",$row["$getf"]);
		$xx=$tname[$mitrx][$i];
		if(!empty($xx) or $xx <> ""){$xx=$xx."( ".$x[0]." )";}
		echo "<td>". $xx."</td>";		
	}
	echo "</tr>";
}

echo "</table>";	 
}
else
{
	echo " ΔΕΝ ΥΠΑΡΧΟΥΝ ΑΝΑΦΟΡΕΣ ΓΙΑ ΣΤΟΛΗ";
}
?>
<br >
<br >
<br >
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>
</html>