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

	$db = new Connect($_GET['mySchool']);
	$dc = $db->connect_db($_GET['mySchool']);
	
	//$_SESSION['cours'] = $_POST['cours'];
	//$_SESSION['result'] = "ok2";
	$_SESSION['t'] = 0;
	
	$query = 'SELECT nom, postnom, numInterro, cotEsur, dateCoteInterro, sujet FROM professeur,interro,coteinterro WHERE professeur.numProf= "'.$_GET['numProf'].'" AND interro.numProf = "'.$_GET['numProf'].'" AND coteinterro.idInterro = interro.idInterro AND interro.classe = "'.$_GET['idClasse'].'" AND interro.cours = "'.$_GET['afficherCours'].'" AND interro.anneeScolaire = "'.$_GET['anneeScolaire'].'" AND coteinterro.anneeScolaire = "'.$_GET['anneeScolaire'].'" AND coteinterro.periode = "'.$_GET['perSem'].'" AND interro.validite = "OUI" AND coteinterro.validite = "OUI" AND cotEsur<>0 GROUP BY nom, postnom, numInterro, cotEsur, dateCoteInterro, sujet ORDER BY numInterro';
	//die();
	$q=$dc->prepare($query);
	$q->execute();
	
	$v = 1;
	$cotEsurMoit = array();

	while ($a = $q->fetch()) {
	    $_SESSION['cotEsurMoit'.$v] = $a['cotEsur']/2;
	    $_SESSION['numeInt'.$v] = $a['numInterro'];
		$_SESSION['numInt'] = $a['numInterro'];
		$_SESSION['t'] = $_SESSION['t'] + 1;
		$_SESSION['date'.$v] = $a['dateCoteInterro'];
		$_SESSION['sujet'.$v] = $a['sujet'];
		$_SESSION['prof'] = strtoupper($a['nom']." ".$a['postnom']);
		$_SESSION['reussite'.$v] = 0;
		$_SESSION['echec'.$v] = 0;
		$_SESSION['vide'.$v] = 0;
		$v++;
	}
	
	
	$query = 'SELECT classeeleve.idEleve as idEleve, nom, postnom FROM `classeeleve`, eleve, classe WHERE classeeleve.idEleve=eleve.idEleve AND classeeleve.idClasse=classe.idClasse AND classeeleve.anneeScolaire = "'.$_GET['anneeScolaire'].'" AND classeeleve.idClasse="'.$_GET['idClasse'].'" AND classeeleve.validite="OUI" AND eleve.validite="OUI" AND classe.validite="OUI" ORDER BY nom, postnom, prenom';
	//die();
	$q = $dc->prepare($query);
	$q->execute();
	
	$serie = 1;
	
	$tabEleve = array();
	$tabInt = array();
	$tabCote = array();
	$tabNumInt = array();
			
?>

<!DOCTYPE html>
<html lang="en">
<head><meta charset="euc-kr">

<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 2px #000000;
    
    padding:5px;
}
td
{
    text-align: left;
    border: solid 2px #000000;
    padding:3px;
}
-->
</style>

<body>
	
	
	<table>
	    
	    <col style="width: 5%">
	    <col style="width: 20%">
	    
	    <?php for($i=1; $i<=$_GET['t']; $i++){ ?>
	    
	        <col style="width: 3%">
	    
	    <?php } ?>
	    
	    <col style="width: 4%">
	    <col style="width: 4%">
	
	    <tr>
	        
	        <th colspan="2" style="text-align:left"> ENSEIGNANT : <?php echo $_SESSION['prof']; ?> </th>
	        <th colspan="<?php echo $_GET['t']; ?>"> </th>
	        <th> </th>
	        <th> </th>
	        
	        <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>
	   
	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:left"> BRANCHE : <?php echo mb_strtoupper($_GET['afficherCours']); ?> </th>
	        <th colspan="<?php echo $_GET['t']; ?>"> </th>
	        <th> </th>
	        <th> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>
	   
	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:left"> CLASSE : <?php echo $_GET['afficherClasse']; ?> </th>
	        <th colspan="<?php echo $_GET['t']; ?>"> </th>
	        <th> </th>
	        <th> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>
	   
	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:left"> SEMESTRE : </th>
	        <th colspan="<?php echo $_GET['t']; ?>"> </th>
	        <th> </th>
	        <th> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>
	   
	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:left"> PERIODE : <?php echo $_GET['perSem']; ?> </th>
	         <?php for($i=1; $i<=$_GET['t']; $i++) { ?>
	            <th> </th>
	         <?php } ?>
	         <th> </th>
	         <th> </th>
	         
	          <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>

	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:center; vertical-align:middle; height:120px"> SUJET DE L'INTERROGATION </th>
	        
	        <?php for($i=1; $i<=$_GET['t']; $i++) { if($i<10){ $i="0".$i; } ?>
	        
	            <th style="vertical-align:middle; text-align:left;"> <div style="rotate:90;"> <?php echo "Interro_".$i;// $_SESSION['sujet'.$i]; ?> </div> </th>
	        
	        <?php } ?>
	        <th> </th>
	        <th> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>

	    </tr>
	    
	    <tr>
	        
	        <th colspan="2" style="text-align:center; vertical-align:middle; height:80px"> DATE </th>
	        <?php for($i=1; $i<=$_GET['t']; $i++) { $dt = DateTime::createFromFormat('Y-m-d',$_SESSION['date'.$i]); $dateOk = $dt->format('d-m'); ?>
	        
	            <th style="vertical-align:middle;text-align:left;"> <div style="rotate:90;"> <?php echo $dateOk;//$_SESSION['date'.$i];  ?> </div> </th>
	        
	        <?php } ?>
	        <th> </th>
	        <th> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>

	    </tr>
	    
	    <tr>
	        
	        <th> N° </th>
	        <th> NOMS ET POSTNOMS </th>
	        <?php 
	        
	            $cotEsurTot = 0;
	            
	            for($i=1; $i<=$_GET['t']; $i++) { ?>
	        
	            <th> <?php echo $_SESSION['cotEsur'.$i] = $_SESSION['cotEsurMoit'.$i]*2; $cotEsurTot = $cotEsurTot + ($_SESSION['cotEsurMoit'.$i]*2); ?>  </th>
	        
	        <?php } ?>
	        
	        <th> Tot./ <br/> <?php echo $cotEsurTot; ?> </th>
	        <th> Moy./ <br/> <?php echo $_GET['maxima']; ?> </th>
	        
	         <?php for($c=1; $c<=(23-$_GET['t']); $c++){ ?>
	    
    	        <td style="color:#FFFFFF;"> 100 </td>
    	    
    	    <?php } ?>
	   
	    </tr>
	    
	    <?php 
	    
	        //$dao = new DaoClasse($_SESSION['maBD']); $dao->getListCoteInterroTabProf($_GET['numProf'],$_GET['idClasse'],$_GET['idProf'],$_GET['t'],$_GET['afficherCours'],$_GET['anneeScolaire'],$_GET['perSem']); 
	    
	        while ($a = $q->fetch()) {
	    
        	    $t=1;
        	    
        	    $queryx = 'SELECT coteinterro.idEleve as idEleve, coteInterro, numInterro, cotEsur FROM interro, coteinterro WHERE coteinterro.idEleve = "'.$a['idEleve'].'" AND coteInterro <>"" AND cotEsur <>"0" AND coteinterro.idInterro=interro.idInterro AND coteinterro.validite="OUI" AND interro.validite="OUI" AND interro.classe="'.$_GET['idClasse'].'" AND coteinterro.periode="'.$_GET['perSem'].'" AND interro.periode="'.$_GET['perSem'].'" AND coteinterro.anneeScolaire="'.$_GET['anneeScolaire'].'" AND interro.anneeScolaire="'.$_GET['anneeScolaire'].'" AND interro.cours="'.$_GET['afficherCours'].'" AND interro.numProf="'.$_GET['numProf'].'" ORDER BY numInterro';
        		//die();
        		$qx = $dc->prepare($queryx);
        		$qx->execute();
        		
        		$tabCote = array();
        		
        		while ($aa = $qx->fetch()) {
        		    //$_SESSION['numInt'.$t] = $aa['numInterro'];
        		    $tabNumInt[$t] = $aa['numInterro'];
        		    $tabCote[$aa['numInterro']] = $aa['coteInterro'];
        		    $tabCotEsur[$aa['numInterro']] = $aa['cotEsur']/2;
        		    $t++;
        		}
        		
        		//echo ($t-1)."**";
        		//echo $compt; die();
        		
        		if ($t < $compt+1){
        		    
        		    for($j=1;$j<=$compt;$j++) {
        		        $rep = "non";
        			    for($r=1;$r<=($t-1);$r++) {
        			        if($j == $tabNumInt[$r]) { $rep = "oui"; }
        			    }
        			    if($rep == "non") { $tabCote[$j] = ""; }
        			    
        			}
        		    
        		}
        		
        		
        		$_SESSION['total'.$serie]=0;
        		$_SESSION['cotEsurTot'] = 0;
        		$rep = "nok"; $ast2=""; $ast3="";
        		
        		if( $serie<10 ){ $serie="0".$serie; }
        		
        		if(fmod($serie-1, 5)==0 && $serie<>1){
        		    
        		    echo '<tr> 
        		
        		        <td style="color:#FFFFFF;" colspan="27"> 100 </td> ';
        		        
        		echo '</tr>';
        		    
        		}
        	    
        		echo '<tr> 
        		
        		        <td style="text-align:center"> '.$serie.' </td> 
        		        <td>'.strtoupper($a['nom']." ".$a['postnom']).'</td>'; 
        		        
        		        for($j=1;$j<=$_GET['t'];$j++) { $col=""; $ast1=""; if( ($tabCote[$j] < $tabCotEsur[$tabNumInt[$j]]) && (trim($tabCote[$j]) <> "") ){ $col="#FF0000"; $ast1="*"; } 
        		        
        		            echo '<td style="color:'.$col.';text-align:right">'.$ast1.$tabCote[$j].'</td>'; $_SESSION['total'.$serie]=$_SESSION['total'.$serie]+$tabCote[$j]; if($tabCote[$j]<>""){ $rep="ok"; $_SESSION['cotEsurTot'] = $_SESSION['cotEsurTot'] + $_SESSION['cotEsur'.$j]; } 
        		            
        		        }
        		        
        		        $coulMoy = "";
        		        $coulMoyyy = "";
        		        
        		        if($_SESSION['total'.$serie] < $cotEsurTot/2){ $coulMoy="#FF0000"; $ast2="*"; }
        		        
        		        $moy = round(($_SESSION['total'.$serie]/$_SESSION['cotEsurTot'])*$_GET['maxima']);
        		        
        		        if($moy < $_GET['maxima']/2){ $coulMoyyy="#FF0000"; $ast3="*"; }
        		        
        		        if($rep == "nok"){ $_SESSION['total'.$serie]=""; $ast2=""; $ast3=""; $moy=""; }
        		        
        		        echo '<td style="color:'.$coulMoy.';text-align:right; font-weight:bold"> '.$ast2.$_SESSION['total'.$serie].' </td>'; 
        		        
        		        echo '<td style="color:'.$coulMoyyy.';text-align:right; font-weight:bold"> '."$ast3".$moy.' </td>';
        		        
        		        for($c=1; $c<=(23-$_GET['t']); $c++){
	    
                	        echo '<td style="color:#FFFFFF;"> 100 </td>';
                	    
                	    }
        		        
        		echo '</tr>';
        		
        	    $serie+=1;
        	
        	}
	    
	    
	    ?>
	    
	</table>
	
	
</body>
</html>


<?php 

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

