<!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>Bulletin</title>
<style type="text/css">
<!--

@media print  { .noprint  { display: none; }
.page-break  { display:block; page-break-after:always; }
@page  
{ 
   size: 210mm 297mm; 
  /* Chrome sets own margins, we change these printer settings */
  margin: 5mm 5mm 5mm 5mm;
        }

}
body,td,th {
font-family: "Times New Roman", Times, serif;
size:12px;
}
	

-->
</style>
</head>

<body bgcolor="#FFFFFF">

<form method="post" action="_listSubgrades.php" >
<?php
echo "<div class='noprint'>";
include 'header.php';
echo "</div>";
$cycle=$_GET['cycle'];
include '_serveur.php';?>
<input name="cycle" type="hidden" value="<?php $cycle=$_REQUEST['cycle']; echo $cycle; ?>">
<?php
$sql = 'SELECT * from classes where cycleID="'.$cycle.'" order by id DESC';
   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
echo '<div class="noprint">';
echo '<label class="w3-text-teal" >Classe:</label><select name="cla" class="w3-select w3-border w3-light-grey">';

 while($data = mysqli_fetch_array($req)) {
$classe=$data['name'];
$classeid=$data['id'];
$classe=strtoupper($classe);
 echo ' <option value="'.$classeid.";".$classe.'">'.$classe.'</option>';
        };

echo '</select>';  
$sql = 'SELECT * from semesters';
   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" >Contrôle:</label>
<select name="ctrl" class="w3-select w3-border w3-light-grey">';

 while($data = mysqli_fetch_array($req)) {
$ctrln=$data['name'];
$ctrlid=$data['id'];
 echo ' <option value="'.$ctrlid.";".$ctrln.'">'.$ctrln.'</option>';
        };

echo '</select>';


$sql1 = 'SELECT * from subSubjects JOIN subjects on subSubjects.subjectID=subjects.id
                                    join gradesSubjects on subSubjects.id=gradesSubjects.subSubjectID
									join classes on gradesSubjects.classID=classes.id where classes.id="'.$classeid.'"  order by subjects.id, subSubjects.id ';
   if(!(mysqli_query($link, $sql1))){
    echo "ERROR: Could not able to execute $sql1. " . mysqli_error($link); 
	}
$req1=  mysqli_query($link, $sql1);
echo 'Matière:<select name="sub" class="w3-select w3-border w3-light-grey">';

 while($data1 = mysqli_fetch_array($req1)) {
$subject=$data1[4]; 
$matiere=$data1[2];
$subSubjectID=$data1[0];
 echo '<option value="'.$subSubjectID.";".$matiere.'">'.$subject."-".$matiere.'</option>';
        };

echo '</select>'; 

 echo '<input name="chercher" type="submit" class="style19" value="Envoyer" bgcolor="#CC99FF" /></form>';
echo '<button type="button" class="noprint" onclick="window.print()" /><img src="imprimante.png" height="32" width="40" /></div>';

if (isset ($_POST['chercher'])){
	$cla1=$_POST['cla'];
	$cellcla=explode(";",$cla1);
$classeID=$cellcla[0];
$classe=$cellcla[1];

$ctrl1=$_POST['ctrl'];
	$cellctrl=explode(";",$ctrl1);
$ctrlID=$cellctrl[0];
$control=$cellctrl[1];
$sub1=$_POST['sub'];
$cellsub=explode(";",$sub1);
$subSubjectID=$cellsub[0];
$matiere=$cellsub[1];
echo "Classe:".$classe."&nbsp;&nbsp;&nbsp;".$matiere."&nbsp;&nbsp;&nbsp;".$control."&nbsp;&nbsp;&nbsp;Date :".date('d/m/Y');
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>Recit1</th> <th>Recit2</th> <th>Recit3</th> <th>Ctrl1</th><th>Ctrl2</th><th>Ctrl3</th></tr>";
$sql = 'SELECT * from  Subgrades join students on students.id=Subgrades.studentID
                where Subgrades.classID="'.$classeID.'" and Subgrades.semesterID="'.$ctrlID.'" and Subgrades.subSubjectID="'.$subSubjectID.'"  order by students.firstName,students.lastName,Subgrades.classID,Subgrades.subSmesteriD ASC';
   if(!(mysqli_query($link, $sql))){
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
$req=  mysqli_query($link, $sql);
$i=0;
  while($data = mysqli_fetch_array($req)){
		 $studentid1[$i]=$data['studentID']; 
		$Subgrade1[$i]=$data['grade'];
	    $subgradecoef1[$i]=$data['coef'];	
	  $Subid1[$i]=$data['subSmesteriD'];
	  $firstn[$i]=$data['firstName'];
	  $lastn[$i]=$data['lastName'];
	  $i=$i+1;
	  }
	  $k=0;
	  $j=1;
	  $trig=1;
      $num=1;
	  $m=0;
	 while( $k<$i){
	// echo $firstn[$i]."&nbsp;".$lastn[$i]."&nbsp;".$Subgrade1[$i]."/".$subgradecoef1[$i]."<br>";
//	if($trig==0) {echo "<tr><td>".$num."</td><td>".$firstn[$k]."&nbsp;".$lastn[$k]."</td><td>".$Subgrade1[$k]."/".$subgradecoef1[$k]."</td>"; $trig=1;
	if(($k==0)||($trig==0))
	{echo "<tr><td>".$num."</td><td>".$firstn[$k]."&nbsp;".$lastn[$k]."</td><td>".$Subgrade1[$k]."/".$subgradecoef1[$k]."</td>";
	 $num=$num+1;$trig=1; $k=$k+1;$j=$j+1;
	 }           //} 
	elseif(($studentid1[$j]==$studentid1[$k]))
	 {
		echo "<td>".$Subgrade1[$k]."/".$subgradecoef1[$k]."</td>";
		$m=1;
		 $k=$k+1;$j=$j+1;
	 }
	elseif(($studentid1[$j]<>$studentid1[$k])&&($m==1))
		{
		echo "<td>".$Subgrade1[$k]."/".$subgradecoef1[$k]."</td></tr>";
		$trig=0;
		 $k=$k+1;$j=$j+1;
		 }
	else
	{
		   $trig=0;
			echo "</tr>";
	}

  
	 
	  
	  
	  
  }
}
?>
</body>
</html>