<?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 = $dbcon->prepare("SELECT DISTINCT b.mathima FROM bthis as b,allstudentinfo as a where
b.mitroo=a.mitroo and a.tmima like 'Γ%' ORDER BY b.mathima ASC");
$sql2->execute();
  
?>
<form  method='post'> 
  <label>Επέλεξε Μάθημα:</label>
  <select name='mathid' >
  <?php
  echo "<option value='---'>select</option>";
  while($row2=$sql2->fetch(PDO::FETCH_ASSOC) ) {
          echo "<option value='$row2[mathima]'>$row2[mathima]</option>";
      }
      ?>
 </select>
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>
<?php
if (isset($_POST['submit1']))
{
	$math=rtrim(ltrim($_POST['mathid']));

$sql2 = $dbcon->prepare("select b.*,al.eponimo,al.onoma,al.tmima FROM bthis as b,allstudentinfo as al
          where b.mitroo=al.mitroo and b.mathima=? and al.tmima like 'Γ%' and b.exetasi > 0");
$sql2->execute([$math]);

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;$ns=0;
while($row=$sql2->fetch(PDO::FETCH_ASSOC))
{
 $mitr=$row['mitroo'];
 $tmima=$row['tmima'];
 $name=$row['eponimo']." ".$row['onoma'];;
 $b1=$row['bathmosa']; 
 $b2=$row['bathmosb'];
 $ex=$row['exetasi'];	
 $dif1=$b2-$b1;
 $mot=($b1+$b2)/2;
 $dif2=$mot-$ex;
 $bathmos=(($mot*70)+($ex*30))/100;
	
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $mitr . "</td>";
  echo "<td>". $tmima . "</td>";
  echo "<td >". $name . "</td>";
  echo "<td >". $b1 . "</td>";
  echo "<td >". $b2 . "</td>";
  if ($dif1 >=0 and $dif1 <=3)
   
	{
	   echo "<td>"."<p align=right>".$dif1."</td>";
	   }
	    else if ($dif1 >= 4)
	{
		echo "<td bgcolor='#6FFA0C'>"."<p align=right>".$dif1."</td>";
	}
	else
    {
	echo "<td bgcolor='#FF0000'>"."<p align=right>".$dif1."</td>";
    }
	
	echo "<td >". $mot . "</td>";
	if ($ex > $mot)
   	{
	  echo "<td bgcolor='#6FFAaC'>"."<p align=right>".$ex."</td>";
	}
	else
		{
	   echo "<td>"."<p align=right>".$ex."</td>";
	   }
	echo "<td >". $dif2. "</td>";
	echo "<td >". $bathmos . "</td>";
	echo "</tr>";
	if ($ex > 0 and $mot >0)
	{
      $tot1=$tot1+$mot;
	  $tot2=$tot2+$ex;
	  $ns++;
	}
	$i++;
}
if ($ns > 0)
	{
  $mo1=$tot1/$ns;
  $mo2=$tot2/$ns;
	}
echo "</table>";  
  echo "ΜΕΣΟΣ ΤΕΤΡΑΜΗΝΩΝ : ".number_format($mo1,2)."<br>";
   echo "ΜΕΣΟΣ ΟΡΟΣ ΕΞΕΤΑΣΗΣ : ".number_format($mo2,2)."<br>";
}




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

</body>
</html>