<?php
include "scrinit.php";
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>
</head>
<body>

<?php 
require("dbconnect.php");
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$gym1=$gym+1;
$teach = $_SESSION['n'];
$usr=$_SESSION['pmp'];
$less=$_SESSION['less'];
$ora=$_SESSION['ora'];
$flagekd=$_SESSION['flagekd'];
$day = date('D', strtotime($dt));
?>

<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'> $teach </font> "; 
$teacher=$teach;
if(isset($_POST['dt'])){
$dt=$_POST['dt'];}
$day = date('D', strtotime($dt));
$_SESSION['day']=$day;
if ($day=="Sat" or $day=="Sun")
{
    echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΜΑΤΑ ΣΗΜΕΡΑ"."<br>";
}
else 
{
include "apousiologioproc.php";
}
?>
<br ><br >
<input type="submit"  name="apou" style="color:green;font-size:18px" value="Υπογραφή και Υποβολή Απουσιολογίου" />
<br >
</form>
<?php

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

$syl=$_POST['syllabi'];

$i=0;$k=1;
while ($k <=$gym ){
if ($perio[$k]==$k){

$sql = $dbcon->prepare("UPDATE syllabi SET pmp=?, per=?, date=?,perigrafi=? WHERE pmp=? AND date=? AND per=?") ;
$sql->execute([$usr,$k,$dt,$syl[$i],$usr,$dt,$k]);
$i++;}
$k++;
}
}
///////////////
if (isset($_POST['apou']))
{
$sql = $dbcon->prepare("SELECT sign FROM teachers WHERE PMP=?" );
$sql->execute([$usr]);
$row=$sql->fetch(PDO::FETCH_ASSOC);
$signt=$row['sign'];
$sign="/signs/".$signt;
$today=date('Y-m-d');
$time=date('h:i:sa');
$sql2 = $dbcon->prepare("SELECT date,teacher,posted,code FROM apousiologio WHERE teacher=? AND date=?" );
$sql2->execute([$usr,$today]);
$set= $sql2->rowCount();
$row2 = $sql2->fetch(PDO::FETCH_ASSOC);
if ($set == 0) 
{
    $sql1 = $dbcon->prepare("INSERT INTO  apousiologio (date,teacher,posted,time) VALUES (?,?,?,?)  " );
    $sql1->execute([$today,$usr,1,CURRENT_TIME()]);
}
else
{
   $code1=$row2['code'];
   $sql1 = $dbcon->prepare("UPDATE  apousiologio 
   SET lastchange=?,lasttime=CURRENT_TIME(),posted=1  WHERE teacher=? AND code=?" );
   $sql1->execute([$today,$usr,$code1]);
}
?> 
<br ><br >

<img src=<?php echo $sign;?>  />
<br ><br >
<?php
echo "<font face='arial' size='2pt'> $teach </font> ";  
}
else
{
?>
<br ><br >
ΥΠΟΓΡΑΦΗ ΕΚΠΑΙΔΕΥΤΙΚΟΥ
<br ><br ><br >
.....................................
<?php
}
?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a>

</body>
</html>