<?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"; 
//$dt=$_SESSION['dt'];

$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ASC");
  
?>
<form  method='post'> 
  <label>Επέλεξε Τμήμα:</label>
  <select name='tmimaid' >
  <?php
  echo "<option value='---'>select</option>";
  while($row2 = mysqli_fetch_array($sql2) ) {
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
      }
      ?>
 </select>
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>
<?php
if (isset($_POST['submit1']))
{
	$tmima=$_POST['tmimaid'];
    $mathima=array();
    $result = mysqli_query($con,"SELECT DISTINCT b.mathima FROM bthis as b,allstudentinfo as a 
          where a.tmima='$tmima' and b.mitroo=a.mitroo ");
    $m=0;
    while ($rowm=mysqli_fetch_array($result))
	{
	  $m++;
	  $mathima[$m]=$rowm['mathima'];
	}
	$result = mysqli_query($con,"select b.*,al.eponimo,al.onoma FROM bthis as b,allstudentinfo as al
          where b.mitroo=al.mitroo and al.tmima='$tmima' and b.exetasi > 0");
	echo '<p style="color: blue; text-align: left; font-weight: bold;"> ΑΝΑΛΥΤΙΚΗ ΒΑΘΜΟΛΟΓΙΑ ΤΜΗΜΑΤΟΣ  </p>';

	$i=1;
	$row = mysqli_fetch_array($result);
	while(!empty($row))
	{
	 $mitr[$i]=$row['mitroo'];
	 $name[$i]=$row['eponimo']." ".$row['onoma'];
	 $k=0;
	 while($mitr[$i]==$row['mitroo'])
	  {
		$k++; 
		$bathmosa[$mitr[$i]][$row['mathima']]=$row['bathmosa']; 
		$bathmosb[$mitr[$i]][$row['mathima']]=$row['bathmosb'];
		$exet[$mitr[$i]][$row['mathima']]=$row['exetasi'];
		$row = mysqli_fetch_array($result);	
	  }
	  $i++;
	}
	$ns=$i--;
echo "ΤΜΗΜΑ:".$tmima."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>A/M</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>";
// print titles
for ($i=1;$i<=$m;$i++)
{ 
  echo "<th>".$mathima[$i]."</th>";
}
echo "<th>M.O</th>";
echo "</tr>";
  
for ($i=1;$i<$ns;$i++)
{	
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $mitr[$i] . "</td>";
  echo "<td >". $name[$i] . "</td>";
  
  $tot=0;
  for ($j=1;$j<=$m;$j++)
  {
	$x=$bathmosb[$mitr[$i]][$mathima[$j]]-$bathmosa[$mitr[$i]][$j];
    $av=($bathmosb[$mitr[$i]][$mathima[$j]]+$bathmosa[$mitr[$i]][$j])/2;
	$ex=$exet[$mitr[$i]][$j];
	if ($bathmosb[$mitr[$i]][$mathima[$j]] >0)
	{
		if ($x >=0 and $x <=3)
		{
		   echo "<td>"."<p align=right>".$x." ( ".$av." )".$ex."</td>";
		}
		else if ($x >= 4)
		{
			echo "<td bgcolor='#6FFA0C'>"."<p align=right>".$x." ( ".$av." )".$ex."</td>";
		}
		else
		{
		echo "<td bgcolor='#FF0000'>"."<p align=right>".$x." ( ".$av." )".$ex."</td>";
		}	
        $tot=$tot+$av;
		$mo=$tot/$k;
    }
    else
	{
		echo "<td>"."<p align=right>"." "."</td>"; 
	}
  
  echo "<td>"."<p align=right>".number_format($mo,2)."</td>";echo "</tr>"; 
  }
echo "</table>";

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

</body>
</html>