<?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">
<title>Modifier Observations</title>
</head>

<body>

<form method='post' action='continuerobs.php' >

<?php 
include("_serveur.php");
include 'header.php';

echo "<a href=\"javascript:history.go(-1)\"><button type='button' >Retourner</button></a>";
$classeID=$_SESSION['classeID'];
	$sql = 'SELECT * from students inner join observationsele on observationsele.classID=students.classID and                                                                 observationsele.studentID=students.id
								 where observationsele.classID="'.$classeID.'" order by students.firstName,students.LastName';

   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                               }
$req=  mysqli_query($link, $sql);
$cl=1;
$n=0;
echo '<table class="w3-table w3-striped w3-bordered">';
 while($data = mysqli_fetch_array($req)) {
	 $obserID[$n]=$data[5];
	 $studentID=$data[0];
	 $classID=$data[4];
	 $obser=$data[9];
	 $classe=$data[1];
	 $prenom=$data[2];
	 $fam=$data[3];
	
echo"<tr><td>".$cl."</td><td>".$prenom."</td><td>".$fam."</td>"; ?>
<td><input type="text" name="obser1[]" value="<?php echo $obser ?>"/></td> 
<?php
$cl=$cl+1;
$n=$n+1;
}
                              
			   echo "</table>";				  

 echo '<button class="w3-btn w3-blue-grey" name="modifier">Modifier Observations</button>';
 if(isset($_POST['modifier']))
 {
	  $j=0;
	  $obs=$_POST['obser1'];
	  $obs1=array();
	   $obs1=$obs;
	   print_r($obs1);
	  while($j<$n){
	 $sql='UPDATE observationsele SET obser="'.$obs1[$j].'" where id="'.$obserID[$j].'"';
	    if(!(mysqli_query($link, $sql))){
   echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                       }

	 $j=$j+1;
	  }
	    echo ' <div class="w3-panel w3-leftbar w3-sand w3-xxlarge w3-serif">
    <p align="center"><i>"Observations Modifiées"</i></p>
  </div>';

 }


?>
</body>
</html>