<?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>ΠΕΡ.</th>
<th>ΔΕΥΤΕΡΑ</th>
<th>ΤΡΙΤΗ</th>
<th>ΤΕΤΑΡΤΗ</th>
<th>ΠΕΜΠΤΗ</th>
<th>ΠΑΡΑΣΚΕΥΗ</th>";
?>
<h3> ΕΦΗΜΕΡΕΥΟΝΤΕΣ ΒΟΗΘΟΙ </h3>
<p> Ο εφημερεύων της ημέρας δηλώνεται στη θέση 0. 
Την πρώτη περίόδο δεν δηλώνεται ο εφημερέυων ημέρας αλλά ο εφμερέυων 1ης περ.
</p>
<form method="post" >
<?php

$sql = $dbcon->prepare("SELECT * FROM efimeries order by id asc ");
$sql->execute();
for ($d=1;$d<=5;$d++)
{
	for ($i=0;$i<=$gym;$i++)
	{
		$row=$sql->fetch(PDO::FETCH_ASSOC);
		$ef[$i][$d]=$row['pmp'];
	}
}

for ($i=0;$i<=$gym;$i++)
{
	echo "<tr>";
	echo "<td>".$i. "</td>";
	for ($d=1;$d<=5;$d++)
	{
		echo "<td> <input type='text' name='efim[$i][$d]' value='".$ef[$i][$d]."'  size='6'/> </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 efimeries;');
	$ef=$_POST['efim'];
	$dayt=array('Sun','Mon','Tue','Wed','Thu','Fri');
	try
    { 
	for ($d=1;$d<=5;$d++)
	{
		for ($i=0;$i<=$gym;$i++)
		{
		   $dp=$dayt[$d].$i;
		   $sql = $dbcon->prepare("INSERT INTO efimeries (pmp,dayper) values (?,?) "); 	
		   $sql->execute([$ef[$i][$d],$dp]);	
		}
	}
	}	
	catch(PDOException $e)
	{
	   handle_sql_errors($selectQuery, $e->getMessage());
	}
} 
function handle_sql_errors($query, $error_message)
{
    echo '<pre>';
    echo $query;
    echo '</pre>';
    echo $error_message;
    die;
}

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

</body>
</html>