<?php
include "scrinit.php";
include $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>
<script type="text/javascript">
$(function() {
 $("#mathsubid").bind("change", function() {
     $.ajax({
         url: "change1.php",
         data: "mathsubid="+$("#mathsubid").val(),
         success: function(html) {
             $("#codeid").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>

</head>

<body>

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


include "selectmath.php";
echo "<p class='p1'>". "ΟΝΟΜΑ ΧΡΗΣΤΗ ΓΙΑ ΤΕΑΜS". "</p>";
echo "<p class='p2'>". "ΕΠΙΛΟΓΗ ΤΜΗΜΑΤΟΣ/ΣΥΝΔΙΔΑΣΚΑΛΙΑΣ". "</p>";

$ind=$ind-1;
$tm=$_POST['mathsubid'];
?>
<form  method='post' > 

	<label><b>Τμήμα/Μάθημα: </b></label><select name='mathsubid' >
	<?php
	echo "<option value=' '>-----------</option>";
	foreach ($mathsubj as $m)
	{ 		  
		  echo "<option value='$m' selectd='<?php if($tm==$m) echo "."selected;"."?>'>$m</option>";
	}
	?>
	</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]);

	
$result = mysqli_query($con,"SELECT DISTINCT s.mitroo,a.eponimo,a.onoma,a.tmima 
FROM syndidaskalies as s,allstudentinfo as a, syndcodes as sc 
WHERE sc.synd = '$tmima' AND s.mitroo=a.mitroo AND sc.syndid=s.syndid ORDER BY a.eponimo,a.onoma");
$crow1=mysqli_num_rows($result);

if ($crow1 > 0)
{
	$cr=1;
	while($row=mysqli_fetch_array($result))
	{	
		$mt[$cr]=$row['mitroo'];
		$r = mysqli_query($con,"SELECT user FROM kodikoi WHERE mitroo='$mt[$cr]'  ");
		$rr= mysqli_fetch_array($r);
		$user[$cr]=$rr['user'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$cr++;
	}
}
else
{	
$result = mysqli_query($con,"SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima='$tmima' ORDER BY eponimo,onoma  ");
$crow1=mysqli_num_rows($result);
    $cr=1;
    while($row = mysqli_fetch_array($result))
     {
	 $mt[$cr]=$row['mitroo'];
	 $r = mysqli_query($con,"SELECT user FROM kodikoi WHERE mitroo='$mt[$cr]'  ");
	 $rr= mysqli_fetch_array($r);
	 $user[$cr]=$rr['user'];
	 $epo[$cr]=$row['eponimo']." ".$row['onoma'];
	 $tmim[$cr]=$tmima;
	 $cr++;
	 } 
}
// number of students
$ns=$cr-1;	

echo "<table class='myTable3' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>
<th>Χρήστης TEAMS</th>
</tr>";
$i=1;
while($i <=$ns){
  echo "<tr>";
  echo "<td>" .$i;
  echo "<td>". $mt[$i] . "</td>";
  echo "<td>". $tmim[$i] . "</td>";
  echo "<td>". $epo[$i] . "</td>";
  echo "<td>". $user[$i] ."</td>"; 
  echo "</tr>";
  $i++;
}
echo "</table>";

}

?>
<br><br>
<a  href='<?php echo $menu;?>' ><button  type="button" class="sb1" >Επιστροφή</button> </a>
</body>
</html>