<?php
include "scrinit.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">
table.o { border-collapse:collapse;border:solid 2px #00F ;}
table.o td {border:solid 2px #00F; padding:2px ; word-wrap:break-word;} 
table.o th { border:2px solid black; background-color: #CCF;padding:2px;font-size:10pt;word-wrap:break-word; }
<p style="font-size:10px;"></p>
</style>
<body>

<?php
require "dbconnect.php";
$dt=date('Y-m-d');
   
 
//..............................
$ep1=$ep2=$ep3=$ep4=array();
$sql=mysqli_query($con,"SELECT * FROM epitropes order by code" );
$c=mysqli_num_rows($sql);
$pere=array();

while ($row = mysqli_fetch_array($sql))
	{
		
		$cc[$row['code']]=$row['code'];
		$pere[$row['code']]=$row['perigrafi'];
		
	}
echo "<table class='o' >
<tr>
<th>ΚΩΔ.</th>
<th>ΕΠΙΤΡΟΠΗ</th>
<th>ΠΡΟΤΙΜΗΣΗ 1</th>
<th>ΠΡΟΤΙΜΗΣΗ 2</th>
<th>ΠΡΟΤΙΜΗΣΗ 3</th>
<th>ΠΡΟΤΙΜΗΣΗ 4</th>
</tr>";
$coun=$ep=array();
foreach ($cc as $cd)
{	
	echo "<tr>";
	echo "<td>".$cd."</td>";
	echo "<td>".$pere[$cd]."</td>";
	$sql = mysqli_query($con,"SELECT t.Name FROM teachers as t,dilosiep as d WHERE d.teach=t.PMP and code1='$cd' " );
	echo "<td>";
	while ($row = mysqli_fetch_array($sql))
	{
		echo $row['Name'].",";
		$coun[$cd]++;
		$ep[$cd][$coun[$cd]]=$row['Name'];
		
	}
	echo "</td>";
	$sql = mysqli_query($con,"SELECT t.Name FROM teachers as t,dilosiep as d WHERE d.teach=t.PMP and code2='$cd' " );
	echo "<td>";
	while ($row = mysqli_fetch_array($sql))
	{
		echo $row['Name'].",";
		$coun[$cd]++;
		$ep[$cd][$coun[$cd]]=$row['Name'];
	}
	echo "</td>";
	$sql = mysqli_query($con,"SELECT t.Name FROM teachers as t,dilosiep as d WHERE d.teach=t.PMP and code3='$cd' " );
	echo "<td>";
	while ($row = mysqli_fetch_array($sql))
	{
		echo $row['Name'].",";
		$coun[$cd]++;
		$ep[$cd][$coun[$cd]]=$row['Name'];
	}
	echo "</td>";
	$sql = mysqli_query($con,"SELECT t.Name FROM teachers as t,dilosiep as d WHERE d.teach=t.PMP and code4='$cd' " );
	echo "<td>";
	while ($row = mysqli_fetch_array($sql))
	{
		echo $row['Name'].",";
		$coun[$cd]++;
		$ep[$cd][$coun[$cd]]=$row['Name'];
	}
	echo "</td>";
	echo "</tr>";
}
echo "</table>";
print_r($ep);
?> <h3> ΔΕΝ ΔΗΛΩΣΑΝ ΕΠΙΤΡΟΠΕΣ </h3>
<?php
$sql = mysqli_query($con,"SELECT a.Name,a.PMP FROM teachers AS a 
WHERE (NOT EXISTS (  SELECT b.teach   FROM dilosiep AS b   WHERE a.PMP=b.teach )) and a.access=1 and a.workhrs > 8" );
$i=1;
while ($row = mysqli_fetch_array($sql))
{
	echo "<br>".$i." ".$row['Name'];
	$i++;
}


$xls_filename = 'export_'.date('Y-m-d').'.xls'; // 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".","."ΚΑΘΗΓΗΤΗΣ";
print "$header\n";
 
// Start while loop to get data
$k=1;
for ($i=1;$i<=$c;$i++)
{
for ($k=1;$k<=$coun[$i];$k++)
{
	$data = $i.",".$pere[$i].",".$k.",".$ep[$i][$k];
$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>