<?php
include "scrinit.php";
include $menu;
?>

<head>
<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:11pt; }
<p style="font-size:11px;"></p>
</style>

</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change.php",
         data: "tmimaid="+$("#tmimaid").val(),
         success: function(html) {
             $("#nameid").html(html);
         }
     });
 }); 
});

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=900, height=300, top='+top+', left='+left);
}
</script>
</head>
<body>
<h3> ΑΠΟΝΤΕΣ ΜΑΘΗΤΕΣ ΗΜΕΡΑΣ</h3>

<?php 

require("dbconnect.php");
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$dat=$dt;
/*
$dat = isset($_POST['datex']) ? $_POST['datex'] : $dt;
$fhtml = '<form method="post" name = "form1">
<input type="date" name="datex" value="'.$dat.'" >
<input name="anaf" type="submit" value="ΕΠΙΛΟΓΗ ΗΜΕΡΟΜΗΝΙΑΣ" />
</form>';
echo $fhtml;    

if(isset($_POST['anaf']))
{
//$datex=$_POST['datex'];
$dat = isset($_POST['datex']) ? $_POST['datex'] : $dt;
*/
$sql = $dbcon->prepare("SELECT a.dateout, a.mitroo, a.period,al.tmima,al.eponimo,al.onoma 
FROM apousies as a,allstudentinfo as al WHERE (a.apousia=1 and a.kath IS NULL ) AND a.dateout=? AND 
(a.mitroo=al.mitroo) AND (a.mitroo not in (select mitroo from apousies where kath > 0 and dateout='$dat' and a.period=period )) 
                        ORDER BY al.tmima,a.mitroo,a.period " );
$sql->execute([$dat]);
echo "<br>";
echo "Για εντοπισμό μαθητή/τριας να κάνετε κλικ στην αντίστοιχη περίοδο";	
$apouall=array();
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Α/Α</th>
<th>Α.Μητρ</th>
<th>Τμήμα</th>
<th>Όνομα</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";

$row=$sql->fetch(PDO::FETCH_ASSOC);
$cc=1;
while(!empty($row)) {
	  $per1=$per2=array();
	  $pmp=$row['mitroo'];
	  $tmima=$row['tmima'];
	  $eponimo=$row['eponimo'];
	  $onoma=$row['onoma'];
	  echo "<td>". $cc . "</td>";
	  echo "<td>". $pmp . "</td>";
	  echo "<td>". $tmima . "</td>";
	  echo "<td>". $eponimo."  ".$onoma . "</td>";
	  while ($pmp==$row['mitroo'])
	  {
	     
		 $per1[$row['period']]=$row['period'].$pmp;
		 $row=$sql->fetch(PDO::FETCH_ASSOC);
      }
    //.....elexos gia ekdiloseis tin parousa hmerominia
    $q=$dbcon->prepare("SELECT e.onoma,s.* FROM ekdilosi as e,ekdilosistu as s 
	                    WHERE e.date = ? and e.code=s.code and s.pmp=?");
    $q->execute([$dat,$pmp]);
    $ce=$q->rowCount();
	if ($ce > 0 ) 
	{
      $row2=$q->fetch(PDO::FETCH_ASSOC);
	  $onomaekd=$row2['onoma'];  
	}
	else
	{
	  $onomaekd="";	
	}
    for ($i=1;$i<=$gym;$i++)
	{
		 if (empty($per1[$i]))
		 { 
			$per2[$i]="  ";
		 }
	     else 
		 { 
		    $per2[$i]="?";
			$apouall[$i]++;
		 }
		 if ($ce > 0 ) 
		 {
			  $p="p".$i;  
			  if ($row2["$p"]==1) {$per2[$i]="***"; }
		 }
		
		?>
		 <td>
         <a href="#" onClick="popupCenter('locate2.php?per=<?php echo $per1[$i];?>')"><?php echo $per2[$i]; ?></a>
         </td>
         <?php 
	}
	 echo "<td>". $onomaekd."</td>";
     echo "</tr>";
	 
	 $cc++;  
}
echo "<tr>";
echo "<td colspan=4>"."<b>"."ΣΥΝΟΛΟ ΑΝΑ ΠΕΡΙΟΔΟ"."</b>";
for ($i=1;$i<=$gym;$i++)
{
	
	echo "<td>".$apouall[$i]."</td>";
}
echo "</tr>";
echo "</table>";	 
//}

?>

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