<?php
include "scrinit.php";
include $menu;
?>
<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; }

</style>
<body>

<h3> ΕΠΙΛΟΓΗ  ΜΑΘΗΜΑΤΟΣ </h3>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$access=$_SESSION['access'];
$gym=$_SESSION['gym'];
if ($access == 4 or $access == 5 or $acess==8)
{
	$_POST['mathsubid']='1';
}
else
{
include "selectsubj1.php";
?>
<form method='post'> 
    <label><b>Επιλογή Μαθήματος : </b></label><select name='mathsubid' id='mathsubid'>
    <?php
    foreach ($mathsubj as $m)
	{ 
          echo "<option value='$m'>$m</option>";
    }
    ?>
    </select>
<input type="submit" name="submitb" value="Επιβεβαίωση Επιλογής" >
</form>
<br>
<?php
}

if (isset($_POST['mathsubid']))
{	
$tm=$_POST['mathsubid'];
$df=array('','Επιπρόσθετος χρόνος','Ορθογραφία/Σύνταξη','Απλοποίηση δοκιμίου','Μεταγραφέας','Έμφαση στα Προφορικά','Μικρά διαλείμματα');
if ($tm <> '1')
{
$ar=explode("/",$tm);
$synd=trim($ar[0]);

$result = mysqli_query($con,"SELECT  mitroo,eponimo,onoma,tmima FROM allstudentinfo WHERE tmima='$synd' ORDER BY eponimo,onoma");
if(mysqli_num_rows($result) == 0)
{
   $result = mysqli_query($con,"SELECT  DISTINCT a.mitroo,a.eponimo,a.onoma,a.tmima FROM syndidaskalies as s,allstudentinfo as a,syndcodes as c 
   WHERE c.synd = '$synd' AND s.syndid=c.syndid AND s.mitroo=a.mitroo ORDER BY a.eponimo,a.onoma");	
}
}
else
{
$result = mysqli_query($con,"SELECT  mitroo,eponimo,onoma,tmima FROM allstudentinfo ORDER BY eponimo,onoma");
}
$crow1=mysqli_num_rows($result);
$cr=1;
while($row=mysqli_fetch_array($result))
	{	
		$mt[$cr]=$row['mitroo'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$dfx='';
		$flag[$cr]=0;
		$sql = mysqli_query($con,"SELECT * FROM problimata WHERE mitroo='$mt[$cr]'  " );
        $c=mysqli_num_rows($sql);
        if ($c > 0)
           {
			$row = mysqli_fetch_array($sql);
		    $problima[$cr]=$row['problima'];
			$aporos[$cr]=$row['aporos'];
			$flag[$cr]=1;
			for ($k=1;$k<=6;$k++)
			{
			  $x='dief'.$k;
			  if ($row["$x"]<>0){$dfx=$dfx.$row["$x"].",";} 
			}
			$dfx=trim($dfx,',');
		}
		$diefk[$cr]=$dfx;
		$sql = mysqli_query($con,"SELECT * FROM apallagesm WHERE mitroo='$mt[$cr]'  " );
        $c=mysqli_num_rows($sql);
		$ap='';
        if ($c > 0)
        {
			$flag[$cr]=1;
			$i=1;
			while($row=mysqli_fetch_array($sql))
			{
			   $apalg[$i]=$row['mathima'];
			   $pera[$i]=$row['per'];
			   $ap=$ap.$apalg[$i]."(".$pera[$i]."),";
			   $i++;
			}
			$apa[$cr]=rtrim($ap,',');
        }
		$sql = mysqli_query($con,"SELECT * FROM stiriksim WHERE mitroo='$mt[$cr]'  " );
        $c=mysqli_num_rows($sql);
		$st='';
        if ($c <> 0)
        {
			$flag[$cr]=1;
			$i=1;
			while($row=mysqli_fetch_array($sql))
			{
				$stir[$i]=$row['mathima'];
				$pers[$i]=$row['per'];
				$st=$st.$stir[$i]."(".$pers[$i]."),";
				$i++;
			}
		}
		$str[$cr]=rtrim($st,',');
		$cr++;
	}
if (array_search(1,$flag) == 0) 
{
	echo "ΔΕΝ ΥΠΑΡΧΟΥΝ ΜΑΘΗΤΕΣ/ΤΡΙΕΣ";
}
else
{
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>α/α</th>
<th>Α.Μ</th>
<th>Τμήμα</th>
<th>Όνοματεπώνυμο</th>
<th>Προβλήματα</th>
<th>Άπορος/η</th>
<th>Στήριξη</th>
<th>Διευκολύνσεις</th>
<th>Απαλλαγές</th>
</tr>";

$ii=1;$j=1;
while($ii<=$crow1)
{
	if($flag[$ii]==1)
	{
	 echo "<tr>";
	 echo "<td>" .$j;
	 echo "<td>". $mt[$ii]. "</td>";
	 echo "<td>". $tmim[$ii]. "</td>";
	 echo "<td>". $epo[$ii] . "</td>";
	 echo "<td>".$problima[$ii]."</td>";
	 echo "<td>".$aporos[$ii]."</td>";
	 echo "<td>".$str[$ii]."</td>";
	 echo "<td>". $diefk[$ii]."</td>";
	 echo "<td>". $apa[$ii]."</td>";
	 echo "</tr>";
	 $j++;
	}
     $ii++;
}
echo "</table>";
echo "<br>"."<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:14px'  >
<th>ΚΩΔΙΚΟΣ</th>
<th>ΔΙΕΥΚΟΛΥΝΣΗ</th>
</tr>";
for ($i=1;$i<=6;$i++)
{
	 echo "<tr>";
	 echo "<td>" .$i. "</td>";;
	 echo "<td>". $df[$i]. "</td>";
	 echo "</tr>";
}
echo "</table>";
}


}
?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>

</body>
</html>