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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=900, height=300, top='+top+', left='+left);
}
</script>
<style type="text/css">
input.right{  text-align:right;  }
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:10pt; }
</style>
</head>

<body>

<h3> ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ  ΜΑΘΗΜΑΤΟΣ </h3>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
	$math=$_GET['mathid'];
	$arr = explode("/", $math);
    $lesson = trim($arr[0]);
	$subject = trim($arr[1]);
	$pmp=trim($arr[2]);
	///////
   $day=array("Mon","Tue","Wed","Thu","Fri");
   $result = mysqli_query($con,"SELECT * FROM timetable WHERE pmp='$pmp'  " ); 
   $row = mysqli_fetch_array($result);
   $c = mysqli_num_rows($result);
   $id1=$row['id']+1;
   $result1 = mysqli_query($con,"SELECT * FROM timetable WHERE id='$id1'  " ); 
   $row1 = mysqli_fetch_array($result1);
   $i=0;
   $ind=1;
   while($i <= 4)
   {
	  $per=1;
      
	  while ($per <= $gym) 
	  {
		  $dayf=$day[$i].$per;
		  $lesson= trim($row["$dayf"]);
		  if (!empty($lesson))
		  {
			//$lesson=ltrim(rtrim($lesson));
			$subj=$row1["$dayf"];
			$mathima[$ind]=$lesson;
			$ls[$dayf]=$lesson;
			$ar=explode('/',$subj);
			$subject[$ind]= $ar[1];
			$sb[$dayf]=$ar[1];
			$mathsubj[$ind]=$mathima[$ind]."/".$subject[$ind];
			$ind++;
		  }
		  $per++;
	  }
    
	  $i++;
	}
	$math=$_GET['mathid'];
	$arr = explode("/", $math);
    $lesson = trim($arr[0]);
	$subject = trim($arr[1]);
	$pmp=trim($arr[2]);
	$sql=mysqli_query($con,"select * from syllabi where pmp='$pmp' and trim(mathima)='$lesson' order by date,per");

echo "<b>"."Προγραμμaτισμός για: ".$math."</b>";	
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Ημερομηνία</th>
<th>Περ</th>
<th>Περιγραφή Αναλυτικού</th>
<th>Απόντες/ούσες</th>
</tr>";
$i=1;
while($row=mysqli_fetch_array($sql))
{
  $day = date('D', strtotime($row['date']));
  $dayf=$day.$row['per'];
  if (trim($sb[$dayf]) == trim($subject))
  {
  echo "<tr>";
  echo "<td>" .$i;
  echo "<td>". date('d-m-Y',strtotime($row['date']));$row['date'] . "</td>";
  echo "<td>". $row['per'] . "</td>";
  echo "<td>". $row['perigrafi'] . "</td>";
  $dd=$row['date'];
  $pr=$row['per'];
  $disp="";
  $sqlx = $dbcon->prepare("SELECT a.mitroo, al.onoma, al.eponimo FROM apousies as a,allstudentinfo as al WHERE (a.apousia=1 and a.kath IS NULL) AND a.dateout=?
  and period=? AND a.mitroo=al.mitroo AND a.teacher=? AND a.mathima=? AND (a.mitroo not in (select mitroo from apousies where kath > 0 and dateout=? and a.period=?)) " );	 
  $sqlx->execute([$dd,$pr,$pmp,$lesson,$dd,$pr]);
  while($rowx=$sqlx->fetch(PDO::FETCH_ASSOC)) 
	{
      $disp=$disp.$rowx['eponimo']." ".$rowx['onoma']."-(".$rowx['mitroo']."),";
	  
	}
	$disp=rtrim($disp, ",");
	echo "<td>". $disp . "</td>";
  $i++;
  }
}
echo "</table>";	

?>
<br><br>
<button onClick="window.print()">	Εκτύπωση Σελίδας</button>
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"> 
</body>
</html>