<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="w3.css">
<title>Affiche Agenda</title>
 
</head>
<style>
body {width:90%;}
</style>
<body>

<div class="w3-card-4">
<form method="post" action="_afficheagendap.php" >
<?php
include 'header';
$id=$_SESSION['id'];

include("_serveur.php");
$sql = 'SELECT * FROM teachersSubjects  join subjects on teachersSubjects.subjectID=subjects.id
                                       	join classes on teachersSubjects.classID=classes.id
	                                    where userID= "'.$id.'" order by classes.id,subjects.ordering';
if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
echo '<label class="w3-text-teal" >Classe et Matière:</label><select name="cla" class="w3-select w3-border w3-light-grey">';

while ($data = mysqli_fetch_array($req)) {

$classID=$data[6];
$classen=$data[7];
$ctrlID=$data[20];
$ctrl=$data[21];
$subject=$data[4];
$subjectID=$data[3];

$subSubjectID=$data[9];
$matiere=$data[11];

 echo' <option value="'.$classID.";".$subjectID.'">'.$classen." - ".$subject.'</option>';
	
}

echo '</select><label class="w3-text-teal">Date:</label> <input class="w3-input w3-border w3-light-grey" type="date" name="date" value="'.date("Y-m-d").'" />';
                    
 echo'  <input name="chercher" type="submit" class="style19" value="Envoyer" bgcolor="#CC99FF" /></form></div>';
               
if (isset ($_POST['chercher'])){
$cont1=$_POST['cla'];
 $cellm=explode(";",$cont1);
 $classeid=$cellm[0];
 $subjectId=$cellm[1];
$date=$_POST['date'];	

$sql = 'SELECT * FROM agenda JOIN classes on agenda.classID=classes.id
                             JOIN subjects on agenda.subjectID=subjects.id where agenda.subjectID="'.$subjectId.'" and agenda.classID= "'.$classeid.'"  and agenda.date = "'.$date.'"  ';

   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                            }
echo '<div class="w3-container">

<h2>Agenda</h2>';
$j=1;
$req=mysqli_query($link, $sql);

while ($data = mysqli_fetch_array($req)) {
// on affiche les résultats
$classe=$data[7];
$description=$data[4];
$date=$data['date'];
$matiere=$data['name'];
echo '<div class="w3-container w3-left-align">';
if($j==1) echo '<table width="90%" border=0><tr><td colspan="2"><p align="left"><b>&nbsp;&nbsp;'.$classe.'&nbsp;&nbsp;</b></p></td</tr>';
echo "<tr><td>".$matiere.'</b>&ensp;&ensp;&ensp;&ensp;&ensp;</td><td><button onclick="myFunction('.$j.')" class="w3-button w3-circle w3-blue">+</button></td></tr>
<tr><td colspan="2"><div id="'.$j.'" class="w3-container w3-hide">
  <div class="w3-panel w3-pale-green">'.$description.'</td></tr></div></div></div>';

$j=$j+1;

}
}
?>
<script>
function myFunction(id) {
  var x = document.getElementById(id);
  if (x.className.indexOf("w3-show") == -1) {
    x.className += " w3-show";
  } else { 
    x.className = x.className.replace(" w3-show", "");
  }
}
</script>


</body>
</html>