<?php
$i=0;
foreach($briks as $briksup) {
	$seq = mysqli_query($bdd,"SELECT seq_id, seq_nom, SUBSTR(seq_nom,1,20), SUBSTR(seq_nom,1,13), niveau FROM ".$prefix."_sequences WHERE seq_id ='".$briksup['seq_id']."'");
	$seq_info = mysqli_fetch_assoc($seq);
	$seq_nomaff = @mb_ereg_replace("[?]","",mb_convert_encoding($seq_info['SUBSTR(seq_nom,1,13)'],"utf-8"));
	$seq_nomaffopt = @mb_ereg_replace("[?]","",mb_convert_encoding($seq_info['SUBSTR(seq_nom,1,20)'],"utf-8"));
	if($colorsys_info['valeur']=='niv') {
		$colorniv = null;
		if($nivs_info['valeur']=="PER") { 
			foreach ($sorted_caracs as $prefixe => $niveau) {
			    // Si la division commence par ce préfixe, on a trouvé le niveau
			    if (strpos($briksup['division'], $prefixe) === 0) {
			        $colorniv = $niveau;
			        break; // On arrête la boucle une fois le niveau trouvé
			    }
			}
			if($colorniv!==null&&@$colorniv!='r') {
				$color = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$colorniv."'");
				$color_info = mysqli_fetch_assoc($color);
				$bgcolor = $color_info['bgcolor'];
			}
		}
		else {
			$colorniv = substr($briksup['division'],0,1);
			if($colorniv!='6'&&$colorniv!='5'&&$colorniv!='4'&&$colorniv!='3'&&$colorniv!='2'&&$colorniv!='1'&&$colorniv!='t'&&$colorniv!='T') { $colorniv = 'a'; }
			$color = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$colorniv."'");
			$color_info = mysqli_fetch_assoc($color);
			$bgcolor = $color_info['bgcolor'];
		}			
	}
	else if($colorsys_info['valeur']=='cod') {
		if(isset($briksup['code'])) {
			$color = mysqli_query($bdd,"SELECT bgcolor_code FROM ".$prefix."_edtcode WHERE code = '".$briksup['code']."'");
			$color_info = mysqli_fetch_assoc($color);
			$bgcolor = @$color_info['bgcolor_code'];
		}
		else {
			$bgcolor = '#fff';
		}
	}
	
	if($noseq==0) { 
		echo '<td'; 
		if($briksup['activ_brik']==0) { echo ' class="brik_desactiv"'; }
		else if($briksup['activ_brik']==1) { echo ' class="brik_activ"'; }
		echo ' id="td'.$briksup['brik_id'].'">'; include('./db/proc/edt_cartouche.php'); echo ' <a onmousedown="toggleDiv(\'param'.$briksup['brik_id'].'\');"><img style="height:24px;" src="./img/div/param.png" /></a><div class="radio-item-emb"><div class="radio-item activ"><input type="radio" id="chkActiv'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',1);ChgtColor(\'td'.$briksup['brik_id'].'\',1);"'; if($briksup['activ_brik']==1) { echo ' checked'; } echo ' /></div> <div class="radio-item desactiv"><input type="radio" id="chkDesact'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',0);ChgtColor(\'td'.$briksup['brik_id'].'\',0);"'; if($briksup['activ_brik']==0) { echo ' checked'; } echo ' /></div> <div class="radio-item archiv"><input type="radio" id="chkArchiv'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',2);ChgtColor(\'td'.$briksup['brik_id'].'\',2);" /></div></div><div id="param'.$briksup['brik_id'].'" class="parambrik" style="display:none;">';
		include('edt_briques_td_param.php');
		echo '</div></td>'; 
	}
	else if($noseq==1) {
		echo '<td'; 
		if($briksup['activ_brik']==0) { echo ' class="brik_desactiv"'; }
		else if($briksup['activ_brik']==1) { echo ' class="brik_activ"'; }
		echo ' id="td'.$briksup['brik_id'].'">'; include('./db/proc/edt_cartouche.php'); echo ' <a onmousedown="toggleDiv(\'param'.$briksup['brik_id'].'\');"><img style="height:24px;" src="./img/div/param.png" /></a>
		<div class="radio-item-emb">
		<div class="radio-item activ"><input type="radio" id="chkActiv'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',1);ChgtColor(\'td'.$briksup['brik_id'].'\',1);"'; if($briksup['activ_brik']==1) { echo ' checked'; } echo ' /></div> 
		<div class="radio-item desactiv"><input type="radio" id="chkDesact'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',0);ChgtColor(\'td'.$briksup['brik_id'].'\',0);"'; if($briksup['activ_brik']==0) { echo ' checked'; } echo ' /></div> 
		<div class="radio-item archiv"><input type="radio" id="chkArchiv'.$briksup['brik_id'].'" name="chkBrik'.$briksup['brik_id'].'" onclick="StatusBrik('.$briksup['brik_id'].',2);ChgtColor(\'td'.$briksup['brik_id'].'\',2);" /></div></div><div id="param'.$briksup['brik_id'].'" class="parambrik" style="display:none;">';
		include('edt_briques_td_param.php');
		echo '</div></td>';
		$k++;
	}
	$i++;
}
?>