<?php
$list = trim($_POST['pronliste']);
$listAr = explode("\n", $list);
$listAr = array_filter($listAr, 'trim');
echo '<table>';
foreach ($listAr as $line) {
	$snom = mysqli_real_escape_string($bdd,substr($line, 1, strpos($line," ")-1));
	$guill2_pos = strpos($line, '"', 1); // on définit la position des 2e guillemets
	$esp_pos = strrpos($line, ' ', -(strlen($line)-$guill2_pos)); // on définit l'espace avant le prénom
	$sprenom = mysqli_real_escape_string($bdd,substr($line, ($esp_pos+1), (($guill2_pos-$esp_pos)-1)));
	$debdiv = substr($line,($guill2_pos+2),1);
	$eleveq = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves WHERE nom LIKE '%".$snom."%' AND prenom LIKE '%".$sprenom."%' "); 
	echo '<tr><td class="td_limit">'.$line.'</td><td>&rarr;</td>';
	if(mysqli_num_rows($eleveq)==0||substr($snom,0,1)=='') { echo '<td>'.UNKNOWN.'</td>'; }
	else if(mysqli_num_rows($eleveq)>1) {
		echo '<td style="background-color:red;">';
		foreach($eleveq as $elevei) {
			echo '<input type="checkbox" id="pro'.$elevei['eleves_id'].'" name="'.$elevei['eleves_id'].'" /><label for="pro'.$elevei['eleves_id'].'"> '.$elevei['nom'].', '.$elevei['prenom'].' ('.$elevei['division'].')</label><br>';
		}
		echo '</td>';
	}
	else {
		$elevei = mysqli_fetch_assoc($eleveq);
		echo '<td><input type="checkbox" id="pro'.$elevei['eleves_id'].'" name="'.$elevei['eleves_id'].'" checked /><label for="pro'.$elevei['eleves_id'].'"> '.$elevei['nom'].', '.$elevei['prenom'].' ('.$elevei['division'].')</label></td>';
	}
	echo '</tr><input type="hidden" name="proncheck" value="1" />';
}
echo '</table>';
?>