Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/divers/listcheckbox.php
<?php

/**
 * permet de créer le pseudo-composant
 * @param :
 * - nom : le nom du composant
 * - structure : les colonnes, les dimensions, les alignements (tableau)
 * - contenu : les elements : valeur checkbox + autres colonnes (tableau)
 * - selection : tableau de valeur a selectionner (correspond a la valeur de la checkbox)
 * - extra : permet de rajouter un champ, pour differiencier les selects
 */

function checkedSelect( $nom, $structure, $contenu, $disable=False,$extra) {
	
	//////////////// entete du composant \\\\\\\\\\\\\\\\\\\\\\\\\
	$checked = "";
	
	$str = '<div class="div_select'.$extra.'">'
		.'<div class="div_select_header">'
		.'<table height="10px" width="100%" border="2">'
		.'<tr>'
		.'<td style="width: 2px;" align="left"><input type="checkbox" id="'.$nom.'" onClick="javascript:selectAllLC(this);" '.$checked.'/></td>';
	
	//--- colonnes
	for($i = 0, $max = sizeof($structure); $i < $max; $i++) {
		$str .= '<td id="td'.$i.'"';
		//echo $structure[$i]["name"]." STRUCT  ".$structure[$i]["width"];
		if(isset($structure[$i]["align"])) $str .= 'align="'.$structure[$i]["align"].'" ';
        $wd=$structure[$i]["width"];
		if(isset($structure[$i]["width"])) $str .= ' width="'.$wd.'" ';
		$str .= '><input class="main_input" disabled="disabled" style="width: 100%;" value='.$structure[$i]["name"].'></td>';
	}
	
	$str .= '<td width="4"></td>'
		.'</tr>'
		.'</table>'
		.'</div>';
	
	//////////////// contenu du composant \\\\\\\\\\\\\\\\\\\\\\\\\
	$str .= '<div class="div_select_content'.$extra.'" >'
		.'<table id="main_table_'.$nom.'" width="100%" border="2">';
	
	//--- 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(isset($selection) && $selection != null && in_array($contenu[$i][0],$selection)) {
			$checked = ' checked';
			$css = 'select_checked';
		}
		else {
			$checked = '';
			$css = $css_defaut;
		}
		//--- la checkbox
		$str .= '<tbody id="tr_div_'.$nom.$i.'"><tr id="tr_'.$nom.$i.'" class="'.$css.'" onMouseOver=\'javascript:setEvenement("'.$nom.'","'.$i.'","over","'.$css.'","td");\' onMouseOut=\'javascript:setEvenement("'.$nom.'","'.$i.'","out","'.$css_defaut.'","td");\' '
			.' onClick=\'javascript:setEvenement("'.$nom.'","'.$i.'","click", "'.$css_defaut.'","td");\' >'
			.'<td style="width: 2px;\" ><input type="checkbox" id="'.$nom.$i.'" name="Check'.$nom.'[]" value="'.$contenu[$i][0].'" onClick=\'javascript:setEvenement("'.$nom.'","'.$i.'","click","'.$css_defaut.'","ck");\' '.$checked.' /></td>';
		//--- les colonnes
		for($j = 0; $j < sizeof($contenu[$i]); $j++) {
			//	echo $structure[$j-1]["align"];
			$str .= '<td ';
			if(isset($structure[$j]["align"])) $str .= 'align="'.$structure[$j]["align"].'" ';
			if(isset($structure[$j]["width"])) $str .= 'width="'.$structure[$j]["width"].'" ';
          if ($disable)
			$str .= '><input disabled="disabled" name="'.$structure[$j]["name_input"].'[]" style="width: 100%;" id="'.$structure[$j]["name"].$i.'" value="'.$contenu[$i][$j].'"></td>';

			else
			$str .= '><input  name="'.$structure[$j]["name_input"].'[]" style="width: 100%;" id="'.$structure[$j]["name"].$i.'" value="'.stripslashes($contenu[$i][$j]).'"></td>';
		}
		$str .= '</tr></tbody>';
	}
	//--- fermeture des balises
	$str .= '</table>'
		.'</div>'
		.'</div>';
	
	return $str;
}


?>
Return current item: phpMyPrepaid