<?php
include "scrinit.php";
include "logo.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
<p style="font-size:11px;"></p>
</style>


</head>
<body  style="width:995px; margin:0 auto; ">

<?php 
require("dbconnect.php");
$sql=mysqli_query($con,"SELECT  b.mitroo,a.eponimo,a.onoma,a.tmima,sum(b.bathmosa) as suma,count(b.bathmosa) as cnta,sum(b.bathmosa) as sumb,count(b.bathmosb) as cntb,sum(b.exetasi) as sume,count(b.exetasi) as cnte 
     from  bthis as b,allstudentinfo as a where (b.mathima IS NOT NULL) and b.bathmosa <> 0 and b.mitroo=a.mitroo group by b.mitroo order by a.tmima,a.mitroo");

echo "ΑΡΙΣΤΟΙ Α΄ ΤΕΤΡΑΜΗΝΟΥ";
echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>Α/Α</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
<th>ΟΛΙΚΟ</th>
<th>ΑΡ. ΜΑΘ.</th>
<th>ΜΕΣΟΣ ΟΡΟΣ</th>
</tr>";
$i=1;$ca=0;$cb=0;$cg=0;$aa=0;$ab=0;$ag=0;	
while($row = mysqli_fetch_array($sql))
{  
   $cn=$row['cnta'];
   if ($cn > 0) 
   {
     $mesos=$row['suma']/$cn;
   }
   $tmima=$row['tmima'];
   $taxi=mb_substr($tmima, 0, 1, 'utf-8');
   switch ($taxi) 
   {
    case 'Α':
        $ca++;
        break;
    case 'Β':
        $cb++;
        break;
    case 'Γ':
        $cg++;
        break;
   }
   if ($mesos >=18.5 and $row['cnta'] > 5)
   {
	   $taxi=mb_substr($tmima, 0, 1, 'utf-8');
	   switch ($taxi) 
	   {
		case 'Α':
			$aa++;
			break;
		case 'Β':
			$ab++;
			break;
		case 'Γ':
			$ag++;
			break;
	   }   
	   echo "<tr>";
	   $mitrooar[$i]=$row['mitroo'];
	   echo "<td>". $i. "</td>";
	   echo "<td>". $mitrooar[$i]. "</td>";
	   echo "<td>". $tmima. "</td>";
	   echo "<td>". $row['eponimo'] ." ".$row['onoma']. "</td>";
	   echo "<td>". $row['suma']. "</td>";
	   echo "<td>". $row['cnta']. "</td>";
	   echo "<td>". round($mesos, 2). "</td>";
	   echo "</tr>";
	   $i++;
   }
}
echo "</table>"; 

$result = mysqli_query($con,"SELECT  count(DISTINCT(mitroo)) as stus FROM bthis where mathima IS NOT NULL  " );
$row=mysqli_fetch_array($result);
$pa=$pb=$pg=0;
if ($ca > 0) $pa=100*$aa/$ca;
if ($cb > 0) $pb=100*$ab/$cb;
if ($cg > 0) $pg=100*$ag/$cg;
$tot=$row['stus'];
echo "<br>"."ΣΥΝΟΛΟ ΜΑΘΗΤΩΝ : ".$tot;
$atot=$ca+$cb+$cg;
echo "<br>"."ΣΥΝΟΛΟ ΑΞΙΟΛΟΓΟΥΜΕΝΩΝ ΜΑΘΗΤΩΝ : ".$atot;
$ta=$tb=$tg=0;
if($aa > 0) $ta=100*$aa/$tot;
if($ab > 0) $tb=100*$ab/$tot;
if($ag > 0) $tg=100*$ag/$tot;
echo "<br>";echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>ΤΑΞΗ</th>
<th>ΣΥΝΟΛΟ</th>
<th>ΑΡΙΣΤΟΙ</th>
<th>ΠΟΣΟΣΤΟ ΤΑΞΗΣ %</th>
<th>ΠΟΣΟΣΤΟ ΣΧΟΛΕΙΟΥ %</th>
</tr>";
echo "<tr>";
   echo "<td>".'Α'. "</td>";
   echo "<td>".$ca. "</td>";
   echo "<td>".$aa. "</td>";
   echo "<td>".round($pa, 2). "</td>";
   echo "<td>".round($ta, 2). "</td>";
echo "</tr>"; 
echo "<tr>";
   echo "<td>".'Β'. "</td>";
   echo "<td>".$cb. "</td>";
   echo "<td>".$ab. "</td>";
   echo "<td>".round($pb, 2). "</td>";
   echo "<td>".round($tb, 2). "</td>";
echo "</tr>";
echo "<tr>";
   echo "<td>".'Γ'. "</td>";
   echo "<td>".$cg. "</td>";
   echo "<td>".$ag. "</td>";
   echo "<td>".round($pg, 2). "</td>";
   echo "<td>".round($tg, 2). "</td>";
echo "</tr>";  
echo "<tr>";
   echo "<td colspan=4>".'ΣΥΝΟΛΙΚΟ ΣΧΟΛΕΙΟΥ'. "</td>";
   $tot=$ta+$tb+$tg;
   echo "<td>".round($tot, 2)."%". "</td>";
echo "</tr>";   
echo "</table>"; 
//***********************

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

</body>
</html>