<?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>
<h3> ΒΑΘΜΟΙ ΤΜΗΜΑΤΟΣ </h3>

<?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 'Γ%' and b.exetasi > 2 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 'Γ%' and b.exetasi > 2 ");
 $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>
<th>ΔΙΑΦΟΡΑ</th>
<th>ΒΑΘΜΟΣ</th>";

$i=1;$tot1=0;$tot2=0;$c=0;
$bathmos=$mitr=$tmima=$name=$b1=$b2=$ex=$dif1=$dif2=$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'];	
 $dif1[$i]=$b2[$i]-$b1[$i];
 $mot[$i]=($b1[$i]+$b2[$i])/2;
 $dif2[$i]=$mot[$i]-$ex[$i];
 $bathmos[$i]=(($mot[$i]*70)+($ex[$i]*30))/100;
	if ($b1[$i] >0 and $b2[$i] >0 and $ex[$i] > 0)
	{
		$tot1=$tot1+$mot[$i];
		$tot2=$tot2+$ex[$i];
		$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,$dif1,SORT_DESC,$dif2,SORT_DESC,$mot,SORT_DESC);
for ($i=0;$i<=$c;$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>";
  
  if ($dif1[$i] >=0 and $dif1[$i] <=3)
   
	{
	   echo "<td>"."<p align=right>".$dif1[$i]."</td>";
	   }
	    else if ($dif1[$i] >= 4)
	{
		echo "<td bgcolor='#6FFA0C'>"."<p align=right>".$dif1[$i]."</td>";
	}
	else
    {
	echo "<td bgcolor='#FF0000'>"."<p align=right>".$dif1[$i]."</td>";
    }
	
	echo "<td >". $mot[$i] . "</td>";
	if ($ex[$i] > $mot[$i])
   	{
	  echo "<td bgcolor='#6FFAaC'>"."<p align=right>".$ex[$i]."</td>";
	}
	else
		{
		echo "<td>"."<p align=right>".$ex[$i]."</td>";
	   }
	echo "<td >". $dif2[$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>