<?php
include "scrinit.php";
include $menu;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<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>
<style>
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
.fieldset
{
    width:750px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
.select {overflow-y: scroll;}
</style>
<body>
<?php
require("dbconnect.php");
$name=$_SESSION['n'];
$usr=$_SESSION['pmp'];
$dt=$_SESSION['dt'];
$ac=$_SESSION['access'];
echo "<p class='p1'>"."EΠΕΛΕΞΕ ΝΕΑ/ΥΦΙΣΤΑΜΕΝΗ ΔΡΑΣΤΗΡΙΟΤΗΤΑ:"."</p> ";
if ($ac == 1) 
{
	$sql = "SELECT onoma,code,date FROM ekdilosi where teacher='$usr' and katddk <> 0 order by date DESC";
	$result = $dbcon->prepare($sql);
	$result->execute([$usr]);
} 
else 
{ 
   $sql = "SELECT onoma,code,date FROM ekdilosi where katddk <> 0 order by date desc";
   $result = $dbcon->prepare($sql);
   $result->execute();
}
///// get next autoinncrement
$sqlx = "SHOW TABLE STATUS LIKE 'ekdilosi'";
$resultx=$con->query($sqlx);
$rowx = $resultx->fetch_assoc();
$ncode= $rowx['Auto_increment'];

$ekdilo=array();
if (isset($_POST['ekd1']))
{
	$ekdilo1[1]=$_POST['ekdilo1'];}
else
{
	$ekdilo[1]="ΝΕΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑ";
}

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

<?php
$i=1;
echo "<select name='ekdilo1'>";
echo "<option value ='".$ekdilo[$i]."'>".$ekdilo[$i]."</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=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$ekdilo="";
$_SERVER['PHP_SELF'];
$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>
<form  method="post" action = "ekdin.php" > 
<fieldset fieldset class="fieldset" >
<legend>ΣΤΟΙΧΕΙΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑΣ:<?php echo "<b>".$ekdilo1."</b>";  ?> </legend>
<p> ΗΜΕΡΟΜΗΝΙΑ:<input type="date"  name = 'dat' value= <?php echo $dat; ?> required >  </p >
<p> ΔΡΑΣΤΗΡΙΟΤΗΤΑ  :<input type='text' name='ekdilo' size = '60' value="<?php echo $ekdilo; ?>" required >
 ΚΩΔΙΚΟΣ:<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; ?>" required /> 
ΜΕΧΡΙ ΠΕΡ.:<input type='text' name='permexri' size = '3' value = "<?php echo $permexri; ?>" required /> </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>