<?php
session_start();
include "logo.php";
$menu=$_SESSION['menu'];
//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; }
<p style="font-size:11px;"></p>
</style>

</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">


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=1000, height=300, top='+top+', left='+left);
}

function KeepCount()  { 
    var elements = document.getElementsByName("mathkat[]");
    var total = 0;
    for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;
        if(total>4) {
            alert("Να επιλέξετε 3 ή 4 μαθήματα");
            element.checked = false;
            return false;    
        }
    }
  } 
  
function KeepCount2()  { 
    var elements = document.getElementsByName("mathimaglo[]");
    var total = 0;
    for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;
        if(total>2) {
            alert("Να επιλέξετε 2 μαθήματα");
            element.checked = false;
            return false;    
        }
    }
  }
function KeepCount3()  { 
    var elements = document.getElementsByName("mathendi[]");
    var total = 0;
    for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;
        if(total>2) {
            alert("Να επιλέξετε 2 μαθήματα");
            element.checked = false;
            return false;    
        }
    }
  }  

function myFunction() {
var elements = document.getElementsByName("mathimaglo[]");
var total = 0;
for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;}
if(total<2) {
            alert("Να επιλέξετε 2 Γλώσσες");
            element.checked = false;
            return false;
}     

document.forms["form"].submit();
return false;
}

function myFunction2() {
var elements = document.getElementsByName("mathimaglo[]");
var elements1 = document.getElementsByName("mathendi[]");
var total = 0;
var total1 = 0;
for(var i in elements) {
        var element = elements[i];
        if(element.checked) total++;}
if(total<2) {
            alert("Να επιλέξετε 2 Γλώσσεσ");
            element.checked = false;
            return false;
}     
for(var i in elements1) {
        var element1 = elements1[i];
        if(element1.checked) total1++;}
if(total1<2) {
            alert("Να επιλέξετε 2 μαθήματα");
            element1.checked = false;
            return false;
}     
document.forms["form1"].submit();
return false;
}
</script>

</head>
<body  style="width:995px; margin:0 auto; ">

<?php 
$dt2 = date('Y-m-d h:i:sa');
echo $dt2;
if ($dt2 > '2015-02-16 10:00:00') { 
?>
<h2> ΤΟ ΣΥΣΤΗΜΑ ΕΠΙΛΟΓΗΣ ΜΑΘΗΜΑΤΩΝ ΕΧΕΙ ΑΠΕΝΕΡΓΟΠΟΙΗΘΕΙ </h2> 
<?php
} else {

require("dbconnectdilosi.php");

$usr=$_SESSION['usr'];
$tax=$_SESSION['tax'];
$sql=  mysqli_query($con,"SELECT  mitroo FROM dilosimath WHERE mitroo='$usr'");
$row=mysqli_fetch_array($sql);
$c=mysqli_num_rows($sql);
if ($c > 0 ) { //o mathitis exei kanei dilosi
  
  ?><h2>ΑΛΛΑΓΗ  ΜΑΘΗΜΑΤΩΝ  <?php echo $tax." Τάξης"?> </h2><?php
   $_SESSION['allagi']=1;
}
else
{
?><h2>ΕΠΙΛΟΓΗ ΜΑΘΗΜΑΤΩΝ <?php echo $tax." Τάξης"?> </h2><?php
$_SESSION['allagi']=0;
}

$sql = mysqli_query($con,"SELECT  no,mathima FROM mathimata WHERE taxi='$tax' And katigoria='KAT'");
$sql1 = mysqli_query($con,"SELECT  no,mathima FROM mathimata WHERE taxi='$tax' And katigoria='GLO'");
$sql2 = mysqli_query($con,"SELECT  no,mathima,notallowed,musthave FROM mathimata WHERE taxi='$tax' And katigoria='ENDI'");

$sql3=  mysqli_query($con,"SELECT  * FROM dilosimath  WHERE mitroo='$usr' " );
$row3=mysqli_fetch_array($sql3);
   $mthk[1]=$row3['math1'];
   $mthk[2]=$row3['math2'];
   $mthk[3]=$row3['math3'];
   $mthk[4]=$row3['math4'];
   $mthe[1]=$row3['endi1'];
   $mthe[2]=$row3['endi2'];
   $mthg[1]=$row3['glo1'];
   $mthg[2]=$row3['glo2'];
?>


<h3>ΜΑΘΗΜΑΤΑ ΚΑΤΕΥΘΥΝΣΗΣ - <b>Επέλεξε 3 η 4 μαθήματα!</b></h3>
<form  name='xx' method='post'>
<div style="overflow:scroll; border:1px solid black;width:400px; height: 400px">
<?php
$i=1;
while($row = mysqli_fetch_array($sql) ) 
  { 
  $mth[$i]=$row['mathima'];
  if (in_array($mth[$i], $mthk)) {
     echo "<br>"."<input type='checkbox' value='$mth[$i]' name='mathkat[]' onClick='return KeepCount()' checked >" .$mth[$i];}
   else
   {
	 echo "<br>"."<input type='checkbox' value='$mth[$i]' name='mathkat[]' onClick='return KeepCount()'  >" .$mth[$i];   
   }

  }
?>
</div>
<br>
<input type="submit" name="submit1" value="Επιλογή Μαθημάτων Κατεύθυνσης" >
</form>

<?php
if (isset($_POST['submit1']))
{
$mathkat=$_POST['mathkat'];
$_SESSION['mathkat']=$mathkat;
$cnt=count($mathkat);
echo " Έχετε επιλέξει 3 μαθήματα κατεύθυνσης";	echo "<br>";
echo "Τα μαθήματα που έχετε επιλέξει : "."<br>";
foreach ($mathkat as $mkat) {echo $mkat." ";}
//print_r($mathkat);

if ($cnt < 3) {
 echo 
  "<script type=\"text/javascript\">".
  "window.alert('ΠΡΕΠΕΙ ΝΑ ΕΠΙΛΕΞΕΤΕ 3 η 4 ΜΑΘΗΜΑΤΑ ΚΑΤΕΥΘΥΝΣΗΣ! ');".
  "top.location = 'diloseisB.php';".
  "</script>";       
}
else
{
if ($cnt==4) {
	?>
    <div>
    <h3>ΞΕΝΕΣ ΓΛΩΣΣΕΣ ΚΟΙΝΟΥ ΚΟΡΜΟΥ- <b>Επέλεξε 2 Γλώσσες!</b></h3>
    
<form id="form" name="form" action='diloseisin.php'>
<div style="overflow:scroll; border:1px solid black;width:400px; height: 200px">

    <?php
    $i=1;
    while($row1 = mysqli_fetch_array($sql1) )
    { 
      $mth1[$i]=$row1['mathima'];
	  if (in_array($mth1[$i], $mthg)) {
     echo "<br>"."<input type='checkbox' value='$mth1[$i]' name='mathimaglo[]' onClick='return KeepCount2()' checked >" .$mth1[$i];}
   else
   {
	 echo "<br>"."<input type='checkbox' value='$mth1[$i]' name='mathimaglo[]' onClick='return KeepCount2()' >" .$mth1[$i];   
   }
    }
    ?>
    </div>
    <br>  
<input name="submit2" onClick="myFunction()" type="button" value="EΠΙΛΟΓΗ ΞΕΝΩΝ ΓΛΩΣΣΩΝ">
</form>
  
    <?php
    if (isset($_POST['submit2']))
    {
    $mathglo=$_POST['mathimaglo'];
    print_r($mathglo);
    $cnt1=count($mathglo);}
}
else
{
   ?>
   <h3>ΝΑ ΕΠΙΛΕΞΕΙΣ 2 ΜΑΘΗΜΑΤΑ ΕΝΔΙΑΦΕΡΟΝΤΟΣ ΚΑΙ 2 ΞΕΝΕΣ ΓΛΩΣΣΕΣ</b></h3>
   <h3>ΜΑΘΗΜΑΤΑ ΕΝΔΙΑΦΕΡΟΝΤΟΣ- <b>Επέλεξε 2!</b></h3>  
  <form id="form1" name="form1" action='diloseisin.php'>
   <div style="overflow:scroll; border:1px solid black;width:400px; height: 200px">
    <?php
    $i=1;
    while($row2 = mysqli_fetch_array($sql2) )
    { 
      $endi[$i]=$row2['notallowed'];
	  $must[$i]=$row2['musthave'];
	  $mthendi[$i]=$row2['mathima'];
	  if (!in_array($endi[$i],$mathkat) And $must[$i] == NULL){
	      if (in_array($mthendi[$i], $mthe)) {
    echo "<br>"."<input type='checkbox' value='$mthendi[$i]' name='mathendi[]' onClick='return KeepCount3()' checked >" .$mthendi[$i];}
         else
   {
	echo "<br>"."<input type='checkbox' value='$mthendi[$i]' name='mathendi[]' onClick='return KeepCount3()' >" .$mthendi[$i];   
   }	  
	  }
     
	  if (in_array($must[$i],$mathkat)) {
	  if (in_array($mthendi[$i], $mthe)) {
    echo "<br>"."<input type='checkbox' value='$mthendi[$i]' name='mathendi[]' onClick='return KeepCount3()' checked >" .$mthendi[$i];}
   else
   {
	echo "<br>"."<input type='checkbox' value='$mthendi[$i]' name='mathendi[]' onClick='return KeepCount3()' >" .$mthendi[$i];   
   }
	  }  
	}
	
    ?>
    </div>
    <h3>ΞΕΝΕΣ ΓΛΩΣΣΕΣ ΚΟΙΝΟΥ ΚΟΡΜΟΥ- <b>Επέλεξε 2 Γλώσσες!</b></h3>
    <div style="overflow:scroll; border:1px solid black;width:400px; height: 200px">
    <?php
    $i=1;
    while($row1 = mysqli_fetch_array($sql1) )
    { 
      $mth1[$i]=$row1['mathima'];
	  if (in_array($mth1[$i], $mthg)) {
     echo "<br>"."<input type='checkbox' value='$mth1[$i]' name='mathimaglo[]' onClick='return KeepCount2()' checked >" .$mth1[$i];}
   else
   {
	 echo "<br>"."<input type='checkbox' value='$mth1[$i]' name='mathimaglo[]' onClick='return KeepCount2()' >" .$mth1[$i];   
   }
   
    }
    ?>
    </div>
    <br>  
    <input name="submit2" onClick="myFunction2()" type="button" value="EΠΙΛΟΓΗ ΜΑΘ.ΕΝΔΙΑΦΕΡΟΝΤΟΣ ΚΑΙ ΞΕΝΩΝ ΓΛΩΣΣΩΝ">
</form>
    <?php
   
}
}
}
}
?>	
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>

</body>
</html>