<?php
include "scrinit.php";
?><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:11px; }
<p style="font-size:09px;"></p>
</style>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];
$mitr=$_GET['mit'];

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

$sql = mysqli_query($con,"SELECT code FROM ekdilosistu WHERE pmp='$mitr' " );
$row = mysqli_fetch_array($sql);
$code=$row['code'];
if (!$sql) {die('Error: ' . mysqli_error($con));   }
$sql1 = "SELECT * FROM declarations WHERE class='$tmima'  ORDER BY testdate " ;
if (!mysqli_query($con,$sql1)) {die('Error: ' . mysqli_error($con));   }
$res=mysqli_query($con,$sql1);

?>
<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>
</tr>";	
  while ($row = mysqli_fetch_array($res))
  {
     $testdate=$row['testdate'];
	 $subject=$row['subject'];
	 $duration=$row['duration'];
     if ($testdate >= $dt) 
	 {
		 echo "<tr bgcolor='#33FFCC'>"; 
	 }
	 else  echo "<tr>";
 
	 $datedisp= date('d-m-Y', strtotime($testdate));
     echo "<td>" . $datedisp. "</td>";
	 $day = date('D', strtotime($testdate));
	 $daymap = array('Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο');
      
     $d = $daymap[date('w', strtotime($testdate))];
/*switch ($day) {
  case "Mon":
    $d="ΔΕΥΤΕΡΑ";
    break;
  case "Tue":
    $d="ΤΡΙΤΗ";
    break;
  case "Wed":
    $d="ΤΕΤΑΡΤΗ";
    break;
  case "Thu":
    $d="ΠΕΜΠΤΗ";
    break;	
  case "Fri":
    $d="ΠΑΡΑΣΚΕΥΗ";
    break;
}*/
     echo "<td>" . $d. "</td>";
	 echo "<td>" . $subject. "</td>";
     echo "<td>" . $duration. "</td>";
     echo "</tr>"; 
	
	//.............................................
}
echo "</table>";

//check for diagonismata/////////////////////////////////////////////////////////
echo "<br>";
?>
<h3> ΔΙΑΓΩΝΙΣΜΑΤΑ ΜΑΘΗΤΗ ΓΙΑ ΤΙΣ ΕΠΟΜΕΝΕΣ 10 ΜΕΡΕΣ </h3>
<?php 
$x=date('Y-m-d',strtotime($dt));
for ($i=1;$i<=10;$i++)
{
	$in=0;
	
	$x = strtotime("+1 day", strtotime($x));
	$dt1=date('Y-m-d',$x);
	$dt2= date('d-m-Y', strtotime($dt1));
	echo "<br>".$dt2;
	$x=date('Y-m-d',strtotime($dt1));
$tdia=mysqli_query($con,"SELECT * FROM declarations WHERE testdate='$dt1'");
If (mysqli_num_rows($tdia) > 0)
{
  $in=0;
  while ($trow=mysqli_fetch_array($tdia))
  {
	$class=$trow['class'];$fr=$trow['perapo'];$subj=$trow['subject'];
	$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='$mitr'");
    If (mysqli_num_rows($tdia1) > 0)
	{
		$in=1;
		$subjf=$subj;$frf=$fr;
    }
    else
    {		
	   $tdia2=mysqli_query($con,"SELECT mitroo FROM allstudentinfo WHERE tmima='$class' and mitroo='$mitr'");
	   If (mysqli_num_rows($tdia2) > 0){$in=1;$subjf=$subj;$frf=$fr;} 
	}
  }
}
if ($in==1)	
{
echo "<font face='arial' size='4pt' color='#ff0000'>  Ο μαθητής/τρια έχει διαγώνισμα ".$subjf." την ".$frf." περίοδο</font>";
}
}
?>
<br><br> 
<input type="button" name="epistrofi" value="Επιστροφή" onClick="self.close()">  
</body>
</html>