<?php
	ob_start();
	require 'connexionBD.php';

	$db = new Connect($_GET['mySchool']);
	$dc = $db->connect_db($_GET['mySchool']);
	
	//Nom du professeur
	
	$query='SELECT nom, postnom, prenom FROM professeur WHERE numProf = "'.$_GET['numProf'].'" AND validite = "OUI"';

	$q=$dc->prepare($query);
	$q->execute();
		   	
   	while($a=$q->fetch()){
   	    $professeur = strtoupper($a['nom'])." ".strtoupper($a['postnom'])." ".ucfirst($a['prenom']);
   	}
   	
   	//Liste de tous les élèves inscrits dans une classe
   	
   	$queryx='SELECT nom, postnom, prenom, numPerm FROM eleve, classeeleve WHERE classeeleve.idEleve = eleve.idEleve AND classeeleve.idClasse = "'.$_GET['idClasse'].'"  AND classeeleve.anneeScolaire = "'.$_GET['annee'].'" AND eleve.validite = "OUI" AND classeeleve.validite = "OUI" ORDER BY nom, postnom, prenom';
				  // echo $query;
	$qx=$dc->prepare($queryx);
	$qx->execute();
	
	$elve = array();
	$numPerm1 = array();
	$p=1;	 
	
   	while($a=$qx->fetch()){
   	    $eleve[$p] = strtoupper($a['nom']." ".$a['postnom'])." ".ucfirst(strtolower($a['prenom']));
   	    $numPerm1[$p] = $a['numPerm'];
   	    $p++;
   	}
	
	//Les moyennes de la 1ereP de différents élèves
	
	$queryq='SELECT resulteleve.numPerm as numPerm2, nom, postnom, prenom, SUM(result) as result, libelle FROM eleve, resulteleve, cours WHERE resulteleve.idCours = cours.idCours AND resulteleve.numPerm = eleve.numPerm AND resulteleve.perSem = "1ereP" AND resulteleve.idCours = "'.$_GET['idCours'].'" AND resulteleve.idClasse = "'.$_GET['idClasse'].'" AND resulteleve.anneeScolaire = "'.$_GET['annee'].'" AND eleve.validite = "OUI" AND cours.validite = "OUI" AND resulteleve.validite = "OUI" GROUP BY resulteleve.numPerm, nom, postnom, prenom, libelle ORDER BY nom, postnom, prenom';
				  
	$qq=$dc->prepare($queryq);
	$qq->execute();
	
	$i=1;
	$coteP1 = array();
	$classe = array();
	$numPermP1 = array();
		   	
   	while($a=$qq->fetch()){
   	    
   	    $prof = strtoupper($a['nom']." ".$a['postnom']);
   	    $numPermP1[$i] = $a['numPerm2'];
   	    $coteP1[$i] = $a['result'];
	    $i++;
	    
	}
	
	
	//Les moyennes de la 2emeP de différents élèves
	
	$queryq='SELECT resulteleve.numPerm as numPerm2, nom, postnom, prenom, SUM(result) as result, libelle FROM eleve, resulteleve, cours WHERE resulteleve.idCours = cours.idCours AND resulteleve.numPerm = eleve.numPerm AND resulteleve.perSem = "2emeP" AND resulteleve.idCours = "'.$_GET['idCours'].'" AND resulteleve.idClasse = "'.$_GET['idClasse'].'" AND resulteleve.anneeScolaire = "'.$_GET['annee'].'" AND eleve.validite = "OUI" AND cours.validite = "OUI" AND resulteleve.validite = "OUI" GROUP BY resulteleve.numPerm, nom, postnom, prenom, libelle ORDER BY nom, postnom, prenom';
				  
	$qq=$dc->prepare($queryq);
	$qq->execute();
	
	$i=1;
	$coteP2 = array();
	$numPermP2 = array();
		   	
   	while($a=$qq->fetch()){
   	    
   	    $numPermP2[$i] = $a['numPerm2'];
   	    $coteP2[$i] = $a['result'];
	    $i++;
	    
	}
	
	//Les cotes de l'examen du 1er semestre de différents élèves
	
	//echo $queryq='SELECT eleve.numPerm as numPerm2, nom, postnom, prenom, coteExamen as result, libelle FROM eleve, coteexamen, examen WHERE coteexamen.idExamen=examen.idExamen AND coteExamen.idExamen in (SELECT idExamen FROM examen WHERE cours in (SELECT libelle FROM cours WHERE idCours="'.$_GET['idCours'].'" AND validite="OUI")) coteexamen.idEleve=eleve.idEleve AND coteexamen.perSem = "E1erS" AND examen.classe = "'.$_GET['idClasse'].'" AND coteexamen.anneeScolaire = "'.$_GET['annee'].'" AND eleve.validite = "OUI" AND cours.validite = "OUI" AND coteexamen.validite = "OUI" GROUP BY eleve.numPerm, nom, postnom, prenom, libelle ORDER BY nom, postnom, prenom';
				  
	$queryq='SELECT eleve.numPerm as numPerm2, nom, postnom, prenom, coteExamen as result FROM eleve, coteexamen, examen WHERE coteexamen.idExamen=examen.idExamen AND coteexamen.idExamen in (SELECT idExamen FROM examen WHERE cours in (SELECT libelle FROM cours WHERE idCours="'.$_GET['idCours'].'" AND validite="OUI")) AND coteexamen.idEleve=eleve.idEleve AND coteexamen.semestre = "E1erS" AND examen.classe = "'.$_GET['idClasse'].'" AND coteexamen.anneeScolaire = "'.$_GET['annee'].'" AND eleve.validite = "OUI" AND examen.validite = "OUI" AND coteexamen.validite = "OUI" GROUP BY eleve.numPerm, nom, postnom, prenom, coteExamen ORDER BY nom, postnom, prenom';

	
	$qq=$dc->prepare($queryq);
	$qq->execute();
	
	$i=1;
	$coteE1 = array();
	$numPermE1 = array();
		   	
   	while($a=$qq->fetch()){
   	    
   	    $numPermE1[$i] = $a['numPerm2'];
   	    $coteE1[$i] = $a['result'];
	    $i++;
	    
	}
	
			
?>

<!DOCTYPE html>
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="http://templateq.com" />
</head>
<style type="text/css">
<!--
table
{
    width:  100%;
    border:none;
    border-collapse: collapse;
}
th
{
    text-align: center;
    border: solid 1px #000000;
    background: #f8f8f8;
    padding:3px;
}
td
{
    text-align: center;
    border: solid 1px #000000;
    padding:3px;
}
-->
</style>

<body>
	
	<div>
		
	</div>
	
	
	<div style="position:absolute; left:10px; top:10px; border:1px solid; padding:10px; width:170px; font-size:13px; text-align:left">
		LYCEE DR SHAUMBA <br/> <br/>
		
		13, Av. Mgr SHAUMBA <br/>
		0898926444 <br/>
		KINSHASA <br/><br/>
	</div>
	
	<div style="position:relative; left:400px; top:5px; padding:10px; width:450px; font-size:14px; text-align:left;">
		<?php echo"Année : ".$_GET['annee']; ?> <br/><br/>
		<?php echo"Classe : ".$_GET['afficherClasse']; ?> <br/><br/>
		
		<div style="border:1px solid;padding:10px;font-size:20px; width:200px; text-align:center">
		    FICHE DES COTES 
		</div> <br/>
		
		<?php echo mb_strtoupper($_GET['afficherCours']); ?> <br/><br/>
		<?php echo"Professeur : ".mb_strtoupper($professeur); ?> <br/>
	</div>
	
	<div style="position:relative; left:15px; top:35px; padding:3px; font-size:12px; text-align:center">
		
		<table>
		    
		    <col style="width: 5%">
			<col style="width: 30%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 5%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 6%">
			<col style="width: 6%">
		    
		    <tr>
		        <th colspan="2">  </th>
	            <th colspan="4"> PREMIER SEMESTRE </th>
                <th colspan="5"> DEUXIEME SEMESTRE </th>
                <th> </th>
		    </tr>
		    
		    <tr>
		        <th colspan="">  </th>
		        <th colspan="">  </th>
		        <th colspan="" style="text-align:center"> 1 ère P </th>
		        <th colspan="" style="text-align:center"> 2 ème P </th>
		        <th colspan="" style="text-align:center"> Comp I </th>
		        <th colspan="" style="text-align:center"> Total I </th>
		        <th colspan="" style="text-align:center"> 3 ème P </th>
		        <th colspan="" style="text-align:center"> 4 ème P </th>
		        <th colspan="" style="text-align:center"> Comp II </th>
		        <th colspan="" style="text-align:center"> Total II </th>
		        <th colspan="" style="text-align:center"> Total G. </th>
		        <th colspan="" style="text-align:center"> % </th>
		    </tr>
		    
		    <tr>
		        <th colspan="" style="text-align:center"> N° </th>
		        <th colspan="" style="text-align:center"> NOM COMPLET / MAXIMA </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']*2; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']*4; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']*2; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']*4; ?> </th>
		        <th colspan="" style="text-align:center"> <?php echo $_GET['maxima']*8; ?> </th>
		        <th colspan="" style="text-align:center"> 100 </th>
		    </tr>
		    
		    <?php for($j=1; $j<=count($eleve); $j++){ $p1=""; $p2=""; $e1=""; $p3=""; $p4=""; $e2=""; $s1=""; $s2=""; ?>
		    
		    <tr>
		        <td style="text-align:center"> <?php echo $j; ?>  </td>
	            <td style="text-align:left"> <?php echo $eleve[$j]; ?> </td>
	            
                <td style="text-align:center">
                    <?php
                        
                        for($x=1; $x<=count($numPermP1); $x++){
                            if($numPerm1[$j] == $numPermP1[$x]) { if($coteP1[$x] < ($_GET['maxima']/2)){ echo "*"; } echo $p1=$coteP1[$x]; }
                        }
                    
                    ?> 
                </td>
                
                <td style="text-align:center"> 
                    <?php
                        
                        for($x=1; $x<=count($numPermP2); $x++){
                            if($numPerm1[$j] == $numPermP2[$x]) { if($coteP2[$x] < ($_GET['maxima']/2)){ echo "*"; } echo $p2=$coteP2[$x]; }
                        }
                    
                    ?>
                </td>
                
                <td style="text-align:center"> 
                    <?php
                        
                        for($x=1; $x<=count($numPermE1); $x++){
                            if($numPerm1[$j] == $numPermE1[$x]) { if($coteE1[$x] < $_GET['maxima']){ echo "*"; } echo $e1=$coteE1[$x]; }
                        }
                    
                    ?>
                </td>
                
                <td style="text-align:center"> 
                
                    <?php
                        
                        $s1 = $p1 + $p2 + $e1;
                        
                        if($s1 < ($_GET['maxima']*2)){ echo "*"; }
                        
                        echo $s1;
                        
                        /*for($x=1; $x<=count($numPerm2); $x++){
                            if($numPerm1[$j] == $numPerm2[$x]) { echo $coteP1[$x]+$coteP2[$x]+$coteE1[$x]; }
                        }*/
                    
                    ?>
                
                </td>
                
                <td style="text-align:center">  </td>
                <td style="text-align:center">  </td>
                <td style="text-align:center">  </td>
                <td style="text-align:center">  </td>
                <td style="text-align:center">  </td>
                <td style="text-align:center">  </td>
		    </tr>
		    
		    <?php } ?>
		    
		</table>
		
	</div>
	
	
</body>
</html>


<?php 
   
	$content = ob_get_clean();
    require_once 'html2pdf.class.php';
    try
    {
        $html2pdf = new HTML2PDF("P", "A4", "fr");
        $html2pdf->setDefaultFont("Arial");
        $html2pdf->writeHTML($content);
        $html2pdf->Output("votre_pdf.pdf");
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }
	
?>

