<?php
include "scrinit.php";
include "logo.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style>
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
.fieldset
{
    width:850px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
</style>
<body>
<?php
require("dbconnect.php");
$gym=$_SESSION['gym'];
if (isset($_POST['apoudr']))
{
$mitr = $_POST['mt'];
$papo = $_POST['perapo'];
$pm=$_POST['permexri'];
$code=$_POST['code'];
$apoum=$_POST['apou'];
$apoudr=$_POST['p'];

$q1 = $dbcon->prepare("delete from ekdilosistu where code=?");
$q1->execute([$code]);

$i=0;
foreach ($apoum as $mit)
{
  echo $mit;
  for ($l=1;$l<=9;$l++){$met[$l]=0;}
  $sql1= $dbcon->prepare("SELECT tmima FROM allstudentinfo WHERE mitroo=?");
  $sql1->execute([$mit]);
  $row=$sql1->fetch(PDO::FETCH_ASSOC);
  $tmep=$row['tmima'];echo $tmep;
  for ($k=$papo;$k<=$pm;$k++)
  { 
	$met[$apoudr[$i]]=1;
	$i++;
  }
	$sql=$dbcon->prepare("INSERT INTO ekdilosistu (code,pmp,tmima,p1,p2,p3,p4,p5,p6,p7,p8,p9) VALUES 
  (?,?,?,?,?,?,?,?,?,?,?,?)");
   $sql->execute([$code,$mit,$tmep,$met[1],$met[2],$met[3],$met[4],$met[5],$met[6],$met[7],$met[8],$met[9]]);
}
////
$result = $dbcon->prepare("SELECT pmp,tmima,p1,p2,p3,p4,p5,p6,p7,p8,p9 FROM ekdilosistu WHERE code = ? ");
$result->execute([$code]);
$rowcount=$result->rowCount();
////////////////////////////////////////////////////////////

echo "<br>"."ΝΕΟΣ ΚΑΤΑΛΟΓΟΣ ΜΑΘΗΤΩΝ"."</b>". "<br>"."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73' >
<th>α/α</th>
<th>Μητρώο</th>
<th>Τμήμα</th>
<th>Επώνυμο</th>
<th>Όνομα</th>
<th>ΠΑΡΟΥΣΙΑ</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
$mit=$tm=$pr=$cpr=array();
$i=0;
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
	 $i++;
	 $mit[$i]=$row['pmp'];
	 $tm=$row['tmima'];
	 for ($k=1;$k<=$gym;$k++)
	 {
		 $in='p'.$k;
		 if($row["$in"]==1)
		 {
			$pr[$mit[$i]][$k]=$k; 
		 }
		 else
		 {
			$pr[$mit[$i]][$k]=0;  
		 }
		 
	 }
	 $sql1 = "SELECT eponimo, onoma FROM allstudentinfo WHERE mitroo =?";
     $rt = $dbcon->prepare($sql1);
	 $rt->execute([$mit[$i]]);
	 $row1 = $rt->fetch(PDO::FETCH_ASSOC);
	 $epo=$row1['eponimo'];
	 $nm=$row1['onoma'];
	 echo "<tr>";
	 echo "<td>" .$i;
	 echo "<td>". $mit[$i] . "</td>";
	 echo "<td>". $tm. "</td>";
	 echo "<td>". $epo. "</td>";
     echo "<td>". $nm . "</td>";
	 ?>
     <td>
     <input  type='checkbox' name='apou[]' value='<?php echo $mit[$i];?>' checked /> 
     </td>
                        
     <?php
     for ($j=1;$j<=$gym;$j++)
	 {
		 
	   ?>
       <td>
       <input type='checkbox' onclick="return false;" name='p[]' value='<?php echo $pr[$mit[$i]][$j]; ?>'   <?php if($pr[$mit[$i]][$j]<>0) {echo 'checked';} else echo 'unchecked'; ?>  /> 
       </td>
	   <?php
	   
	 }
	 echo "</tr>";
	 
}
echo "</table>";
////
}

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