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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid green;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></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=800, height=700, top='+top+', left='+left);
}
</script>
<body>
<h2>ΑΠΟΥΣΙΕΣ ΕΚΠΑΙΔΕΥΤΙΚΩΝ</h2>

<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
echo "Ημερομηνία: ".$dt;

$sql=mysqli_query($con,"SELECT pmp,datefrom from apousieskath where datefrom='$dt'  ");
$apontes=array();
$i=1;
while ($row = mysqli_fetch_array($sql))
{
$apontes[$i]=$row['pmp'];
$i++;	
}

$result = mysqli_query($con,"SELECT Name,PMP FROM teachers ORDER BY Name ");

?>
<h4> ΕΠΕΛΕΞΕ ΤΟΥΣ ΕΚΠΑΙΔΕΥΤΙΚΟΥΣ ΠΟΥ ΑΠΟΥΣΙΑΖΟΥΝ ΣΗΜΕΡΑ</h4>
<?php
echo "<table  >
<tr style='border:0px ' >
</tr>";
echo "<tr>";
echo "<td>";

?>
<form  name='xx' method='post' >
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:320px; height: 550px">
<?php
echo "<table style='width:300px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>ΚΑΘΗΓΗΤΗΣ/ΚΑΘΗΓΗΤΡΙΑ</th>
<th> </th>
<th>ΑΠΩΝ</th>
</tr>";

$i=1;
while ($row = mysqli_fetch_array($result)) 
  { 
    $namet[$i]=$row['Name'];
	$pmp[$i]=$row['PMP'];
	if(in_array($pmp[$i],$apontes))
	{
	   $checked = "checked";
	}
	else
	{
		$checked = "";
    }
	echo "<tr>";
	echo "<td>".$namet[$i]."</td>";
	echo "<td>"." "."</td>";
    echo "<td ALIGN=center>"."<input type='checkbox' name='apon[]' value='$namet[$i]'  {$checked} >"."</td>";
	
	echo "</tr>";
    $i++;
}
echo "</table>";
?>
</div>
<br>
<input type="submit" name="apoukath" value="Επιβεβαίωση Επιλογών" >
</form>
<?php
echo "</td>";
echo "<td>"."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"."</td>";
echo "<td>";

if (isset($_POST['apoukath']))
{
?>
<h4> ΚΑΤΑΣΤΑΣΗ ΑΠΟΥΣΙΩΝ ΠΟΥ ΕΚΚΡΕΜΟΥΝ</h4>
<?php

echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:10px'  >
<tr>
<th>Α/Α</th>
<th>ΠΜΠ</th>
<th>ΕΚΠΑΙΔΕΥΤΙΚΟΣ</th>
<th>ΗΜΕΡΟΜΗΝΙΑ</th>
</tr>";		
	$apon = $_POST['apon'];
	$i=1;
	if (!empty($apon))
	{
    foreach ($apon as $a)
	{
	 $sql=mysqli_query($con,"select PMP from teachers where Name='$a'")	;
	 $row=mysqli_fetch_array($sql);
	 $pmp=$row['PMP'];
	 $sql1=mysqli_query($con,"SELECT * from apousieskath where datefrom='$dt' and pmp='$pmp' ");
	 $row1=mysqli_fetch_array($sql1);
     if (mysqli_num_rows($sql1)==0)
	 {
	    mysqli_query($con,"insert into apousieskath (pmp,datefrom) values  ('$pmp','$dt')");	 
	 }
	 $datefrom=$dt;
	 
	 if($row1['status']<>1 )
	 {
	 echo "<tr>";
	 echo "<td>" . $i. "</td>";
	 $pmpdate=$pmp."/".$datefrom;
     ?>
     <td>
     <a href="#" onClick="popupCenter('apousieskath1.php?data=<?php echo $pmpdate; ?>')"><?php echo $pmp; ?></a>
     </td>
     <?php
	 echo "<td>" . $a. "</td>";
	 echo "<td>" .$dt. "</td>";
     echo "</tr>";
     $i++;
	 }
	}}
	
	 $sql1=mysqli_query($con,"SELECT a.pmp,a.datefrom,t.Name from apousieskath as a, teachers as t where a.pmp=t.PMP and a.datefrom<>'$dt' and a.status<>'1'  ");
	 while ($row=mysqli_fetch_array($sql1))
	{
	 $pmp=$row['pmp'];
	 $datefrom=$row['datefrom'];
	 $name=$row['Name'];
	 echo "<tr>";
	 echo "<td>" . $i. "</td>";
	 $pmpdate=$pmp."/".$datefrom;
     ?>
     <td>
     <a href="#" onClick="popupCenter('apousieskath1.php?data=<?php echo $pmpdate; ?>')"><?php echo $pmp; ?></a>
     </td>
     <?php
	 echo "<td>" . $name. "</td>";
	  echo "<td>" .$datefrom. "</td>";
     echo "</tr>";
     $i++;	
	}
//....................................
}
echo "</td>";
echo "</table>";

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