<?php
include "scrinit.php";
include "logo.php";
require "dbconnect.php";
date_default_timezone_set("Europe/Athens");
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style>
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
.fieldset
{
    width:900px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
</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,w,h);
}
</script>
<body>
<h4> ΗΜΕΡΟΛΟΓΙΟ ΗΜΕΡΙΣΙΩΝ ΕΡΓΑΣΙΩΝ/ΣΥΜΒΑΝΤΩΝ</h4>
<?php
$dt=$_SESSION['dt'];
$time=date("H:i:s");
$daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
$datedisp= date('d-m-Y', strtotime($dt)); 
$day = date('D', strtotime($dt));
$daytext = $daymap[date('w', strtotime($dt))];

$datex=$dt;
$timefrom=date("H:i:s",time());
$timeto=date("H:i:s",time());
$usr=$_SESSION['usr'];
$its = $_GET['itemSelect'];
?>
<form  name="hmrologio2" method="post" >
<fieldset fieldset class="fieldset" >
<br>

<?php
switch ($its) 
{
    case 1:
        $code= "ΓΕΝΙΚΟ";
		
        break;
    case 2:
		echo "ΕΚΠΑΙΔΕΥΤΙΚΟΣ:";
        $code= "ΚΑΘΗΓΗΤΕΣ";
		$result=mysqli_query($con,"select PMP,Name from teachers order by Name");
		
		echo "<select name='vsel' id='teach'>";
	    while ($row = mysqli_fetch_array($result)) 
		{
			echo "<option value='" . $row['PMP'] . "'>" . $row['Name'] . "</option>";
		}
		echo "</select>";
        break;
    case 3:
		echo "ΓΟΝΕΙΣ ΜΑΘΗΤΗ/ΜΑΘΗΤΡΙΑΣ:";
        $code= "ΓΟΝΕΙΣ";
		$result=mysqli_query($con,"select mitroo,eponimo,onoma,tmima from allstudentinfo order by tmima,eponimo,onoma");
		
		echo "<select name='vsel' id='student'>";
	    while ($row = mysqli_fetch_array($result)) 
		{
			$d=$row['tmima']." ".$row['eponimo']." ".$row['onoma'];
			echo "<option value='" . $row['mitroo'] . "'>" . $d . "</option>";
		}
		echo "</select>";
        break;
	case 4:
        $code= "ΜΑΘΗΤΕΣ";
        break;
    case 5:
        $code= "ΕΠΙΘΕΩΡΗΤΕΣ";
        break;
    case 6:
        $code= "ΤΟΥ ΥΠΟΥΡΓΕΙΟΥ";
        break;	
    default:
        echo "ΔΕΝ ΥΠΑΡΧΕΙ";
}
?>
<legend> <?php echo "<b>".$code."</b>"; ?> </legend>
<p>HMEROMHNIA:<input type='date' name='datex' value ='<?php echo $datex; ?>' />
&nbsp&nbsp&nbsp&nbspΕΝΑΡΞΗ:<input  type='time' name='timefrom' value='<?php echo $timefrom;?>' />
&nbsp&nbsp&nbsp&nbspΛΗΞΗ:<input type='time'  name='timeto' value='<?php echo $timeto; ?>'/>
&nbsp&nbsp&nbsp&nbspΠΕΡΙΟΔΟΣ:<input type='text'  name='per' size='3'/></p>
<table>
<tr>
<td>
ΠΕΡΙΓΡΑΦΗ:<br>
<textarea name='perigrafi' required rows="10" cols="60"><?php echo $perigrafi; ?></textarea></td>
<td>
ΣΧΟΛΙΑ / ΕΝΕΡΓΕΙΕΣ:<br>
<textarea name='energies' rows="10" cols="60" > <?php echo $energies; ?></textarea></td>
</tr>
</table>
<input type='hidden' name='its' value = '<?php echo $its; ?>' />
</fieldset>
<br>
<input type="Submit" name="Submit" value="Καταχώρηση και Επιστροφή" >
&nbsp&nbsp&nbsp&nbsp<input type="button" name="epistrofi" value="Ακύρωση και Επιστροφή" onClick="self.close()"> 
</form>
<?php

if (isset($_POST['Submit'])) 
{
	$datex=$_POST['datex'];
	$whois=$_POST['vsel'];
	$whocode=$_POST['its'];
	$times=$_POST['timefrom'];
	$timef=$_POST['timeto'];
	$perigrafi=$_POST['perigrafi'];
	$sxolia=$_POST['energies'];
	$per=$_POST['per'];
	
	//if ($whocode==2)
	//{
    $sql="insert INTO imerologio  (pmp,date,times,timef,period,perigrafi,whocode,whois,sxolia) 
	values  ('$usr','$datex','$times','$timef','$per','$perigrafi','$whocode','$whois','$sxolia') ";
	    if (mysqli_query($con, $sql)) {
            echo "H ΝΕΑ ΕΓΓΡΑΦΗ ΕΓΙΝΕ ΜΕ ΕΠΙΤΥΧΙΑ";
        } 
		else 
		{
            echo "Error updating record: " . mysqli_error($con);
        }  
	//}
    
	echo "<script>window.close();</script>";
}

?>	
<br /><br />

</body>
</html>