<?php
session_start();
if ($_SESSION['islogin']=='' ) { 
  echo "ΠΡΕΠΕΙ ΝΑ ΕΓΓΡΑΦΕΙΤΕ ΓΙΑ ΝΑ ΧΡΗΣΙΜΟΠΟΙΗΣΕΤΕ ΤΟ ΣΥΣΤΗΜΑ"."<BR>";
  sleep(2);
  header("Location: loginall.php"); /* Redirect browser */
  exit();
  }
$menu=$_SESSION['menu'];
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:600px;
	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>

<?php
$dt=$_SESSION['dt'];
$time=date("H:i:s");
$data=$_GET['data'];
$ar=explode("/",$data);
$mitroo=$ar[0];
$nid=$ar[1];
//echo $nid;
$sql=mysqli_query($con,"select * from simvrantevou where id='$nid' ");
if (mysqli_num_rows($sql)==0)
{
	$datex=$dt;
	$timefrom=date("H:i:s",time());
    $timeto=date("H:i:s",time());
    $perigrafi=" ";
    $energies=" ";
}
else
{
  $row=mysqli_fetch_array($sql);
  $datex=$row['date'];
  $id=$row[id];
  $timefrom=$row['timefrom'];
  $timeto=$row['timeto'];
  $perigrafi=$row['perigrafi'];
  $energies=$row['energies'];
}

?>
<form  name="problems" method="post" >
<fieldset fieldset class="fieldset" >
<legend> <?php echo "<b>"."ΣΤΟΙΧΕΙΑ ΑΚΡΟΑΣΗΣ"."</b>"; ?> </legend>
<p>Ημερμηνία:<input type='date' name='datex' value ='<?php echo $datex; ?>' /></p>
<p>Ώρα Έναρξης:<input  type='time' name='timefrom' value='<?php echo $timefrom;?>' />
&nbsp&nbsp&nbsp&nbsp&nbspΏρα λήξης:<input type='time'  name='timeto' value='<?php echo $timeto; ?>'/></p>
<p>
ΠΕΡΙΓΡΑΦΗ:<br>
<textarea name='perigrafi' required rows="6" cols="80"><?php echo $perigrafi; ?></textarea>
</p><p>
ΣΧΟΛΙΑ / ΕΝΕΡΓΕΙΕΣ:<br>
<textarea name='energies' rows="6" cols="80" > <?php echo $energies; ?></textarea>
</p>
<input type='hidden' name='hid' value = '<?php echo $id; ?>' />
<input type='hidden' name='mitroo' value = '<?php echo $mitroo; ?>' />
<input type="Submit" name="Submit" value="Καταχώρηση" >
</fieldset>
</form>
<?php

if (isset($_POST['Submit'])) 
{
	$datex=$_POST['datex'];
	$mitroo=$_POST['mitroo'];
	$timefrom=$_POST['timefrom'];
	$timeto=$_POST['timeto'];
	$perigrafi=$_POST['perigrafi'];
	$energies=$_POST['energies'];
	$id=$_POST['hid'];
	$sql=mysqli_query($con,"select * from simvrantevou where id='$nid' ");
    if (mysqli_num_rows($sql)==0)
    {
		$sql="insert INTO simvrantevou  (mitroo,date,timefrom,timeto,perigrafi,energies) values  ('$mitroo','$datex','$timefrom','$timeto','$perigrafi','$energies') ";
	    if (mysqli_query($con, $sql)) {
            echo "H ΝΕΑ ΕΓΓΡΑΦΗ ΕΓΙΝΕ ΜΕ ΕΠΙΤΥΧΙΑ";
        } 
		else 
		{
            echo "Error updating record: " . mysqli_error($con);
        }  
	}
    else
    {	
		$sql="update simvrantevou  set date='$datex',timefrom='$timefrom',timeto='$timeto',perigrafi='$perigrafi',energies='$energies' where id='$id' ";
	    if (mysqli_query($con, $sql)) 
		{
            echo "ΤΟ ΑΡΧΕΙΟ ΕΝΗΜΕΡΩΘΗΚΕ ΜΕ ΕΠΙΤΥΧΙΑ";
        } 
		else 
		{
            echo "Error updating record: " . mysqli_error($con);
        }
	}
}

?>	
<br /><br />
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</body>
</html>