<?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'];



   $sqla = mysqli_query($con,"SELECT datexar FROM apousiesabakio " );
   $rowa = mysqli_fetch_array($sqla);
   $dx=$rowa['datexar'];
   $datexar=date('d-m-Y', strtotime($dx));
   ?>
<h3> ΑΠΟΥΣΙΕΣ ΜΕΧΡΙ: <?php echo $datexar; ?> </h3>
<?php
   $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= "Α/Α".","."ΜΗΤΡΩΟ".","."ΤΜΗΜΑ".","."ΟΝΟΜΑ".","."ΣΥΝΟΛΟ ΑΠΟΥΣΙΩΝ".","."ΑΠΟ ΑΠΟΒΟΛΕΣ".","."ΥΠΟΓΡΑΦΗ";

   $sqlt = mysqli_query($con,"SELECT mitroo,eponimo,onoma,tmima FROM allstudentinfo order by tmima,eponimo,onoma " );
   $rowt = mysqli_fetch_array($sqlt);
  
   while(!empty($rowt)) 
	{
		  $tmima=$rowt['tmima'];
		  $oldt=$tmima;
		  print "$header\n";
		  $i=1;
	  	  while($tmima==$oldt)
		  {
		  $stname=$rowt['eponimo']." ".$rowt['onoma'];
		  $mitr=$rowt['mitroo'];
		  $sqla = mysqli_query($con,"SELECT apousiestotal,apouapovoles FROM apousiesabakio WHERE mitroo='$mitr'  " );
		  $rowa = mysqli_fetch_array($sqla);
		  $data = $i.",".$mitr.",".$tmima.",".$stname.",".$rowa['apousiestotal'].",".$rowa['apouapovoles'];
          $data = trim($data) . "\n";
          $data = str_replace( "\r" , "" , $data );
          print "$data";
		  $i++;
		  $rowt = mysqli_fetch_array($sqlt);
		  $tmima=$rowt['tmima'];
		  }
		  
	} 
	


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