<?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 and b.mathima IS NOT NULL ");
$m=0;
while ($rowm=mysqli_fetch_array($result))
{
	$m++;
	$mathima[$m]=$rowm['mathima'];
}


$result = mysqli_query($con,"select b.*,a.eponimo,a.onoma FROM bthis as b,allstudentinfo as a 
          where a.tmima='$tmima' and b.mitroo=a.mitroo ");
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'];;
 while($mitr[$i]==$row['mitroo'])
  {
    $bathmos[$mitr[$i]][$row['mathima']]=$row['bathmosa']; 
    $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;
  $k=0;
  for ($j=1;$j<=$m;$j++)
  {
    $x=$bathmos[$mitr[$i]][$mathima[$j]];
	if ($x > 0)
	{
		$k++;
		
	if ($x >=10)
	{
	   echo "<td>"."<p align=right>".$x."</td>";
	}
    else
    {
	echo "<td bgcolor='#FF0000'>"."<p align=right>".$x."</td>";
    }	
    $tot=$tot+$x;
  
    $mo=$tot/$k;
	}
	else
	{
	echo "<td>"."<p align=right>"." "."</td>";	
	}
	  }
  echo "<td>"."<p align=right>".number_format($mo,2)."</td>";echo "</tr>"; 
  
}
echo "<tr>";
echo "<td colspan=3>".""."</td>"; 

for ($j=1;$j<=$m;$j++)
{
	$c=0;$sum=0;
	for ($k=1;$k<=$ns;$k++)
    {
		$x=$bathmos[$mitr[$k]][$mathima[$j]];
		if ($x > 0)
		{
		  $sum=$sum+$x;
		  $c++;
		}
	}
	$mo=$sum/$c;
	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>