<?php
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="style1.css" rel="stylesheet" type="text/css" />

</head>
<body>
<p class="p1"> ΑΠΟΥΣΙΟΛΟΓΙΟ ΜΑΘΗΜΑΤΟΣ </p>
<?php
echo "Ημερομηνία:".date('d-m-Y', strtotime($dt));
$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" />
Περίοδος:&nbsp <input type='text' name='per' value=<?php echo $per; ?> size='3' /> 
&nbsp;&nbsp;&nbspΤμήμα/Συνδ.:&nbsp <input type='text' name='lesson' value=<?php echo $lesson; ?> /> 
&nbsp;&nbsp;&nbspΜαθημα:&nbsp <select name="subjectx">
<?php
echo "<option value='$subject'>$subject</option>";
echo "<option value='Δ.Δ.Κ'>Δ.Δ.Κ</option>";
?>
</select>
<?php
if ($subject == 'Δ.Δ.Κ')
{	
$d=$gym+1;
}
else
{
$d=$gym;	
}

?>
<p>
<input type="button" class="bt1"
              id="toggle" value="Επιλογή όλων των μαθητών/τριών" onClick="do_this()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class="bt2" value="** ALERT ΟΜΑΔΑ ΑΣΦΑΛΕΙΑΣ **" onclick="window.open('smstoasf.php?alp=<?php echo $per;?>','','width=500,height=200')" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class="bt2" value="** ALERT Δ/ΤΗΣ**" onclick="window.open('smstohead.php?alp=<?php echo $per;?>','','width=500,height=200')" />
<?php include "rooms.php";?>
</p>
<?php
FUNCTION smshd()
{
 include "smstohead.php";
 }
FUNCTION smsasf()
{
 include "smstoasf.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: 14pt'>".$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='6'   >" ."</td>";
	 echo "<td>". "<input type='checkbox' value='$mt[$i]' name='stoli[]' $stoli[$i] size='6'>" ."</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>"; }
	 if ($omada=='Α') {$omx='Β';} else {$omx='Α';}
	 if ($ap[$i] == 'disabled' ) { echo "<td>"."ΟΜΑΔΑ ".$omx."</td>"; }
	 echo "</tr>";
     $i++;
}
echo "</table>";
$_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);
 $perigrafi=$row['perigrafi'];
echo "<textarea name='perigrafi' cols='100' rows='3'> $perigrafi </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="Καταχώρηση Απουσιολογίου" class="sb">
</form> 
<?php echo " &nbsp&nbsp&nbsp ";?> 
<input type="button" class="bt3" onclick="window.open('listsylabi.php?kathmath=<?php echo $tm;?>','','width=600,height=500')" value="Προγραμματισμός Μαθήματος" />
&nbsp&nbsp&nbsp <input type="button" class="bt3" onclick="window.open('proforikos.php?kathmath=<?php echo $tm;?>','','width=800,height=800')" value="Ημερήσια Προφορική Αξιολόγηση" />
&nbsp&nbsp&nbsp <input type="button" class="bt3" onclick="window.open('profsynoptiko.php?kathmath=<?php echo $tm;?>','','width=1200,height=900')" value="Συνοπτικό Βαθμολόγιο Προφορικού" />
</body>
</html>



