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

<body>
<form method='post' action='effacernotes.php' >
<?php
include("_serveur.php");
include 'header.php';

echo "<a href=\"javascript:history.go(-1)\"><button type='button' >Retourner</button></a>";
$classe=$_SESSION['classe'];
$classeID=$_SESSION['classeid'];
$controle1=$_SESSION['ctrl1'];
$subSubjectID1=$_SESSION['subSubjectID'];
$cellctr=explode(";",$controle1);
$ctrlID=$cellctr[0];
$controle1=$cellctr[1];


$sql1 = 'SELECT * from grades join gradesSubjects on gradesSubjects.classID= grades.classID and gradesSubjects.subSubjectID=grades.subSubjectID
                              join students on grades.studentID=students.id and grades.classID=students.ClassID
							  join users on users.id=students.userID
 where grades.classID = "'.$classeID.'" and grades.semesterID="'.$ctrlID.'" and grades.subSubjectID = "'.$subSubjectID1.'"
 order by students.firstName,students.lastName,users.firstName';
   if(!(mysqli_query($link, $sql1))){
    echo "ERROR: Could not able to execute $sql1. " . mysqli_error($link);
}
$req1=  mysqli_query($link, $sql1);
echo '<div class="w3-panel w3-blue w3-round-xlarge"><p>'.$classe1.'<pre>'.$controle1.'</p></div>';

echo '<table class="w3-table w3-striped w3-bordered" align="center">';
	 echo "<tr><th><strong>Numéro</th></strong><th><strong>Prénom&emsp;Père&emsp;Famille</strong> </th>
	 <th>Notes</th><th>Coefficient</th></tr>";
$i=0;
$n=0;
 while($data1 = mysqli_fetch_array($req1)) {
	     $gradeid[$n]=$data1[0];
          $grade=$data1[5];
		  $coef=$data1[8];
		  $firstName=$data1[12];
		  $lastName=$data1[13];
		  $middleName=$data1[18];
          
	 $num=$i+1;
	 echo "<tr><td><strong>".$num."</td></strong><td><strong>".$firstName."&emsp;".$middleName."&emsp;".$lastName."</strong> </td>";
echo "<td>".$grade."</td>";
 echo "<td>".$coef."</td></tr>";
   $i=$i+1;
    $n=$n+1;
 }
echo '</table>'; 
 echo '<button class="w3-btn w3-blue-grey" name="effacer">Effacer Les Notes</button>';
 if(isset($_POST['effacer']))
 {
	  $j=0;
	  while($j<$n){
	 $sql='DELETE from grades where id="'.$gradeid[$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>"Notes effacées"</i></p>
  </div>';

 }
?>

 
</body>
</html>