<?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 "<p>"."ΟΙ ΑΠΟΥΣΙΕΣ ΕΙΝΑΙ ΧΑΡΑΚΤΗΡΙΣΜΕΝΕΣ ΜΕΧΡΙ : ".date('d-m-Y', strtotime($rowa['datexar']))."</p>";
   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>ΑΠ.ΑΒΑΚΙΟ B Τετρ </th>
<th>ΑΠΟΥΣΙΕΣ ΣΥΣΤ ΑΠΟ (".$datexar.") </th>
<th>ΑΠΟΥΣΙΕΣ ΟΛΙΚΟ</th>";
$sql = mysqli_query($con,"SELECT mitroo,apousiestotal,apousiesbtotal,datexar FROM apousiesabakio WHERE apousiestotal> '$ar' order by apousiestotal DESC  " );
$row = mysqli_fetch_array($sql);
   $totap=array();
   $i=1;
   while($row = mysqli_fetch_array($sql)) 
	{
		  $mitr=$row['mitroo'];
		  $sqlt = mysqli_query($con,"SELECT eponimo,onoma,tmima FROM allstudentinfo WHERE mitroo='$mitr'  " );
		  $rowt = mysqli_fetch_array($sqlt);
		  if (mysqli_num_rows($sqlt) > 0)
		  {
		  $stname=$rowt['eponimo']." ".$rowt['onoma'];
		  $tmima=$rowt['tmima'];
		  }
		  else
		  {
			  $stname="<b>"."ΔΙΑΓΡΑΦΗΚΕ"."</b>";
			  $tmima="";
		  }
		  
		  $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);
		  echo "<tr>";
		  echo "<td>".$i. "</td>"; 
		  echo "<td>".$row['mitroo']."</td>"; 
		  echo "<td>".$tmima."</td>"; 
		  echo "<td>".$stname."</td>";
		  echo "<td>".$row['apousiestotal']."</td>";
		  echo "<td>".$row['apousiesbtotal']."</td>";
		  echo "<td>".$rowx['apcx']."</td>";
		  $apt=$rowx['apcx']+$row['apousiestotal'];
		  echo "<td>".$apt."</td>";
		  echo "</tr>";
		  $i++;  
	  }
	} 
	echo "</table>";
	


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