<?php
include "scrinit.php";
include $menu;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:4px;font-size:9pt; }
<p style="font-size:12px;"></p>
</style>
</head>

<body>
<h3> ΠΑΙΔΑΓΩΓΙΚΗ ΟΜΑΔΑ ΤΜΗΜΑΤΟΣ</h3>
  
<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$dd=date('D', strtotime($dt));
$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima "); 
?>

<form  method='post'> 
<h4> ΕΠΙΛΟΓΗ  ΤΜΗΜΑΤΟΣ</h4>
<label>Τμήμα:</label>
<select name='tmimaid' id='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['tmimaid']))
{
  $tetramino=$_SESSION['tetramino'];
  $tmimax=$_POST['tmimaid'];
  $sql = mysqli_query($con,"SELECT onoma,eponimo,mitroo FROM allstudentinfo WHERE tmima='$tmimax'  " );
  $nst=mysqli_num_rows($sql);
  $markf=$subject=array();
  $k=0;$q=0;
  while($row = mysqli_fetch_array($sql))
  {
	$q++;
	$stname[$q]=$row['eponimo']." ".$row['onoma'];
	$mitroo[$q]=$row['mitroo']; 
    $mitr=$row['mitroo']; 
    $sql2 = mysqli_query($con,"select a.code,a.subject,a.type,a.maxmark,AVG(b.bathmos) as gr
    from (SELECT code,pmpteacher,tmima,subject,type,maxmark from aksinfo 
        where code in (select code from aksiologisi where mitroo='$mitr')) 
		 as a,aksiologisi as b 
		 where a.code=b.code and b.mitroo='$mitr'  
		 group by a.subject,a.type");
		 
    $row2 = mysqli_fetch_array($sql2);
    $i=0;
   
    while(!empty($row2)) 
    {
	  $mark=0;
	  $i++;
	  $sub[$i]=trim($row2['subject']);
	  if (!in_array($sub[$i], $subject)) {$k++;$subject[$k]=$sub[$i];}
	  while ($sub[$i] == $row2['subject'])
	  {
		  $t=$row2['type'];
		  $m=$row2['maxmark'];
		  $b=$row2['gr'];
		  //$sql1 = mysqli_query($con,"select percent from aksiologiseis where trim(type)='$t' and trim(subject)='$sub[$i]'");
		  //$row1 = mysqli_fetch_array($sql1);
		  //$p=$row1['percent'];
		  //if ($p==0) {$p=100;}
		  if ($m==0) {$m=20;}
		  //$mark=$mark+($b*(20/$m)*($p/100));
		  $mark=$b*(20/$m);
		  $row2 = mysqli_fetch_array($sql2);
	  }
	  $markf[$mitr][$sub[$i]]=$mark;
	  
    } 
  }
  echo $k."xx".$q;

echo "<br>";
echo "<table  class='myTable' >
<tr style='border:1px solid black' bgcolor='#FFAF80'   >
<th> A/A </th>
<th>ΜΗΤΡΩΟ</th>
<th>ΜΑΘΗΤΗΣ / ΤΡΙΑ</th>";	
for ($i=1;$i<=$k;$i++)
{
	echo "<th>".$subject[$i]."</th>";
}
echo "</tr>";
for ($i=1;$i<=$q;$i++)
{
	  echo "<td>". $i;
	  echo "<td>". $mitroo[$i]. "</td>";
	  echo "<td>". $stname[$i]. "</td>";
	  //$sqlt=mysqli_query($con,"select Name from teachers where PMP='$teacher[$i]'");
	  //$rowt=mysqli_fetch_array($sqlt);$tname=$rowt['Name'];
	  //echo "<td>".$tname."</td>";
	  
	  for ($j=1;$j<=$k;$j++)
	  {
	        echo "<td>"."<p align=right>".number_format($markf[$mitroo[$i]][$subject[$j]],2)."</td>";
	  }	
	  echo "</tr>"; 
}			
  
echo "</table>";

}

 ?>
<br /><br />

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