<?php
include "scrinit.php";
include $menu;
date_default_timezone_set("Europe/Athens");
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style>
.fieldset
{
    width:400px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
</style>
<body>

<h3>ΟΛΙΓΟΩΡΗ ΑΠΟΥΣΙΑ ΕΚΠΑΙΔΕΥΤΙΚΟΥ</h3>
<?php
$name=$_SESSION['n'];
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];

require "dbconnect.php";
$time=date("H:i:s");
$sql = $dbcon->prepare("SELECT * FROM shortapou WHERE date = ? and pmp=?");
$sql->execute([$dt,$usr]);
$row=$sql->fetch(PDO::FETCH_ASSOC);
$count=$sql->rowCount();
if ($count > 0)
{
	echo "<b>"."ΔΕΝ ΔΙΚΑΙΟΥΣΤΕ ΑΛΛΗ ΈΞΟΔΟ - ΜΟΝΟ ΜΕ ΠΡΟΣΩΠΙΚΗ ΑΔΕΙΑ ΑΠΟ ΔΙΕΥΘΥΝΤΗ"."</b>";
	echo "<br>";
	$timeout=$row['timeout'];
	$timeback=$row['timeback'];
	$reason=$row['reason'];
	$exit=1;
}
else
{
	$exit=0;
	$timeout=date("H:i:s",time());
	$timeback=date("H:i:s",time());
}

?> 
<br> 
<form  name='shapou' method='post'>
<fieldset fieldset class="fieldset" style="width:500px">
<legend>Εκπαιδευτικός: <?php echo $name;?> </legend>
<p>Ημερομηνία: <input type='date' name='dat' value = '<?php echo $dt; ?>' readonly  /></p>
<p>Ώρα Αποχώρησης:<input  type='time' name='timeo' value='<?php echo $timeout;?>'<?php if ($exit==1) {echo 'readonly';}?> /> 
Ώρα Επιστροφής:<input type='time'  name='timeb' value='<?php echo $timeback; ?>'<?php if ($exit==0) {echo 'readonly';}?> /></p>
<p>Λόγος απουσίας:<input type='text'  name='reasonx' size='100' value='<?php echo $reason; ?>'<?php if ($exit==1) {echo 'readonly';}?> /></p>
<input  type='hidden' name='pmpx' value='<?php echo $usr;?>' />
<br><br>
<input type="submit" name="submit1" value="ΚΑΤΑΧΩΡΙΣΗ " >
</fieldset>
</form>

<?php
if (isset($_POST['submit1']))
{
	$pmp = $_POST['pmpx'];
	$date = $_POST['dat'];
    $timeo=$_POST['timeout'];
	$timei=$_POST['timeback'];
	$t1= date('H:i',strtotime($timeout) );
	$t2= date('H:i',strtotime($timeback) );
	$reason=$_POST['reasonx'];
	mysqli_query($con, "delete from shortapou where date='$date' and pmp='$pmp'" );
	$sql=mysqli_query($con, "insert into shortapou (date,pmp,timeout,timeback,reason)
	values ('$date','$pmp','$t1','$t2','$reason' )");
}
 
?>	
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>

</body>
</html>