<?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'];}
			
	 }
}

$sql=mysqli_query($con,"select mitroo from wc where date='$dt' and teacher='$usr' and lesson='$lesson' and period='$per' ");
$c2= mysqli_num_rows($sql);
if ($c2 > 0)
while ($row = mysqli_fetch_array($sql))
{	
	for($i=1;$i<=$crow1;$i++)
     {
		if ( $mt[$i]== $row['mitroo']){
	    	$wc[$i]='checked';}
			
	 }
}

$sql=mysqli_query($con,"select mitroo,period from wc where date='$dt' and teacher='$usr' and lesson='$lesson' order by period ");
$c2= mysqli_num_rows($sql);
if ($c2 > 0)
{
while ($row = mysqli_fetch_array($sql))
{	
	$mit=$row['mitroo'];
	$wcr[$mit]=$wcr[$mit].",".$row['period'];
}
}
?>
<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>W/C</th>
<th>WCR</th>
<th>Στολή/Εμφ</th>
<th>Εκτός τάξης/Να μπαίνει απουσία</th>
<th>Rapid Test</th>
</tr>";

$i=1;
while($i<=$crow1)
{
 //////////////////////////////// display apousies periodon///////////////////////
 $mtr=$mt[$i];
 $per1=array();
 $katoiko=mysqli_query($con,"SELECT * FROM noapousies WHERE mitroo='$mt[$i]' and fromdate <= '$dt' AND todate >=  '$dt'");
			$rowk=mysqli_fetch_array($katoiko);
			if (!empty($rowk)) $ap[$i]="disabled";
 $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='<?php echo $mt[$i];?>' name='att[]' <?php echo $ap[$i];?> ></td> <?php
		 }
		 else 
		 {
	       if ($per1[$p]==1) { echo "<td bgcolor='#FF0000'>" ." ". "</td>"; }
		   else { echo "<td >" ." ". "</td>";}}
	 }
	 $mit=$mt[$i];
	 $wr=trim($wcr[$mit],',');
	 echo "<td>". "<input type='text' name='kath[]' value='$kath[$i]' size='3'   >" ."</td>";
	 echo "<td>". "<input type='checkbox' value='$mt[$i]' name='wc[]' $wc[$i] size='3'>" ."</td>";
	 echo "<td>". "<input type='text' name='wcr1' value='$wr' size='3' readonly  >" ."</td>";
	 echo "<td>". "<input type='checkbox' value='$mt[$i]' name='stoli[]' $stoli[$i] size='3'>" ."</td>"; 
	 
	$dr=''; 
///////////////////////////////................
	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) $dr=$onomaekd[$i1];
		 }		   
		 $i1++; 
		}
	 }
	 if ($ap[$i] == 'disabled') $dr='Kατ οίκον εκπ/ Εναλλακτικό';
	 
	 ///////////////////////////
	 $cov=mysqli_query($con, "select * from spiticovid where mitroo='$mt[$i]'");
	 $cv=mysqli_num_rows($cov);
	
     if ($cv > 0)
	 {
	    $rowc=mysqli_fetch_array($cov);
		$dout=$rowc['dateout'];
		$din=$rowc['dateback'];
		$r=$rowc['reason'];
		if ($r=='3')
		{
			$dr='Ε-ΟΜΑΔΑ';
		}
		else
		{
		if (($dt >= $dout and $dt < $din) )
		{
			switch ($r) 
			{
				case 1:
					$dr='ΚΡΟΥΣΜΑ';
					break;
				case 2:
					$dr='ΕΠΑΦΗ';
					break;
			}
		}
		else
		{
			if ($dt == $din)
			{
			$dr='ΕΠΙΣΤΡΕΦΕΙ '.date('d-m-Y', strtotime($din)); 
			}
		}
		}
		
	 }
	 echo "<td>".$dr."</td>";
	//if ($ap[$i] == 'disabled') { echo "<td>". "ΕΝΑΛΛΑΚΤΙΚΟ" ."</td>"; }
	 //if ($omada=='Α') {$omx='Β';} else {$omx='Α';}
	 //if ($ap[$i] == 'disabled' ) { echo "<td>"."ΟΜΑΔΑ ".$omx."</td>"; }
	
	$x=$mt[$i];
	$sqlr = mysqli_query($con,"SELECT mpoli,covid,testdate from rapidimg where mitroo='$x' ");
	$rowr=mysqli_fetch_array($sqlr);
	$dcovid=$rowr['covid'];
    $drapid=$rowr['testdate'];
	$mpoli=$rowr['mpoli'];
	$dater = strtotime("+3 day", strtotime($drapid));
	$dat= date('d-m-Y', $dater);
	
	if ($mpoli === '0')
	{
	if( strtotime($dcovid) == strtotime('0000-00-00'))
	{
		
	    if(strtotime($dt) > strtotime($dat) )
			{
				?><td style='background-color: #FF0000;'><b><?php echo "ΕΛΗΞΕ/".$dat;?></b></td><?php
				echo "<td>". "<input type='date' name='newdr1[$mt[$i]]' value='$newdr1[$i]' >" ."</td>";
				echo "<input type='hidden' name='mitr[]' value='$mt[$i]' >";
			}
	}
	}
	 
	 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>



