<?php
session_start();
ob_start();
$menu = $_SESSION['menu'];
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:12px; }
<p style="font-size:12px;"></p>
</style>
<body>
<div id="wrap">
<div id="header">
     <h4><?php include 'logo.php'?> </h4>
</div>
<body>
<h3>ΛΙΣΤΑ ΔΙΑΓΩΝΙΣΜΑΤΩΝ ΤΜΗΜΑΤΟΣ </h3>
<?php
date_default_timezone_set("Europe/Athens");
require "dbconnect.php";
$usr=$_SESSION['usr'];
$teacher=$_SESSION['n'];
$dt=$_SESSION['dt'];
echo "<br>";
//$dt1=date_format(new DateTime('2019/09/09'), 'Y-m-d');

$sql = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ");
if (isset($_POST['submit1']))
{
  $tmima=$_POST['tmimaid'];
}
?>
<form  method='post'> 
</select>
<label>Τμήμα:</label><select name='tmimaid' id='tmimaid'>
  <?php
	  while($row = mysqli_fetch_array($sql) ) 
	  {
		  $tm=$row['tmima'];
          ?><option value=<?php echo $tm;?> selected=<?php if($tm==$tmima) echo "selected";?> /><?php echo $tm;?> </option> <?php
      }
      ?>
</select>
  
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
    </form>

<?php
if (isset($_POST['submit1']))
{
  $tmima=$_POST['tmimaid'];
  $_SERVER['PHP_SELF'];
 ?>
<h3> ΔΙΑΓΩΝΙΣΜΑΤΑ ΓΙΑ ΤΟ ΤΜΗΜΑ <?php echo $tmima; ?> </h3>
<?php  
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:12px'  >
<tr>
<th>ΗΜΕΡ. ΔΙΑΓΩΝ.</th>
<th>ΗΜΕΡΑ</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΔΙΑΡΚ.</th>
<th>ΑΡ. ΜΑΘΗΤΩΝ</th>
</tr>";	
$sql1 = "SELECT * FROM declarations WHERE class='$tmima' or class like '".$tmima."%%%' ORDER BY testdate " ;
if (!mysqli_query($con,$sql1)) {die('Error: ' . mysqli_error($con));   }
$res=mysqli_query($con,$sql1);
while ($row = mysqli_fetch_array($res))
{
     $testdate=$row['testdate'];
	 $subject=$row['subject'];
	 $duration=$row['duration'];
     $datedisp= date('d-m-Y', strtotime($testdate));
	 echo "<tr>"; 
     echo "<td>" . $datedisp. "</td>";
	 $day = date('D', strtotime($testdate));
	 $daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
     $d = $daymap[date('w', strtotime($testdate))];
     echo "<td>" . $d. "</td>";
	 echo "<td>" . $tmima. "</td>";
	 echo "<td>" . $subject. "</td>";
     echo "<td>" . $duration. "</td>";
	 echo "<td>" . " ". "</td>";
     echo "</tr>"; 
	
	//.............................................
}
$st=array();
$fl=mb_substr($tmima,0,1);
$sql = mysqli_query($con,"SELECT eponimo,onoma,mitroo FROM allstudentinfo WHERE tmima='$tmima'  " );
$i=1;
while($row = mysqli_fetch_array($sql))
{
    $st[$i]=$row['mitroo'];
	$i++;
}
$star = join(',', $st);

$tdia=mysqli_query($con,"SELECT * FROM declarations 
WHERE testdate >= '$dt' AND class <> '$tmima' AND class like "."'".$fl."%'");
If (mysqli_num_rows($tdia) > 0)
{
  
  while ($row=mysqli_fetch_array($tdia))
  {

	$class=$row['class'];
	$tdia1=mysqli_query($con,"SELECT s.mitroo FROM syndidaskalies as s, syndcodes as sc 
		   WHERE sc.synd='$class' and sc.syndid=s.syndid and s.mitroo IN ($star)");
    If (mysqli_num_rows($tdia1) > 0)
	{
			 $testdate=$row['testdate'];
			 $subject=$row['subject'];
			 $duration=$row['duration'];
			 $datedisp= date('d-m-Y', strtotime($testdate));
			 echo "<tr>"; 
			 echo "<td>" . $datedisp. "</td>";
			 $day = date('D', strtotime($testdate));
			 $daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
			 $d = $daymap[date('w', strtotime($testdate))];
			 echo "<td>" . $d. "</td>";
			 echo "<td>" . $class. "</td>";
			 echo "<td>" . $subject. "</td>";
			 echo "<td>" . $duration. "</td>";
			 echo "<td>" . $ns. "</td>";
			 echo "</tr>";  
    }
  }
}

echo "</table>";
}

echo "<br>"."<br>";

 ?>
 <br /> <br />
<input type='button' value='Επιστροφή ' onclick='javascript: window.close();' />  
</body>
</html>