<?php session_start(); 
require_once(dirname(__DIR__, 2) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
include('../../css/css.php');?>
<style>
td.eee {
	background-color:#eee;
	color:black;
	text-align:center;
}
td.ora {
	background-color:orange;
	color:black;
	text-align:center;
}
td.gre {
	background-color:green;
	color:black;
	text-align:center;
}
td.red {
	background-color:red;
	color:black;
	text-align:center;
}
</style>
<?php
echo '<meta charset="utf-8" />';

echo '<link rel="stylesheet" media="print" href="../../css/idl_print.css" />';
$diveval = $_SESSION['diveval'];
$eleve_id = $_SESSION['id'];
$deb_diveval = substr("$diveval", 0, 1);
$nom_ele = $_SESSION['nom'];
$prenom_ele = $_SESSION['prenom'];
$div_ele = $_SESSION['div'];

// Sélection du niveau :
if($deb_diveval=="6")
{ $div = "6"; }
else if($deb_diveval=="5")
{ $div = "5"; }
else if($deb_diveval=="4")
{ $div = "4"; }
else if($deb_diveval=="3")
{ $div = "3"; }
else if($deb_diveval=="2")
{ $div = "2"; }
else
{ $div = "t"; }

// Sélection des grilles d'évaluation :
$verif_param_sav_select = "SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'savoirs'";
$verif_param_sav = mysqli_query($bdd,$verif_param_sav_select);
$verif_param_sav_info = mysqli_fetch_array($verif_param_sav);
if($verif_param_sav_info['valeur'] == "A1E0P0")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'FPD%' OR sav.s".$div."_id LIKE 'APD%' ";
}
else if($verif_param_sav_info['valeur'] == "A1E1P0")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'FPD%' OR sav.s".$div."_id LIKE 'APD%' OR sav.s".$div."_id LIKE 'EMI%' ";
}
else if($verif_param_sav_info['valeur'] == "A1E1P1")
{
	$savchoix = "";
}
else if($verif_param_sav_info['valeur'] == "A1E0P1")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'FPD%' OR sav.s".$div."_id LIKE 'APD%' OR sav.s".$div."_id LIKE 'PER%' ";
}
else if($verif_param_sav_info['valeur'] == "A0E1P0")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'EMI%' ";
}
else if($verif_param_sav_info['valeur'] == "A0E1P1")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'EMI%' OR sav.s".$div."_id LIKE 'PER%' ";
}
else if($verif_param_sav_info['valeur'] == "A0E0P1")
{
	$savchoix = "WHERE sav.s".$div."_id LIKE 'PER%' ";
}

// Récupération des données :
$tabsav_select = 
"SELECT sav.nom_savoir nom_savoir, SUBSTR(sav.nom_savoir,1,45) savsub, SUBSTR(sav.s".$div."_id,7,3) sidsub, SUBSTR(sav.s".$div."_id,1,3) cadre, sav.s".$div."_id savdiv_id, sc.bgcolor bg
FROM ".$prefix."_savoirs".$div." sav
INNER JOIN ".$prefix."_savchamps sc
ON sav.champs_id = sc.champs_id
".$savchoix."
ORDER BY s".$div."_id ASC";
$tabsav = mysqli_query($bdd,$tabsav_select);
$tabsav_nb = mysqli_num_rows($tabsav);
$tabdiv_select = 
"SELECT e.nom nom, e.prenom prenom, sav.s".$div."_id savdiv_id, sav.nom_savoir savoir, s.eleves_id, s.s_id s_id, s.eval eval
FROM ".$prefix."_eleves e
INNER JOIN ".$prefix."_savele s
ON s.eleves_id = e.eleves_id
INNER JOIN ".$prefix."_savoirs".$div." sav
ON sav.s".$div."_id = s.s_id
WHERE e.eleves_id='$eleve_id'
GROUP BY nom";

// Si aucun savoir à évaluer :
if($tabsav_nb == 0) {
	echo EDTEL_STATS5;
}
// Sinon :
else {

// Affichage :
$tabdiv = mysqli_query($bdd,$tabdiv_select);
?><table class="evaltab evalt">
	<thead class="evalt">
		<tr>
		<th class="evalt">Ceci est un bilan des savoirs en information-documentation acquis par <br /> <?php echo ''.$prenom_ele.' '.$nom_ele.EVAL_INF1.$div_ele.EVAL_INF2;?></th>
		<?php foreach($tabdiv as $eleve) {
			echo '<th class="evalt">'.NIV1.'</th><th class="evalt">'.NIV2.'</th><th class="evalt">'.NIV4.'</th>';
		}
		echo '</tr>';
	?>
	</thead>

	<tbody class="evalt">
	<?php
	foreach ($tabsav as $savoir)
	{
		echo '<tr>';
		echo '<td class="eval_sav_imp evalt" style="background-color:'.$savoir['bg'].';">
		<span title="'.$savoir['nom_savoir'].'">'.$savoir['cadre'].'-'.$savoir['sidsub'].'. '.$savoir['nom_savoir'].'';
		echo '</td><!--<td style="padding-right:360px;"></td>-->';
		foreach ($tabdiv as $eleve)
		{

			$tabeval_select = "SELECT eval FROM ".$prefix."_savele WHERE eleves_id='".$eleve['eleves_id']."' AND s_id='".$savoir['savdiv_id']."'";
			$tabeval = mysqli_query($bdd,$tabeval_select);
			$tabeval_info = mysqli_fetch_assoc($tabeval);
			$savid_opt = ''.$eleve['eleves_id'].':'.$savoir['savdiv_id'].'';
			echo '<td class="evaltd">';
			if($tabeval_info['eval']==1) {
				echo 'X</td>';
			}
			else {
				echo '</td>';
			}
			echo '<td class="evaltd">';
			if($tabeval_info['eval']==2) {
				echo 'X</td>';
			}
			else {
				echo '</td>';
			}
			echo '<td class="evaltd">';
			if($tabeval_info['eval']==3) {
				echo 'X</td>';
			}
			else {
				echo '</td>';
			}
			$_SESSION['eid'] = $eleve['eleves_id'];
			$_SESSION['sid'] = $savoir['savdiv_id'];
			
			
		}
		echo "</tr>";
	}
	
	?>
	</tbody>
</table>
<input class="preins" type="button" onclick="javascript:window.print()" value="<?php echo PRINT1;?>" />
<?php
}
mysqli_close($bdd);
?>
