<?php
include "scrinit.php";
?>
<head>
<html xmlns="https://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
.bt1 {
  color: green;
  border-radius: 5px;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid ;
  padding:4px;
}
<p style="font-size:10px;"></p>
</style>

</head>
<body>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$tetramino = $_SESSION['tetramino'];
$gym=$_SESSION['gym'];
if ($fromx==0)
{
$km=$_GET['kathmath'];
$arr = explode("/", $km);
$usr = trim($arr[0]);
$lesson = trim($arr[1]);
$sb=trim($arr[2]);
}
echo "<br>";
echo "ΠΡΟΦΟΡΙΚΟ ΒΑΘΜΟΛΟΓΙΟ ΓΙΑ ".$lesson." ( ".$sb." ) ";
echo "<br>";
$sql="select DISTINCT date from proforikos 
where pmpteacher='$usr' and mathima='$lesson' and subject='$sb' and tetramino='$tetramino' ORDER BY date ASC";

$c=mysqli_num_rows(mysqli_query($con, $sql)); 

$sq=mysqli_query($con, $sql);
$dat=array();
$k=0;
while ($row = mysqli_fetch_array($sq))
{
	$k++;
	$dat[$k]=$row['date'];
}

$mit=$name=$tmima=array();

$result = $dbcon->prepare("SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima=? ORDER BY eponimo,onoma");
$result->execute([$lesson]);
$crow1 = $result->rowCount();
if ($crow1 > 0) 
{
  $cr=0;
  while ($row = $result->fetch(PDO::FETCH_ASSOC))
     {
	  $cr++; 
	  $mit[$cr]=$row['mitroo'];
	  $name[$cr]=$row['eponimo']." ".$row['onoma'];
	  $tmima[$cr]=$lesson;
	  
	  }
}
else // den eine amiges tmima alla syndidaskalia
{
  $result = $dbcon->prepare("SELECT distinct sc.synd,sy.mitroo,al.eponimo,al.onoma,al.tmima FROM 
  syndidaskalies as sy,allstudentinfo as al,syndcodes as sc WHERE sc.syndid=sy.syndid and trim(sc.synd) = ? AND sy.mitroo=al.mitroo 
  ORDER BY al.eponimo,al.onoma");
  $result->execute([$lesson]);
  $crow1 = $result->rowCount();
  if ($crow1 > 0) 
  {
	$cr=0;
	while ($row = $result->fetch(PDO::FETCH_ASSOC))
	{	
		$cr++;
		$mit[$cr]=$row['mitroo'];
	    $name[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmima[$cr]=$row['tmima'];
	}
  }
}
$b=array();
$sq="select mitroo,bathmos,sxolio from proforikos 
where pmpteacher='$usr' and mathima='$lesson' and subject='$sb' and tetramino='$tetramino'  order by mitroo,date";
$sql=mysqli_query($con,$sq);
$dd=mysqli_num_rows($sql);

$rowx=mysqli_fetch_array($sql);
$mt=$rowx['mitroo'];
while(!empty($rowx))
{
	$j=1;
	for ($i=1;$i<=$k;$i++)
	{
		$b[$mt][$j]=$rowx['bathmos'];
		$j++;
		$b[$mt][$j]=$rowx['sxolio'];
		$j++;
		$rowx=mysqli_fetch_array($sql);
		$mt=$rowx['mitroo'];
	}
}


echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr bgcolor='#66CC99'>
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>";
for ($i=1;$i<=$k;$i++)
{
	echo "<th>Βαθμός</th>";
	echo "<th>Σχόλια</th>";
}
echo "</tr>";
echo "<tr>";
echo "<td colspan=4>".""."</td>";
for ($i=1;$i<=$k;$i++)
{
   echo "<td colspan=2 align=center>".date('d-m-Y', strtotime($dat[$i]))."</td>";
}


for ($i=1;$i<=$cr;$i++)
{
	echo "<tr>";
	echo "<td>".$i."</td>";
	echo "<td>".$mit[$i]."</td>";
	echo "<td>".$tmima[$i]."</td>";
	echo "<td>".$name[$i]."</td>";
	$cc=$k*2;
	for ($n=1;$n<=$cc;$n++)
	{
	    echo "<td>".$b[$mit[$i]][$n]."</td>";
	}
	echo "</tr>";
}

echo "</table>";

?>
<br><br>
<?php
if($fromx==0)
{
	
?><input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"><?php 
}
else
{
?><a  href=<?php echo $menu;?> style="color:blue "><button>Επιστροφή στο Μενού</button> </a><?php	
}
?>
</body>
</html>