<?php
$archives = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_res_archives'"));
if($archives['valeur']=='1') {
	$freqp = 'freqres';
	$addfreq = 'freq.statut, ';
	$inscrits_select = "SELECT freq.".$freqp."_id, freq.eleves_id, freq.date_".$freqp.", freq.code_activ, freq.hor_name, ".$addfreq." espaces.espace_id, espaces.espace_nom, eleves.eleves_id, eleves.nom, eleves.prenom, eleves.division 
	FROM ".$prefix."_".$freqp." freq 
	INNER JOIN ".$prefix."_eleves eleves
	ON freq.eleves_id = eleves.eleves_id
	LEFT JOIN ".$prefix."_espaces espaces
	ON espaces.espace_id = freq.espace_id
	WHERE eleves.eleves_id = '".$eleve_id."'  
	AND freq.date_".$freqp." >= DATE_SUB(CURDATE(), INTERVAL 4 MONTH)
	ORDER BY freq.date_".$freqp." DESC";
	$inscrits = mysqli_query($bdd,$inscrits_select);
	$inscrits_info = mysqli_fetch_assoc($inscrits);
	$nb_inscrits = mysqli_num_rows($inscrits);
	if($nb_inscrits>0) {
		echo '<div style="clear:both;" class="scroll"><br>&nbsp; <br><h2>'.RESAPAST.'</h2>';
		echo '<table id="tablesorter" class="tablesorter journaltable"><thead><tr><th>'.DIV_TINY.'</th><th>'.DATE.'</th><th>'.CREN1.'</th>';
		if($espopt['valeur']==1) { echo '<th>'.ZONE.'</th>'; }
		echo '<th>'.ACTIV.'</th><th>'.FREQC_RETAR11.'</th>';
		echo '</tr></thead><tbody>';
		foreach($inscrits as $liste) {
			echo '<tr id="tr'.$liste[$freqp.'_id'].'"><td>'.$liste['division'].'</td>';
			echo '<td>'.date('d/m/Y', strtotime(str_replace("/","-",$liste['date_'.$freqp]))).'';				
			// créneau
			$hor = mysqli_query($bdd,"SELECT num_creneau, debut, fin FROM ".$prefix."_horaires WHERE hor_name = '".$liste['hor_name']."'");
			$hor_info = mysqli_fetch_assoc($hor);
			$deb_cren = substr($liste['hor_name'], 0, 1);
			echo '<td>';
			if($hor_info['num_creneau']<10) {
				$affcren = '0'.$hor_info['num_creneau'].' - ';
			}
			else {
				$affcren = ''.$hor_info['num_creneau'].' - ';
			}
			$affcren .= MOMENT[$deb_cren];
			$fin_cren = substr($liste['hor_name'], 1, 1);
			$affcren .= ' ('.$deb_cren.$fin_cren.') de ';
			$deb = $hor_info['debut'];
			$dh = substr($deb, 0, 2);
			$dm = substr($deb, 3, 2);
			$affcren .= ''.$dh.'h'.$dm.' à ';
			$fin = $hor_info['fin'];
			$fh = substr($fin, 0, 2);
			$fm = substr($fin, 3, 2);
			$affcren .= ''.$fh.'h'.$fm.'';
			echo $affcren;
			if(isset($_POST['liste_modif'])&&$_SESSION['crenpickercheck'] == 1) {
				echo '<p class="signal">'.$_SESSION['crenpick'].'</p>';
			}
			echo '</td>';
			// espace
			if($espopt['valeur']==1) {
				echo '<td>';
				if($liste['espace_id']==0) { echo $esp0['valeur']; }
				else { echo $liste['espace_nom']; }
				echo '</td>';
			}
			// activité
			$activ = mysqli_query($bdd,"SELECT nom_activ FROM ".$prefix."_freqactiv WHERE code_activ = '".$liste['code_activ']."'");
			$activ_info = mysqli_fetch_assoc($activ);
			echo '<td>';
			if(@$activ_info['nom_activ']!="") { echo @$activ_info['nom_activ']; }
			echo '</td>';
			// cas
			echo '<td>';
			if(@$liste['statut']=='0') { echo WAITING; }
			else if(@$liste['statut']=='1') { echo ABORDED; }
			else if(@$liste['statut']=='2') { echo DONE; }
			else if(@$liste['statut']=='4') { echo RESIDU; }
			//echo ' ('.$liste['statut'].')';
			echo '</td>';
			echo '</tr>';	
		}
		echo '</tbody></table></div></div>';
	}
}