<?php
session_start();
$menu=$_SESSION['menu'];
include $menu;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h4>ΛΥΚΕΙΟ ΑΓΙΑΣ ΦΥΛΑΞΕΩΣ 2013-2014 - ΚΑΤΑΧΩΡΗΣΗ ΑΠΟΥΣΙΩΝ</h4>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$name = stripslashes($name);

echo "<br>"."ΗΜΕΡΟΜΗΝΙΑ:".$dt."...."." ΕΚΠΑΙΔΕΥΤΙΚΟΣ:".$name;
echo "<br>"; 
echo "<br>"." ΕΠΙΛΟΓΗ ΠΕΡΙΟΔΟΥ ΔΙΔΑΣΚΑΛΙΑΣ";
?>

<form name 'ora' method='POST' ><input type='hidden' name='__token_timestamp__' value='1402845193'><input type='hidden' name='__token_val__' value='5343d0c12025a077478cefe21dbbefbb'>
<select name="per" >
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
</select>
<input type="submit" name "select" value="Select">
</form>

<?php


if (isset($_POST['per']))
{	
   $per = $_POST["per"];
   $_SESSION['per']=$per;
   $day=date('D').$per;
   echo $day;
   $name = $_SESSION['n'];
   $result = mysqli_query($con,"SELECT * FROM timetable WHERE Teacher='$name'  " ); 
   $row = mysqli_fetch_array($result);
   $lesson= $row["$day"];
   $lesson=trim($lesson);
   $crow1=0;
   
if ( $lesson == ""){ echo " Δεν υπάρχει μάθημα ";}

else 
{
if (strlen($lesson)==4) {
	$lesson=str_replace(" ","0",$lesson);
	$less=$lesson;
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$lesson' ");
$crow1=mysqli_num_rows($result);

$i=1;
 while($row = mysqli_fetch_array($result))
     {
	 $mt[$i]=$row['mitroo'];
	 $epo[$i]=$row['eponimo']." ".$row['onoma'];
	 
	 $i++;}
}
if (strlen($lesson) > 4)
{
	$result = mysqli_query($con,"SELECT pmp,mathitis,tmima FROM syndidaskalies WHERE synd = '$lesson' ");
	$crow1=mysqli_num_rows($result);
	$cr=1;
	while($row=mysqli_fetch_array($result)){	
		$mt[$cr]=$row['pmp'];
	    $epo[$cr]=$row['mathitis'];	
		$cr++;}
	}
	
	if ($crow1==0){
		
		$pos=strpos($lesson,"Α");
		
		$les=substr($lesson,$pos,2);
		
		$pos=$pos+2;
		
		$les1=substr($lesson,$pos,1);
		
		$les=trim($les)."0".trim($les1);
		echo "xxx".$les."xxx";
		$les=ltrim(rtrim($les));
		$_SESSION['less']=$lesson;
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$les' ");
$crow1=mysqli_num_rows($result);
    $i=1;
    while($row = mysqli_fetch_array($result))
     {
	 $mt[$i]=$row['mitroo'];
	  $epo[$i]=$row['eponimo']." ".$row['onoma'];
	 $i++;
	 }
	
	
	
	
}	
		
//..............................................

$res1=mysqli_query($con, "SELECT code,onoma FROM ekdilosi WHERE date = '$dt' ");
$c1=mysqli_num_rows($res1);
echo "<br >"."ΣΥΝΟΛΟ ΔΡΑΣΤΗΡΙΟΤΗΤΩΝ ΣΤΙΣ:".$dt. " .ΕΙΝΑΙ. ". $c1."<br >";

 if ($c1 > 0)  {  
 $i=0;
 while($row = mysqli_fetch_array($res1))
     {
	 $codekd[$i]=$row['code'];
	 $onomaekd[$i]=$row['onoma'];
	 $i++;
    }
 }
echo " Διδάσκων :<input type='text' name='name' value='$name' />" ;
echo " Περίοδος :<input type='number' name='per' value='$per' /> ";
echo " Τμήμα/Συνδ.:<input type='text' name='lesson' value='$lesson' /> <br /><br />  ";
$_SESSION['less']=$lesson;


?>

<form method="POST" name = "eggrafi" action="eggrafi.php" ><input type='hidden' name='__token_timestamp__' value='1402845193'><input type='hidden' name='__token_val__' value='5343d0c12025a077478cefe21dbbefbb'>
<p> Να βάλετε την απουσία τικάροντας το αντίστοιχο κουτί και να σημειώσετε την καθυστέρηση στην κατάλληλη στήλη. Πατήστε Submit για να καταγραφούν οι απουσίες </p>
<?php
echo "<table border='3'>
<tr>
<th>α/α</th>
<th>Α.Μ</th>
<th>Όνοματεπώνυμο</th>
<th>Απουσία</th>
<th>Καθυστ.</th>
<th>Δραστηριότητα</th>

</tr>";


$i=1;
 while($i<=$crow1)
     {
	 echo "<tr>";
	 echo "<td>" .$i;
	 echo "<td>". "<input type='text' name='mt[]' value='$mt[$i]' size='6' >" . "</td>";
	 echo "<td>". "<input type='text' name='epo[]' value='$epo[$i]' size='30' >" . "</td>";
     echo "<td>". "<input type='checkbox' name='att[]' value='$mt[$i]'>" ."</td>";
	 echo "<td>". "<input type='number' name='kath[]' size='5' >" ."</td>";
 	 //................
	 if ($c1 > 0 ) {
	 
	 $i1=0;
	 
	 foreach ($codekd as $cdo) {
	 
	 	 $q2 =mysqli_query($con, "SELECT p1,p2,p3,p4,p5,p6,p7 FROM ekdilosistu WHERE pmp = '$mt[$i]' AND code='$cdo' ");
	 $c2=mysqli_num_rows($q2);
	 if ($c2 > 0){
	   
	 $row2 = mysqli_fetch_array($q2);
	  $p1=$row2['p1'];$p2=$row2['p2'];$p3=$row2['p3'];$p4=$row2['p4'];$p5=$row2['p5'];$p6=$row2['p6'];$p7=$row2['p7'];		
		$np="p".$per;
	    if ($$np == 1) { echo "<td>". $onomaekd[$i1] ."</td>"; }}
			   
	 $i1++; }}

	 echo "</tr>";
$i++;
}

echo "</table>";
$_SESSION['fg']=$i;

echo "ΚΑΤΑΓΡΑΦΗ ΤΗΣ ΥΛΗΣ...μπορεί να γίνει και αργότερα από το απουσιολόγιο";
echo "<br>";
echo "<textarea name='perigrafi' cols='80' rows='3'> Καταγραφή της Ύλης </textarea >"."<br >";

?>
<input type="Submit" name="Submitapou" value="Καταχώρηση">
</form>
<?php
}
}
echo "<br>";
echo "<br>";
?>
<a  href=<?php echo $menu;?> style="color:blue "  >  Επιστροφή στο Μενού  </a>
</body>
</html>