<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="w3.css">

<title>Bulletin</title>
<style type="text/css">
<!--

.style1 {
	font-size: 24px;
	font-weight: bold;
}
body,td,th {
	color: #000033;
	font-size: 14px;
	
}
body {
	background-color: #FFFFFF;
}

.carnet {
	
	font-size:14px;
	height:29px;
	font-weight: bold;
}
.carnet1 {
	font-weight:normal;
	font-size:14px;
	height:29px;
	
}
.joe {
	font-style: italic;
}
-->
</style>
</head>
<body>

<form method="post" action="_affichenotespaerclassec1.php" >

<?php
include 'header.php';
$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 ASC';
   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:</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.'</option>';
        };

echo '</select>';

                    
 echo'  <input name="chercher" type="submit" class="style19" value="Envoyer" bgcolor="#CC99FF" /></form>';

if (isset ($_POST['chercher'])){
$classeid1=$_POST['cla'];
$sql = 'SELECT * from classes inner JOIN classesSemesters on classes.id=classesSemesters.classID
                               inner JOIN semesters on semesters.id=classesSemesters.semesterID where classesSemesters.classID="'.$classeid1.'" order by semesters.id' ;

   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)){
   $cont[$i]=$data[8];
   $i=$i+1;
  }
$sql = 'SELECT * from gradesSubjects inner join subSubjects on gradesSubjects.subSubjectID=subSubjects.id
							   inner join subjects on subSubjects.subjectID=subjects.id
							   where gradesSubjects.classID="'.$classeid1.'" order by subjects.ordering,gradesSubjects.ordering  ' ;
   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)){
	  $coefficient1[$i]=$data[2];
	  $sousmatid1[$i]=$data[4];
	  $matsous[$i]=$data[5];
	  $sousmat1[$i]=$data[6];
	  $matid1[$i]=$data[7];
	  $mat1[$i]=$data[8];
	  
	 // echo  $matid1[$i]." ".$mat1[$i]." ".$sousmatid1[$i]." ".$sousmat1[$i]." ".$coefficient1[$i]."<br>";
  $i=$i+1;
   }
   $matid2 = array_unique($matid1, SORT_REGULAR);

   $mat2=array_unique($mat1, SORT_REGULAR);
   
$sql = 'SELECT * from  classes  left join students on  students.classID=classes.id
                                left  join grades on students.id=grades.studentID and students.classID=grades.classID 
                                left join gradesSubjects on grades.subSubjectID=gradesSubjects.subSubjectID and grades.classID=gradesSubjects.classID
							     left join subSubjects on grades.subSubjectID=subSubjects.id
							    left join subjects on subSubjects.subjectID=subjects.id
							    left join classesSemesters on classesSemesters.classId=classes.id and grades.semesterID=classesSemesters.semesterID
							    left join semesters on semesters.id=classesSemesters.semesterID 
                                where classes.id="'.$classeid1.'" order by students.firstName,students.lastName,subjects.id,subSubjects.id,semesters.id , subjects.ordering' ;
   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)){
		 $studentid[$i]=$data[3]; 
		 $prenom[$i]=$data[5];
	  	 $famille[$i]=$data[6];
		$grade[$i]=$data[13];
	  $discipcoef[$i]=$data[16];	
	  $discipid[$i]=$data[18];
	  $discip[$i]=$data[20];
	  $matid[$i]=$data[21];
	  $mat[$i]=$data[22];
	  $orderm[$i]=$data[23];
	  $ctrlid[$i]=$data[28];
	  $ctrl[$i]=$data[29];
	  $cl[$i]=$data[1];
//echo $studentid[$i]." ".$prenom[$i]." ".$famille[$i]." ".$cl[$i]." ".$ctrl[$i]." ".$mat[$i]." ".$discip[$i]." ".$grade[$i]." ". $discipcoef[$i]."<br>";
//echo $studentid[$i]." ". $matid[$i]. " " .$discipid[$i]. " ". $discipcoef[$i]."<br>";
  $i=$i+1;
}
$num=0;
$trig=1;
//echo $classeid1." taille d'une classe:".sizeof($studentid);
if (sizeof($studentid)<=1) 
{ echo " Classe n'existe pas"; exit(0);}
while($num<sizeof($studentid))
{
	if($trig==1){
	echo '<div class="page-break"><table width="100%" border="0">
  <tr>
    <td colspan="4" ><h3 align="left">SOEURS BASILIENNES CHOUERITES<br />
      ECOLE NOTRE-DAME 
      DE LA PAIX -
    DORA</h3></td>
  </tr>
  <tr  class="carnet">
    <td colspan="5" align="center">RELEVE DES NOTES  <br />
                                    2023-2024   </td>
  </tr>
  <tr class="carnet">
  <td width="15%" height="30">Nom et Prénom:</td><td width="20%" bgcolor="#FFFFFF">'. $prenom[$num].'</td>
  <td width="20%" bgcolor="#FFFFFF">'.$famille[$num].'</td><td width="30%" bgcolor="#FFFFFF">'.$famille[$num].'</td>
  <td width="15%">Classe:'.strtoupper($cl[$num]).'</td></tr>
</table>
<table width="98%" border="1" align="center" cellspacing="0">

  <tr class="carnet">
  
    <td width=40%  height="25" >Matières</span></td>
    <td width="10%">Coef.</td>';
	$trig=0;
		$j=0;
	while($j<sizeof($cont))
	{
    echo '<td width="10%">'.$cont[$j].'<br /></td>';
	
	$j=$j+1;
	}
	 echo '<td width="10%"><b>M.G.</b><br /></td>';	
 echo "</tr>";
	}
		$m=$num;
		$sou=0;
		$s=0;
		$totlagen1=0;$moycoef1=0;
		$totlagen2=0;$moycoef2=0;
		$totlagen3=0;$moycoef3=0;
 		$totlagen4=0;$moycoef4=0;
		$coeftot=0;
	 while($s<=sizeof($studentid)){
		 $coefsou=0;
		$discpsum1=0;
		 $discpsum2=0;
		 $discpsum3=0;
		 $discpsum4=0;
		 $matcoef1=0;
		$matcoef2=0;
		 $matcoef3=0;
		 $matcoef4=0;

		 $coefmat2s[$mat2[$s]]=0;
		 if($mat2[$s]!=""){
		echo "<tr><td width=40%  height='25' align='center'>
		<label class='w3-text-blue'  ><b>".$mat2[$s]."</b></label><br></td><td></td><td></td>
		<td></td><td></td><td></td><td></td>";
		    $countdisc=0;
			
	      while($matsous[$sou]==$matid2[$s]){
		
            echo "<tr><td>". $sousmat1[$sou]."<br>";
			echo "<td align='center'><b>". $coefficient1[$sou]."</b></td>";
			$sumg=0;
			$col1=0;
			$coefmat2s[$mat2[$s]]=$coefmat2s[$mat2[$s]]+ $coefficient1[$sou];
			$coeftot=$coeftot+$coefficient1[$sou];
			$countgra=0;
			

			while(($discipid[$m]==$sousmatid1[$sou])&&($studentid[$m]==$studentid[$num])){  
                   if($ctrl[$m]=="Ctrl 1") {//$matcoef1=$matcoef1+$coefficient1[$sou];
				                            $matcoef1=$matcoef1+$discipcoef[$m];
				                            $discpsum1=$discpsum1+$grade[$m]; 
									  	    $sumg=$sumg+$grade[$m];
						 echo "<td>".$grade[$m]."</td>";
						 if($grade[$m]<>0) $countgra=$countgra+1;
						 }
				   elseif($ctrl[$m]=="Ctrl 2") {//$matcoef2=$matcoef2+$coefficient1[$sou];
				   				                $matcoef2=$matcoef2+$discipcoef[$m];
				                                $discpsum2=$discpsum2+$grade[$m];$sumg=$sumg+$grade[$m]; 
				                                 echo "<td>".$grade[$m]."</td>";
								if($grade[$m]<>0) $countgra=$countgra+1;}
								
				   elseif($ctrl[$m]=="Ctrl 3") {// $matcoef3=$matcoef3+$coefficient1[$sou];
				   				                 $matcoef3=$matcoef3+$discipcoef[$m];
				                                 $discpsum3=$discpsum3+$grade[$m];$sumg=$sumg+$grade[$m];
				                            echo "<td>".$grade[$m]."</td>";
											if($grade[$m]<>0) $countgra=$countgra+1;}
				   elseif($ctrl[$m]=="Ctrl 4") {//$matcoef4=$matcoef4+$coefficient1[$sou];
				                                 $matcoef4=$matcoef4+$discipcoef[$m];
												$discpsum4=$discpsum4+$grade[$m];$sumg=$sumg+$grade[$m];
				   echo "<td>".$grade[$m]."</td>";
				   if($grade[$m]<>0) $countgra=$countgra+1;}
				   elseif($grade[$m]==0) echo "<td> </td>";
				   
				  $m=$m+1;
				   $col1=$col1+1;
			     }
				  
                  $sou=$sou+1; 
				  $ajoutcol=4;
				  $ajoutcol=$ajoutcol-$col1;
				while( $ajoutcol!=0){
					  echo "<td></td>";
					  $ajoutcol=$ajoutcol-1;  
				  }
				  if($countgra==0) $countgra=1;
				  $moyg=$sumg/$countgra;
				  $moyg=round($moyg,1);
			      echo "<td>".$moyg."</td></tr>";
		    
				 }

				 echo "<tr><td><b> Total ".$mat2[$s]." </b></td>";
				 echo "<td align='center'><b>".$coefmat2s[$mat2[$s]]."</b></td>";
				 if($discpsum1<>0) $countdisc=$countdisc+1; echo "<td><b>".$discpsum1. "</b></td>";
				 if($discpsum2<>0) $countdisc=$countdisc+1;  echo "<td><b>".$discpsum2."</b></td>";
				  if($discpsum3<>0) $countdisc=$countdisc+1;echo "<td><b>".$discpsum3."</b></td>";
 				 if($discpsum4<>0) $countdisc=$countdisc+1;echo "<td><b>".$discpsum4."</b></td>";
				 if($countdisc==0) $countdisc=1;
				 $disctotal=($discpsum1+$discpsum2+$discpsum3+$discpsum4)/$countdisc;
				 $disctotal=round($disctotal,1);
				 echo "<td><b>".$disctotal."</b></td></tr>";
				 $matcoef11=$matcoef1;$matcoef22=$matcoef2;$matcoef33=$matcoef3;$matcoef44=$matcoef4;
				 if($matcoef1==0) $matcoef11=1;
				  if($matcoef2==0) $matcoef22=1;
				 if($matcoef3==0) $matcoef33=1; 
				 if($matcoef4==0) $matcoef44=1;

			     echo "<tr><td><b> Moyenne ".$mat2[$s]." </b></td>";
				 echo "<td align='center'><b>20</b></td>";
				 echo "<td><b>".round($discpsum1*20/$matcoef11,1)."</b></td>";
				 echo "<td><b>".round($discpsum2*20/$matcoef22,1)."</b></td>";
				 echo "<td><b>".round($discpsum3*20/$matcoef33,1)."</b></td>";
 				 echo "<td><b>".round($discpsum4*20/$matcoef44,1)."</b></td>";
				
				 $moymatf=($discpsum1*20/$matcoef11+$discpsum2*20/$matcoef22+$discpsum3*20/$matcoef33+$discpsum4*20/$matcoef44)/$countdisc;
				 
				 $moymatf=round($moymatf,1);
				 echo "<td><b>".$moymatf."</b></td></tr>";

		        }
                $totlagen1=$totlagen1+$discpsum1;
				$moycoef1=$moycoef1+$matcoef1;
				$totlagen2=$totlagen2+$discpsum2;
				$moycoef2=$moycoef2+$matcoef2;
                $totlagen3=$totlagen3+$discpsum3;
				$moycoef3=$moycoef3+$matcoef3;
				$totlagen4=$totlagen4+$discpsum4;
                $moycoef4=$moycoef4+$matcoef4;
				 $s=$s+1; 				
              }
			  echo "<tr><td><b> Total Général</b></td>";
				 echo "<td align='center'><b>". $coeftot."</b></td>";
				 echo "<td><b>".$totlagen1."</b></td>";
				 echo "<td><b>".$totlagen2."</b></td>";
				 echo "<td><b>".$totlagen3."</b></td>";
 				 echo "<td><b>".$totlagen4."</b></td>";
				 echo "<td></td></tr>"; 
				   echo "<tr><td><b> Moyenne Générale</b></td>";
				 echo "<td align='center'><b>20</b></td>";
				if($moycoef1==0)  echo "<td><b></b></td>"; else echo "<td><b>".round($totlagen1*20/$moycoef1,1)."</b></td>";
				 if($moycoef2==0) echo "<td><b></b></td>"; else echo "<td><b>".round($totlagen2*20/$moycoef2,1)."</b></td>";
				if($moycoef3==0)  echo "<td><b></b></td>"; else echo "<td><b>".round($totlagen3*20/$moycoef3,1)."</b></td>";
 				 if($moycoef4==0) echo "<td><b></b></td>"; else echo "<td><b>".round($totlagen4*20/$moycoef4,1)."</b></td>";
				 echo "<td></td></tr>";  
				    echo "<tr><td><b> Mention</b></td>";
				 echo "<td></td>";
				if(round($totlagen1*20/$moycoef1,1)>=18)  echo "<td><b>Exc.</b></td>"; 
				                   elseif(round($totlagen1*20/$moycoef1,1)>=16) echo "<td><b>T.B.</b></td>";
				                   elseif(round($totlagen1*20/$moycoef1,1)>=14) echo "<td><b>B.</b></td>";
							       elseif(round($totlagen1*20/$moycoef1,1)>=12) echo "<td><b>A.B.</b></td>";
							       elseif(round($totlagen1*20/$moycoef1,1)>=10) echo "<td><b>P.</b></td>";
							       else echo "<td><b>F.</b></td>";
                     			   echo "<td></td></tr>";  	 			
       echo "</table>";
	   
	 echo '<div class="w3-panel w3-white w3-border w3-round-xlarge">
        <p>Observations:</p>
          </div>';
		$num=$m; 
		//$num=$num+1;
	$trig=1;
	
	 } 
} 
?>
</body>
</html>
