<?php
include "scrinit.php";
include "logo.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<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>
</head>
<body>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
if (isset($_POST['aponk']))
{
   $ap=$_POST['apon'];
}
else
{
	$ap=$_SESSION['mt'];	
}
?>
<h4> ΚΑΤΑΧΩΡΗΣΗ ΗΜΕΡΟΜΗΝΙΑΣ ΚΑΙ ΛΟΓΟΥ ΑΠΟΥΣΙΑΣ</h4>

<form  method='post' >
<?php
echo "<table style='width:1130px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#adcd82'  >
<th>A/A</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
<th>ΑΠΟ ΗΜΕΡ</th>
<th>ΜΕΧΡΙ ΗΜΕΡ</th>
<th>ΛΟΓΟΣ</th>
</tr>";
$namet=array();
$i=1;
foreach($ap as $mitr)
{
    $result = mysqli_query($con,"SELECT mitroo,tmima,eponimo,onoma FROM allstudentinfo 
    where mitroo='$mitr' ORDER BY tmima,eponimo,onoma");
	$row=mysqli_fetch_array($result);
    $namet[$i]=$row['eponimo']." ".$row['onoma'];
	$tm[$i]=$row['tmima'];
	$mitrk[$i]=$mitr;
	$sq=mysqli_query($con,"SELECT * from apontestil where mitroo='$mitr'");
	$row1=mysqli_fetch_array($sq);
    $dfk[$i]=$row1['datefrom'];
    $dtk[$i]=$row1['dateto'];
    $logosk[$i]=$row1['logos'];
    echo "<tr>";
 	echo "<td>".$i."</td>";
	echo "<td >".$tm[$i]."</td>";
	echo "<td >".$mitrk[$i]."</td>";
	echo "<td >".$namet[$i]."</td>";
	echo "<td>"."<input type='date' name='df1[]' value='$dfk[$i]'>"."</td>";
    echo "<td>"."<input type='date' name='dt1[]' value='$dtk[$i]'>"."</td>";
	echo "<td>"."<input type='text' name='reasx[]' value='$logosk[$i]' size='50'>"."</td>";
	echo "</tr>";
	echo "<input type='hidden' name='mitr1[]' value='$mitrk[$i]'>";
    $i++;
}
echo "</table>";
?>
<br>
<input type="submit" name="aponk1" value="Επιβεβαίωση Επιλογών" >
</form>

<?php
if (isset($_POST['aponk1']))
{
 	
 
 $df1=$_POST['df1'];print_r($dxf);
 $dt1=$_POST['dt1'];print_r($dxt);
 $reason=$_POST['reasx'];
 $mt=$_POST['mitr1'];
 print_r($mt);
 $c=count($mt);
 $i=0; 
 for ($i=0;$i<$c;$i++)
 {		
	$mitr=$mt[$i];
	$dxf=$df1[$i];
	$dtf=$dt1[$i];
	$r=$reason[$i];
	mysqli_query($con,"delete from apontestil where mitroo='$mitr'");
	if(strtotime($dtf) <= 0) $dtf=$dxf;
	$query="insert into apontestil (mitroo,datefrom,dateto,logos) values ('$mitr','$dxf','$dtf','$r') ";
        if (mysqli_query($con, $query)) 
		{
			echo "New record created successfully";
        } 
		else 
		{
            echo "Error: " . $query . "<br>" . mysqli_error($con);
        }	
 }
$_SESSION['mt']=$mt;		
header("Location: apontestil1.php");
}
//<?php


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