Location: PHPKode > scripts > PSPLMultiselect > psplmultiselect/pspl_multiselect.class.php
<?


class PSPLMultiselect{
  
  var $arrowOnPath;                //path of arrow hover image
  var $arrowOffPath;               //path of normal arrow image
  var $arrowClassName;             //css class for arrow image
  var $textBoxClassName;           // css class for textbox
  var $optionDivClassName;         //css class for options container
  var $cellClassName;              //css class for each cell of the list
  var $cellHoverClassName;         //css class for cells for hover effect
  var $cellSelectedClassName;      //css class for cells when that cell is selected
  var $classSelectBox;             //css class for the container SPAN
  
  
  function PSPLMultiSelect( $imgArrowOn, $imgArrowOff, $classArrow, $classTxtBox, $classOptionDiv, $classCell, $classCellHover, $classCellSelected, $classSelBox ){
    //initialize all variables
	$this->arrowOnPath = $imgArrowOn;
	$this->arrowOffPath = $imgArrowOff;
	$this->arrowClassName = $classArrow;
	$this->textBoxClassName = $classTxtBox;
	$this->optionDivClassName = $classOptionDiv;
	$this->cellClassName = $classCell;
	$this->cellHoverClassName = $classCellHover;
	$this->cellSelectedClassName = $classCellSelected; 
	$this->classSelectBox = $classSelBox;	
  }
  
  //this function Generates the html and javascript required for displaying pspl multi select boxes
  //
  // $controlId is the the name of the box and also the its 'id'
  // $options is the array of options for the select box in following formats
  // first format :
  // ---------------------------
  //  $options = array( 'optionValue1' => 'optionText1',
  //			 'optionValue2' => 'optionText2',
  //			 'optionValue3' => 'optionText3',
  //			 'optionValue4' => 'optionText4' );
  //  $selectedValues is array of selected elements
  //  $selectedValues = array( 'optionValue1', 'optionValue3' );
  //   
  //  actual function call for this format will be like
  //  GenerateMultiSelect( $controlID, $options, $selectedValues, "YES"  ){
  //
  // second format :
  // ----------------------------
  //  $options = array( 'optionText1', 'optionText2', 'optionText3', 'optionText4' );
  //  $selectedValues = array( 'optionText1', 'optionText3' );
  //
  //  actual functioncall for this format will be like
  //  GenerateMultiSelect( $controlID, $options, $selectedValues, "YES"  ){
  //
  //
  // this function returns the resulting html code
  // useful for scripts which generate whole page code, then echo it.
  function GenerateMultiSelect( $controlID, $options, $selectedValues, $optionValuesPresent ){
    
	$tmpHtml = '
<span id="'.$controlID.'_box" class="'.$this->classSelectBox.'" >
<select id="'.$controlID.'" name="'.$controlID.'[]" multiple size="3" class="msel">';
	
	foreach( $options As $optionValue => $optionText ){
	  if( $optionValuesPresent == 'NO' ){
		$tmpHtml .= '<option'.( in_array($optionText, $selectedValues)?" selected": '' ).'>'.$optionText.'</option>';
      }else{
	    $tmpHtml .= '<option value="'.$optionValue.'"'.( in_array($optionValue, $selectedValues)?" selected": '' ).'>'.$optionText.'</option>';
	  }
	}
	$tmpHtml .= '
</select>
</span>
<script language="javascript">';
$tmpHtml .= '
Init( "'.$controlID.'", "'.$this->arrowOnPath.'", "'.$this->arrowOffPath.'","'.$this->arrowClassName.'", "'.$this->textBoxClassName.'", "'.$this->optionDivClassName.'", "'.$this->cellClassName.'", "'.$this->cellHoverClassName.'", "'.$this->cellSelectedClassName.'" );
</script>';

	return $tmpHtml;

  }
  
  //print the boxcode to screen
  // this function takes same parameters as GenerateMultiSelect()
  // only difference is this one dont return anything, just echos the code 
  function PrintMultiSelect( $controlID, $options, $selectedValues, $optionValuesPresent ){
	echo $this->GenerateMultiSelect( $controlID, $options, $selectedValues, $optionValuesPresent );
  }
  
}



?>
Return current item: PSPLMultiselect