<?php
include "scrinit.php";
include $menu;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.fieldset
{
    width:700px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;	
    border-radius:4px;	
}
</style>

</head>

<body>

<?php
require("dbconnect.php");

$name=$_SESSION['n'];
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];

$sql = "SELECT * FROM offperiods ORDER BY datefrom ASC";
$result = mysqli_query($con,$sql);
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } 
?>
<form  method="post"   > 
<fieldset fieldset class="fieldset" >
<legend><b>EΠΕΛΕΞΕ ΝΕΑ/ΥΦΙΣΤΑΜΕΝΗ ΕΚΔΗΛΩΣΗ</b> </legend>
<br>
<?php

$i=2;
echo "<select name='ekdilo1'>";

$ekdilo[1]="ΝΕΑ ΕΓΓΡΑΦΗ";
echo "<option value ='".$ekdilo[1]."'>".$ekdilo[1]."</option>";
while ($row = mysqli_fetch_array($result)) 
{
	$ekdilo[$i]=$row['description'];
	$df[$i]=date('d-m-Y', strtotime($row['datefrom'])); 
	$dispekd[$i]="(".$df[$i].")".$ekdilo[$i];
   	echo "<option value ='".$ekdilo[$i]."'>".$dispekd[$i]."</option>";
	$i++;
}
echo "</select>";
?>&nbsp&nbsp&nbsp	
<input type="Submit" name="ekd1" value="Επιλογή Αργείας/Εκδήλωσης" >
<br>
</fieldset>
</form>	

<?php

if (isset($_POST['ekdilo1'])) 
{
$ekdilo=" ";
$ekdilo1=$_POST['ekdilo1'];
if ($ekdilo1 != "ΝΕΑ ΕΓΓΡΑΦΗ")
{
$sql = "SELECT * FROM offperiods WHERE description='$ekdilo1'";
$result = mysqli_query($con,$sql);	
$row = mysqli_fetch_array($result);
$datefrom = $row['datefrom'];
$dateto=$row['dateto'];
$perapo = $row['perapo'];
$permexri = $row['permexri'];
$tmimafrom=$row['tmimafrom'];
$tmimamexri=$row['tmimamexri'];
$id=$row['id'];
$ekdilo = $ekdilo1;
$flag=1;

}
else {$ekdilo=" ";
$tmimafrom="Επιλογή";
$tmimamexri="Επιλογή";
$flag=0;
}
$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ");
?>
<br><br><br>
<form  method="post" action = "offperiods1.php" > 
<fieldset fieldset class="fieldset" >
<legend> ΣΤΟΙΧΕΙΑ ΕΚΔΗΛΩΣΗΣ:<?php echo $ekdilo1;  ?> </legend>
<br > ΑΠΟ ΗΜΕΡΟΜΗΝΙΑ : <input type="date"  name = 'datefrom' value= <?php echo $datefrom; ?> > 
 ΜΕΧΡΙ ΗΜΕΡΟΜΗΝΙΑ : <input type="date"  name = 'dateto' value= <?php echo $dateto; ?> ><br > <br >
ΑΡΓΕΙΑ/ΕΚΔΗΛΩΣΗ  :<input type='text' name='ekdilo' size = '60' value="<?php echo $ekdilo; ?>" /> <br > 
<br > ΑΠΟ ΠΕΡ.  :<input type='number' name='perapo' value ="<?php echo $perapo; ?>"  /> 
ΜΕΧΡΙ ΠΕΡ.:<input type='number' name='permexri' value = "<?php echo $permexri; ?>" /> <br /> <br >

<label>ΤΜΗΜΑ ΑΠΟ : </label>
<select name='tmimaf' >
<option value=<?php echo $tmimafrom;?> > <?php echo $tmimafrom;?> </option>
    <?php
	while($row2 = mysqli_fetch_array($sql2) ) 
	{
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
    }
?>
</select> 
	 
<label>ΤΜΗΜΑ ΜΕΧΡΙ: </label>
<select name='tmimat' >
<?php
$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ");	
?>  
<option value=<?php echo $tmimamexri;?> > <?php echo $tmimamexri;?> </option>
<?php
    while($row2 = mysqli_fetch_array($sql2) ) 
	{
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
    }
?>
</select> 
<input type="hidden"  name = 'flag' value= <?php echo $flag; ?> > 
<input type="hidden"  name = 'id' value= <?php echo $id; ?> > 	 
<br /> <br ><br >	 
<input type="Submit" name="Submitekd" value="Καταχώρηση" >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<input type="Submit" name="Submitdel" value="Διαγραφή Εκδήλωσης" 
       onClick='return confirm("Να προχωρήσει η διαγραφή της Εκδήλωσης;")'  >
</fieldset>
</form>	

<?php
}

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