<?php
session_start(); // start up your PHP session!
 if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΚΑΝΕΤΕ ΕΓΓΡΑΦΗ ΓΙΑ ΧΡΗΣΗΣ ΤΟΥ ΣΥΣΤΗΜΑΤΟΣ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); 
  exit();
  }
$menu=$_SESSION['menu'];
include "logo.php";

?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>
</script>

</head>

<body>

<?php
require "dbconnect.php"; 

$sql2 = mysqli_query($con,"SELECT distinct b.mathima FROM bthis as b,allstudentinfo as al 
        where b.mitroo=al.mitroo and al.tmima like 'Γ%' ORDER BY b.mathima ASC");
//$sql2 = mysqli_query($con,"SELECT distinct mathima FROM bthis where exetasi > 0");		
echo mysqli_num_rows($sql2);
$k=1;
while($row2 = mysqli_fetch_array($sql2) ) 
{
 $math=$row2['mathima'];
 $result = mysqli_query($con,"select b.*,al.eponimo,al.onoma,al.tmima FROM bthis as b,allstudentinfo as al
          where b.mitroo=al.mitroo and b.mathima='$math' and al.tmima like 'Γ%' ");
 $pl=mysqli_num_rows($result);
 echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΑΝΑΛΥΤΙΚΗ ΒΑΘΜΟΛΟΓΙΑ ΜΑΘΗΜΑΤΟΣ  </p>';

echo "ΜΑΘΗΜΑ:".$math."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>A/M</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
<th>A ΤΕΤΡ</th>
<th>B ΤΕΤΡ</th>
<th>ΜΟ ΤΕΤΡ</th>
<th>ΕΧΕΤΑΣΗ</th>
<th>ΒΑΘΜΟΣ</th>";

$i=1;$tot1=0;$tot2=0;$c=0;
$bathmos=$mitr=$tmima=$name=$b1=$b2=$ex=$mot=array();
while($row = mysqli_fetch_array($result))
{
 $mitr[$i]=$row['mitroo'];
 $tmima[$i]=$row['tmima'];
 $name[$i]=$row['eponimo']." ".$row['onoma'];;
 $b1[$i]=$row['bathmosa']; 
 $b2[$i]=$row['bathmosb'];
 $ex[$i]=$row['exetasi'];	
 $mot[$i]=($b1[$i]+$b2[$i])/2;
 $tot1=$tot1+$mot[$i];
 $bathmos[$i]=$mot[$i];
 if ($ex[$i] > 0)
 {
    $bathmos[$i]=(($mot[$i]*70)+($ex[$i]*30))/100;
	$tot2=$tot2+$ex[$i];
 }
 else
 {
	 $tot2=0;
 }
 $c++;
 $i++;
}
//////////////////
array_multisort($bathmos,SORT_DESC,$mitr,SORT_DESC,$tmima,SORT_DESC,$name,SORT_DESC,$b1,SORT_DESC,$b2,SORT_DESC,$ex,SORT_DESC,$mot,SORT_DESC);
for ($i=0;$i<=5;$i++)
{
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $mitr[$i] . "</td>";
  echo "<td>". $tmima[$i] . "</td>";
  echo "<td >". $name[$i] . "</td>";
   echo "<td >". $b1[$i] . "</td>";
    echo "<td >". $b2[$i] . "</td>";
  echo "<td >". $mot[$i] . "</td>";
  echo "<td >"."<p align=right>".$ex[$i]."</td>";
  echo "<td >". $bathmos[$i] . "</td>";
  echo "</tr>";
}
////////////////////

  $motetr[$k]=$tot1/$c;
  $moex[$k]=$tot2/$c;
  $mth[$k]=$math;
  
echo "</table>"; 
   echo "ΑΡΙΘΜΟΣ ΜΑΘΗΤΩΝ : ". $c."<br>";
   echo "ΜΕΣΟΣ ΤΕΤΡΑΜΗΝΩΝ : ".number_format($motetr[$k],2)."<br>";
   echo "ΜΕΣΟΣ ΟΡΟΣ ΕΞΕΤΑΣΗΣ : ".number_format($moex[$k],2)."<br>";
   $k++;
}




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

</body>
</html>