<?php
include "scrinit.php";
include $menu;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<title>ΔΗΛΩΣΗ ΜΑΘΗΤΩΝ ΓΙΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑ</title>
</head>

<body>
<h3> ΕΞΩΔΙΔΑΚΤΙΚΕΣ ΔΡΑΣΤΗΡΙΟΤΗΤΑΣ </h3>
<?php
require("dbconnect.php");
$name=$_SESSION['n'];
$usr=$_SESSION['pmp'];
$dt=$_SESSION['dt'];

echo "<BR>"."<b>"."EΠΕΛΕΞΕ ΤΗΝ ΔΡΑΣΤΗΡΙΟΤΗΤΑ:"."</b>"."<br>"."<br>";

   $sql = "SELECT onoma,code,date FROM ekdilosi WHERE katddk<>0 order by date desc";
   $result = $dbcon->prepare($sql);
   $result->execute();


$s=$dbcon->prepare("select MAX(code) as maxcode from ekdilosi order by code");
$row=$s->fetch(PDO::FETCH_ASSOC);
if ($s->rowCount() > 0)
 {$ncode=$row['maxcode']+1;}
else
{$ncode=1;}
$ekdilo1=array();
if (isset($_POST['ekd1']))
{
	$ekdilo1[1]=$_POST['ekdilo1'];}
else
{$ekdilo[1]="ΝΕΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑ";}

?>
<form  method="post"  name="ekdilosi" action="drasi.php"> 

<?php
$i=2;
echo "<select name='ekdilo1'>";
echo "<option value ='".$ekdilo[1]."'>".$ekdilo[1]."</option>";
while ($row =$result->fetch(PDO::FETCH_ASSOC)) 
{
	$ekdilo[$i]=$row['onoma'];
	$code=$row['code'];$dat= date('d-m-Y', strtotime($row['date']));
   	echo "<option value ='".$ekdilo[$i]."'>".$dat." / ".$ekdilo[$i]." (".$code.") "."</option>";
	$i++;
}
echo "</select>";
?>	
<input type="Submit" name="ekd1" value="Επιλογή Δραστηριότητας" >

</form>	

<?php

if (isset($_POST['ekd1'])) 
{
$dat=$dt;
$ekdilo=" ";
$flg=1;
$_SESSION['flg']=$flg;
$ekdilo1=$_POST['ekdilo1'];
$sq=$dbcon->prepare("select * from ddkportfolio where mark <> 0 order by aa ");
$sq->execute();

if ($ekdilo1 != "ΝΕΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑ")
{
   $sql = "SELECT e.*,d.portfolio FROM ekdilosi as e,ddkportfolio as d WHERE e.katddk=d.aa and e.onoma=?";
   $result = $dbcon->prepare($sql);
   $result->execute([$ekdilo1]);
   $row =$result->fetch(PDO::FETCH_ASSOC);
   $dat = $row['date'];
   $ncode = $row['code'];
   $katddk= $row['katddk'];
   $perigkat=$row['portfolio'];
   $perapo = $row['perapo'];
   $permexri = $row['permexri'];
   $ekdilo = $ekdilo1;
   $flg=2;
   $_SESSION['flg']=$flg;
 
}
?>
<br><br><br>
<form  method="post" action = "ekdin.php" > 
<fieldset style="width: 750px; ">
<legend>ΣΤΟΙΧΕΙΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑΣ:<?php echo "<b>".$ekdilo1."</b>";  ?> </legend>
<p> ΗΜΕΡΟΜΗΝΙΑ:<input type="date"  name = 'dat' value= <?php echo $dat; ?> >  </p >
<p> ΔΡΑΣΤΗΡΙΟΤΗΤΑ  :<input type='text' name='ekdilo' size = '60' value="<?php echo $ekdilo; ?>" /> 
 ΚΩΔΙΚΟΣ:<input type='text' name='code' size = '5' value="<?php echo $ncode; ?>" /></p > 
<p> ΚΑΤΗΓΟΡΙΑ Δ.Δ.Κ. : 
<select name='portf'>
<?php
while ($row1 =$sq->fetch(PDO::FETCH_ASSOC)) 
{
	$portfolio=$row1['portfolio'];
	$kat=$row1['aa'];
	if($kat == $katddk){$sel="selected";} else {$sel="";}
   	echo "<option value ='".$kat."' ".$sel.">".$portfolio." (".$kat.") "."</option>";
	}
?>
</select> 
</p >
<p > ΑΠΟ ΠΕΡ.  :<input type='text' name='perapo' size = '3' value ="<?php echo $perapo; ?>"  /> 
ΜΕΧΡΙ ΠΕΡ.:<input type='text' name='permexri' size = '3' value = "<?php echo $permexri; ?>" /> </p>   

<br ><br ><input type="Submit" name="Submit" value="Υποβολή Στοιχείων Δραστηριότητας" >
</fieldset>
</form>	

<?php
}

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