⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hierselect.php

📁 Piwik#Opensourcewebanalytics一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大.无色提示:按照需要PHP5.1以上和MySQL数据库支持。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: *//** * Hierarchical select element *  * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.01 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_01.txt If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category    HTML * @package     HTML_QuickForm * @author      Herim Vasquez <vasquezh@iro.umontreal.ca> * @author      Bertrand Mansion <bmansion@mamasam.com> * @author      Alexey Borzov <avb@php.net> * @copyright   2001-2007 The PHP Group * @license     http://www.php.net/license/3_01.txt PHP License 3.01 * @version     CVS: $Id: hierselect.php 444 2008-04-11 13:38:22Z johmathe $ * @link        http://pear.php.net/package/HTML_QuickForm *//** * Class for a group of form elements */require_once 'HTML/QuickForm/group.php';/** * Class for <select></select> elements */require_once 'HTML/QuickForm/select.php';/** * Hierarchical select element *  * Class to dynamically create two or more HTML Select elements * The first select changes the content of the second select and so on. * This element is considered as a group. Selects will be named * groupName[0], groupName[1], groupName[2]... * * @category    HTML * @package     HTML_QuickForm * @author      Herim Vasquez <vasquezh@iro.umontreal.ca> * @author      Bertrand Mansion <bmansion@mamasam.com> * @author      Alexey Borzov <avb@php.net> * @version     Release: 3.2.9 * @since       3.1 */class HTML_QuickForm_hierselect extends HTML_QuickForm_group{       // {{{ properties    /**     * Options for all the select elements     *     * @see       setOptions()     * @var       array     * @access    private     */    var $_options = array();        /**     * Number of select elements on this group     *     * @var       int     * @access    private     */    var $_nbElements = 0;    /**     * The javascript used to set and change the options     *     * @var       string     * @access    private     */    var $_js = '';    // }}}    // {{{ constructor    /**     * Class constructor     *      * @param     string    $elementName    (optional)Input field name attribute     * @param     string    $elementLabel   (optional)Input field label in form     * @param     mixed     $attributes     (optional)Either a typical HTML attribute string      *                                      or an associative array. Date format is passed along the attributes.     * @param     mixed     $separator      (optional)Use a string for one separator,     *                                      use an array to alternate the separators.     * @access    public     * @return    void     */    function HTML_QuickForm_hierselect($elementName=null, $elementLabel=null, $attributes=null, $separator=null)    {        $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);        $this->_persistantFreeze = true;        if (isset($separator)) {            $this->_separator = $separator;        }        $this->_type = 'hierselect';        $this->_appendName = true;    } //end constructor    // }}}    // {{{ setOptions()    /**     * Initialize the array structure containing the options for each select element.     * Call the functions that actually do the magic.     *     * Format is a bit more complex than for a simple select as we need to know      * which options are related to the ones in the previous select:     *     * Ex:     * <code>     * // first select     * $select1[0] = 'Pop';     * $select1[1] = 'Classical';     * $select1[2] = 'Funeral doom';     *     * // second select     * $select2[0][0] = 'Red Hot Chil Peppers';     * $select2[0][1] = 'The Pixies';     * $select2[1][0] = 'Wagner';     * $select2[1][1] = 'Strauss';     * $select2[2][0] = 'Pantheist';     * $select2[2][1] = 'Skepticism';     *     * // If only need two selects      * //     - and using the deprecated functions     * $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');     * $sel->setMainOptions($select1);     * $sel->setSecOptions($select2);     *     * //     - and using the new setOptions function     * $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');     * $sel->setOptions(array($select1, $select2));     *     * // If you have a third select with prices for the cds     * $select3[0][0][0] = '15.00$';     * $select3[0][0][1] = '17.00$';     * // etc     *     * // You can now use     * $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');     * $sel->setOptions(array($select1, $select2, $select3));     * </code>     *      * @param     array    $options    Array of options defining each element     * @access    public     * @return    void     */    function setOptions($options)    {        $this->_options = $options;        if (empty($this->_elements)) {            $this->_nbElements = count($this->_options);            $this->_createElements();        } else {            // setDefaults has probably been called before this function            // check if all elements have been created            $totalNbElements = count($this->_options);            for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {                $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());                $this->_nbElements++;            }        }                $this->_setOptions();    } // end func setMainOptions    // }}}    // {{{ setMainOptions()        /**     * Sets the options for the first select element. Deprecated. setOptions() should be used.     *     * @param     array     $array    Options for the first select element     *     * @access    public     * @deprecated          Deprecated since release 3.2.2     * @return    void     */    function setMainOptions($array)    {        $this->_options[0] = $array;        if (empty($this->_elements)) {            $this->_nbElements = 2;            $this->_createElements();        }    } // end func setMainOptions        // }}}    // {{{ setSecOptions()        /**     * Sets the options for the second select element. Deprecated. setOptions() should be used.     * The main _options array is initialized and the _setOptions function is called.     *     * @param     array     $array    Options for the second select element     *     * @access    public     * @deprecated          Deprecated since release 3.2.2     * @return    void     */    function setSecOptions($array)    {        $this->_options[1] = $array;        if (empty($this->_elements)) {            $this->_nbElements = 2;            $this->_createElements();        } else {            // setDefaults has probably been called before this function            // check if all elements have been created            $totalNbElements = 2;            for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) {                $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());                $this->_nbElements++;            }        }                $this->_setOptions();    } // end func setSecOptions        // }}}    // {{{ _setOptions()        /**     * Sets the options for each select element     *     * @access    private     * @return    void     */    function _setOptions()    {        $toLoad = '';        foreach (array_keys($this->_elements) AS $key) {            $array = eval("return isset(\$this->_options[{$key}]{$toLoad})? \$this->_options[{$key}]{$toLoad}: null;");            if (is_array($array)) {                $select =& $this->_elements[$key];                $select->_options = array();                $select->loadArray($array);                $value  = is_array($v = $select->getValue()) ? $v[0] : key($array);                $toLoad .= '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $value) . '\']';            }        }    } // end func _setOptions        // }}}    // {{{ setValue()    /**     * Sets values for group's elements     *      * @param     array     $value    An array of 2 or more values, for the first,     *                                the second, the third etc. select     *     * @access    public     * @return    void     */    function setValue($value)    {        // fix for bug #6766. Hope this doesn't break anything more         // after bug #7961. Forgot that _nbElements was used in        // _createElements() called in several places...         $this->_nbElements = max($this->_nbElements, count($value));        parent::setValue($value);        $this->_setOptions();    } // end func setValue        // }}}    // {{{ _createElements()    /**     * Creates all the elements for the group     *      * @access    private     * @return    void     */    function _createElements()    {        for ($i = 0; $i < $this->_nbElements; $i++) {            $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes());        }    } // end func _createElements    // }}}    // {{{ toHtml()    function toHtml()    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -