<?php
include "scrinit.php";
include $menu;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<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>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=700, height=600, top='+top+', left='+left);
}

</script>
</head>

<body>

<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];

echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>A/A</th>
<th>ΜΗΤΡΩΟ</th>
<th>ΚΑΘΗΓΗΤΗΣ</th>
<th>ΗΜΕΡΑ</th>
<th>ΠΕΡΙΟΔΟΣ</th>";
?>
<h3> ΠΡΟΓΡΑΜΜΑ ΕΠΙΣΚΕΨΗΣ ΓΟΝΕΩΝ/ΚΗΔΕΜΟΝΩΝ </h3>
<p> </p>
<form method="post" >
<?php
$sql = $dbcon->prepare("SELECT pmp,Teacher FROM timetable where (id % 2 <> 0)");
$sql->execute();
$epday=$epper=array();
$i=1;
while ($row=$sql->fetch(PDO::FETCH_ASSOC))
{
	$epday[$row['pmp']]='';
	$epper[$row['pmp']]='';
	$epmp[$i]=$row['pmp'];
	$ekath[$i]=$row['Teacher'];
	$i++;
}
$sql1 = $dbcon->prepare("SELECT * FROM episkepsis ");
$sql1->execute();

while ($row1=$sql1->fetch(PDO::FETCH_ASSOC))
{
	$epday[$row1['pmp']]=$row1['day'];
	$epper[$row1['pmp']]=$row1['period'];
}
$n=count($epmp);

for ($i=1;$i<=$n;$i++)
{

	echo "<tr>";
	echo "<td>".$i. "</td>";
	echo "<td>".$epmp[$i]. "</td>";
	echo "<td>".$ekath[$i]. "</td>";
    echo "<td> <input type='text' name='ed[$i]' value='".$epday[$epmp[$i]]."'  size='12'/> </td>";
	echo "<td> <input type='text' name='ep[$i]' value='".$epper[$epmp[$i]]."' size='6'  /> </td>";
	echo "<input type='hidden' name='epm[$i]' value='".$epmp[$i]."'  /> </td>";
	echo "</tr>";
}

echo "</table>";
?>
	
<p><input type="submit" value="Καταχώριση Στοιχείων" name="submitef">
<input type="button" value="ΠΜΠ ΒΟΗΘΩΝ" onclick="window.open('bdpmp.php','','width=400,height=600')" />
</p>
<?php
if(isset($_POST['submitef']))
{
	mysqli_query($con,'TRUNCATE TABLE episkepsis;');
	$ed=$_POST['ed'];
	$ep=$_POST['ep'];
	$pmp=$_POST['epm'];
	$n=count($pmp);
    for ($i=1;$i<=$n;$i++)
    {
	    $sql = $dbcon->prepare("INSERT INTO episkepsis (pmp,day,period) values (?,?,?) "); 	
	    $sql->execute([$pmp[$i],$ed[$i],$ep[$i]]);	
    }	
	
}
 ?>
<br /><br />
<a  href=<?php echo $menu; ?>  style="color:blue "  > <button>  Επιστροφή στο Μενού  </a>

</body>
</html>