<?php
session_start();
ob_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu = $_SESSION['menu'];
include "logo.php";
?>

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

</head>
<body>
<?php 
require("dbconnect.php");
$dt=$_SESSION['dt'];
echo "<b>"."<p style='font-size:16px;'>"."ΑΝΑΦΟΡA ΕΠΙΛΟΓΩΝ ΣΕ EXCEL: ".date('d-m-Y', strtotime($dt))."</p>"."</b>";


 

$xls_filename = 'epiloges_'.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".","."katefthinsi".","."epilogi1".","."epilogi2".","."taxi";
print "$header\n";

$sql=mysqli_query($con,"SELECT  mitroo from allstudentinfo where tmima LIKE 'Α%' order by tmima");

$k=1;
while ($row=mysqli_fetch_array($sql))
{
   $mitroo=$row['mitroo'];
   $sqle = mysqli_query($con,"SELECT e.*,k.code as katc,el.code as mathc from epiloges as e,kats aS k,electscode as el
       where e.mitroo='$mitroo' and e.epilogi=el.mathima and e.kat=k.kat");	

   if (mysqli_num_rows($sqle) > 0)
   {
	  $i=1; $j=1; $ep="";$met=""; $math=array();
     while ($rowe=mysqli_fetch_array($sqle))
     {
       $kat=$rowe['katc'];
	   $epilog=$rowe['epilogi'];
	   if ($epilog <> "")
	    {	 $math[$i]=$rowe['mathc'];
	         $epilog[$i]=$epilog;
			 $i++;
			 }
	   else
	    {   $math[$i]="";
	        $epilog[$i]="";
			 } 
     }
   }
   else
   {
	 $kat=" ";
     $math[1]=" ";$math[2]=" ";
	 $epilog[1]=" ";$epilog[2]="";
   }
   $data = $k.",".$mitroo.",".$kat.",".$math[1].",".$math[2].",".$epilog[1].",".$epilog[2].",".$class;
   $data = trim( $data ) . "\n";
   $data = str_replace( "\r" , "" , $data );
   print "$data";
   $k++;
}

?>

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