<?php
include "scrinit.php";
$fn=$_GET['fn'];
if ($fn == 0 and is_numeric($fn)) 
{ 
  include $menu ;
}
else
{
	include "logo.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:4px;font-size:9pt; }
<p style="font-size:12px;"></p>
</style>
</head>

<body>
<h3> ΠΑΙΔΑΓΩΓΙΚΗ ΟΜΑΔΑ ΤΜΗΜΑΤΟΣ</h3>
  
<?php
require "dbconnect.php";
$dt=$_SESSION['dt'];
$gym=$_SESSION['gym'];
$dd=date('D', strtotime($dt));
include "selecttmima.php";

if (isset($_POST['tmimaid']))
{
	$tmima=$_POST['tmimaid'];
	$sql = $dbcon->prepare("SELECT mitroo FROM allstudentinfo WHERE tmima = ? ");
    $sql->execute([$tmima]);
    $count=$sql->rowCount();
	$j=1;
	$syndkath=array();
	while($row=$sql->fetch(PDO::FETCH_ASSOC))
	{
		$mitr=$row['mitroo'];
		$result = $dbcon->prepare("SELECT sc.kathigitis,sc.synd FROM syndidaskalies as s,syndcodes as sc 
		WHERE s.mitroo=? and s.syndid=sc.syndid");
        $result->execute([$mitr]);
	    while($rows=$result->fetch(PDO::FETCH_ASSOC))
		{
			$syndkath[$j]=$rows['synd']."/".$rows['kathigitis'];
			$j++;
		}
	}

	$tm=array();
	$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
	//$ind=1;
	for ($x=1;$x<=5;$x++){
	   $per=1;
       while ($per<=$gym){
         $day=$dayf[$x].$per;
         $sql = $dbcon->prepare("SELECT id,Teacher FROM timetable WHERE ($day) = ? ");
		 $sql->execute([$tmima]);
		 $c=$sql->rowCount();
		 if ($c > 0) 
		  {
		       $row=$sql->fetch(PDO::FETCH_ASSOC);
		       $id=$row['id'];
			   $nid=$id+1;
			   $teachr=$row['Teacher'];
	           $res1 = mysqli_query($con,"SELECT ($day) FROM timetable WHERE id='$nid'  " ); 
               $row3 = mysqli_fetch_array($res1); 
	           $room= $row3["$day"];
		  } 
		 $arr = explode("/", $room);
		 $syndkath[$j]=$arr[1]."/".$teachr;
		 $j++;
		 $per++;
      }
    } //for loops

$st=array_values(array_unique($syndkath));
$tm1=$teach1=array();
$tot = count($st);
$k=0;
for ($i=0;$i<=$tot;$i++)
{
	$k++;
	$ar = explode("/",$st[$i]);
	$teach1[$k]=$ar[1];
	$tm1[$k]=$ar[0];
}	
echo "<br>"."<br>";
echo "ΠΑΙΔΑΓΩΓΙΚΗ ΟΜΑΔΑ ΤΜΗΜΑΤΟΣ : ".$tmima;
echo "<table  class='myTable' >
<tr style='border:1px solid black' bgcolor='#FFAF80'   >
<th>Α/Α</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΔΙΔΑΣΚΩΝ</th>
</tr>";

for  ($i=1;$i<=$tot;$i++)
{
	echo "<tr>";
	echo "<td>".$i."</td>";
	echo "<td>" . $tm1[$i]. "</td>";
	echo "<td>" . $teach1[$i]. "</td>";
	echo "</tr>";
}
echo "</table>";

}

?>	
<br /><br /><br />
<?php
//$fn=$_GET['fn'];
if ($fn == 0 and is_numeric($fn)) 
{ 
   ?><a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a><?php 
} 
else 
{
   ?><input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"><?php
}
?>
</body>
</html>

