<?php
include "scrinit.php";
include $menu;
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>entopismos mathiti</title>
</script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function() {
 $("#tmimaid").bind("change", function() {
     $.ajax({
         url: "change.php",
         data: "tmimaid="+$("#tmimaid").val(),
         success: function(html) {
             $("#nameid").html(html);
         }
     });
 }); 
});

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=900, height=300, top='+top+', left='+left);
}
</script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }

.fieldset1
{
    width:800px;
	background: #F5F9F0;
	border:2px solid green;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;	
    border-radius:4px;	
}
</style>
</head>

<body>

<?php
require "dbconnect.php";
$gym=$_SESSION['gym'];
$usr=$_SESSION['pmp'];
$dt=$_SESSION['dt'];

$sql2 = mysqli_query($con,"SELECT DISTINCT tmima FROM allstudentinfo ORDER BY tmima ASC");
   
?>
 
<form  method='post'> 
<fieldset fieldset class="fieldset1" >
<legend><b>EΝΤΟΠΙΣΜΟΣ ΜΑΘΗΤΗ / ΤΡΙΑΣ </b></legend>
<?php
require "selectst.php";
?>
<input type="submit" name="submit1" value="Επιβεβαίωση Επιλογής" >
<br><br>

</form>
<?php
//................................
if (isset($_POST['nameid']))
{
    include "allagiprog.php";
    $per=$_POST['ora']; 
    $am=$_POST['nameid'];
    $tm1=trim($_POST['tmimaid']);
	$lesson="";
	$dayx="day".$per;
	$sql = "SELECT mitroo,eponimo,onoma  FROM allstudentinfo WHERE mitroo='$am'";
    $result = mysqli_query($con,$sql);
	$row = mysqli_fetch_array($result);
	$nm=$row['eponimo']." ".$row['onoma'];
	$sql = "SELECT * FROM dailytab WHERE trim(".$dayx.")='$tm1' ";
	$result = mysqli_query($con,$sql);
	$c=mysqli_num_rows($result);
	if ($c > 0 ) 
	{
		$row = mysqli_fetch_array($result);
		$name=$row['Teacher'];
		$id=$row['id'];
		$nid=$id+1;
	    $res1 = mysqli_query($con,"SELECT * FROM dailytab WHERE id='$nid'  " ); 
        $row3 = mysqli_fetch_array($res1); 
	    $roomx= $row3["$dayx"];
	}
	else
	{
		$sql = "SELECT sc.synd,sc.kathigitis  FROM syndidaskalies as s,syndcodes as sc 
		WHERE s.mitroo='$am' and s.syndid=sc.syndid";
		$result = mysqli_query($con,$sql);
		
		 while ($row = mysqli_fetch_array($result)) 
		 {
			$name=rtrim(ltrim($row['kathigitis']));
			$res = mysqli_query($con,"SELECT * FROM dailytab WHERE Teacher='$name' " ); 
			$row2 = mysqli_fetch_array($res);
			$id=$row2['id'];
			$lesson=$row2["$dayx"];
			$lesson=rtrim(ltrim($lesson));
			if ((rtrim(ltrim($row['synd']))==$lesson) OR ($lesson==$tm1))
			  {
				$nid=$id+1;
				$res1 = mysqli_query($con,"SELECT * FROM dailytab WHERE id='$nid'  " ); 
				$row3 = mysqli_fetch_array($res1); 
				$roomx= $row3["$dayx"];
			   
				break ;
			  }
	     }
	}
	 
echo "<br>";
echo '<p style="color: red"> ΑΠΟΤΕΛΕΣΜΑ ΕΝΤΟΠΙΣΜΟΥ </p>';
echo "<table class='myTable' >
<tr style='border:1px solid black' >
<th>Περίοδος</th>
<th>Τμήμα/Συνδιδασκαλια</th>
<th>Α.Μ</th>
<th>Όνοματεπώνυμο</th>
<th>Τμήμα</th>
<th>Αίθουσα/Μάθημα</th>
<th> Καθηγητής / Ύλη</th>
</tr>";

		 echo "<tr >";
		 echo "<td>". $per. "</td>";
	     echo "<td>". $lesson.  "</td>";
		 echo "<td>". $am. "</td>";
	     echo "<td>". $nm. "</td>";
	     echo "<td>". $tm1. "</td>";
	     echo "<td>". $roomx. "</td>";
		 echo "<td>". $name . "</td>";
	     echo "</tr>"; 
echo "</table>";	 
//}
}
 ?>
<br /><br />
</fieldset>

</body>
</html>