<?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>modifier agenda</title>
</head>

<body>
<?php
include("_serveur.php");

$classeid =$_SESSION['classeid'];
$subjectId=$_SESSION['subjectId'];
$date=$_SESSION['date'];
echo '<form method="post" action="continuemod.php" >';

$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
$agendaid=$data[0];
$classe=$data[7];
$description=$data[4];
$date=$data[3];
$matiere=$data[10];
echo '<input class="w3-input w3-border w3-light-grey" type="hidden" name="agendaID" value="'.$agendaid.'" />';

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></tr>
<tr><td colspan="2"><div id="'.$j.'" class="w3-container">
<div class="w3-panel w3-w3-light-grey"><textarea name="des" cols="60" rows="4" class="style16" > 
                                     '.$description.'</textarea></td></tr></div></div></div>';

$j=$j+1;

}
 echo'</table><table width="90%"><tr><td><input name="modifier"  class="w3-input w3-border w3-light-grey" type="submit" class="style19" value="Modifier" bgcolor="#CC99FF" /></td</tr></table></form></div>';
if (isset ($_POST['modifier'])){
	$agendaID1=$_POST['agendaID'];
	$des1=$_POST['des'];

		 $sql='UPDATE agenda SET description="'.$des1.'" where id="'.$agendaID1.'"';
	    if(!(mysqli_query($link, $sql))){
   echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                                    }
	  echo '<tr><td> <div class="w3-panel w3-leftbar w3-sand w3-xxlarge w3-serif">
    <p align="center"><i>Agenda modifiée avec succès</i></p>
  </div></td></tr>'; 
								

}
?>


</body>
</html>