<?php
session_start();$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>ΑΠΟΥΣΙΟΛΟΓΙΟ ΕΚΠΑΙΔΕΥΤΙΚΟΥ</title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11pt; }
<p style="font-size:11px;"></p>
</style>
<!-- Be sure to place the above styles (i.e. everything between the <style></style> tags) into the document 'head' (i.e. between the <head></head> tags. Everything below goes inside the <body></body> tags) -->

</head>
<body>

<?php 
require("dbconnect.php");
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['pmp'];
$less=$_SESSION['less'];
$ora=$_SESSION['ora'];
$flagekd=$_SESSION['flagekd'];
?>

<form  name="apous1" method="post"  >
ΗΜΕΡΟΜΗΝΙΑ: <input type="date"  name = 'dt' value =<?php if (isset($_POST['dt'])) { echo $dt;$_SESSION['dt']=$dt; } else {$dt=date('Y-m-d');echo $dt;} ?> autofocus  >
<input type="submit"  name="bapou" value=" Επιβεβαίωση" /> 
<br />
ΚΑΘΗΓΗΤΗΣ :
<?php 
echo "<font face='arial' size='4pt'> $name </font> "; 

if(isset($_POST['dt'])){
$dt=$_POST['dt'];}
$day = date('D', strtotime($dt));

echo "<table class='myTable' >
<tr style='border:1px solid black' >
<th>Π.</th>
<th>Τμήμα/Συνδιδασκαλια</th>
<th>Α.Μ</th>
<th>Όνοματεπώνυμο</th>
<th>Τμήμα</th>
<th>Καθ</th>
<th> Δραστηριότητα / Ύλη</th>
</tr>";
//initialize arrray
//
$sql = mysqli_query($con,"SELECT dateout, mitroo, period,apousia,kath,mathima FROM apousies WHERE teacher='$usr' AND dateout='$dt' AND stoli <> 1 ORDER BY period,apousia " );
$row = mysqli_fetch_array($sql);

$sqlsy=	mysqli_query($con,"SELECT per,perigrafi FROM syllabi WHERE pmp='$usr' AND date='$dt' ORDER BY per " );
$c2=mysqli_num_rows($sqlsy);


$result = mysqli_query($con,"SELECT * FROM timetable WHERE Teacher='$name'  " ); 
$row2 = mysqli_fetch_array($result);
$id=$row2['id']+1;
   $i=1;
   while ($i<=7) {
   $perio[$i]=0;
   $in=$day.$i;
   $l=$row2["$in"];
   $lesson[$i]= rtrim(ltrim($l));
   $perigrafi[$i]=" ";
    $i++;
   }

//.......... get the subject
$q = mysqli_query($con,"SELECT * FROM timetable WHERE id = '$id'");
$rowx = mysqli_fetch_array($q);
   $i=1;
   while ($i<=7) {
      $in=$day.$i;
      $d1=$rowx["$in"];
      $subject[$i]= trim(strrev(strstr(strrev((strstr($d1, '/'))), '(')), '/(');
      $i++;
   }

//$subject = trim(strrev(strstr(strrev((strstr($d1, '/'))), '(')), '/(');
//................................   
   while ($rowsy = mysqli_fetch_array($sqlsy))
   {
   		$perigrafi[$rowsy['per']]=$rowsy['perigrafi'];
		
   }
   


$per=1;$k=1;
while(!empty($row) ) 
{ 
	 while ($per != $row['period'] AND !empty($row) )
	  {
		 if ($lesson[$per] > "---" ){
		 echo "<tr >";
		 echo "<td>".$per. "</td>";
		 
		 if ($per == $ora AND $flagekd == "ΔΔΚ"){ $subject="ΔΔΚ";}
         
	     echo "<td>". $lesson[$per]."/".$subject[$per]. "</td>";
		 echo "<td>"." ". "</td>";
	     echo "<td>". "  ". "</td>";
	     echo "<td>". " " . "</td>";
	     echo "<td>". "  " . "</td>";
		 echo "<td>"."<textarea name='syllabi[]'> $perigrafi[$per] </textarea >"."</td>";
	     echo "</tr>";
		 }else{echo "<tr  bgcolor='silver' >";
		 echo "<td>".$per. "</td>";
	     echo "<td>"." " .  "</td>";
		 echo "<td>"." ". "</td>";
	     echo "<td>". "  ". "</td>";
	     echo "<td>". " " . "</td>";
	     echo "<td>". "  " . "</td>";
		 echo "<td>"." "."</td>";
	     echo "</tr>";}
	     $per++;
	  }
	
	  echo "<td>".$row['period'] . "</td>";
	     $math=$row['mathima'];
		 if ($period == $ora AND $flagekd == "ΔΔΚ"){ $subject="ΔΔΚ";}
	  echo "<td>". $row['mathima']."/".$subject[$row['period']]. "</td>";
	  $perio[$row['period']]=$row['period'];
	  $j=1;
	  while ($row['apousia']==1 AND $per==$row['period'])
	  {
	  $m=$row['mitroo'];
	  $sql2 = mysqli_query($con,"SELECT tmima,eponimo,onoma FROM allstudentinfo WHERE mitroo='$m' " );
	  $row2 = mysqli_fetch_array($sql2);
	
	  if ($j <> 1 )
	  {
	    echo "<td>". " " . "</td>";
	    echo "<td>". " " . "</td>";
	  }
	  
	  echo "<td>".$row['mitroo']. "</td>";
	  echo "<td>". trim($row2['eponimo'])."  ".trim($row2['onoma']) . "</td>";
	  echo "<td>". $row2['tmima'] . "</td>";
	  echo "<td>". "  " . "</td>";
	  if ($j==1) {
	   echo "<td>"."<textarea name='syllabi[]'> $perigrafi[$per] </textarea >"."</td>";
	  } else
	  {echo "<td>". "  " . "</td>";}
	  echo "</tr>";
	  $j++;
	  $row = mysqli_fetch_array($sql);
	  }
	   //kataxorisi kathisteriseon
	  $k=1;
	  while ($per==$row['period'])
	  {
	  $m=$row['mitroo']; 
	  $sql2 = mysqli_query($con,"SELECT tmima,eponimo,onoma FROM allstudentinfo WHERE mitroo='$m' " );
	  $row2 = mysqli_fetch_array($sql2);
	
	  if ($k <>1)
	  {
	    echo "<td>". " " . "</td>";
	    echo "<td>". " " . "</td>";
	  }
	  echo "<td>".$row['mitroo']. "</td>";
	   echo "<td>". trim($row2['eponimo'])."  ".trim($row2['onoma']) . "</td>";
	  echo "<td>". $row2['tmima'] . "</td>";
	  echo "<td>". $row['kath'] . "</td>";
	  if ($k==1) {
	   echo "<td>"."<textarea name='syllabi[]' > $perigrafi[$per] </textarea >"."</td>";
	  } else
	  {echo "<td>". "  " . "</td>";}
	   echo "</tr>";
	   
	  $k++;
	  $row = mysqli_fetch_array($sql);
	  }

	  $per++;
}
 while ($per  <= 7 AND empty($row))
	  {  if ($lesson[$per] > "---" ){
		 echo "<tr >";
		 echo "<td>".$per. "</td>";
		
		 if ($per == $ora AND $flagekd == "ΔΔΚ"){ $subject="ΔΔΚ";}
	     echo "<td>". $lesson[$per]. "/".$subject[$per]; "</td>";
		 echo "<td>"." ". "</td>";
	     echo "<td>". "  ". "</td>";
	     echo "<td>". " " . "</td>";
	     echo "<td>". "  " . "</td>";
		 echo "<td>"."<textarea name='syllabi[]'> $perigrafi[$per] </textarea >"."</td>";
	     echo "</tr>";
		 }else{echo "<tr  bgcolor='silver' >";
		 echo "<td>".$per. "</td>";
	     echo "<td>"." " .  "</td>";
		 echo "<td>"." ". "</td>";
	     echo "<td>". "  ". "</td>";
	     echo "<td>". " " . "</td>";
	     echo "<td>". "  " . "</td>";
		 echo "<td>"." "."</td>";
	     echo "</tr>";}
	     $per++;
	  }	 
echo "</table>";	 

?>
<input type="submit"  name="apou" value="Υποβολη Απουσιολογίου" />
<br >
</form>
<?php

if (isset($_POST['syllabi'])){

$syl=$_POST['syllabi'];

$i=0;$k=1;
while ($k <=7 ){
if ($perio[$k]==$k){
mysqli_query($con,"UPDATE syllabi SET pmp='$usr', per='$k', date='$dt',perigrafi='$syl[$i]' WHERE pmp='$usr' AND date='$dt' AND per='$k'") ;

$i++;}
$k++;
}
}

?>
<br ><br >
ΥΠΟΓΡΑΦΗ ΕΚΠΑΙΔΕΥΤΙΚΟΥ
<br ><br ><br >



........................................

<br /><br />
<a href=<?php echo $menu;?> ><span>Επιστροφή στο Μενού</span></a>

</body>
</html>