<?php
session_start();
$menu = $_SESSION['menu'];
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=800, top='+top+', left='+left);
}
</script>

<script type="text/javascript">
var prompt=true;

		$(document).ready(function() {

				$('input:not(submit),textarea,select').change(function () {
					window.onbeforeunload = function () {
						if (prompt == true) 
							return 'Δεν έχετε κάμει έλεγχο για την ημερομηνία και δε θα γίνει καταχώρηση';
						}
					});


				$('input:submit').click(function(e) {
					prompt = false;
					});
	    });
		
</script>

<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:9pt; }
<p style="font-size:09px;"></p>

body {
    font: 0.8em/1.1em Verdana, Geneva, Arial, Helvetica, sans-serif;
    background-color:#FFF; }

#wrap {
   font-size: 1em/1.1em;
   width: 900px;
   padding: 15px;
   margin: 0 auto; 
   background-color: #fff;
   position: relative; }

/* These styles create the dropdown menus. */
#navbar {
   margin: 0;
   padding: 0;
   height: 1.2em; }
#navbar li {
   list-style: none;
   float: left; }
#navbar li a {
   display: block;
   padding: 3px 8px;
   background-color: #5e8ce9;
   color: #fff;
   text-decoration: none; }


#header h1 img { 
border: none; 
}   
</style>

<div id="wrap">
<div id="header">
     <h4><?php include 'logo.php'?> </h4>
<h4>ΔΗΛΩΣΗ ΔΙΑΓΩΝΙΣΜΑΤΟΣ</h4>

<body>
<?php

require("dbconnect.php");
$name = $_SESSION['n'];
$tetramino=$_SESSION['tetramino'];
$xronia=$_SESSION['xronia'];

$dt= date("Y-m-d h:i:sa");

$strenc2= $_GET['data'];
$arr = unserialize(urldecode($strenc2));
$math=$arr[1]  ;
$period =$arr[2] ;
$day=$arr[3];
$thisdp=$day.$period; 

$flagtaxi=mb_substr($math, 0, 1, 'utf-8');
$_SESSION['flagtaxi']=$flagtaxi;

//.......... get the subject

$q = mysqli_query($con,"SELECT id FROM timetable WHERE Teacher = '$name'");
$row = mysqli_fetch_array($q);
$id=$row['id']+1;
echo $id."xxx".$name."xxx".$math;
$q = mysqli_query($con,"SELECT ".$thisdp." FROM timetable WHERE id = '$id'");
$row = mysqli_fetch_array($q);
$d1=$row["$thisdp"];
$ar=explode("/",$d1);
$subject = $ar[1];

//................................
?>

<form  action="diagonisma3.php" method="post">
<fieldset style="width: 700px; ">
<legend> ΣΤΟΙΧΕΙΑ ΔΙΑΓΩΝΙΣΜΑΤΟΣ</legend>
<br > Ημερομηνία Δήλωσης:<input type="text"  name = 'dt' value= <?php echo $dt; ?> > <br >
<br >Τμήμα/Συνδιδασκαλία :<input type='text' name='math' size = '15' value="<?php echo $math; ?>" />
 ΘΕΜΑ  :<input type='text' name='subject' size = '40' value="<?php echo $subject; ?>" /><br >
<br >Διάρκεια  :<input type='text' name='duration' size = '3' value='40' /> λεπτά.
Από περίοδο :<input type='text' name='perapo' size = '3' value="<?php echo $period; ?>" /> 
, Μέχρι :<input type='text' name='permexri' size = '3' value="<?php echo $period; ?>" /> 
   
<br ><br >

</fieldset>
<?php

   $day=array("Mon","Tue","Wed","Thu","Fri");
   $result = mysqli_query($con,"SELECT * FROM timetable WHERE teacher='$name'  " ); 
   $row = mysqli_fetch_array($result);
   $c = mysqli_num_rows($result);

   $i=0;
  echo "<br>";    
  while($i < 5)
  {
	  $per=1;     
	  while ($per <= 7) {
	  $dayf=$day[$i].$per;
  if ($math == $row["$dayf"]) {
		  $mera[$i]=$day[$i];
		  $thisdp=$dayf;
  }
	  
	  $per++;
	  }
	$i++;
  }

echo "<br>";
echo "<font face='arial' size='4pt'>ΕΠΙΛΟΓΗ ΗΜΕΡΟΜΗΝΙΑΣ ΓΙΑ ΔΙΑΓΩΝΙΣΜΑ : $math </font> "; 
echo "<br>";


//...................................... display  week schedule.......
$startdate=strtotime("now");
echo "<br>";

echo "<table class='myTable' >
<tr style='border:1px solid black;padding:4px;font-size:14px'  >";
$dd=1;

while ($dd<=7) {
echo "<tr>	";
$new=$startdate;
for ($i=1;$i<=7;$i++){

$dave =	date("D", $new);

$ddd=date("D, d F Y", $new);
$tday=date('Y-m-d', strtotime($ddd));

	$qx1 = mysqli_query($con,"SELECT testdate,class,subject FROM declarations WHERE testdate = '$tday'");
    $c1=mysqli_num_rows($qx1);
	
    $q2 = mysqli_query($con,"SELECT perapo,permexri FROM offperiods WHERE (datefrom <= '$tday') AND (dateto >= '$tday') ");
    $c2=mysqli_num_rows($q2);
	$row2=mysqli_fetch_array($q2);
	$papo=$row2['perapo'];
	$pmexri=$row2['permexri'];
	
$result = mysqli_query($con,"SELECT * FROM syndidaskalies WHERE synd = '$math'");
$crow1=mysqli_num_rows($result);
if ($crow1==0) //amiges tmima .. oloi oi mathites mazi
	{$amiges=1; }
else 
	{$amiges=0;}
$_SESSION['amiges']=$amiges;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if (in_array($dave, $mera)) 
{
 /* if ($c2 > 0) // yparxei ekdilosi afti tin hmerominia  
      {
	  if ($papo == 1 AND $pmexri == 7) 
	  {
			echo "<td bgcolor='#FF0000'> ";
			echo "<input type='checkbox' name='check' disabled value='$ddd' />";
			echo "<font color='#FFFFFF'> $ddd </font>";
	        echo "</td>";
	  }
	  else
	  {         
		    $comment= "Eκδήλωση:περ. ".$papo. " μέχρι ".$pmexri;
		    $mes=$ddd." / ".$comment;
		    echo "<td bgcolor='#330099'> ";
			echo "<input type='checkbox' name='check' value='$ddd' />";
			echo "<font color='#FFFFFF'#0000FF''> $mes </font>";
	        echo "</td>";  
		}
  }
  else
  {*/
	if ($c1>0 ) 
            {		  
			 $q1 = mysqli_query($con,"SELECT testdate,class,teacher,subject FROM declarations WHERE testdate = '$tday' AND class='$math'");
             $c3=mysqli_num_rows($q1);
	         $row1=mysqli_fetch_array($q1);
			 if ($c3 > 0){// yparxei diagonisma stin idia taksi
			     $mes=$ddd." / ". "Τμήμα: ".$math."/".$row1['subject'];
			     echo "<td bgcolor='red'> ";
			     echo "<input type='checkbox' name='check' disabled value='$ddd' />";
			     echo "<font color='#FFFFFF'> $mes </font>";
	             echo "</td>"; }
			 else
			 {
				 $ok=0;
			while ($rowx1=mysqli_fetch_array($qx1)){ 
			 $math1=$rowx1['class'];	 
			 
			 if ($flagtaxi=="Α" AND (mb_substr($math1, 0, 1, 'utf-8')=="Α"))
				 {
				  if ((mb_substr($math, 1, 1, 'utf-8')) == (mb_substr($math1, 1, 1, 'utf-8'))){
					$ok=1; 
					$sok=$rowx1['subject'];}
				else
					 
				  {
				  if (strlen($math) > 4 ) {
				   $tm=mb_substr($math, 1, 1, 'utf-8'); 
				   $tm1=mb_substr($math1, 2, 1, 'utf-8');}
				   
				   else
				   {
				   $tm=mb_substr($math,2, 1, 'utf-8'); 
				   $tm1=mb_substr($math1, 1, 1, 'utf-8');}
			}
				  
				   if ($tm==$tm1) 
				   {
					   $ok=1;
					   $sok=$rowx1['subject'];
				   }}}
				   
			 if ($ok==1){
					 $mes=$ddd." / ". "Τμήμα: ".$math1."/".$sok;
			         echo "<td bgcolor='red'> ";
			         echo "<input type='checkbox' name='check' disabled value='$ddd' />";
			         echo "<font color='#FFFFFF'> $mes </font>";
	                 echo "</td>";    
				    }
			   	 else
			 {
		        echo "<td bgcolor='white'> "; 
			    echo "<input type='checkbox' name='check' value='$ddd'/>";
	            echo "<font color='red'>$ddd  </font> ";  
			    echo "</td>";     }}
	 }
	else
	{	   
     echo "<td>";
     echo "<input type='checkbox' name='check' value='$ddd'/>";
     echo "<font face='arial' size=' 2pt' color='red'>$ddd  </font> ";
     echo "</td>";
	}
 // }
}		      
else //..........................................
{	
  if ($dave=='Sat' or $dave=='Sun') 
  {
	  echo "<td>"; 
	  echo "<input type='checkbox' name='check' disabled value='$ddd'/>";
	  echo "<font face='arial' size=' 2pt' color='grey'>$ddd  </font> ";
	  echo "</td>";
  }	
  else
  { 
  if ($c2 > 0) // yparxei ekdilosi afti tin hmerominia  
      {
	  if ($papo == 1 AND $pmexri == 7) 
	  {
			echo "<td bgcolor='#FF0000'> ";
			echo "<input type='checkbox' name='check' disabled value='$ddd' />";
			echo "<font color='#FFFFFF'> $ddd </font>";
	        echo "</td>";
	  }
	  else
	  {         
		    $comment= "Eκδήλωση:περ. ".$papo. " μέχρι ".$pmexri;
		    $mes=$ddd." / ".$comment;
		    echo "<td bgcolor='#330099'> ";
			echo "<input type='checkbox' name='check' value='$ddd' />";
			echo "<font color='#FFFFFF'> $mes </font>";
	        echo "</td>";  
		}
  }
  else
  {
      echo "<td>";
      echo "<input type='checkbox' name='check1' disabled  value='$ddd'/>";
      echo "<font face='arial' size=' 2pt' color='orange'>$ddd  </font> ";
      echo "</td>";
  }
  }
  
}		 
	
	
    

$new = strtotime("+7 day", $new);
echo "</td>";
}// end for
$startdate = strtotime("+1 day", $startdate);
$dd++;
}// end while

echo "</tr>	";
echo "</table>";
echo "<br>" ;

?>
<br>
<input type="text"  name = 'dt' HIDDEN value= <?php echo $dt; ?> > <br >

<input type="submit" name= "epilogi1" value='Έλεγχος Ημερομηνίας' >
<input type="submit" name= "epilogi2" value=' | ' >
<input type="submit" name= "epilogix3" value='Δήλωση για συμφωνημένη ("καρφωτή") ημερομηνία' >
</form>

<?php
?>
<br> <br>
<a href='diagonismanew.php' style="color:blue " >  Επιστροφή στην προηγούμενη οθόνη  </a>
<a href='#'><span>|</span></a>
<a href='#'><span>|</span></a>
<a  href=<?php echo $menu;?> style="color:blue "  >  Επιστροφή στο Μενού  </a>
		
</body>
</html>