<?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'];
$_SESSION['tax']='Γ';
$sql=  mysqli_query($con,"SELECT  * FROM electscode");
$elects=array();
while($row=mysqli_fetch_array($sql))
{
	 $elects[$row['code']]=$row['mathima'];	
}

$sql1=mysqli_query($con,"select distinct mitroo from epiloges where class='Γ'" );
$i=1;$d=array();
while($row=mysqli_fetch_array($sql1))
{
	$d[$i]=$row['mitroo'];
	$i++;
}

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

$dif=array_diff($dal,$d);
$n=count($dif);
$i=1;
foreach($dif as $xmitr)
{  
	$sql=  mysqli_query($con,"SELECT  e.*,k.name,m.electnum 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']];
	$electnum=$row['electnum'];
	$class='Γ';
	for ($i=1;$i<=$electnum;$i++)
	{
	  $sql= "INSERT INTO epiloges (date,mitroo,omp,kat,epilogi,metataksi,class) VALUES ('$dt','$xmitr','','$bkat','$elect[$i]','','$class')" ;	
	  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 epiloges where class='Γ') 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 epiloges where class='Γ'" );
$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 epiloges where epilogi <>'' and class='Γ' 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('mathitesepilogi.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 epiloges where class='Γ'" );
$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>