<?php
include "scrinit.php";
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"; 
    $mathima=array();
	$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.exetasi > 0");
	echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΠΑΡΑΠΕΜΠΟΜΕΝΟΙ ΣΕ ΑΝΕΞΕΤΑΣΗ  </p>';

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>A/M</th>
<th>TMHMA</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΒΑΘΜΟΣ</th>";
$i=1;
$ar=$mitr=$tmima=$name=$tel=$math=array();
$ar=["Βιολογία","Χημεία"];

while($row = mysqli_fetch_array($result))
{
	 $mitr[$i]=$row['mitroo'];
	 $tmima[$i]=$row['tmima'];
	 $name[$i]=$row['eponimo']." ".$row['onoma'];
	 $ba=$row['bathmosa'];
	 $bb=$row['bathmosb'];
	 $exet=$row['exetasi'];
	 $tel[$i]=round((0.35*$ba+0.35*$bb+0.3*$exet),0);
	 $math[$i]=trim($row['mathima']);
	 if ($math[$i] == "Βιολογία") {$bioa=$ba;$biob=$bb;$bexet=$exet;}
	 if ($math[$i] == "Χημεία") {$xhma=$ba;$xhmb=$bb;$xexet=$exet;}
	 if ($tel[$i] < 10 and !in_array($math[$i],$ar))
	 {
		if ($math[$i]=="Χημεία-Βιολογία")
		{
		    $biol=round((0.35*$bioa+0.35*$biob+0.3*$bexet),0);
			$xhm=round((0.35*$xhma+0.35*$xhmb+0.3*$xexet),0);
			if ($biol < 10) {$math[$i]="Βιολογία";$tel[$i]=$biol;}
			if ($xhm < 10) {$math[$i]="Χημεία";$tel[$i]=$xhm;}
		}
		echo "<tr>";
		echo "<td>". $i;
		echo "<td>". $mitr[$i]. "</td>";
		echo "<td>". $tmima[$i] . "</td>";
		echo "<td >". $name[$i]. "</td>";
		echo "<td>".$math[$i]."</td>";
		echo "<td>"."<p align=right>".number_format($tel[$i],0)."</td>";
		echo "</tr>";
		
		$i++;
	 }
}	
echo "</table>";

array_multisort($math, $mitr, $tel,$name,$tmima);
$c=count($math);
$i=0;
echo "<table class='myTable' >
	<tr style='border:1px solid black' bgcolor='#d6ff73'  >
	<th>No.</th>
	<th>A/M</th>
	<th>ΜΑΘΗΜΑ</th>
	<th>TMHMA</th>
	<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
	<th>ΒΑΘΜΟΣ</th>";
while ($i <= $c)
{
	//echo $math[$i];
	$mt=$math[$i];

	
	//$k=1;
	//while ($mt=$math[$i] and $i < $c)
	//{
			echo "<tr>";
			echo "<td>". $k;
			echo "<td>". $mitr[$i]. "</td>";
			echo "<td>".$math[$i]."</td>";
			echo "<td>". $tmima[$i] . "</td>";
			echo "<td >".$name[$i]. "</td>";
			echo "<td>"."<p align=right>".number_format($tel[$i],0)."</td>";
			echo "</tr>";
			//$k++;
			$i++;
	//}	
}
echo "</table>";
?>
<br><br>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>