<?php
if(!isset($_SERVER['HTTP_REFERER'])){
    // redirect them to your desired location
    header('location:../index.php');
    exit;
}
?>
<?php 
include_once('config.php');

?>
<?php
//fetch.php
if(isset($_POST["action"]))
{
 $output = '';
 if($_POST["action"] == "anneeId")
 {
   $query = "SELECT * FROM affectation_module,modules
   where  affectation_module.moduleId=modules.moduleId and affectation_module.anneeId = '".$_POST["query"]."' 
   GROUP BY affectation_module.moduleId ORDER BY affectation_module.moduleId ASC";
    
  $result = mysqli_query($conn, $query);
  
  $output .= '<option value="">Sélectionnez module</option>';
  while($row = mysqli_fetch_array($result))
  {
   $output .= '<option value="'.$row["moduleId"].'">'.$row["Designation"].'</option>';
  }
 }
 if($_POST["action"] == "moduleId")
 {
  $query = "SELECT * FROM groupes,modules WHERE modules.moduleId = '".$_POST["query"]."' and groupes.anneeId=modules.anneeId";
  $result = mysqli_query($conn, $query);
  $output .= '<option value="">Sélectionnez groupe</option>';
  while($row = mysqli_fetch_array($result))
  {
   $output .= '<option value="'.$row["groupeId"].'">'.$row["designation"].'</option>';
  }
 }
 
 echo $output;
}


?>
