<?php
function zerofill ($num, $zerofill = 5){
    return str_pad($num, $zerofill, '0', STR_PAD_LEFT);
}
//fonction retounant le mois en francais
function getMois($month){
	$mois["January"] = "Janvier";
	$mois["February"] = "Février";
	$mois["March"] = "Mars";
	$mois["April"] = "Avril";
	$mois["May"] = "Mai";
	$mois["June"] = "Juin";
	$mois["July"] = "Juillet";
	$mois["August"] = "Août";
	$mois["September"] = "Septembre";
	$mois["October"] = "Octobre";
	$mois["November"] = "Novembre";
	$mois["December"] = "Décembre";
	return $mois[$month];
}
function entete1($nom, $prenom, $sexe, $date_nais, $lieu_nais, $matricule, $sigleDomaine, $diplome, $sigleMention, $intituleFilieres){
	$text2 ='<style>
		.fine
		{
			text-decoration:underline;
		}
		.semestre
		{
			display: inline-bloc;
			text-align: center;
			border: 2px solid red;
			margin: auto;
			margin-right: 12px;
		}

	</style><br/><br/>
	<table  font-style="italic">
		<tr>
			<td class="fine" width="4.5cm">Noms et Prénoms</td>
			<td width="0.5cm">:</td>
			<td width="7cm">'.$nom.' '.$prenom.'</td>
			<td class="fine" width="4.5cm">Sexe</td>
			<td width="0.5cm">:</td>
			<td>'.$sexe.'</td>
		</tr>

		<tr>
			<td class="fine">Date et lieu de naissance</td>
			<td>:</td>
			<td width="7cm">'.$date_nais.' à '.$lieu_nais.'</td>
			<td class="fine">N° d\'inscription </td>
			<td>:</td>
			<td>'.$matricule.'</td>
		</tr>

		<tr>
			<td class="fine">Domaine</td>
			<td>:</td>
			<td>'.$sigleDomaine.'</td>
			<td class="fine">Diplôme préparé</td>
			<td>:</td>
			<td>'.$diplome.'</td>
		</tr>

		<tr>
			<td class="fine">Mention</td>
			<td>:</td>
			<td>'.$sigleMention.'</td>
			<td></td>
			<td></td>
			<td></td>
		</tr>

		<tr>
			<td class="fine">Spécialité</td>
			<td>:</td>
			<td>'.$intituleFilieres.'</td>
		</tr>
	</table>';
	return $text2;
}

function entete2(){
$contenu_releve=
<<<EOF
<br/><br/><br/>
<style>
	.vert
	{
		background-color: rgb(0,255,0);
		font-size: 12px;
		text-align: center;
	}
	.entete
	{
		background-color: rgb(210,210,255);
	}
	.entete1
	{
		background-color: rgb(210,210,255);
		text-align: center;
		font-weight: bold;
		font-size: 9px;
	}
	.ue
	{
		text-align: left;
		padding-left: 15px;
		font-style: italic;
	}
	.pieds
	{
		width: 1200px;
		margin: auto;
	}

	.valide
	{
		font-size: 10px;
		color: black;
		font-weight: bold;
	}
	.nonValide
	{
		font-size: 10px;
		color: red;
		font-weight: bold;
	}
	.ligne
	{
		height: 10px;
	}
	.table_bas
	{
		margin-top: 30px;
	}
	.table
	{
		text-align: center;
		padding: 10px;
	}
	.entete_bas
	{
		background-color: rgb(210,210,255);
		font-style: italic;
		text-align: center; 
	}
</style>

<table border="0.5" cellspacing="0" cellpadding="1">
	<tr style="font-weight: bold;" class="entete1">
		<td width="14%" >Code</td>
		<td width="35%" class="ue">Unités d'Enseignement (UE) </td>
		<td width="9%" >Période</td>
		<td width="7%">Crédits affectés</td>
		<td width="7%">Crédits obtenus</td>
		<td width="4%">Fré*</td>
		<td width="8%">Note</td>
		<td width="7%">Grade ECTS</td>
		<td width="10%">Décision du Jury</td>
	</tr>
EOF;
return $contenu_releve;
}

function message($bdd, $matricule, $annee){
	$sql = 'SELECT resultat, resultatS1, resultatS2 FROM `tabinscription` WHERE `idFiliere` =? AND `annee` =? AND `niveauFormation` =? AND `annee_acad` =? AND matricule=?';
	$p_res = $bdd->prepare($sql);
	$p_res->execute(array($_SESSION['idFiliere'], $annee, $_SESSION['niveau'], $_SESSION['academique'], $matricule));
	$res = $p_res->fetch();

	$message = "";
	if($_SESSION['annee'] != "0") {
		if($_SESSION['annee'] == 1) {
			switch($res['resultat']) {
				case  'A' 	: $message = '<span style="color: blue; font-weight: bold;">  Est admis en Deuxième Année.</span>'; break;
				case  'ENJ' : $message = '<span style="color: #b35900; font-weight: bold;">  Est admis en Deuxième Année avec reprise.</span>'; break;
				case  'R'   : $message = '<span style="color: #ff5500; font-weight: bold;">  Redouble.</span>'; break; 
				case  'E'   : $message = '<span style="color: #ff0000; font-weight: bold;">  Exclu.</span>'; break; 
			}
		}else if($_SESSION['annee'] == 2) {
			if($_SESSION['niveau'] == 1) { //Pour la Licence 2
				switch($res['resultat']) {
					case  'A' 	: $message = '<span style="color: blue; font-weight: bold;">  Est admis en Troisième Année.</span>'; break;
					case  'ENJ' : $message = '<span style="color: #b35900; font-weight: bold;">  Est admis en Troisième Année avec reprise.</span>'; break;
					case  'R'   : $message = '<span style="color: #ff5500; font-weight: bold;">  Redouble.</span>'; break; 
					case  'E'   : $message = '<span style="color: #ff0000; font-weight: bold;">  Exclu.</span>'; break; 
				}
			}else{ //Pour le master 2
				switch($res['resultat']) {
					case  'A' 	: $message = '<span style="color: blue; font-weight: bold;">  Admis.</span>'; break;
					case  'R'   : $message = '<span style="color: #ff5500; font-weight: bold;">  Redouble.</span>'; break; 
					case  'E'   : $message = '<span style="color: #ff0000; font-weight: bold;">  Exclu.span>'; break; 
				}
			}
		}else if($_SESSION['annee'] == 3) {
			switch($res['resultat']) {
				case  'A' 	: $message = '<span style="color: blue; font-weight: bold;">  Admis.</span>'; break;
				case  'R'   : $message = '<span style="color: #ff5500; font-weight: bold;">  Redouble.</span>'; break; 
				case  'E'   : $message = '<span style="color: #ff0000; font-weight: bold;">  Exclu.</span>'; break; 
			}
		}
	}else{
		$res1 = ($_SESSION['idSemestre'] % 2 == 0) ? $res['resultatS2'] : $res['resultatS1'];
		switch($res1) {
			case  'V' 	 : $message = '<span style="color: blue; font-weight: bold;">  Semestre Validé.</span>'; break;
			case  'NV'   : $message = '<span style="color: #ff5500; font-weight: bold;"> Semestre Non Validé.</span>'; break; 
		}
	}
	return $message;
}
function affichePieds1($CreditFormation, $total_ue_entame, $total_ue_valide, $total_ue_restant_a_valide, $total_credit_cumule, $total_credit_capitalie, $id_semestre1, $id_semestre2){
	$espace1 = '&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;';
	$espace2 = '&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;';
	if($_SESSION['format'] == '1') {
		$td  = "<td width=\"20%\">Total UE validées semestre $id_semestre1 & $id_semestre2 </td>";
		$td2 = "<td width=\"20%\"> <strong> Total crédits capitalisés semestre $id_semestre1 & $id_semestre2 </strong> </td>";
	}else{
		$td  = "<td width=\"20%\">Total UE validées semestre $id_semestre1 </td>";
		$td2 = "<td width=\"20%\"> <strong> Total crédits capitalisés semestre $id_semestre1 </strong> </td>";
	}
	$contenu_releve="</table>";
	$contenu_releve.="
	<div style=\"\">
		<table border=\"0.5\" cellspacing=\"0\" cellpadding=\"0\" class=\"table_bas\" class=\"table\" width=\"100%\" >
			<tr class=\"entete_bas\">
				<td width=\"20%\"><strong>Total crédit de la formation</strong></td>
				<td width=\"13%\">Total UE entamées</td>
				".$td."
				<td width=\"13%\">Total UE restant à valider semestre 1 à $id_semestre2</td>
				<td width=\"15%\"> <strong> Total crédits cumulés dans le cursus </strong> </td>
				".$td2."
			</tr>
			<tr>
				<td> <div>".formater($CreditFormation, '25%', $espace1)."</div> </td>
				<td> <div>".formater($total_ue_entame, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_ue_valide, '25%', $espace1)."</div> </td>
				<td> <div>".formater($total_ue_restant_a_valide, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_credit_cumule, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_credit_capitalie, '25%', $espace1)."</div> </td>
			</tr>
		</table>
	</div>";
	return ($contenu_releve);
}

function affichePiedsParcourt($CreditFormation, $total_ue_entame, $total_ue_valide, $total_ue_restant_a_valide, $total_credit_cumule, $total_credit_capitalie, $id_semestre1, $id_semestre2){
	$espace1 = '&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;';
	$espace2 = '&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;';
	$td  = "<td width=\"20%\">Total UE validées semestre $id_semestre1 & $id_semestre2 </td>";
	$td2 = "<td width=\"20%\"> <strong> Total crédits capitalisés semestre $id_semestre1 & $id_semestre2 </strong> </td>";
	$contenu_releve="</table>";
	$contenu_releve.="
	<div style=\"\">
		<table border=\"0.5\" cellspacing=\"0\" cellpadding=\"0\" class=\"table_bas\" class=\"table\" width=\"100%\" >
			<tr class=\"entete_bas\">
				<td width=\"20%\"><strong>Total crédit de la formation</strong></td>
				<td width=\"13%\">Total UE entamées</td>
				".$td."
				<td width=\"13%\">Total UE restant à valider semestre 1 à $id_semestre2</td>
				<td width=\"15%\"> <strong> Total crédits cumulés dans le cursus </strong> </td>
				".$td2."
			</tr>
			<tr>
				<td> <div>".formater($CreditFormation, '25%', $espace1)."</div> </td>
				<td> <div>".formater($total_ue_entame, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_ue_valide, '25%', $espace1)."</div> </td>
				<td> <div>".formater($total_ue_restant_a_valide, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_credit_cumule, '40%', $espace2)."</div> </td>
				<td> <div>".formater($total_credit_capitalie, '25%', $espace1)."</div> </td>
			</tr>
		</table>
	</div>";
	return ($contenu_releve);
}

//fonction permettant d'afficher le pied du document.
function affichePiedsParcourt2($decision, $frequence, $moyenne, $grad, $ville){
//**********
$dates = Date('d');
$an    = Date('Y');
$month = Date('F');
//**********
$mois = getMois($month);

$contenu_releve = '
	<div style="font-family:Calibri;font-size:10px;">
		<table border="0" cellspacing="0" cellpadding="0" class="table_bas" class="table" width="100%">
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$frequence.'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$ville.', le '.$dates.' '.$mois.' '.$an.'
				</td>
			</tr>

		</table>
	</div>';
	return ($contenu_releve);
}

//fonction permettant d'afficher le pied du document.
function affichePieds($decision, $frequence, $moyenne, $grad, $ville){
//**********
$dates = Date('d');
$an    = Date('Y');
$month = Date('F');
//**********
$mois = getMois($month);

$contenu_releve = '
	<div style="font-family:Calibri;font-size:10px;">
		<table border="0" cellspacing="0" cellpadding="0" class="table_bas" class="table" width="100%">
			<tr>
				<td colspan=3; style="display:inline-block;text-align:left;vertical-align:top;">
					'.$decision.'
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$frequence.'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$ville.', le '.$dates.' '.$mois.' '.$an.'
				</td>
			</tr>

			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$_SESSION['signe1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$_SESSION['signe2'].'
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:9px;">
					<div>'.formater($moyenne, '100%', '').'</div>
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:9px;">
					<div>'.formater($grad, '100%', '').'</div>
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$_SESSION['nom1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$_SESSION['nom2'].'
				</td>
			</tr>
		</table>
	</div>';
	return ($contenu_releve);
}


//fonction permettant d'afficher le pied du document.
function piedAttestation($ville){
//**********
$dates = Date('d');
$an    = Date('Y');
$month = Date('F');
//**********
$mois = getMois($month);

$contenu_releve = '
	<div style="font-family:Calibri;font-size:10px;">
		<table border="0" cellspacing="0" cellpadding="0" class="table_bas" class="table" width="100%">
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$ville.', le '.$dates.' '.$mois.' '.$an.'
				</td>
			</tr>

			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$_SESSION['signe1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">L\'impétrant(e)
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$_SESSION['signe2'].'
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;;vertical-align:top;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">				
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					'.$_SESSION['nom1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
					'.$_SESSION['nom2'].'
				</td>
			</tr>
		</table>
	</div>';
	return ($contenu_releve);
}


//fonction permettant d'afficher le pied du document.
function piedFrequentation($ville){
//**********
$dates = Date('d');
$an    = Date('Y');
$month = Date('F');
//**********
$mois = getMois($month);

$contenu_releve = '
	<div style="font-family:Calibri;font-size:10px;">
		<table border="0" cellspacing="0" cellpadding="0" class="table_bas" class="table" width="100%">
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$ville.', le '.$dates.' '.$mois.' '.$an.'
				</td>
			</tr>

			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;font-family:Comic;font-size:13px;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$_SESSION['signe2'].'
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;;vertical-align:top;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">				
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;font-family:Comic;font-size:13px;">					
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$_SESSION['nom2'].'
				</td>
			</tr>
		</table>
	</div>';
	return ($contenu_releve);
}

//fonction permettant d'afficher le pied du document.
function piedCertificat($ville){
//**********
$dates = Date('d');
$an    = Date('Y');
$month = Date('F');
//**********
$mois = getMois($month);

$contenu_releve = '
	<div style="font-family:Calibri;font-size:10px;">
		<table border="0" cellspacing="0" cellpadding="0" class="table_bas" class="table" width="100%">
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
					
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:10px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$ville.', le '.$dates.' '.$mois.' '.$an.'
				</td>
			</tr>

			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;font-family:Comic;font-size:13px;">
					'.$_SESSION['signe1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$_SESSION['signe2'].'
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;;vertical-align:top;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;">				
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;">
				</td>
			</tr>
			<tr>
				<td style="width:40%;display:inline-block;text-align:left;vertical-align:top;font-family:Comic;font-size:13px;">
					'.$_SESSION['nom1'].'
				</td>
				<td style="width:20%;display:inline-block;text-align:center;font-family:Comic;font-size:11px;">
				</td>
				<td style="width:40%;display:inline-block;text-align:right;vertical-align:top;padding-left:100px;font-family:Comic;font-size:13px;">
					'.$_SESSION['nom2'].'
				</td>
			</tr>
		</table>
	</div>';
	return ($contenu_releve);
}


/**
 * Récupérer et renvoyer tous les ue sous forme d'un tableau d'objets ue
 * @param  int $filiere FIlière concerné
 * @param  int $semestre Semestre concerné
 * @param  MyPDO $db       Instance de connexion à la base de donnée
 * @return un tableau d'objets ue
 */
function getAllUE($filiere, $semestre, $annee, $niveauFormation, $anneeacad, $db) {
	/**Récupér tout les ue du semestre $semestre qui sont dans la filière $filière*/
	$sql = 'SELECT
	  `idUE`,
	  `code_unite`,
	  `intituleUnite`,
	  `credit`,
	  `semestre`,
	  `idFiliere`,
	  `annee`,
	  `niveauFormation`,
	  `annee_acad`,
	  `type_ue`,
	  `insertion`,
	  `moy_pondere`
	FROM
	  `unites`
	WHERE
		`idFiliere` =? AND `semestre` =? AND  `annee` =? AND `niveauFormation` =? AND `annee_acad` =?';									 
										 
	$p_ueDuFiliere = $db->prepare($sql);
	$p_ueDuFiliere->execute(array($filiere, $semestre, $annee, $niveauFormation, $anneeacad));
	$ueDuFiliere = $p_ueDuFiliere->fetchAll();
	return $ueDuFiliere;
}

// Prendre les ecus qui sont dans une ue
function getMoyWithUE($codeue, $filiere, $semestre, $annee, $niveauFormation, $anneeacad, $matricule, $db) {
	$info = [];
	
	$sql0       = 'SELECT moy_pondere, credit FROM unites WHERE `idFiliere` =? AND `code_unite` =? AND  `annee` =? AND `niveauFormation` =? AND `annee_acad` =?';
	$pondere    = $db->prepare($sql0);
	$pondere->execute(array($filiere, $codeue,  $annee, $niveauFormation, $anneeacad));
	$moyP = $pondere->fetch();
	$p = $moyP['moy_pondere'];
	$moyDeUE = '';
	$moyue  = 0;
	if($p == 'NO') {
    	$sql = 'SELECT AVG(noteEcu) AS moyenne
    	FROM
    	  `noteEcu`
    	WHERE
    		`idFiliere` =? AND `code_unite` =? AND  `annee` =? AND `niveauFormation` =? AND `annee_acad` =? AND matricule=?';
    	$p_EcuDeUE = $db->prepare($sql);
    	$p_EcuDeUE->execute(array($filiere, $codeue,  $annee, $niveauFormation, $anneeacad, $matricule));
    	$moyDeUE = $p_EcuDeUE->fetch();
    	$moyue  = sprintf("%.2f",myround($moyDeUE['moyenne'],2));
    }else{
    	$sql = 'SELECT noteEcu, code_ecu 
    	FROM
    	  `noteEcu`
    	WHERE
    		`idFiliere` =? AND `code_unite` =? AND  `annee` =? AND `niveauFormation` =? AND `annee_acad` =? AND matricule=?';
    	$p_EcuDeUE = $db->prepare($sql);
    	$p_EcuDeUE->execute(array($filiere, $codeue,  $annee, $niveauFormation, $anneeacad, $matricule));
    	$j = 0;
    	while($row = $p_EcuDeUE->fetch(PDO::FETCH_ASSOC))  {
    		$code_ecu 	= $row['code_ecu'];
    		$noteEcu   	= $row['noteEcu'];
 
        	$sql2       = 'SELECT credit, insertion FROM ecu WHERE `idFiliere` =? AND `code_unite` =?  AND `code_ecu` =? AND  `annee` =? AND `niveauFormation` =? AND `annee_acad` =?';
        	$credit    = $db->prepare($sql2);
        	$credit->execute(array($filiere, $codeue, $code_ecu, $annee, $niveauFormation, $anneeacad));
        	$c = $credit->fetch();
        	$crd_ec = $c['credit'];
        	if($c['insertion'] == 'NO') {
        	    $moyue  = $moyue + $noteEcu * $crd_ec;
        	    $j      = $j + $crd_ec;
        	}
    	}
    	if($j == 0) $j = 1;
    	$moyue  = $moyue / $j;
    	$moyue  = sprintf("%.2f",myround($moyue,2));
    }
    
	$entier = intval($moyue);  // et la partie avant
	if(strlen($entier) < 2){
		  $moyue = "0".$moyue;
	}
	
	$info[0] = $moyue;
	$info[1] = gradeECTS($moyue, $db);
	return $info;
}

function gradeECTS($moyenne, $db) {
	$grade = "F";
	$requette = "SELECT * FROM gradeects";
	$statement = $db->prepare($requette);
	$statement->execute();
	$tab=$statement->fetch(PDO::FETCH_ASSOC);
	$a1 = $tab['a1'];										
	$a2 = $tab['a2'];										
	$a3 = $tab['a3'];										
	$a4 = $tab['a4'];										
	$a5 = $tab['a5'];	
	switch($moyenne){
		case  (($moyenne < $a1))                 	: $grade = "F"; break;
		case  (($moyenne >= $a1)&&($moyenne < $a2)) : $grade = "E"; break;
		case  (($moyenne >= $a2)&&($moyenne < $a3)) : $grade = "D"; break;
		case  (($moyenne >= $a3)&&($moyenne < $a4)) : $grade = "C"; break;
		case  (($moyenne >= $a4)&&($moyenne < $a5)) : $grade = "B"; break;
		default : $grade = "A"; break;
	}
	return $grade;    
}
//fonction pour arrondir les notes
function myround($value, $places=0) {
    if ($places < 0) { 
      $places = 0; 
    }    
    $mult = pow(10, $places);
    
    $number1  =  $value * $mult;
    $number2  = intval($number1);
    $number3  = $number1 - $number2;

    if($number3 >= 0.5) {
      return ceil($value * $mult) / $mult;
    } else {
      return floor($value * $mult) / $mult;
    }
}
//
function formater($donnees, $per, $espace) {
	$donnees = $espace.'<table align="right" border="1" cellpadding="1" cellspacing="0" >
		<tr style="background-color:#ffe6e6;color:#0000FF;">
			<td width="'.$per.'" align="center">'. $donnees.' </td>
		</tr>
	</table>';
	return $donnees;
}
//fonction de verifictaion de validation
function validation($filiere, $codeue,  $annee, $niveauFormation, $anneeacad, $matricule, $db) {
	global $total_credi_formation, $total_ue_entame,
    $total_ue_valide, $total_ue_restant_a_valide,
    $total_credit_cumule,
    $total_credit_capitalie,
    $somme_moyenne,
    $j;
        
	$sql = 'SELECT resultat, premiere_inscription, inscription_actuelle, credit FROM `tabinscriunite` INNER JOIN unites ON tabinscriunite.code_unite = unites.code_unite 
	WHERE unites.`idFiliere` =? AND unites.`code_unite` =? AND unites.`annee` =? AND unites.`niveauFormation` =? AND `premiere_inscription` =? AND matricule=?';
	$p_res = $db->prepare($sql);
	$p_res->execute(array($filiere, $codeue,  $annee, $niveauFormation, $anneeacad, $matricule));
	$res = $p_res->fetch();
	
	$diffAnnee = $res['inscription_actuelle'] - $res['premiere_inscription'];
	$frequence = $diffAnnee + 1;
	
	if($diffAnnee == 0 ) {
	  $periodeDep 	= $res['premiere_inscription'] - 1;
	  $periodeFin 	= $res['premiere_inscription'];//substr($res['premiere_inscription'], 2);
	  $periode 		= $periodeDep.'-'.$periodeFin;
	}else{
	  $periodeDep 	= $res['inscription_actuelle'] - 1;
	  $periodeFin 	= $res['inscription_actuelle']; //substr($res['inscription_actuelle'], 2);
	  $periode 		= $periodeDep.'-'.$periodeFin;
	}
	$valide= [];
	if($res['resultat'] == 'A') {
		$valide[0]	=	"<td style=\"text-align: center;\" class=\"valide\">Validé</td>";
		$valide[1] 	=	$res['credit']; 
		$valide[2] 	=	$frequence; 
		$valide[3] 	=	$periode; 
		$total_credit_capitalie += $res['credit'];
		$total_ue_valide++;
	}else{
		$valide[0]="<td style=\"text-align: center;\" class=\"nonValide\">Non Validé</td>";
		$valide[1] 	=	0; 
		$valide[2] 	=	$frequence; 
		$valide[3] 	=	$periode; 
		//$total_ue_restant_a_valide++;
	}
	return $valide;
}

//fonction d'affichage des matieres dans le tableau
function afficher_matiere($les_ue, $filiere, $semestre, $annee, $niveauFormation, $anneeacad, $matricule, $db) {
	global $total_credi_formation, $total_ue_entame,
    $total_ue_valide, $total_ue_restant_a_valide,
    $total_credit_cumule,
    $total_credit_capitalie, $total_credit,
    $somme_moyenne, $j;
	
	$contenu="";
	
	foreach ($les_ue as $ue) {
		$note_ue 	= getMoyWithUE($ue['code_unite'], $filiere, $semestre, $annee, $niveauFormation, $anneeacad, $matricule, $db);//contient la moyenne de l'ue et le grade.
		$validation = validation($filiere, $ue['code_unite'],  $annee, $niveauFormation, $anneeacad, $matricule, $db);
		$type_ue = $ue['type_ue'];			
		if($type_ue == 0) {
			$couleur = '#000000';
		}else if($type_ue == 1) {
			$couleur = '#ff0000';
		}else if($type_ue == 2) {
			$couleur = '#0000ff';
		}else if($type_ue == 3) {
			$couleur = '#008100';
		}		
		$somme_moyenne = $somme_moyenne + $note_ue[0] * $ue['credit'];	
		$total_credit+=$ue['credit'];
		$contenu.="<tr>
	            <td height=\"10px\" style=\"text-align: center; \">
	                 ".$ue['code_unite']."
	            </td >
	            <td class=\"ue\">
	                 <font color = \"$couleur\">".$ue['intituleUnite']."</font>
	            </td >
	            <td style=\"text-align: center;\">
	                 ".$validation[3]." 
	            </td >
	            <td style=\"text-align: center;\">
	                 ".$ue['credit']."
	            </td >
	            <td style=\"text-align: center;\">
	                 ".$validation[1]."
	            </td >
	            <td style=\"text-align: center;\">
	                 ".$validation[2]."
	            </td >
	            <td style=\"text-align: center;\">
	                 ".$note_ue[0]."
	            </td>
	            <td style=\"text-align: center;\">
	                 ".$note_ue[1]."
	            </td>
	                 ".$validation[0]."
	      </tr>";

	      $j++;
	}
	return $contenu;
}

define("COULEUR_1", "#8888FF");
define("COULEUR_2", "#CCCCFF");
function couleurAlterner()	{
	  static $couleur = COULEUR_1;
	  if (strcmp($couleur,COULEUR_1)==0)
		{
		 $couleur = COULEUR_2; 
		}
	   else
		{
		 $couleur = COULEUR_1; 
		}
	   return $couleur;
}

//Génération du tableau de spécification d'une filière
function tableauSpecification($idFiliere, $annee, $niveauFormation, $anneeacad, $bp, $bdd) {
	$html = '<table cellpadding="2" cellspacing="0" width="100%">
		<tr>
			<td width="10%"> </td>
			<td width="80%">
				<table border="1" cellpadding="2" cellspacing="0" width="100%">
					<tr>
						<td width="100%" bgcolor = "#d7e4db" colspan = "2" align="center"> LEGENDE NOTES ECTS (European Credits Transfer System)</td>
					</tr>
					<tr style="background-color:#ffe6e6;color:#0000FF;">
						<td width="20%" align="center"> Intervalles Notes ECTS</td>
						
						<td width="10%" align="center">Notes ECTS</td>
						
						<td width="70%" align="center">Appréciation : Commentaire</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">[15, 20]</td>
						
						<td width="10%" align="center">A</td>
						
						<td width="70%">EXCELLENT : Résultat remarquable, avec seulement quelques insuffisances mineures</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">[12, 15[</td>
						
						<td width="10%"  align="center">B</td>
						
						<td width="70%">TRES BIEN : Résultat supérieur à la moyenne, malgré un certain nombre d\'insuffisances notables</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">[10, 12[</td>
						
						<td width="10%"  align="center">C</td>
						
						<td width="70%">BIEN : Travail généralement bon, malgré un certain nombre d\'insuffisances notables</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">[8, 10[</td>
						
						<td width="10%"  align="center">D</td>
						
						<td width="70%">SATISFAISANT : Travail honnête, mais comportant des lacunes importantes</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">[6, 8[</td>
						
						<td width="10%"  align="center">E</td>
						
						<td width="70%">PASSABLE : Le résultat satisfait aux critères minimaux</td>
					</tr>
					
					<tr>
						<td width="20%" align="center">< 6</td>
						
						<td width="10%"  align="center">F</td>
						
						<td width="70%">INSUFFISANT : Un travail supplémentaire considérable est nécessaire</td>
					</tr>
				</table>
			</td>
		</tr>
	</table><br /><br />';
	$html .= '<table>
		<tr>
			<td width="28%"> </td>
			<td>
				<table border="1" cellpadding="2" cellspacing="0"  style="margin:0;padding:5;padding-top:20px;">
					<tr>
						<td width="100%" bgcolor = "#d7e4db" colspan = "2" align="center"> LEGENDE TABLEAU DE SPECIFICATION</td>
					</tr>
					<tr>
						<td width="7%" bgcolor = "#000000"> </td>
						
						<td width="93%"> Unité de Connaissance Fondamentales </td>
					</tr>
					
					<tr>
						<td width="7%" bgcolor = "#ff0000"> </td>
						
						<td width="93%" > Unité de Spécialité </td>
					</tr>
					
					<tr>
						<td width="7%" bgcolor = "#0000ff"> </td>
						
						<td width="93%" > Unité de Méthodologie </td>
					</tr>
					
					<tr>
						<td width="7%" bgcolor = "#008100"> </td>
						
						<td width="93%" > Unité de Culture Générale </td>
					</tr>
				</table>
			</td>
		</tr>
	</table>';
	if($_SESSION['format'] == '1') {
		$semestre1 = $annee * 2 - 1; // Calcul du numero de semestre cumule jusqu'au premier semestre de la filière
		$semestre2 = $annee * 2; // Calcul du numero de semestre cumule jusqu'au second semestre de la filière
	}else{
		$semestre1 = $_SESSION['idSemestre'];
	}
	$html .= '	
	<br /><br />
	<table border="1" cellpadding="2" cellspacing="0" width="100%" >
	<thead>
		<tr style="background-color:#ffe6e6;color:#0000FF;">
			<td width="3%" ></td>
			<td width="8%"  align="center">CREDIT UE</td>
			<td width="8%" align="center">CODE UE</td>
			<td width="34%" class="rotate" ><div>INTITULE UNITE D\'ENSEIGNEMENT</div></td>
			<td width="9%"  align="center">CODE EC</td>
			<td width="30%" >INTITULE  ELEMENT CONSTITUTIF (EC)</td>
			<td width="8%" align="center">POIDS EC</td>
		</tr>
	</thead>';
		  
	$reqCredit = "SELECT SUM(credit) AS sum FROM ecu WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad";
	$statement = $bdd->prepare($reqCredit);
	$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
	$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
	$statement->bindParam(':niveau',  $niveauFormation, PDO::PARAM_STR);
	$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
	$statement->execute();
	$row=$statement->fetch(PDO::FETCH_ASSOC);
	$sum = $row['sum'];
	
	$reqCreditS1 = "SELECT SUM(credit) AS sum FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
	$statement = $bdd->prepare($reqCreditS1);
	$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
	$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
	$statement->bindParam(':niveau',  $niveauFormation, PDO::PARAM_STR);
	$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
	$statement->bindParam(':id',  $semestre1, PDO::PARAM_STR);
	$statement->execute();
	$row=$statement->fetch(PDO::FETCH_ASSOC);
	$sum1 = $row['sum'];
	  
	  
	$reqS1 = "SELECT credit, code_unite, intituleUnite, type_ue FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
	$statement = $bdd->prepare($reqS1);
	$statement->bindParam(':idF', 		$idFiliere, PDO::PARAM_STR);
	$statement->bindParam(':an',  		$annee, PDO::PARAM_STR);
	$statement->bindParam(':niveau',  	$niveauFormation, PDO::PARAM_STR);
	$statement->bindParam(':acad',		$anneeacad, PDO::PARAM_STR);
	$statement->bindParam(':id',  		$semestre1, PDO::PARAM_STR);
	$statement->execute();
	if($sum1 < 30)	{
		$color = '#ff0000';
	}else{
		$color = '#00ffff';
	}			
	$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
		<td width=\"3%\" ></td>
		<td width=\"8%\"  align=\"center\" bgcolor = \"$color\">$sum1</td>
		<td width=\"8%\" ></td>
		<td width=\"34%\"></td>
		<td width=\"9%\" align=\"center\">SEMESTRE $semestre1</td>
		<td width=\"30%\" ></td>
		<td width=\"8%\" ></td>
	</tr>";
	$j = 0;
	while($row=$statement->fetch(PDO::FETCH_ASSOC)){
			$c = couleurAlterner();  
			$j++;
			$code = $row['code_unite'];
			$type_ue = $row['type_ue'];			
			if($type_ue == 0) {
				$couleur = '#000000';
			}else if($type_ue == 1) {
				$couleur = '#ff0000';
			}else if($type_ue == 2) {
				$couleur = '#0000ff';
			}else if($type_ue == 3) {
				$couleur = '#008100';
			}
			$reqS1 = "SELECT * FROM ecu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code";
			$statement2 = $bdd->prepare($reqS1);
			$statement2->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
			$statement2->bindParam(':an',  $annee, PDO::PARAM_STR);
			$statement2->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
			$statement2->bindParam(':code',  $code, PDO::PARAM_STR);
			$statement2->execute();
			$total = $statement2->rowCount();
			$row1 = $statement2->fetch(PDO::FETCH_ASSOC);
			$html .= "<tr>   	 	
					<th width=\"3%\"   align=\"center\" rowspan=\"$total\">$j</th>
					<td width=\"8%\" align=\"center\" bgcolor = \"$c\"  rowspan=\"$total\" >$row[credit]</td>
					<td width=\"8%\"  align=\"center\" rowspan=\"$total\" >$row[code_unite]</td>
					<td width=\"34%\"  align=\"left\" rowspan=\"$total\" ><font color = \"$couleur\">$row[intituleUnite]</font></td>
					<td width=\"9%\"  align=\"center\">$row1[code_ecu]</td>
					<td width=\"30%\" align=\"left\" >$row1[intituleEcu]</td>
					<td  width=\"8%\"align=\"center\">$row1[credit]</td>
					</tr>";
			$i = 0;
			while($row2=$statement2->fetch(PDO::FETCH_ASSOC)) {
			$i++;          	
			$html .= "
			<tr>
					<td width=\"9%\" align=\"center\">$row2[code_ecu]</td>
					<td width=\"30%\" align=\"left\" >$row2[intituleEcu]</td>
					<td width=\"8%\" align=\"center\" >$row2[credit]</td>
			</tr>";
			}
	}
	
	if($_SESSION['annee'] != "0") {
		$reqCreditS2 = "SELECT SUM(credit) AS sum FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
		$statement = $bdd->prepare($reqCreditS2);
		$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
		$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
		$statement->bindParam(':niveau',  $niveauFormation, PDO::PARAM_STR);
		$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
		$statement->bindParam(':id',  $semestre2, PDO::PARAM_STR);
		$statement->execute();
		$row=$statement->fetch(PDO::FETCH_ASSOC);
		$sum2 = $row['sum'];

		$reqS1 = "SELECT credit, code_unite, intituleUnite, type_ue FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
		$statement = $bdd->prepare($reqS1);
		$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
		$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
		$statement->bindParam(':niveau',  $niveauFormation, PDO::PARAM_STR);
		$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
		$statement->bindParam(':id',  $semestre2, PDO::PARAM_STR);
		$statement->execute();
						
		if($sum2 < 30)	{
			$color = '#ff0000';
		}else{
			$color = '#00ffff';
		}			
		$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
			<td width=\"3%\" ></td>
			<td width=\"8%\"  align=\"center\" bgcolor = \"$color\">$sum2</td>
			<td width=\"8%\" ></td>
			<td width=\"34%\"></td>
			<td width=\"9%\"  align=\"center\"  >SEMESTRE $semestre2</td>
			<td width=\"30%\"></td>
			<td width=\"8%\" ></td>
		</tr>";

		while($row=$statement->fetch(PDO::FETCH_ASSOC)){
			$c = couleurAlterner();  
			$j++;
			$code = $row['code_unite'];
			$type_ue = $row['type_ue'];			
			if($type_ue == 0) {
				$couleur = '#000000';
			}else if($type_ue == 1) {
				$couleur = '#ff0000';
			}else if($type_ue == 2) {
				$couleur = '#0000ff';
			}else if($type_ue == 3) {
				$couleur = '#008100';
			}
			
			$reqS1 = "SELECT * FROM ecu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code";
			$statement2 = $bdd->prepare($reqS1);
			$statement2->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
			$statement2->bindParam(':an',  $annee, PDO::PARAM_STR);
			$statement2->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
			$statement2->bindParam(':code',  $code, PDO::PARAM_STR);
			$statement2->execute();
			$total = $statement2->rowCount();
			$row1 = $statement2->fetch(PDO::FETCH_ASSOC);
			$html .= "<tr>   	 	
				<th width=\"3%\"  align=\"center\" rowspan=\"$total\">$j</th>
				<td width=\"8%\" align=\"center\" bgcolor = \"$c\"  rowspan=\"$total\" >$row[credit]</td>
				<td width=\"8%\"  align=\"center\" rowspan=\"$total\" >$row[code_unite]</td>
				<td width=\"34%\" align=\"left\" rowspan=\"$total\" > <font color = \"$couleur\">$row[intituleUnite]</font> </td>
				<td  align=\"center\">$row1[code_ecu]</td>
				<td width=\"30%\" align=\"left\" >$row1[intituleEcu]</td>
				<td width=\"8%\" align=\"center\">$row1[credit]</td>
				</tr>";
			$i = 0;
			while($row2=$statement2->fetch(PDO::FETCH_ASSOC)) {
			$i++;          	
			$html .= "
				<tr>
					<td width=\"9%\" align=\"center\">$row2[code_ecu]</td>
					<td width=\"30%\" align=\"left\" >$row2[intituleEcu]</td>
					<td width=\"8%\" align=\"center\" >$row2[credit]</td>
				</tr>";
			}
		}
		if($sum < 60) {
			$color = '#ff0000';
		}else{
			$color = '#00ffff';
		}			
	}
	if($_SESSION['annee'] != "0") {
		$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
			<td colspan = \"6\" align=\"center\">
				TOTAL CREDIT SEMESTRE $semestre1 & SEMESTRE $semestre2
			</td>
			<td align=\"center\"  bgcolor = \"$color\">$sum</td>
		</tr></table>";	
	}else{
		$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
			<td colspan = \"6\" align=\"center\">
				TOTAL CREDIT SEMESTRE $semestre1 
			</td>
			<td align=\"center\"  bgcolor = \"$color\">$sum1</td>
		</tr></table>";	
	}
	$html .= '<table align = "center" style="margin:0;padding:5;padding-top:20px;">
		<tr>
			<td width="28%"> </td>
			<td>
				<table border="0" cellpadding="2" cellspacing="0"  style="margin:0;padding:5;padding-top:20px;">
					<tr>
						<td width="100%" bgcolor = "#d7e4db" colspan = "2" align="center"> Coordonnées</td>
					</tr>
					<tr>						
						<td width="100%"> '.$bp.' </td>
					</tr>
				</table>
			</td>
		</tr>
	</table>';	
	return $html;
}
?>
