<?php
session_start();
ob_start();
$menu = $_SESSION['menu'];
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<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'];
$tetramino=$_SESSION['tetramino'];
echo "<br>";
//$dt1=date_format(new DateTime('2019/09/09'), 'Y-m-d');

echo "<p class='p2'>". "ΕΠΙΛΟΓΗ ΤΜΗΜΑΤΟΣ ΚΑΙ ΜΑΘΗΜΑΤΟΣ". "</p>";
include "selectmath.php";
$ind=$ind-1;
if (isset($_POST['submitb']))
{
   $tm=trim($_POST['mathsubid']);
}
else
{
	$tm="";
}

?>
<form  method='post' > 

	<label><b>Τμήμα/Μάθημα: </b></label>
	<select name='mathsubid' >
	<?php
	echo "<option value=' '>-----------</option>";
	foreach ($mathsubj as $m)
	{ 		  
		  ?> <option value=<?php echo $m;?> <?php if($tm==trim($m)) echo 'selected';?>  /><?php echo $m; ?></option><?php
	}
	?>
	</select>
	<input type="submit" name="submitb" value="Επιβεβαίωση Επιλογής" >
</form>
<?php
if(isset($_POST['mathsubid']))
{
$tm=$_POST['mathsubid'];
$_SERVER['PHP_SELF'];
$arr = explode("/", $tm);
$tmima = trim($arr[0]);
$subject = trim($arr[1]);
require_once 'functions.php';
diagotm($tmima);
/*$st=$tmimax=array();$star="";
$fl=mb_substr($tmima,0,1,'utf-8');echo $fl;
$sql = mysqli_query($con,"SELECT eponimo,onoma,mitroo,tmima FROM allstudentinfo WHERE tmima='$tmima'  " );
$c=mysqli_num_rows($sql);
if ($c > 0)
{
	$i=0;
	while($row = mysqli_fetch_array($sql))
	{
		$i++;
		$st[$i]=$row['mitroo'];	
		$tmimax[$i]=$row['tmima'];
	}
	$star = join(',', $st);
}
else
{
	$sql=mysqli_query($con,"SELECT a.tmima,s.mitroo FROM syndidaskalies as s, syndcodes as sc, allstudentinfo as a 
		   WHERE sc.synd='$tmima' and sc.syndid=s.syndid and s.mitroo=a.mitroo");
	$i=0;
	while($row = mysqli_fetch_array($sql))
	{
		$i++;
		$st[$i]=$row['mitroo'];
		$tmimax[$i]=$row['tmima'];
	}
	$star = join(',', $st);
}
	 echo "<td>" .$i. "</td>";
     echo "</tr>"; 
////////////
$j=$i;
$flag1=mb_substr($tmima, 0, 1, 'utf-8');echo $flag1;
for ($k=1;$k<=$j;$k++)
{
$sqldia = mysqli_query($con,"SELECT * FROM declarations WHERE tetramino='$tetramino' and class like '".$flag1."%' order by testdate " );
$n=mysqli_num_rows($sqldia);
$sqltmima=mysqli_query($con,"SELECT tmima FROM allstudentinfo WHERE mitroo='$st[$k]' " );
$rowtmima = mysqli_fetch_array($sqltmima);
$tmima=$rowtmima['tmima'];

$i=1;
while ($rowdia = mysqli_fetch_array($sqldia))
{
$class=$rowdia['class'];
	
$sql = mysqli_query($con,"SELECT mitroo FROM allstudentinfo WHERE tmima='$class' AND mitroo='$st[$k]' " );
if (mysqli_num_rows($sql) > 0) 
{
	$testduration[$i]=$rowdia['duration'];
	$testsubject[$i] = $rowdia['subject'];
	$testdate[$i]=$rowdia['testdate'];
	$testclass[$i]=$rowdia['class'];
	$i++;
}
else
{
$sql = mysqli_query($con,"SELECT s.mitroo FROM syndidaskalies as s,syndcodes as c 
	   WHERE c.synd='$class' AND s.mitroo='$st[$k]' AND s.syndid=c.syndid  " );
if (mysqli_num_rows($sql) > 0) 
{	
	$testduration[$i]=$rowdia['duration'];
	$testsubject[$i] = $rowdia['subject'];
	$testdate[$i]=$rowdia['testdate'];
	$testclass[$i]=$rowdia['class'];
	$i++;
}
else
{
$flag1=mb_substr($class, 0, 1, 'utf-8');

$flag2=mb_substr($class, 1, 1, 'utf-8');
$flag3=$flag1."0".$flag2;

if ($flag3==$tmima) {
    $testduration[$i]=$rowdia['duration'];
	$testsubject[$i] = $rowdia['subject'];
	$testdate[$i]=$rowdia['testdate'];
	$testclass[$i]=$rowdia['class'];
	$i++;
}
}
}
}
$i=$i-1;

for ($j=1;$j<=$i;$j++)
{
     $datedisp= date('d-m-Y', strtotime($testdate[$j]));
	 echo "<tr>"; 
     echo "<td>" . $datedisp. "</td>";
	 $day = date('D', strtotime($testdate[$j]));
	 $daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
     $d = $daymap[date('w', strtotime($testdate[$j]))];
     echo "<td>" . $d. "</td>";
	 echo "<td>" . $testclass[$j]. "</td>";
	 echo "<td>" . $testsubject[$j]. "</td>";
     echo "<td>" . $testduration[$j]. "</td>";
	 echo "<td>" . " ". "</td>";
     echo "</tr>";
}

}
echo "</table>";
}
$tdia=mysqli_query($con,"SELECT * FROM declarations WHERE testdate >= '$dt' AND class = '$tmima' ");
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>