<?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

   $sqla = mysqli_query($con,"SELECT datexar FROM apousiesabakio " );
   $rowa = mysqli_fetch_array($sqla);
   $dx=$rowa['datexar'];
   $datexar=date('d-m-Y', strtotime($dx));
   
   $xls_filename = 'apou_'.date('Y-m-d').'.txt'; // Define Excel (.xls) file name
//create a file and send to browser for user to download
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$xls_filename");
header("Pragma: no-cache");
header("Expires: 0"); 
// Start of printing column names as names of MySQL fields
$header= "a/a".","."mitroo".","."tmima".","."onoma".","."apoudate".","."apouBdate".","."apouBsimera".","."apouallsimera";
print "$header\n";
   $totap=$totap1=$totap2=array();
   $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];
		   
		   $data = $i.",".$mitr.",".$tmima.",".$stname.",".$rowa['apousiestotal'].",".$rowa['apousiesbtotal'].",".$ball.",".$all;
   $data = trim( $data ) . "\n";
   $data = str_replace( "\r" , "" , $data );
   print "$data";
		  
		  
			$i++;
	} 
	


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