<?php
include "scrinit.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Απουσίες Μαθήματος</title>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
<p style="font-size:10px;"></p>
</style>

</head>

<body>


<?php
$dt=$_SESSION['dt'];
$day = date('D', strtotime($dt));
$gym=$_SESSION['gym'];
$datex=$dt;
?><h4> ΑΠΟΥΣΙΕΣ ΚΑΤΑ ΜΑΘΗΜΑ/ΚΑΘΗΓΗΤΗ - <?php echo date('d-m-Y', strtotime($datex));?></h4><?php
require "allagiprog.php";
$sqlz = mysqli_query($con,"SELECT a.dateout,a.mathc,t.Name,a.teacher,a.mitroo, a.period, a.mathima,
 al.tmima,al.eponimo,al.onoma FROM apousies as a,allstudentinfo as al,teachers as t 
 WHERE (a.apousia=1 ) AND t.PMP=a.teacher AND a.dateout='$datex' AND a.mitroo=al.mitroo 
 AND (a.mitroo not in (select mitroo from apousies where kath > 0 and a.period=period and dateout='$datex')) ORDER BY a.dateout,al.tmima,a.mitroo,a.period  " );

$nr=mysqli_num_rows($sqlz);
if ( $nr> 0)
{
echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>ΑΑ</th>
<th>Μητρ</th>
<th>Τμήμα</th>
<th>Όνομα</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περ ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
$dd=date('D', strtotime($dt));
$row = mysqli_fetch_array($sqlz);
$d=$gym;
$plithos=1;
while(!empty($row)) 
{
	  $mathima=$type=$ekd=$teacher1=$subject=$tmima=$kath=$mthma=$pmpx1=array();
	  $mitroo=$row['mitroo'];
	  $tmima=$row['tmima']; 
	  $eponimo=$row['eponimo'];
	  $onoma=$row['onoma'];
	 
	  $cper=1;
	  while ($mitroo == $row['mitroo'])
	  {
		 $tname=$row['Name'];
		 //$pmpx1[$row['period']]=$row['teacher'];
		 $mathima[$row['period']]=$row['mathima'];
		 $t=$row['mathc'];
		 $ttype="";
		 switch ($t) 
		 {
           case "Α":$ttype="ΑΝΑΠΛΗΡΩΣΗ";break;
		   case "Σ":$ttype="ΣΧΟΛΑΝΕΙ";break;
		   case "Δ":$ttype="Δ.Δ.Κ";break;
		 }
		 if ($ttype<>""){$type[$row['period']]=$ttype;}else{$type[$row['period']]=$row['mathima'];}
		 
		 $kath[$row['period']]=$tname;
		 $row = mysqli_fetch_array($sqlz);
		 $cper++;
	  }
	  $cper--;
	  //////////////
	  
	  if ($cper < $d) //o mathitis exei asimplirotes apousies 
	  {
	    echo "<td>". $plithos . "</td>";
	    echo "<td>". $mitroo . "</td>";
	    echo "<td>". $tmima . "</td>";
	    echo "<td>". $eponimo."  ".$onoma . "</td>";
	    $plithos++;  
	    $sqls = mysqli_query($con,"SELECT e.*,ek.onoma FROM ekdilosistu as e,ekdilosi as ek 
		        WHERE e.pmp='$mitroo' AND e.code=ek.code  AND ek.date='$datex' ");
	    $numsqls=mysqli_num_rows($sqls);
		$sekd=array();
	    while($rows = mysqli_fetch_array($sqls))
		{
	       $ename=$rows['onoma'];
		   switch ($ename)
		   {
			   case "ΑΔΕΙΑ ΕΞΟΔΟΥ":
			   $ae="**ΑΔ.ΕΞ**";
			   break;
			   case "ΑΔΕΙΑ ΕΙΣΟΔΟΥ":
			   $ae="**ΑΔ.ΕΙΣ**";
			   break;
			   case "ΠΜ ΚΑΤΟΙΚΟΝ":
			   $ae="**ΑΠΟΒ**";
			   break;
			   case "ΑΣΘΕΝΕΙΑ":
			   $ae="**ΑΣΘ**";
			   break;
			   default:
			   $ae="**ΕΚΔ**";
		   }
		   for ($j=1;$j<=$gym;$j++)
		   {
			 $p="p".$j;  
			 if ($rows["$p"]==1) {$sekd[$j]=$ae;}
		   }
		 }
	  ////////////////////////
     
	 for ($x=1;$x<=$d;$x++)
	 {
	      
		$day1 ="day".$x;
		//echo $mitroo."xx".$tmima;
	    require ("mathitisprog1.php");
	    $teacher1[$x]=$name; 
	    $arr = explode("/", $room);
	    $tmima1[$x]=  $less;
        $mthma[$x] = $arr[1];
		$pmpx1[$x] = $pmpx;  
     }

	 for ($j=1;$j<=$d;$j++)  //display table
	 {   
		$sb=$tmima1[$j];
		$ls=$mthma[$j];
		$pas=$sb."/".$ls."/".$j."/".$pmpx1[$j]."/"."1"; 
		if (empty($kath[$j]))
		{
		  $ds=$teacher1[$j]."/".$mthma[$j];	
		  if($numsqls > 0) { $ds=$ds.$sekd[$j];}
		  echo "<td >";  
		 	 ?>
			<a href="newmath4.php" style="color: #000000;text-decoration:none;" 
              target="popup" 
              onclick="window.open('newmath4.php?pas=<?php echo $pas;?>','popup','width=800,height=800'); return false;"><?php echo $ds;?>
            </a>
			<?php 
		} 
		else
		{
		  $teach=$kath[$j];
		  $ds=$kath[$j]."/".$type[$j];
		  if($numsqls > 0) { $ds=$ds.$sekd[$j];} 
		   echo "<td bgcolor='#D8D8D8'>";
		   
			 ?>
			<a href="newmath4.php" style="color: #000000;text-decoration:none;" 
              target="popup" 
              onclick="window.open('newmath4.php?pas=<?php echo $pas;?>','popup','width=800,height=800'); return false;"><?php echo "<b>".$ds."</b>";?>
            </a>
			<?php 
		}
		
	 }

     echo "</tr>";
	}
  }
echo "</table>";	 
}
else
{
	echo "<br>"."ΔΕΝ ΥΠΑΡΧΟΥΝ ΑΠΟΥΣΙΕΣ";
}	

?>


</body>
</html>