Source for file HTMLSelect.class.php
Documentation is available at HTMLSelect.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
* Including language specific messages.
include( CLASSPATH. "/forms/items/HTMLSelect/". LANG. ".inc.php" );
echo "<h3>You have to define the constant LANG!</h3>\r\n";
echo "Example for german: define( 'LANG', 'de' );\r\n";
require_once( CLASSPATH. "forms/items/ABSTHTMLFormItem.class.php" );
include_once( CLASSPATH. "forms/items/HTMLHiddenInput.class.php" );
include_once( CLASSPATH. "RegExpConstants.inc.php" );
* A class to generate select fields.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* The charset to be used on option-labels
* @var array $style_class_arr
* @var array $freestyle_arr
* @var array $on_change_order
* @var array $show_standard_label
* @var array $standard_label
* @var integer $show_standard_label_on_single_value
* @var boolean $show_despite_zero_label_count
* @var string $text_on_hidden
* This attribute is to prevent errors if the class MultRelationSelect is
* used. If it is set to true the disabling of this item is not possible.
* @var string $text_on_hidden
* Enter description here...
* @author Daniel Plücken <daniel@debakel.net>
* @param array $label_arr
* @param array $value_arr
* @param string $selected_value
* @param string $on_change_order
* @param string $show_standard_label
* @param string $show_standard_label_on_single_value
$show_standard_label = true,
$show_standard_label_on_single_value = true
$this->value = $selected_value;
$show_standard_label_on_single_value
* Sets the charset for the optionlabels of this select.
* @author Daniel Plücken <daniel@debakel.net>
* @see http://www.php.net/manual/en/function.htmlentities.php
* @see http://www.php.net/manual/en/function.html-entity-decode.php
* Sets the javascript that should execute if the value of the select
* @author Daniel Plücken <daniel@debakel.net>
* Sets the labels of this select in order to the given array.
* @author Daniel Plücken <daniel@debakel.net>
* @param array $stringArray
* Sets the values of this select in order to the given array.
* @author Daniel Plücken <daniel@debakel.net>
* Sets the style classes of the options of this select in order to the
* @author Daniel Plücken <daniel@debakel.net>
* Sets the style attributes of the options of this select in order to the
* @author Daniel Plücken <daniel@debakel.net>
* Adds an option to this this select.
* @author Daniel Plücken <daniel@debakel.net>
* Adds an option to this this select at a specified position.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $position Has to be greater then zero!
if ( intval( $position ) > 0 )
* Set the text that should appear if the select is hidden, cause of zero
* @author Daniel Plücken <daniel@debakel.net>
* Sets the size-attribute of this select.
* @author Daniel Plücken <daniel@debakel.net>
echo "<b>". $int. " is not a valid value for a select!</b>\r\n\r\n";
* Sets this select to be able in selecting multiple values.
* @author Daniel Plücken <daniel@debakel.net>
* Sets the label of this select that schould be shown if no value is
* @author Daniel Plücken <daniel@debakel.net>
* Sets whether the standardlabel of this select schould be shown if no
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $boolean
* @param boolean $show_standard_label_on_single_value
$show_standard_label_on_single_value = true
if ( is_bool( $show_standard_label_on_single_value ) )
$show_standard_label_on_single_value;
* Sets whether the select schould be shown if no value is presented on it.
* @param boolean $boolean
* If the single value template is set, then the method get() will only
* output the parsed template instead of the selectbox. You can use the
* template variable [#label#] to place the single label in the template
* Returns a clone of this object.
* @author Daniel Plücken <daniel@debakel.net>
* @param mixed $selectedValue
* @param string $on_change_order
$newName = !empty( $newName )
if( $selectedValue !== false )
$newInstance->setSelectedValue( $selectedValue );
if( $on_change_order !== false )
$newInstance->setChangeOrder( $on_change_order );
* Returns the array containing the labels of this select.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the array containing the valuess of this select.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the selected label of this select.
* Returns the selected value of this select.
* Returns the javascript that should execute if the value this select
* @author Daniel Plücken <daniel@debakel.net>
* Returns the standard label of this select.
* @author Daniel Plücken <daniel@debakel.net>
* Returns an if-order of a javascript to check whether this item is NOT
* @author Daniel Plücken <daniel@debakel.net>
$outputString = "document.". $this->parentform->name. "."
. $this->name. ".value == \"\"";
* Generates the sourcecode to build this object and returns it.
* @author Daniel Plücken <daniel@debakel.net>
$out .= "unset( \x24label_arr );\r\n";
$out .= "unset( \x24value_arr );\r\n";
$out .= "\x24label_arr = array(\r\n";
for( $i = 0; $i < $cntLab ; $i++ )
$comma = $cntLab - 1 != $i
$out .= "\x24value_arr = array(\r\n";
for( $i = 0; $i < $cntVal ; $i++ )
$comma = $cntVal - 1 != $i
$out .= "unset( \x24value );\r\n";
$out .= "\x24value = \x24_POST[\"". $this->getName(). "\"]\r\n"
. " .\x24_GET[\"". $this->getName(). "\"];\r\n";
$out .= "\x24input[] = new HTMLSelect(\r\n"
? "if( \x24value === \"\" )\r\n"
. " \x24input[count(\x24input)-1]"
. "->setSelectedValue( \"". $tmp. "\" );\r\n\r\n"
* Returns an javascript-function to get the value of a given select.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
$out = " window.getSelectedValueOf = function( which )\r\n"
. " try { cnt = which.options.length; } catch (e) { cnt = 0; }\r\n"
. " for( i = 0; i < cnt; ++i )\r\n"
. " if( which.options[i].selected == true )\r\n"
. " return which.options[i].value;\r\n\r\n"
if( $withJSdeclaration === true )
* Returns an javascript-function to get the selectedoption-object of a given
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
$out = " window.getSelectedOptionOf = function( which )\r\n"
. " try { cnt = which.options.length; } catch (e) { cnt = 0; }\r\n"
. " for( i = 0; i < cnt; ++i )\r\n"
. " if( which.options[i].selected == true )\r\n"
. " return which.options[i];\r\n\r\n"
if( $withJSdeclaration === true )
* Returns an javascript-function to get all values from a given select as
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
window.getAllValuesFrom = function( which )
try { cnt = which.options.length; } catch (e) { cnt = 0; }
for ( var i = 0; i < cnt; i++ )
arr[ arr.length ] = which.options[i].value;
if( $withJSdeclaration === true )
* Returns an javascript-function to get the value of a given select.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
$out = " window.selectValueOf = function( which, val )\r\n"
. " try { cnt = which.length; } catch (e) { cnt = 0; }\r\n"
. " for( i = 0; i < cnt; ++i )\r\n"
. " if( which.options[i].value == val )\r\n"
. " which.options[i].selected = true;\r\n\r\n"
if( $withJSdeclaration === true )
* Returns an javascript-function to move the selected items of a select to
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $withJSdeclaration
window.moveItemTo = function( fromWhich, toWhich )
// Acquire the selected indices of the "from"-item.
for ( var i = 0; i < fromWhich.length; i++ )
if ( fromWhich.options[i].selected == true )
cIA[k] = fromWhich.options[i].cloneNode(true);
|| toWhich.options[toWhich.length-1].text
// Append if the "to"-item is empty or the last
// entry of it is in lower order than the "from"-item
toWhich.appendChild( cIA[k] );
// Insert into correct order.
for ( j = 0; j < toWhich.length; j++ )
if ( toWhich.options[j].text > cIA[k].text )
toWhich.insertBefore( cIA[k], toWhich.options[j] );
sIA[k++] = fromWhich.options[i];
for ( i = 0; i < sIA.length; i++ )
fromWhich.removeChild( sIA[i] );
if( $withJSdeclaration === true )
* Returns a generated string based on the attributes of this object.
* @author Daniel Plücken <daniel@debakel.net>
# Alternative text on zero value/label.
# Template text on single value/label.
$out .= $tmp_h_inp->get();
// this is neccessary for the class
// && !$this->multiple /* PERHAPS -> to proof */
. " id=\"". $this->id. "\"\r\n";
$out .= " onMouseover=\"". $this->mouseover. "\"\r\n";
$out .= " onMouseout=\"". $this->mouseout. "\"\r\n";
$out .= " onMouseup=\"". $this->mouseup. "\"\r\n";
$out .= " style=\"". $this->freestyle. "\"\r\n";
$out .= " size=\"". $this->size. "\"\r\n";
$out .= " multiple=\"multiple\"\r\n";
// this is neccessary for the class MultiRelationSelect
// && !$this->multiple /* PERHAPS -> to proof */
$out .= " disabled=\"disabled\"\r\n";
. "<option value=\"". $this->value_arr[0]. "\">"
$this->label_arr[0], // <- There is the variable ;)
$out .= "<!--\r\n --><option value=\"\">"
$out .= "<!--\r\n --><option value=\"". $value. "\"";
$out .= !empty( $style_class )
? " class=\"". $style_class. "\""
$out .= !empty( $freestyle )
? " style=\"". $freestyle. "\""
$out .= $value == $this->value
? " selected=\"selected\""
$label, // <- There is the variable ;)
$out .= "<!--\r\n--></select>";
$out .= $tmp_h_inp->get();
// this is neccessary for the class MultiRelationSelect
// && !$this->multiple /* PERHAPS -> to proof */
$out .= $tmp_h_inp->get();
} // END of class HTMLSelect
|