<?php
if(substr($seq_info['niveau'],0,1)== "6") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s6_id,-3) sidsub, sav.s6_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs6 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s6_id LIKE 'EMI%' ORDER BY s6_id ASC";
}
else if(substr($seq_info['niveau'],0,1)=="5") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s5_id,-3) sidsub, sav.s5_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs5 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s5_id LIKE 'EMI%' 
	ORDER BY s5_id ASC";
}
else if(substr($seq_info['niveau'],0,1)=="4") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s4_id,-3) sidsub, sav.s4_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs4 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s4_id LIKE 'EMI%' 
	ORDER BY s4_id ASC";
}
else if(substr($seq_info['niveau'],0,1)=="3") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s3_id,-3) sidsub, sav.s3_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs3 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s3_id LIKE 'EMI%' 
	ORDER BY s3_id ASC";
}
else if(substr($seq_info['niveau'],0,1)=="2") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s2_id,-3) sidsub, sav.s2_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs2 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s2_id LIKE 'EMI%' 
	ORDER BY s2_id ASC";
}
else if(substr($seq_info['niveau'],0,1)=="1") {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.s1_id,-3) sidsub, sav.s1_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirs1 sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE s1_id LIKE 'EMI%' 
	ORDER BY s1_id ASC";
}
else {
	$listeemi_savoirs_select = "SELECT SUBSTR(sav.st_id,-3) sidsub, sav.st_id sid, SUBSTR(sav.nom_savoir,1,45) nom_savsub, sav.nom_savoir, sc.bgcolor bg
	FROM ".$prefix."_savoirst sav
	INNER JOIN ".$prefix."_savchamps sc
	ON sav.champs_id = sc.champs_id 
	WHERE st_id LIKE 'EMI%' 
	ORDER BY st_id ASC";
}
$listeemi_savoirs = mysqli_query($bdd,$listeemi_savoirs_select);
$liste_nb = mysqli_num_rows($listeemi_savoirs);
$seqid_beg = strrpos($seq_info['niveau'],'=')+1;
$seqid_end = strrpos($seq_info['niveau'],',');
$seqid_long = $seqid_end - $seqid_beg;
$seq_id = substr($seq_info['niveau'], strrpos($seq_info['niveau'],'=')+1, $seqid_long);
if($liste_nb>0) {
	echo '<select name="savoirsemi[]" class="inptxt" id="savemis" multiple size="'.($liste_nb+1).'">';
	echo '<option value=\'-1\'></option>';
	while($listeemi = mysqli_fetch_assoc($listeemi_savoirs)) {
		$selected = mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqsav WHERE seq_id = '".$seq_info['seq_id']."' AND s_id = '".$listeemi['sid']."'");
		$selected_nb = mysqli_num_rows($selected);
		echo '<option value="'.$listeemi['sid'].'" style="background-color:'.$listeemi['bg'].';" title="';
		echo ''.$listeemi['nom_savoir'].'"';
		if($selected_nb==1) { echo ' selected '; }
		echo '>'; 
		echo ''.$listeemi['sidsub'].' : ';
		echo mb_ereg_replace("[?]","",mb_convert_encoding($listeemi['nom_savsub'],"utf-8"));
		echo '...';
		echo '</option>';
	}
}
echo "</select>";
?>
