<?php 
$_SESSION['etabchoix']=@$_COOKIE['LOGGED_ETAB']; 
$_SESSION['classinscript']=@$_COOKIE['CLASS_INS']; 
require_once(dirname(__DIR__, 2) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');

$classe_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_classe'"));
if(substr($classe_info['valeur'],1)=='-perdiv'||@substr($_SESSION['classinscript'],1)=='-perdiv') {
	$ordg = 'eleves.division ASC, ';
}
else { $ordg = ''; }

if(isset($_POST["idAuteur"])){	
	$liste_ele = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves WHERE division = '".$_POST["idAuteur"]."' ORDER BY replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(nom,'À','A'),'Á','A'),'Â','A'),'Ã','A'),'Ä','A'),'Å','A'),'Ç','C'),'È','E'),'É','E')
	,'Ê','E'),'Ë','E'),'Ì','I'),'Í','I'),'Î','I'),'Ï','I'),'Ò','O'),'Ó','O'),'Ô','O'),'Õ','O')
	,'Ö','O'),'Ù','U'),'Ú','U'),'Û','U'),'Ü','U'),'Ý','Y') ASC, prenom ASC");
	$liste_nb = mysqli_num_rows($liste_ele);
	if($liste_nb>0) {
		echo '<p name="noprint"><div style="display:inline;" id="NbEle" name="'.$liste_nb.'">'.$liste_nb.'</div> sur '.$liste_nb.' élèves</p><ul id="elev">';
		foreach($liste_ele as $liste) {
			echo '<input type="checkbox" class="elc" name="'.$liste['eleves_id'].'" id="check'.$liste['eleves_id'].'" onclick="nb()" checked /> <label for="check'.$liste['eleves_id'].'"> '.$liste['nom'].' '.$liste['prenom'].'</label><br>';
		}
		echo '</ul>';
	}
	else {
		$listeg_ele_select = "SELECT groupedesc.groupe_nom, groupele.groupe_id, eleves.eleves_id, eleves.nom, eleves.prenom, eleves.division 
		FROM ".$prefix."_groupele groupele
		INNER JOIN ".$prefix."_eleves eleves 
		ON groupele.eleves_id = eleves.eleves_id 
		INNER JOIN ".$prefix."_groupes groupedesc 
		ON groupele.groupe_id = groupedesc.groupe_id 
		WHERE groupedesc.groupe_nom = '".$_POST["idAuteur"]."' 
		ORDER BY ".$ordg." replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
	replace(eleves.nom,'À','A'),'Á','A'),'Â','A'),'Ã','A'),'Ä','A'),'Å','A'),'Ç','C'),'È','E'),'É','E')
	,'Ê','E'),'Ë','E'),'Ì','I'),'Í','I'),'Î','I'),'Ï','I'),'Ò','O'),'Ó','O'),'Ô','O'),'Õ','O')
	,'Ö','O'),'Ù','U'),'Ú','U'),'Û','U'),'Ü','U'),'Ý','Y') ASC, eleves.prenom ASC";
		$listeg_ele = mysqli_query($bdd,$listeg_ele_select);
		$listeg_nb = mysqli_num_rows($listeg_ele);
		if($listeg_nb>0) {
			echo '<p name="noprint"><div style="display:inline;" id="NbEle" name="'.$listeg_nb.'">'.$listeg_nb.'</div> '.ON.' '.$listeg_nb.' '.ELEVS1.'</p><ul id="elev">';
			foreach($listeg_ele as $listeg) {
				echo '<input type="checkbox" class="elc" name="'.$listeg['eleves_id'].'" id="check'.$listeg['eleves_id'].'" onclick="nb()" checked /> <label for="check'.$listeg['eleves_id'].'"> '.$listeg['nom'].' '.$listeg['prenom'].' ('.$listeg['division'].')</label><br>';
			}
			echo '</ul>';
		}
	}
}
?>
