<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(10);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
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");

echo "mesoi oroi ";
$taxi='Α0';$mex=array();
for ($k=1;$k<=6;$k++)
{
$tm=$taxi.$k;	
$sql1=mysqli_query($con,"select b.mitroo,sum(b.bathmosa) as sumax,sum(b.bathmosb) as sumbx, count(b.bathmosa) as c1
    from bathmoiab as b,allstudentinfo as a where b.exetasi > 0 and (a.tmima='$tm' and a.mitroo=b.mitroo) group by b.mitroo order by b.mitroo");

	
while($row1 = mysqli_fetch_array($sql1))
{  
   $x=2*$row1['c1'];
   $mex[$row1['mitroo']]=($row1['sumax']+$row1['sumbx'])/$x; 
}
}

$taxi='Α0';
for ($k=1;$k<=6;$k++)
{
$tm=$taxi.$k;	
$sql=mysqli_query($con,"SELECT  b.mitroo,a.eponimo,a.onoma,sum(b.bathmosa) as suma,count(b.bathmosa) 
as cnta, sum(b.bathmosb) as sumb,sum(b.exetasi) as exet,count(b.exetasi)
 as cexet from  bathmoiab as b,allstudentinfo as a 
 where b.mathima not like ' %' and (a.tmima='$tm' and a.mitroo=b.mitroo) group by b.mitroo order by b.mitroo");



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>ΜΕΣΟΣ A</th>
<th>ΜΕΣΟΣ B</th>
<th>ΜΕΣΟΣ tetr</th>
<th>ΜESOS exetasi</th>
</tr>";
$i=1;$ca=0;$cb=0;$cba=0;$cbb=0;$cbal=0;	
while($row = mysqli_fetch_array($sql))
{  
   $suma=$row['suma'];
   $sumb=$row['sumb'];
   $exet=$row['exet'];
   $mit=$row['mitroo'];
   $pm=$row['cnta'];
   $cexet=$row['cexet'];
   if ($pm > 0)
   {
     $mesosa=$suma/$pm;
     $mesosb=$sumb/$pm;
   }
   
   if ($cexet > 0){
   $mesose=$exet/4;
   }
   $tmima=$tm;
   $meall=($mesosa+$mesosb)*0.35+$mesose*0.3;
   if ($pm > 5)
   {
   if ($mesosa >= 18.5) {$cba++;}  
   if ($mesosb >= 18.5) {$cbb++;} 
   if ($meall >= 18.5) {$cbal++;} 
   echo "<tr>";
   echo "<td>". $i. "</td>";
   echo "<td>". $tmima. "</td>";
   echo "<td>". $row['eponimo'] ." ".$row['onoma']. "</td>";
   echo "<td>". $sum. "</td>";
   echo "<td>". $pm. "</td>";
   echo "<td>". round($mesosa, 2). "</td>";
   echo "<td>". round($mesosb, 2). "</td>";
   echo "<td>". round($meall, 2). "</td>";
   echo "<td>". round($mesose, 2). "</td>";
   echo "</tr>";
   $ca=$ca+$mesosa;
   $cb=$cb+$mesosb;
   $ce=$ce+meall;
   $i++;
   }
}
echo "</table>"; 
$plithos=$i--;
$a[$k]=$ca/$plithos;
$p[$k]=$plithos;
$ar[$k]=$cba;

$br[$k]=$cbb;
$b[$k]=$cb/$plithos;
$ar[$k]=$cba;

$bal[$k]=$cbal;
$c[$k]=$ce/4;

}
echo "<br>";echo "<br>";

echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>ΤΜΗΜΑ</th>
<th>ΑΡ. ΜΑΘ</th>
<th>ΑΡΙΣΤΟΙ A</th>
<th>ΜΕΣΟΣ</th>
<th>ΑΡΙΣΤΟΙ B</th>
<th>ΜΕΣΟΣ</th>
<th>ΑΡΙΣΤΟΙ FINAL</th>
<th>ΜΕΣΟΣ</th>
</tr>";
for ($k=1;$k<=6;$k++)
{
   $tm=$taxi.$k;	
   echo "<tr>";
   echo "<td>".$tm. "</td>";
   echo "<td>".$p[$k]. "</td>";
   echo "<td>".$ar[$k]. "</td>";
   echo "<td>".round($a[$k], 2). "</td>";
   echo "<td>".$br[$k]. "</td>";
   echo "<td>".round($b[$k], 2). "</td>";
   echo "<td>".$bal[$k]. "</td>";
   echo "<td>".round($c[$k], 2). "</td>";
   echo "</tr>";  
}  
echo "</table>"; 
//***********************

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

</body>
</html>