<?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));
$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima "); 
?>

<form  method='post'> 
<h4> ΕΠΙΛΟΓΗ  ΤΜΗΜΑΤΟΣ</h4>
<label>Τμήμα:</label>
<select name='tmimaid' id='tmimaid' >
<?php
	echo "<option value='---'>select</option>";
    while($row2 = mysqli_fetch_array($sql2) ) 
	{
          echo "<option value='$row2[tmima]'>$row2[tmima]</option>";
    }
?>
</select>
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
</form>
<?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();
	$dayf=array(" ","Mon","Tue","Wed","Thu","Fri");
	while($row=$sql->fetch(PDO::FETCH_ASSOC))
	{
		$mitroo=$row['mitroo'];
		$sql1 = $dbcon->prepare("SELECT * FROM stutimetable where mitroo=?");
		$sql1->execute([$mitroo]);
		$row1=$sql1->fetch(PDO::FETCH_ASSOC);
		$nid=$row1['id']+1;
		$sql2 = $dbcon->prepare("SELECT * FROM stutimetable where id=?");
		$sql2->execute([$nid]);
		$row2=$sql2->fetch(PDO::FETCH_ASSOC);
		for ($x=1;$x<=5;$x++)
		{
	    for ($per=1;$per<=$gym;$per++)
	    {
            $day=$dayf[$x].$per;
		    $uprow= $row1["$day"];
			$drow=$row2["$day"];
		    $arr = explode("/", $drow);
		    $syndkath[$j]=$uprow."/".$arr[1]."/".$arr[2];
			
			$j++;
        }
		}
    } 

$st=array_values(array_unique($syndkath));

$tm1=$teach1=array();
$tot = count($st);
$k=0;
for ($i=0;$i<=$tot;$i++)
{
	
	$ar = explode("/",$st[$i]);
	if (!empty($ar[2]))
	{
	$k++;	
	$teach1[$k]=$ar[2];
	$tm1[$k]=$ar[0]."/".$ar[1];
	}
}	
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<=$k;$i++)
{
	echo "<tr>";
	echo "<td>".$i."</td>";
	echo "<td>" . $tm1[$i]. "</td>";
	$sql1 = $dbcon->prepare("SELECT Name FROM teachers where PMP=?");
	$sql1->execute([$teach1[$i]]);
	$row1=$sql1->fetch(PDO::FETCH_ASSOC);
	$teacher=$row1['Name'];
	echo "<td>" .$teacher. "</td>";
	echo "</tr>";
}
echo "</table>";

$_SESSION['tm']=$tm1;
$_SESSION['teach']=$teach1;
?>	
<br /><br /><br />
<?php
$fn=$_GET['fn'];
if ($fn == 0 and is_numeric($fn)) 
{ 
   ?>
   
   <a href=<?php echo $menu;?> style="color:blue "  ><button>Επιστροφή στο Μενού</button></a>
   <input type="button" value="Ανακοίνωση Συνεδρίας" onclick="window.open('pedanak.php?tmx=<?php echo $tmima;?>','','width=900,height=900')" />
   <input type="button" value="Αποστολή SMS Συνεδρίας" onclick="window.open('pedasms.php?tmx=<?php echo $tmima;?>','','width=900,height=900')" />
   <?php
} 
else 
{
   ?><input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()"><?php
}
}
?>
</body>
</html>

