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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</script>

</head>

<body>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];

echo "<p class='p1'>". "ΕΠΑΦΕΣ ΚΑΙ ΚΡΟΥΣΜΑΤΑ". "</p>";
$q=mysqli_query($con,"select tmima,count(tmima) as c from allstudentinfo group by tmima");
$i=1;
while($row=mysqli_fetch_array($q))
	{
	 $t[$row['tmima']]=$row['c'];
	 $i++;
	}
$q=mysqli_query($con,"select s.*,a.tmima from spiticovid as s, allstudentinfo as a where s.mitroo=a.mitroo");
$c=mysqli_num_rows($q);
echo "<table class='myTable3' >
<tr> 
<th>ΤΑΞΗ</th>
<th>ΤΜΗΜΑ</th>
<th>ΚΡΟΥΣΜΑ</th>
<th>ΕΠΑΦΕΣ</th>
<th>ΣΥΝΟΛΟ</th>
</tr>";

if ($c==0)
{
	echo "<p class='p2'>". "ΔΕΝ ΥΠΑΡΧΟΥΝ ". "</p>";
}
else
{
	$i=0;
	while($row=mysqli_fetch_array($q))
	{
		
		$m=$row['mitroo'];
		$tmima=$row['tmima'];
		if ($tmx[$i]<> $tmima)
		{
			$i++;
			$tmx[$i]=$tmima;
		}	
		$l=mb_substr($tmima,0,1,'UTF-8');
		$r=$row['reason'];
		if ($r=='1')
		{
			$tmk[$tmima]=$tmk[$tmima]+1;
			if ($l =='Α') $suma++;
			if ($l =='Β') $sumb++;
			if ($l =='Γ') $sumc++;
		}
		if ($r=='2')
		{
		    $tme[$tmima]=$tme[$tmima]+1;
		    if ($l =='Α') $sumae++;
			if ($l =='Β') $sumbe++;
			if ($l =='Γ') $sumce++;
		}
		
	}
	$i=1;
	foreach ($tmx as $tm)
	{
		
		echo "<tr>";
		$l=mb_substr($tm,0,1,'UTF-8');
		echo "<td>". $l."</td>";
		echo "<td>". $tm."</td>";
		echo "<td>". $tmk[$tm]."</td>";
		echo "<td>". $tme[$tm]."</td>";
		echo "<td>". $t[$tm]."</td>";
		echo "</tr>";
		$i++;
	}
	echo "<table>";
echo "<p class='p1'>". "ΣΥΝΟΛΑ". "</p>";	
echo "<table class='myTable3' >
<tr> 
<th>ΤΑΞΗ</th>
<th>ΚΡΟΥΣΜΑ</th>
<th>ΕΠΑΦΕΣ</th>
</tr>";
echo "<tr>";
echo "<td>"."Α"."</td>";
echo "<td>". $suma."</td>";
echo "<td>". $sumae."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"."Β"."</td>";
echo "<td>". $sumb."</td>";
echo "<td>". $sumbe."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"."Γ"."</td>";
echo "<td>". $sumc."</td>";
echo "<td>". $sumce."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>".""."</td>";
$s1=$suma+$sumb+$sumc;
$s2=$sumae+$sumbe+$sumce;
echo "<td>". $s1."</td>";
echo "<td>". $s2."</td>";
echo "</tr>";
}


?>
</body>
</html>