<?php
session_start();
$menu = $_SESSION['menu'];
include "logo.php";
date_default_timezone_set("Europe/Athens");
?>

<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=800, top='+top+', left='+left);
}
</script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:14px; }
<p style="font-size:14px;"></p>
</style>
</head>
<body>
<h4>ΕΠΙΛΟΓΗ ΜΑΘΗΤΗ ΓΙΑ ΔΔΚ</h4>
<?php
require "dbconnect.php"; 
$usr=$_SESSION['usr'];
$_SESSION['link1']="ddktmimalist.php";

$result = $dbcon->prepare("SELECT Class_id FROM voithos WHERE yt=? " );
$result->execute([$usr]);

$c=$result->rowCount();

if ($c == 0) {
	echo "ΔΕΝ ΕΙΣΑΣΤΕ ΥΠΕΥΘΥΝΗ/ΟΣ ΤΜΗΜΑΤΟΣ "."<br>";}
else {
$row=$result->fetch(PDO::FETCH_ASSOC);
$tmima=$row['Class_id'];
$result = $dbcon->prepare("SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima=? order by eponimo,onoma" ); 
$result->execute([$tmima]);   
echo "TMHMA : ".$tmima."<br>"."<br>";
echo "<table class='myTable' >
<tr style='border:2px solid black' >
</tr>";
echo "<tr > 
<th>Α/Α</th>
<th>Μητρώο</th>
<th>Ονοματεπώνυμο Μαθητή/τριας</th>
<th>Σύνολο Μονάδων</th>
</tr>";

$i=1;
 while($row=$result->fetch(PDO::FETCH_ASSOC))
     {
	   $mitroo[$i]=$row['mitroo'];
	   $res1 = $dbcon->prepare("SELECT * FROM ddk WHERE mitroo=? ");
	   $res1->execute([$mitroo[$i]]);
       $row1=$res1->fetch(PDO::FETCH_ASSOC); 
       $n=$res1->columnCount()-1;
       $sum=0;
       for ($j=1;$j<=$n;$j++)
	      {	
	         $field="f".$j;
		     $sum=$sum+$row1["$field"];
	      }
	  $name[$i]=$row['eponimo']." ".$row['onoma'];
      echo "<td>" . $i. "</td>";
	  echo "<td>" . $mitroo[$i]. "</td>";
	 ?>
     <td>
   <a href='ddkbathmos.php?mitr=<?php echo $mitroo[$i]; ?>')"><?php echo $name[$i]; ?></a>
    </td>
<?php

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

</body>
</html>