<?php
?><h3>ΑΠΟΥΣΙΕΣ ΑΝΑΠΛΗΡΩΣΗΣ <?php echo " (".date('d-m-Y', strtotime($dt)).") "; ?></h3>
<?php
//////////////////////////////////////////////////////////////////////////////////////////
$crow1=count($mt);
$res1=$dbcon->prepare("SELECT code,onoma FROM ekdilosi WHERE date=? ");
$res1->execute([$dt]);
$c1 = $res1->rowCount();

 if ($c1 > 0)  {  
 $i=0;
 while ($row = $res1->fetch(PDO::FETCH_ASSOC))
     {
	 $codekd[$i]=$row['code'];
	 $onomaekd[$i]=$row['onoma'];
	 $i++;
    }
 }

$sql=$dbcon->prepare("SELECT a.mitroo,a.apousia,al.tmima FROM apousies as a,allstudentinfo as al
WHERE a.mitroo=al.mitroo AND a.dateout=? AND a.teacher=? 
AND a.mathima=? AND a.period=? AND a.apousia=1 " );
$sql->execute([$dt,$usr,$lesson,$per]);
$c2 = $sql->rowCount(); 

while ($row = $sql->fetch(PDO::FETCH_ASSOC))
{	
	for($i=1;$i<=$crow1;$i++)
     {
		if ( $mt[$i]== $row['mitroo'])
		{
			 $ap[$i]='checked';
			 $stir= $dbcon->prepare("SELECT * FROM stiriksi WHERE mitroo=? AND lessonout=? AND day=? AND period=?");
             $stir->execute([$mt[$i],$lesson,$day,$per]);
             $cnt = $stir->rowCount();
			 if ($cnt > 0){$ap[$i]='disabled';}
			 
			 $apal=$dbcon->prepare("SELECT * FROM apallages WHERE mitroo='$mt[$i]' AND teachout='$usr' AND dayout='$day' AND perout='$per'");
			 $apal->execute([$mt[$i],$usr,$day,$per]);
             $cnta = $apal->rowCount();
			 if ($cnta > 0){$ap[$i]='disabled';}
		}
	 }
}
	 
$sql=$dbcon->prepare("SELECT apousies.mitroo, apousies.stoli,allstudentinfo.tmima FROM apousies,allstudentinfo 
WHERE apousies.mitroo=allstudentinfo.mitroo AND apousies.dateout=? AND apousies.teacher=? 
AND apousies.mathima=? AND apousies.period=? AND apousies.stoli=1" );
$sql->execute([$dt,$usr,$lesson,$per]);
$c2= $sql->rowCount();

while ($row = $sql->fetch(PDO::FETCH_ASSOC))
{	
	for($i=1;$i<=$crow1;$i++)
     {
		if ( $mt[$i]== $row['mitroo']){
			 $stoli[$i]='checked';}
	 }
}


$sql=$dbcon->prepare("SELECT a.mitroo, a.kath, al.tmima FROM apousies as a,allstudentinfo as al 
WHERE a.mitroo=al.mitroo AND a.dateout=? AND a.teacher=? 
AND a.mathima=? AND a.period=? AND a.kath > 0 " );
$sql->execute([$dt,$usr,$lesson,$per]);
$c2= $sql->rowCount();
while ($row = $sql->fetch(PDO::FETCH_ASSOC))
{	
	for($i=1;$i<=$crow1;$i++)
     {
		if ( $mt[$i]== $row['mitroo']){
	    	$kath[$i]=$row['kath'];}
			
	 }
}

?>

<form method="POST" name = "eggrafi" action="eggrafi.php" onSubmit="return tempty()">
 
<?php
echo " Περίοδος :<input type='text' name='per' value='$per' size='3' /> ";
echo " Τμήμα/Συνδ.:<input type='text' name='lesson' value='$lesson' /> ";
?>
Μαθημα:<select name="subjectx">
<?php
echo "<option value='$subject'>$subject</option>";
echo "<option value='Δ.Δ.Κ'>Δ.Δ.Κ</option>";
?>
</select>
<?php
echo "<br>"."<br>";
if ($subject == 'Δ.Δ.Κ')
{	
$d=$gym+1;
}
else
{
$d=$gym;	
}
?>
<TABLE>
<TR>
<TD>
<div style="overflow:scroll; border:1px solid black;background:#F5F9F0;width:800px; height: 550px">
<?php
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<tr bgcolor='#66CC99'>
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>";
for ($i=1;$i<=$d;$i++)
{
	$titep="π".$i;
	echo "<th style='font-size: 12pt'>".$titep."</th>";
}
echo "<th>Καθ.</th>
<th>Στολή</th>
<th>Σε Δραστηριότητα</th>
</tr>";

$i=1;
while($i<=$crow1)
{
 //////////////////////////////// display apousies periodon///////////////////////
 $mtr=$mt[$i];
 $per1=array();
 $sqlx=$dbcon->prepare("SELECT a.period,a.mitroo FROM apousies as a WHERE a.mitroo=? AND (a.apousia=1 AND a.kath IS NULL)
 AND a.dateout=? AND (a.mitroo not in (select mitroo from apousies where kath > 0 AND a.period=period and dateout='$dt')) ORDER BY period " );
 $sqlx->execute([$mtr,$dt]);
  while ($rowx = $sqlx->fetch(PDO::FETCH_ASSOC)) { $per1[$rowx['period']]=1;} 
  if($apr[$i]==1)
  {
    echo "<tr bgcolor='#E4F9FF'>";
  }
  else
  {
    echo "<tr>";
  }

	 
	 echo "<td>" .$i;
	 echo "<td>". "<input type='text' name='mt[]' value='$mt[$i]' size='3' >" . "</td>";
	 echo "<td>". "<input type='text' name='tmim' value='$tmim[$i]' size='3' >" . "</td>";
	 echo "<td>". "<input type='text' name='epo[]' value='$epo[$i]' size='30' >" . "</td>"; 
	 for ($p=1;$p<=$d;$p++){
		 if ($p == $per) 
		 {
			 echo "<td>". "<input type='checkbox' value='$mt[$i]' name='att[]' $ap[$i] >" ."</td>";
		 }
		 else 
		 {
	       if ($per1[$p]==1) { echo "<td bgcolor='#FF0000'>" ." ". "</td>"; }
		   else { echo "<td >" ." ". "</td>";}}
	 }
	 echo "<td>". "<input type='text' name='kath[]' value='$kath[$i]' size='3' >" ."</td>";
	 echo "<td>". "<input type='checkbox' value='$mt[$i]' name='stoli[]' $stoli[$i] size='3'>" ."</td>"; 
	 
///////////////////////////////................
	if ($c1 > 0 ) 
	{	 
		 $i1=0;
		 
		foreach ($codekd as $cdo) 
		{
		   
		 $q2=$dbcon->prepare("SELECT p1,p2,p3,p4,p5,p6,p7 FROM ekdilosistu WHERE pmp = ? AND code=? ");
		 $q2->execute([$mt[$i],$cdo]);
		 $c2= $q2->rowCount();
		 if ($c2 > 0)
		 { 
			$row2=$q2->fetch(PDO::FETCH_ASSOC);
			$p1=$row2['p1'];$p2=$row2['p2'];$p3=$row2['p3'];$p4=$row2['p4'];$p5=$row2['p5'];$p6=$row2['p6'];$p7=$row2['p7'];		
			$np="p".$per;
			if ($$np == 1) { echo "<td>". $onomaekd[$i1] ."</td>"; }
		 }		   
		 $i1++; 
		}
	 }
	 
	 if ($ap[$i] == 'disabled') { echo "<td>". "ΣΤΗΡΙΞΗ/ΑΠΑΛΛΑΓΗ" ."</td>"; }

	 echo "</tr>";
     $i++;
}
echo "</table>";
?>
</div>
</TD>
<td> </td>
<TD>
<div style="overflow:scroll; border:1px solid black;background:#E3CEF6;width:400px; height: 550px">
<center><b>ΤΡΟΠΟΣ ΑΠΑΣΧΟΛΗΣΗΣ ΜΑΘΗΤΩΝ</b></center>
<?php
$q3=$dbcon->prepare("SELECT * FROM apasxolisi  ");
$q3->execute();
$c3= $q3->rowCount();
$i=1;
while($row3=$q3->fetch(PDO::FETCH_ASSOC))
{
	$item=$row3['perigrafi'];
	$ch=$row3['child'];
	$level=$row3['level'];
	if ($level=='Α')
	{
		echo "<b>".$i.".".$item."</b>"."<br>";
	}
	if ($level==$ch)
	{
		$ar=explode(",",$item);
		foreach($ar as $sel)
		{
			?>
			<input type="checkbox" name="movie" value=<?php echo $sel; ?> > <?php echo $sel; ?><br>
			<?php
		}
	}
	
    $i++;	
}
?>
</TD>
</TR>
</TABLE>
</div>
<?php
$_SESSION['fg']=$i;
$tm=$usr."/".$lesson."/".$subject;

echo "<br>"."<b>"."ΠΕΡΙΓΡΑΦΗ ΤΡΟΠΟΥ ΑΠΑΣΧΟΛΗΣΗΣ"."<b>";
echo "<br>";

$sql=$dbcon->prepare("SELECT perigrafi FROM syllabi  WHERE pmp=? AND per=? AND date=?  "); 
$sql->execute([$usr,$per,$dt]);
$row=$sql->fetch(PDO::FETCH_ASSOC);
$perig=$row['perigrafi'];
?>
<textarea  id="tarea"  name="perigrafi"  cols='100' rows='3'  > <?php echo $perig; ?> </textarea ><br >

<input type="hidden" name="usr1" value='<?php echo $usr; ?>' >
<input type="hidden" name="subject" value='<?php echo $subject; ?>' >
<input type="hidden" name="lesson" value='<?php echo $lesson; ?>' >
<input type="hidden" name="per" value='<?php echo $per; ?>' >
<input type="hidden" name="pop" value='<?php echo $pop; ?>' >
<br>
<input type="Submit" name="Submitapou" value="Καταχώρηση Απουσιολογίου" >
</form> 
 


