<?php
include "scrinit.php";
include $menu;
$dt=$_SESSION['dt'];
$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
//$day = date('D', strtotime($date));
$daytext = $daymap[date('w', strtotime($dt))]; 

?>

<head>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:3px;font-size:14px; }
<p style="font-size:12px;"></p>
</style>
</head>

<body>

<?php
$gym=$_SESSION['gym'];
require "dbconnect.php";
$day = date('D', strtotime($dt));
$dayper=$day.$gym;

$sqlv=mysqli_query($con, "SELECT e.pmp,t.Name  FROM efimeries as e,teachers as t  WHERE e.pmp=t.PMP and dayper='$dayper' ");
$rowv=mysqli_fetch_array($sqlv);
$vdname=$rowv['Name'];
echo "<table  class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73' >
<th>ΕΦΗΜΕΡΕΥΩΝ/ΟΥΣΑ ΒΟΗΘΟΣ ΗΜΕΡΑΣ</th> </tr>";
echo "<tr>";
echo "<td>"."<b>"."<p style='font-size:16px;'>".$vdname."</p>";"</b>"."</td>";
echo "</tr>"."</table>";

echo "<br>";
echo "<br>"."<b>"."ΕΦΗΜΕΡΕΥΟΝΤΕΣ/ΟΥΣΕΣ ΒΟΗΘΟΙ ΑΝΑ ΠΕΡΙΟΔΟ"."</b>"."<br>";
//echo "<br>";

$dates=rangeWeek($dt);
$startdate=$dates['start'];

$x=strtotime($startdate);
for ($i=1;$i<=5;$i++)
{
	$dayar[$i]=date('d-m-Y',$x);
	$x = strtotime("+1 day", $x);	
}


 function rangeWeek($datestr) {
    date_default_timezone_set(date_default_timezone_get());
    $dt = strtotime($datestr);
    $res['start'] = date('N', $dt)==1 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('last monday', $dt));
    $res['end'] = date('N', $dt)==7 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('next sunday', $dt));
    return $res;
    }
//.....................................................	
$ef=array();
$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
$sqlv=mysqli_query($con, "SELECT e.*,t.Name  FROM efimeries as e,teachers as t  WHERE e.pmp=t.PMP  order by e.dayper ASC");
while($rowv=mysqli_fetch_array($sqlv))
{
	$dx=$rowv['dayper'];
	$d=substr($dx, 0, 3);
	$r=array_search($d, $dayf);
	$per=substr($dx, -1);
	$vdname=$rowv['Name'];
	$ef[$per][$r]=$vdname;
}

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>Περ.</th>
<th>Δευτερα</th>
<th>Τρίτη</th>
<th>Τετάρτη</th>
<th>Πέμπτη</th>
<th>Παρασκευή</th>
</tr>";
echo "<tr>";
echo "<td>".""."</td>";
echo "<td>".$dayar[1]."</td>";
echo "<td>".$dayar[2]."</td>";
echo "<td>".$dayar[3]."</td>";
echo "<td>".$dayar[4]."</td>";
echo "<td>".$dayar[5]."</td>";
echo "</tr>";
for ($k=1;$k<=$gym;$k++)
{
   echo "<tr>";
   echo "<td>".$k."</td>";
   for ($x=1;$x<=5;$x++)
   { 
	   echo "<td>".$ef[$k][$x]."</td>";
   }
   
}
echo "</table>";



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