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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>entopismos mathiti</title>
</script>
<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>

<br><h3> ΔΙΔΑΧΘΕΙΣΑ ΥΛΗ ΜΑΘΗΜΑΤΟΣ </h3><br />
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];
$dayf=array("Mon","Tue","Wed","Thu","Fri");

$sql = mysqli_query($con,"SELECT mitroo,tmima,eponimo,onoma FROM allstudentinfo WHERE mitroo='$usr'  " );
$row = mysqli_fetch_array($sql);
$stname=$row['eponimo']." ".$row['onoma'];
$tmima=$row['tmima'];
$mitroo=$row['mitroo'];


$res1=mysqli_query($con,"SELECT * FROM stutimetable WHERE mitroo='$mitroo'");
$rows1 = mysqli_fetch_array($res1); 
$res2=mysqli_query($con,"SELECT * FROM stutimetable WHERE id = (SELECT id+1 FROM stutimetable WHERE mitroo='$mitroo')");
$rows2 = mysqli_fetch_array($res2); 
$ind=1;	
for ($x=1;$x<=5;$x++)
{
	for ($per=1;$per<=$gym;$per++)
	{
			$day1=$dayf[$x].$per;
			$less= $rows1["$day1"];
			$srow= $rows2["$day1"];
			$sall=explode("/",$srow);
			$teach= $sall[2];
			$tm[$ind]= $less."/".$teach;
			$ind++;
	}
}

$tm1 = array_values(array_unique($tm));
$tot = count($tm1);
$tot--;
$unmath1=$unteach1=array();
$k=1;
for ($i=0;$i<$tot;$i++)
{
	$ar = explode("/",$tm1[$i]);
	if ($ar[0]<>"")
	{
		$unteach1[$k]=$ar[1];
		$unmath1[$k]=$ar[0];
		$k++;
	}
}
$k--;

?>
<form  method='post'> 
  Επιλογή Μαθήματος :<select name='mathid' >
  <?php
  $i=1;
  foreach ($unmath1 as $m){
		  $x=$m."/".$unteach1[$i];
		  $tc=mysqli_query($con,"SELECT name FROM teachers WHERE PMP='$unteach1[$i]'");
		  $row = mysqli_fetch_array($tc);
		  $z=$m."/".$row['name'];
          echo "<option value='$x'>$z</option>";
		  $i++;
  }
  ?>
  </select>
<input type="submit" name="submitb" value="Επιβεβαίωση Επιλογής" >
</form>
<?php
if (isset($_POST['mathid']))
{
	$math=$_POST['mathid'];
	$arr = explode("/", $math);
    $lesson = ltrim(rtrim($arr[0]));
	$teacher = ltrim(rtrim($arr[1]));
	if ($lesson=='Α3ΦΥΣ' or $lesson=='Α3ΦΥΣκατ')
	{
	$sql=mysqli_query($con,"select * from syllabi where pmp='$teacher' and (mathima='Α3ΦΥΣ' or mathima='Α3ΦΥΣκατ')  order by date,per");	
	}
	else
	{
	$sql=mysqli_query($con,"select * from syllabi where pmp='$teacher' and mathima='$lesson' order by date,per");
	
	}

$tc=mysqli_query($con,"SELECT name FROM teachers WHERE PMP='$teacher'");
$row = mysqli_fetch_array($tc);
$z=$lesson."/".$row['name'];
echo "<br>"."<b>"."Προγραμμaτισμός για: ".$z."</b>";	
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Ημερομηνία</th>
<th>Περ</th>
<th>Περιγραφή Αναλυτικού</th>
<th>Απoυσία</th>
</tr>";
$i=1;
while($row=mysqli_fetch_array($sql))
{
  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 dateout FROM apousies WHERE (apousia=1 and kath IS NULL) AND dateout=?
  and period=? AND mitroo='$mitroo' AND teacher=? AND mathima=? AND (mitroo not in (select mitroo from apousies where kath > 0 and dateout=? and period=?)) " );	 
  $sqlx->execute([$dd,$pr,$teacher,$lesson,$dd,$pr]);
  while($rowx=$sqlx->fetch(PDO::FETCH_ASSOC)) 
	{
      $disp="NAI";
	  
	}
	echo "<td>". $disp . "</td>";
  $i++;
}
echo "</table>";	
}
?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
		
</body>
</html>