<?php
include "scrinit.php";
?>
<head>
<html xmlns="https://www.w3.org/1999/xhtml">
<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:10pt; }
.bt1 {
  color: green;
  border-radius: 5px;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid ;
  padding:4px;
}
<p style="font-size:10px;"></p>
</style>
<script type="text/javascript">
    function do_this(){

        var checkboxes = document.getElementsByName('att[]');
        var button = document.getElementById('toggle');

        if(button.value == 'Επιλογή όλων των μαθητών/τριών'){
            for (var i in checkboxes){
                checkboxes[i].checked = 'FALSE';
            }
            button.value = 'Αποεπιλογή όλων των μαθητών/τριών'
        }else{
            for (var i in checkboxes){
                checkboxes[i].checked = '';
            }
            button.value = 'Επιλογή όλων των μαθητών/τριών';
        }
    }
</script>

</head>
<body>
<?php
require "dbconnect.php"; 
$dt=$_SESSION['dt'];
$name = $_SESSION['n'];
$usr=$_SESSION['usr'];
$gym=$_SESSION['gym'];

$pas=$_GET['pas'];
$ar = explode("/", $pas);
$lesson = $ar[0];
$subject = $ar[1];
$per = $ar[2];

/*if( ! filter_var($per, FILTER_VALIDATE_INT) ){
  echo "Η ΠΕΡΙΟΔΟΣ ΔΕΝ ΕΙΝΑΙ ΑΚΕΡΑΙΟΣ ΑΡΙΘΜΟΣ";
  sleep(3);
  header("Location: index.php"); // Redirect browser 
  exit();
}*/
$user = $ar[3];
$pop = $ar[4];
$rms=$per."/".$ar[5];
$_SESSION['rms']=$rms;
if ($user<>""){$usr=$user;}

$day = date('D', strtotime($dt));  

$less=$lesson;
$result = $dbcon->prepare("SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima=? ORDER BY eponimo,onoma");
$result->execute([$lesson]);
$crow1 = $result->rowCount();
if ($crow1 > 0) 
{
  $i=1;
  while ($row = $result->fetch(PDO::FETCH_ASSOC))
     {
	  $mt[$i]=$row['mitroo'];
	  $epo[$i]=$row['eponimo']." ".$row['onoma'];
	  $tmim[$i]=$lesson;
	  $i++;
	  }
}
else // den eine amiges tmima alla syndidaskalia
{
  $result = $dbcon->prepare("SELECT distinct sc.synd,sy.mitroo,al.eponimo,al.onoma,al.tmima FROM 
  syndidaskalies as sy,allstudentinfo as al,syndcodes as sc WHERE sc.syndid=sy.syndid and sc.synd = ? AND sy.mitroo=al.mitroo 
  ORDER BY al.eponimo,al.onoma");
  $result->execute([$lesson]);
  $crow1 = $result->rowCount();
  if ($crow1 > 0) 
  {
	$cr=1;
	while ($row = $result->fetch(PDO::FETCH_ASSOC))
	{	
		$mt[$cr]=$row['mitroo'];
	    $epo[$cr]=$row['eponimo']." ".$row['onoma'];	
		$tmim[$cr]=$row['tmima'];
		$cr++;}
  }
  else
  {
    	$apr=$mt=$epo=$tmim=$apr=array();
		$pos=strpos($lesson,"Α");
		$les=substr($lesson,$pos,2);
		$pos=$pos+2;
		$les1=substr($lesson,$pos,1);	
		$les=trim($les)."0".trim($les1);
		$les=ltrim(rtrim($les));
		$result = $dbcon->prepare("SELECT mitroo,eponimo,onoma FROM allstudentinfo WHERE tmima=? ORDER BY eponimo,onoma");
		$result->execute([$les]);
		$crow1 = $result->rowCount();
		$i=1;
		while ($row = $result->fetch(PDO::FETCH_ASSOC))
		{
		 $mt[$i]=$row['mitroo'];
		 $epo[$i]=$row['eponimo']." ".$row['onoma'];
		 $tmim[$i]=$les;
		 $i++;
		}
  }		
}	

//*********************** add apallages ston katalogo

$apal= $dbcon->prepare("select ap.mitroo,a.eponimo,a.onoma,a.tmima from apallages as ap,allstudentinfo as a 
                   where ap.teachin=? AND ap.dayout=? AND ap.perout=? AND a.mitroo=ap.mitroo");
$apal->execute([$usr,$day,$per]);
$i=count($mt)+1;
while ($rapal = $apal->fetch(PDO::FETCH_ASSOC))
{
     $mt[$i]=$rapal['mitroo'];
	 $epo[$i]=$rapal['eponimo']." ".$rapal['onoma'];
	 $tmim[$i]=$rapal['tmima'];
	 $apr[$i]=1;
	 $i++;	 
}

//..............................................
$ap=array();$stoli=array();$kath=array();

$cc=count($mt);
//////////// stiriksi out
for ($i=1;$i<=$cc;$i++)
{
/*	
 $stir= $dbcon->prepare("SELECT * FROM stiriksi WHERE mitroo=? AND lessonout=? AND day=? AND period=?");
 $stir->execute([$mt[$i],$lesson,$day,$per]);
 $cnt = $stir->rowCount(); 
			 if ($cnt > 0){$ap[$i]='disabled';}
	
$om= $dbcon->prepare("SELECT * FROM codemit WHERE mitroo=? AND code<>?");
$om->execute([$mt[$i],$omada]);
$cnt = $om->rowCount();
if ($cnt > 0){$ap[$i]='disabled';}	
*/	 
 $apal=$dbcon->prepare("SELECT * FROM apallages WHERE mitroo='$mt[$i]' AND teachout='$usr' AND dayout='$day' AND perout='$per'");
			 $apal->execute([$mt[$i],$usr,$day,$per]);
             $cnta = $apal->rowCount();
			 if ($cnta > 0){$ap[$i]='disabled';}	
			 
}

?>
</body>
</html>