<?php
session_start(); // start up your PHP session!
 if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΚΑΝΕΤΕ ΕΓΓΡΑΦΗ ΓΙΑ ΧΡΗΣΗΣ ΤΟΥ ΣΥΣΤΗΜΑΤΟΣ"."<BR>";
  sleep(3);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu=$_SESSION['menu'];
include "logo.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>
<body>

<?php
require "dbconnect.php";
$dt=date('Y-m-d');
  
$sql= mysqli_query($con,"SELECT semname,plithos,semcode from seminaria order by semcode");
$i=1;$max=0;
while($row=mysqli_fetch_array($sql))
{
   $semname[$i]=$row['semname'];
   $sm[$i]=$row['semcode'];
   $semplithos[$i]=$row['plithos'];
   $sqls= mysqli_query($con,"SELECT a.eponimo,a.onoma,a.tmima,d.mitroo from allstudentinfo as a,dilosisem as d 
         where d.mitroo=a.mitroo and d.semcode='$sm[$i]' order by a.tmima,a.eponimo,a.onoma");
		 $k=0;
         while($rows=mysqli_fetch_array($sqls))
         {
			$k++;
		    $tm[$sm[$i]][$k]=$rows['tmima'];
			$st[$sm[$i]][$k]=$rows['eponimo']." ".$rows['onoma'];
		 }
		 if ($k > $max){$max=$k;}
   $i++;   
}


$xls_filename = 'seminaria_'.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


$data = " ".",".$semname[1].","." ".","." ".",".$semname[2].","." ".","." ".",".$semname[3].","." ";
$data = trim( $data ) . "\n";
$data = str_replace( "\r" , "" , $data );
print "$data";
$header= "Α/Α".","."ΤΜΗΜΑ".","."ΟΝΟΜΑΤΕΠΩΝΥΜΟ ΜΑΘΗΤΗ/ΤΡΙΑΣ".","."a/a".","."ΤΜΗΜΑ".","."ΟΝΟΜΑΤΕΠΩΝΥΜΟ ΜΑΘΗΤΗ/ΤΡΙΑΣ".","."a/a".","."ΤΜΗΜΑ".","."ΟΝΟΜΑΤΕΠΩΝΥΜΟ ΜΑΘΗΤΗ/ΤΡΙΑΣ";
print "$header\n";
for ($i=1;$i<=$max;$i++)
{

  $data = $i.",".$tm[$sm[1]][$i].",".$st[$sm[1]][$i].",".$i.",".$tm[$sm[2]][$i].",".$st[$sm[2]][$i].",".$i.",".$tm[$sm[3]][$i].",".$st[$sm[3]][$i];
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
}
  $data = " ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  $data = " ".",".$semname[4].","." ".",".$semname[5].","." ".",".$semname[6].","." ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  
for ($i=1;$i<=$max;$i++)
{

  $data = $i.",".$tm[$sm[4]][$i].",".$st[$sm[4]][$i].",".$i.",".$tm[$sm[5]][$i].",".$st[$sm[5]][$i].",".$i.",".$tm[$sm[6]][$i].",".$st[$sm[6]][$i];
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
}
  $data = " ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  $data = " ".",".$semname[7].","." ".",".$semname[8].","." ".",".$semname[9].","." ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  
for ($i=1;$i<=$max;$i++)
{

  $data = $i.",".$tm[$sm[7]][$i].",".$st[$sm[7]][$i].",".$i.",".$tm[$sm[8]][$i].",".$st[$sm[8]][$i].",".$i.",".$tm[$sm[9]][$i].",".$st[$sm[9]][$i];
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
}
  $data = " ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  $data = $semname[10].","." ".",".$semname[11].","." ".",".$semname[12].","." ";
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
  
for ($i=1;$i<=$max;$i++)
{

  $data = $i.",".$tm[$sm[10]][$i].",".$st[$sm[10]][$i].",".$i.",".$tm[$sm[11]][$i].",".$st[$sm[11]][$i].",".$i.",".$tm[$sm[12]][$i].",".$st[$sm[12]][$i];
  $data = trim( $data ) . "\n";
  $data = str_replace( "\r" , "" , $data );
  print "$data";
}
?>
<br><br>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>