<?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 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=700, height=600, top='+top+', left='+left);
}
</script>
</head>

<body>

<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];
$datedisp= date('d-m-Y', strtotime($dt)); 
?>
<h3> ΑΠΟΥΣΙΕΣ ΜΕΧΡΙ: <?php echo $datedisp; ?> </h3>
<?php
/*
$sql1 = $dbcon->prepare("SELECT apoulimit FROM parameters " );
	$sql1->execute();
	$row1=$sql1->fetch(PDO::FETCH_ASSOC);
	$arapou=$row1['apoulimit'];
// define the form into a variable
$fhtml = '<form method="post" >
<fieldset style="width:300px; ">
<br>
ΑΡΙΘΜΟΣ ΑΠΟΥΣΙΩΝ: <input type="text" name="arapou" value="'. $arapou. '" size="4" />
<br><br>
<input type="submit" name="submit1" value="Συνέχεια" > 
</fieldset>
</form>';

echo $fhtml;         // output /display the form
echo "<br>"."<br>";
if (isset($_POST['arapou'])) {
$arapou=$_POST['arapou'];}

if (isset($_POST['arapou']))
{
   $ar=$_POST['arapou'];
   $sql1 = $dbcon->prepare("update parameters set apoulimit='$ar' " );
   $sql1->execute();
   */
   $sqla = mysqli_query($con,"SELECT datexar FROM apousiesabakio " );
   $rowa = mysqli_fetch_array($sqla);
   $dx=$rowa['datexar'];
   $datexar=date('d-m-Y', strtotime($dx));
   echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>A/A</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΤΗΣ / ΤΡΙΑ</th>
<th>ΑΠΟΥΣΙΕΣ ΣΥΝΟΛΟ (".$datexar.")</th>
<th>ΑΠΟΥΣΙΕΣ Β ΤΕΤΡ ΜΕΧΡΙ(".$datexar.")  </th>
<th>ΑΠΟΥΣΙΕΣ B ΣΗΜΕΡΑ</th>
<th>ΑΠΟΥΣΙΕΣ ΣΗΜΕΡΑ</th>
";

   //$sql = mysqli_query($con,"SELECT mitroo,count(apousia) as apc FROM apousies 
   //WHERE (apousia=1 and kath IS NULL) and mitroo<>0 group by mitroo order by apc desc" );

   $totap=$totap1=$totap2=array();
   
   //$i=1;
   $sqlt = mysqli_query($con,"SELECT mitroo,eponimo,onoma,tmima FROM allstudentinfo order by tmima,eponimo,onoma " );
   $rowt = mysqli_fetch_array($sqlt);
   $i=1;
   while($rowt = mysqli_fetch_array($sqlt)) 
	{
	  	  $mitr=$rowt['mitroo'];
		  $stname=$rowt['eponimo']." ".$rowt['onoma'];
		  $tmima=$rowt['tmima'];
		  $nam[$mitr]=$stname;
		  $tm[$mitr]=$tmima;
		  $sqla = mysqli_query($con,"SELECT apousiestotal,apousiesbtotal,datexar FROM apousiesabakio WHERE mitroo='$mitr'  " );
		  $rowa = mysqli_fetch_array($sqla);
		  $sqlx = mysqli_query($con,"SELECT count(apousia) as apcx FROM apousies 
			WHERE mitroo='$mitr' and ((apousia=1 and kath IS NULL) and dateout > '$dx') group by mitroo " );
		  $rowx = mysqli_fetch_array($sqlx);
		   $totap[$mitr]=$rowa['apousiestotal'];
		   $totap2[$mitr]=$rowa['apousiesbtotal'];
		   $totap1[$mitr]=$rowx['apcx'];
		   $ball=$totap2[$mitr]+$totap1[$mitr];
		   $all=$totap[$mitr]+$totap1[$mitr];
		  echo "<tr>";
		  echo "<td>".$i. "</td>"; 
		  echo "<td>".$mitr."</td>"; 
		  echo "<td>".$tmima."</td>"; 
		  echo "<td>".$stname."</td>";
		  echo "<td>".$rowa['apousiestotal']."</td>";
		  echo "<td>".$rowa['apousiesbtotal']."</td>";
		  echo "<td>".$ball."</td>";
		  echo "<td>".$all."</td>";
		  echo "</tr>";
			$i++;
	} 
	
	//array_multisort($ar1, $ar2);
	
	echo "</table>";
	echo "<p>"."ΟΙ ΑΠΟΥΣΙΕΣ ΕΙΝΑΙ ΧΑΡΑΚΤΗΡΙΣΜΕΝΕΣ ΜΕΧΡΙ : ".date('d-m-Y', strtotime($rowa['datexar']));



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