<?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:2px;font-size:11px; }
<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=1000, height=900, top='+top+', left='+left);
}
</script>

</head>
<body  style="width:995px; margin:0 auto; ">

<?php 
require("dbconnect.php");
$dt=$_SESSION['dt'];
$sql=  mysqli_query($con,"SELECT  * FROM electscode");
$elects=array();
while($row=mysqli_fetch_array($sql))
{
	 $elects[$row['code']]=$row['mathima'];	
}
mysqli_query($con,'TRUNCATE TABLE epilogesball');
$result = mysqli_query($con,"SELECT  mitroo FROM allstudentinfo where tmima like 'Β%' " );

while($row=mysqli_fetch_array($result)) 
{
	$xmitr=$row['mitroo'];
	$sql=  mysqli_query($con,"SELECT  e.*,k.name,m.electnum,m.must1,m.must2,m.must3 FROM epilogesb as e,kats as k,must as m 
		   WHERE e.mitroo='$xmitr' and k.kat=e.kat and k.kat=m.kat");
	$row=mysqli_fetch_array($sql);
	$bkat=$row['kat'];
	$elect[1]=$elects[$row['elect1']];
	$elect[2]=$elects[$row['elect2']];
	$mst[1]=$row['must1'];
	$mst[2]=$row['must2'];
	$mst[3]=$row['must3'];
	$electnum=$row['electnum'];
	for ($i=1;$i<=$electnum;$i++)
	{
	  $sql= "INSERT INTO epilogesball (mitroo,kat,epilogi) VALUES ('$xmitr','$bkat','$elect[$i]')" ;	
	  if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con));}
	}
	$mustl=4-$electnum;
	for ($i=1;$i<=$mustl;$i++)
	{
	  $sql= "INSERT INTO epilogesball (mitroo,kat,epilogi) VALUES ('$xmitr','$bkat','$mst[$i]')" ;	
	  if (!mysqli_query($con,$sql)){die('Error: ' . mysqli_error($con));}
	}
}
$sql=  mysqli_query($con,"SELECT  a.kat,COUNT(a.kat) as ckat,k.name from (select distinct(mitroo),kat from epilogesball ) as a,kats as k 
WHERE a.kat=k.kat group by a.kat order by a.kat ASC");

echo "ΕΞΕΤΑΖΟΜΕΝΑ Β";
echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>Κατεύθυνση</th>
<th>Αριθμός</th>
</tr>";	
while($row = mysqli_fetch_array($sql))
{
   echo "<tr>";
   ?>
     <td>
   <a href="#" onClick="popupCenter('mathiteskat.php?kat=<?php echo $row['kat']; ?>')"><?php echo $row['name']; ?></a>
    </td>
	<?php
   echo "<td>". $row['ckat'] . "</td>";
   echo "</tr>";
}
echo "</table>"; 

$result = mysqli_query($con,"SELECT  count(DISTINCT(mitroo)) as stus FROM epilogesball" );
$row=mysqli_fetch_array($result);

echo "<br>"."ΣΥΝΟΛΟ ΜΑΘΗΤΩΝ : ".$row['stus'];
//***********************
echo "<br>"."<br>";echo "<br>"."<br>";
$sql=  mysqli_query($con,"SELECT  epilogi,COUNT(epilogi) as cepi from epilogesball where epilogi <>'' group by epilogi ");

echo "ΕΞΕΤΑΖΟΜΕΝΑ Β";
echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>ΜΑΘΗΜΑ</th>
<th>Αριθμός</th>
</tr>";	
while($row = mysqli_fetch_array($sql))
{
   echo "<tr>";
   //echo "<td>". $row['epilogi']." . ".$row['name']. "</td>";
   ?>
     <td>
   <a href="#" onClick="popupCenter('mathitesepilogiexamb.php?less=<?php echo $row['epilogi']; ?>')"><?php echo $row['epilogi']; ?></a>
    </td>
<?php
   echo "<td>". $row['cepi'] . "</td>";
   echo "</tr>";
}
echo "</table>"; 
echo "<br>";echo "<br>";
echo "ΔΕΝ ΔΗΛΩΣΑΝ ΜΑΘΗΜΑΤΑ"."<br>";
$result = mysqli_query($con,"SELECT  DISTINCT mitroo FROM epilogesball" );
$i=1;
while($row=mysqli_fetch_array($result)) {$d[$i]=$row['mitroo'];$i++;}

$result = mysqli_query($con,"SELECT  mitroo,onoma,eponimo,tmima,identity FROM allstudentinfo where tmima like 'Β%' " );
$i=1;
while($row=mysqli_fetch_array($result)) 
{
	$dal[$i]=$row['mitroo'];
	$name[$dal[$i]]=$row['eponimo']." ".$row['onoma'];
	$tmima[$dal[$i]]=$row['tmima'];
	$idt[$dal[$i]]=$row['identity'];
	$i++;}

$dif=array_diff($dal,$d);
$n=count($dif);
$i=1;
foreach($dif as $x)
{  
	echo $i." . ".$x." ".$name[$x]." (".$tmima[$x]." ".$idt[$x]." )"."<br>";$i++;
}
?>	
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>