<?php

function checkedSelect( $nom, $structure, $contenu, $selection = null)
{

//////////////// entete du composant \\\\\\\\\\\\\\\\\\\\\\\\\
if(sizeof($selection) == sizeof($contenu))
$checked = "checked";
else
$checked = "";


$str = '<div class="div_select">'
.'<div class="div_select_header">'
.'<table width="100%">'
.'<tr>'
.'<td width="20" align="center"><input type="checkbox" id="'.$nom.'" onClick="javascript:selectAll(this, '.sizeof($contenu).');" '.$checked.'/></td>';

//--- colonnes
for($i = 0, $max = sizeof($structure); $i < $max; $i++) {
$str .= '<td ';
if(isset($structure[$i]["align"])) $str .= 'align="'.$structure[$i]["align"].'" ';
if(isset($structure[$i]["width"])) $str .= 'width="'.$structure[$i]["width"].'" ';
$str .= '>'.$structure[$i]["name"].'</td>';
}

$str .= '<td width="1"></td>'
.'</tr>'
.'</table>'
.'</div>';

//////////////// contenu du composant \\\\\\\\\\\\\\\\\\\\\\\\\
$str .= '<div class="div_select_content" >'
.'<table width="100%">';

//--- pour chaque ligne
for($i = 0, $max = sizeof($contenu); $i < $max; $i++) {

//--- style css (pair / impair)
if($i%2)
$css_defaut = 'select_odd';
else
$css_defaut = 'select_even';

//--- element selectionne ?
if($selection != null && in_array($contenu[$i][0],$selection)) {
$checked = ' checked';
$css = 'select_checked';
}
else {
$checked = '';
$css = $css_defaut;
}

//--- la checkbox
$str .= '<tr id="tr_'.$nom.$i.'" class="'.$css.'" onMouseOver=\'javascript:setEvenement("'.$nom.'","'.$i.'","over","'.$css.'",'.sizeof($contenu).',"td");\' onMouseOut=\'javascript:setEvenement("'.$nom.'","'.$i.'","out","'.$css_defaut.'",'.sizeof($contenu).',"td");\' '
.' onClick=\'javascript:setEvenement("'.$nom.'","'.$i.'","click", "'.$css_defaut.'",'.sizeof($contenu).',"td");\' >'
.'<td width="20" ><input type="checkbox" id="'.$nom.$i.'" name="'.$nom.'[]" value="'.$contenu[$i][0].'" onClick=\'javascript:setEvenement("'.$nom.'","'.$i.'","click","'.$css_defaut.'",'.sizeof($contenu).',"ck");\' '.$checked.' /></td>';

//--- les colonnes
for($j = 1; $j < sizeof($contenu[$i]); $j++) {
$str .= '<td ';
if(isset($structure[$j-1]["align"])) $str .= 'align="'.$structure[$j-1]["align"].'" ';
if(isset($structure[$j-1]["width"])) $str .= 'width="'.$structure[$j-1]["width"].'" ';
$str .= '>'.$contenu[$i][$j].'</td>';
}

$str .= '</tr>';
}

//--- fermeture des balises
$str .= '</table>'
.'</div>'
.'</div>';

return $str;
}

?>