<?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>
<script type="text/javascript">
function CheckedAll()
{    
     if (document.getElementById('ChkAll').checked) {
         for(i=0; i<document.getElementsByTagName('input').length;i++){
         document.getElementsByTagName('input')[i].checked = true;
         }
     }
     else {
         for(i=0; i<document.getElementsByTagName('input').length;i++){
          document.getElementsByTagName('input')[i].checked = false;
         }
     }
 }
</script>
<style>
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
.fieldset
{
    width:850px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:8px;
    -webkit-border-radius:8px;	
    border-radius:8px;	
}
.select {overflow-y: scroll;}
</style>

</head>

<body>
<h3>ΕΠΙΣΚΟΠΗΣΗ ΕΞΩΔΙΔΑΚΤΙΚΩΝ ΔΡΑΣΤΗΡΙΟΤΗΤΩΝ </h3>
<?php
require("dbconnect.php");
$name=$_SESSION['n'];
$usr=$_SESSION['usr'];
$ac=$_SESSION['access'];
$gym=$_SESSION['gym'];
echo "<BR>"."<b>"."EΠΕΛΕΞΕ ΔΡΑΣΤΗΡΙΟΤΗΤΑ:"."</b>"."<br>"."<br>";

if ($ac <=2 )
{
$sql = "SELECT onoma,code,date FROM ekdilosi WHERE teacher='$usr' and katddk<>0 order by date desc";
}
else
{
$sql = "SELECT onoma,code,date FROM ekdilosi WHERE  katddk<>0 order by date desc";	
}
$result = $dbcon->prepare($sql);
$result->execute();

?>
<form  method="post" > 

<?php
echo "<select class='select' size='10' 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'])) 
{

$ekdilo1=$_POST['ekdilo1'];
$sq=$dbcon->prepare("select * from ddkportfolio where mark <> 0 order by aa ");
$sq->execute();
$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'];
//  
?>
<fieldset fieldset class="fieldset" >
<legend>ΣΤΟΙΧΕΙΑ ΔΡΑΣΤΗΡΙΟΤΗΤΑΣ:</legend>
<p> ΗΜΕΡΟΜΗΝΙΑ:<input type="date"  name = 'dat' value= <?php echo $dat; ?> readonly="readonly" >  </p >
<p> ΔΡΑΣΤΗΡΙΟΤΗΤΑ  :<input type='text' name='ekdilo' size = '60' value="<?php echo $ekdilo1; ?>" readonly="readonly" > 
 ΚΩΔΙΚΟΣ:<input type='text' name='code' size = '5' value="<?php echo $ncode; ?>" readonly="readonly"></p > 
<p > ΑΠΟ ΠΕΡ.  :<input type='text' name='perapo' size = '3' value ="<?php echo $perapo; ?>" readonly="readonly" > 
ΜΕΧΡΙ ΠΕΡ.:<input type='text' name='permexri' size = '3' value = "<?php echo $permexri; ?>" readonly="readonly"> </p>   
</fieldset>
<?php
$result = $dbcon->prepare("SELECT pmp,tmima,p1,p2,p3,p4,p5,p6,p7,p8,p9 FROM ekdilosistu WHERE code = ? ");
$result->execute([$ncode]);
$rowcount=$result->rowCount();
////////////////////////////////////////////////////////////

echo "<br>"."ΚΑΤΑΛΟΓΟΣ ΜΑΘΗΤΩΝ"."</b>". "<br>"."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73' >
<th>α/α</th>
<th>Μητρώο</th>
<th>Τμήμα</th>
<th>Επώνυμο</th>
<th>Όνομα</th>
<th>ΠΑΡΟΥΣΙΑ</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
$mit=$tm=$pr=$cpr=array();
$i=0;
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
	 $i++;
	 $mit[$i]=$row['pmp'];
	 $tm=$row['tmima'];
	 for ($k=1;$k<=$gym;$k++)
	 {
		 $in='p'.$k;
		 if($row["$in"]==1)
		 {
			$pr[$mit[$i]][$k]=$k; 
		 }
		 else
		 {
			$pr[$mit[$i]][$k]=0;  
		 }
		 
	 }
	 $sql1 = "SELECT eponimo, onoma FROM allstudentinfo WHERE mitroo =?";
     $rt = $dbcon->prepare($sql1);
	 $rt->execute([$mit[$i]]);
	 $row1 = $rt->fetch(PDO::FETCH_ASSOC);
	 $epo=$row1['eponimo'];
	 $nm=$row1['onoma'];
	 echo "<tr>";
	 echo "<td>" .$i;
	 echo "<td>". $mit[$i] . "</td>";
	 echo "<td>". $tm. "</td>";
	 echo "<td>". $epo. "</td>";
     echo "<td>". $nm . "</td>";
	 ?>
     <td>
     <input  type='checkbox' name='apou[]' value='<?php echo $mit[$i];?>' checked /> 
     </td>
                        
     <?php
     for ($j=1;$j<=$gym;$j++)
	 {
		 
	   ?>
       <td>
       <input type='checkbox' onclick="return false;" name='p[]' value='<?php echo $pr[$mit[$i]][$j]; ?>'   <?php if($pr[$mit[$i]][$j]<>0) {echo 'checked';} else echo 'unchecked'; ?>  /> 
       </td>
	   <?php
	   
	 }
	 echo "</tr>";
	 
}
echo "</table>";
}
?>
<br><br>
<br>
<br><br>
<a  href=<?php echo $menu; ?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
</body>
</html>