<?php
$tabsavpast_select = 
"SELECT sav.nom_savoir nom_savoir, SUBSTR(sav.nom_savoir,1,50) savsub, SUBSTR(sav.s".$divpast."_id,-3) sidsub, SUBSTR(sav.s".$divpast."_id,1,3) cadre, sav.s".$divpast."_id savdiv_id, sc.bgcolor bg
FROM ".$prefix."_savoirs".$divpast." sav
INNER JOIN ".$prefix."_savchamps sc
ON sav.champs_id = sc.champs_id
".$savchoix."
ORDER BY s".$divpast."_id ASC";
$tabsavpast = mysqli_query($bdd,$tabsavpast_select);
$tabsavpast_nb = mysqli_num_rows($tabsavpast);
$tabdiv_select = 
"SELECT e.nom nom, e.prenom prenom, e.eleves_id
FROM ".$prefix."_eleves e
WHERE e.eleves_id='$eleve_id'
GROUP BY nom";

//Extraction PDF
//if($float=='left') { echo '<p style="position:absolute;bottom:10px;">'; }
//else if($float='right') { echo '<p style="position:absolute;bottom:10px;left:500px;">'; }
echo '';
if(isset($_POST['havepdf'.$float])) {
	include('./include/pdf_loaders/evaluations_past'.$float.'.php');
}
echo '<form id="loadpdf'.$float.'" action="include/pdf_loaders/evaluations_past'.$float.'.php" method="post"><input type="hidden" name="havepdf'.$float.'" value="1" /></form>';

echo '<script type="text/javascript">
function submitpdf'.$float.'(){
	$("#loadpdf'.$float.'").submit()
}
</script></p>';

// Tableaux d'évaluation
$tabdiv = mysqli_query($bdd,$tabdiv_select);
${'tab_eleve'.$float} = '<table name="noprint"'; 
if($float=='left') { ${'tab_eleve'.$float} .= 'class="evalele_left">'; }
else if($float=='right') { ${'tab_eleve'.$float} .= 'class="evalele_right">'; }
${'tab_eleve'.$float} .= '<thead class="eval_thead">
<tr>
<th class="eval_th eval_th_ele">En ';

if($divpast=="6") { ${'tab_eleve'.$float} .= '6ème'; }
else if($divpast=="5") { ${'tab_eleve'.$float} .= '5ème'; }
else if($divpast=="4") { ${'tab_eleve'.$float} .= '4ème'; }
else if($divpast=="3") { ${'tab_eleve'.$float} .= '3ème'; }
else if($divpast=="2") { ${'tab_eleve'.$float} .= '2nde'; }
else if($divpast=="1") { ${'tab_eleve'.$float} .= '1re'; }
${'tab_eleve'.$float} .= '.<p />'.SAV1.'</th><th class="eval_th eval_th_ele"><a onclick="submitpdf'.$float.'();" id="preview-pdf'.$float.'"><img src="img/pdf-icon.png" title="'.PDF_EXTRACT.'"/></a></th>';
${'tab_eleve'.$float} .= '</tr></thead>
<tbody class="eval_tbody eval_tbody_past">';

${'tab_eleve_pdf'.$float} = '<h2>'.$eleve_info['nom'].' '.$eleve_info['prenom'].' '.$diveval.'</h2>';
${'tab_eleve_pdf'.$float} = '<table name="noprint"'; 
if($float=='left') { ${'tab_eleve_pdf'.$float} .= 'class="evalele_left">'; }
else if($float=='right') { ${'tab_eleve_pdf'.$float} .= 'class="evalele_right">'; }
${'tab_eleve_pdf'.$float} .= '<thead class="eval_thead">
<tr>
<th class="eval_th eval_th_ele">'.IN.' ';
if($divpast=="6") { ${'tab_eleve_pdf'.$float} .= '6ème'; }
else if($divpast=="5") { ${'tab_eleve_pdf'.$float} .= '5ème'; }
else if($divpast=="4") { ${'tab_eleve_pdf'.$float} .= '4ème'; }
else if($divpast=="3") { ${'tab_eleve_pdf'.$float} .= '3ème'; }
else if($divpast=="2") { ${'tab_eleve_pdf'.$float} .= '2nde'; }
else if($divpast=="1") { ${'tab_eleve_pdf'.$float} .= '1re'; }
${'tab_eleve_pdf'.$float} .= '.<p />'.SAV1.'</th>';
foreach($tabdiv as $eleve) {
	${'tab_eleve_pdf'.$float} .= '<th class="eleve">'.$eleve['nom'].' '.$eleve['prenom'].'</th>';
}
${'tab_eleve_pdf'.$float} .= '</tr></thead>
<tbody class="eval_tbody eval_tbody_past">';
?><script type="text/javascript">
	function selection(pSelect,pDiv){
		
		var couleur;

		if(pSelect.options[pSelect.selectedIndex].value == "0"){
			couleur = "#eee";
		}
		else if(pSelect.options[pSelect.selectedIndex].value == "1"){
			couleur = "red";
		}
		else if(pSelect.options[pSelect.selectedIndex].value == "2"){
			couleur = "orange";
		}
		<?php
		if($nb_degres==4) {
			echo 'else if(pSelect.options[pSelect.selectedIndex].value == "3"){
				couleur = "yellow";
			}';
		}
		?>
		else if(pSelect.options[pSelect.selectedIndex].value == "4"){
			couleur = "green";
		}
		document.getElementById(pDiv).style.backgroundColor = couleur;

	}
</script>
<?php
if(isset($tabsavpast)) {
	foreach ($tabsavpast as $savpast) {
		${'tab_eleve'.$float} .= '<tr><td class="eval_sav" style="background-color:'.$savpast['bg'].';">
		<span title="'.$savpast['nom_savoir'].'">'.$savpast['cadre'].'-'.$savpast['sidsub'].'. ';
		${'tab_eleve'.$float} .=  mb_ereg_replace("[?]","",mb_convert_encoding($savpast['savsub'],"utf-8"));
		${'tab_eleve'.$float} .=  '...</td><!--<td style="padding-right:360px;"></td>-->';
		${'tab_eleve_pdf'.$float} .= '<tr><td class="eval_sav" style="background-color:'.$savpast['bg'].';"><span title="'.$savpast['nom_savoir'].'">'.$savpast['cadre'].'-'.$savpast['sidsub'].'. '.$savpast['nom_savoir'].'</td>';
		foreach ($tabdiv as $eleve)
		{
			$tabeval_select = "SELECT eval FROM ".$prefix."_savele WHERE eleves_id='".$eleve['eleves_id']."' AND s_id='".$savpast['savdiv_id']."'";
			$tabeval = mysqli_query($bdd,$tabeval_select);
			$tabeval_info = mysqli_fetch_assoc($tabeval);
			$savid_opt = ''.$eleve['eleves_id'].':'.$savpast['savdiv_id'].'';
			if(@$tabeval_info['eval']==0) {
				${'tab_elevea'.$float} = '<td class="evalc evalniv0" id='.$savid_opt.'>';
			}
			else if(@$tabeval_info['eval']==1) {
				${'tab_elevea'.$float} =  '<td class="evalc evalniv1" id='.$savid_opt.'>';
			}
			else if(@$tabeval_info['eval']==2) {
				${'tab_elevea'.$float} = '<td class="evalc evalniv2" id='.$savid_opt.'>';
			}
			else if(@$nb_degres==4&&@$tabeval_info['eval']==3) {
				${'tab_elevea'.$float} = '<td class="evalc evalniv3" id='.$savid_opt.'>';
			}
			else if(@$tabeval_info['eval']==4) {
				${'tab_elevea'.$float} = '<td class="evalc evalniv4" id='.$savid_opt.'>';
			}
			$_SESSION['eid'] = $eleve['eleves_id'];
			$_SESSION['sid'] = $savpast['savdiv_id'];
			${'tab_eleve'.$float} .= ${'tab_elevea'.$float}.'</td>'; 
			${'tab_eleve_pdf'.$float} .= ${'tab_elevea'.$float}.'</td>'; 
		}
		${'tab_eleve'.$float} .= '</tr>';
		${'tab_eleve_pdf'.$float} .= '</tr>';
	}
	${'tab_eleve'.$float} .= '</tbody></table>';
	${'tab_eleve_pdf'.$float} .= '</tbody></table>';
	echo ${'tab_eleve'.$float};
	$_SESSION['evaluation'.$float] = ${'tab_eleve_pdf'.$float};
}

?>
