Пример #1
0
	function toHtml() {
		if(count($this->_cd)>1) {
			load_js('modules/Utils/CommonData/qf.js');
			$id=$this->getAttribute('id');
			if(!isset($id)) {
				$id = $this->getName();
				$this->updateAttributes(array('id'=>$id));
			}
			$val = $this->getValue();
			$val = $val[0];
			if($this->_flagFrozen) {
				eval_js('new Utils_CommonData_freeze(\''.Epesi::escapeJS($id,false).'\', \''.Epesi::escapeJS(json_encode($this->_cd),false).'\')');
				$html = '<span id="'.$id.'_label">&nbsp;</span>';
				$name = $this->getPrivateName();
				// Only use id attribute if doing single hidden input
				$html .= '<input' . $this->_getAttrString(array(
					     'type'  => 'hidden',
					     'name'  => $name,
					     'value' => $val,
					     'id'    => $id
					 )) . ' />';
				return $html;
			}
			eval_js('new Utils_CommonData(\''.Epesi::escapeJS($id,false).'\', \''.Epesi::escapeJS($val,false).'\', \''.Epesi::escapeJS(json_encode($this->_cd),false).'\', '.($this->_add_empty_fields?1:0).')');
		}
	        return parent::toHtml();
	}
Пример #2
0
 function getValue()
 {
     $val = parent::getValue();
     if (is_array($val)) {
         return $val[0];
     }
     return $val;
 }
Пример #3
0
 function toHtml()
 {
     if ($this->_hiddenLabel) {
         $this->_generateId();
         return '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
     } else {
         return parent::toHtml();
     }
 }
Пример #4
0
 /**
  * Class constructor
  *
  * @param     string    Select name attribute
  * @param     mixed     Label(s) for the select (not used)
  * @param     mixed     Data to be used to populate options
  * @param     mixed     Either a typical HTML attribute string or an associative array (not used)
  * @since     1.0
  * @access    public
  * @return    void
  */
 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, $attributes);
     $this->_persistantFreeze = true;
     $this->_type = 'hiddenselect';
     if (isset($options)) {
         $this->load($options);
     }
 }
Пример #5
0
 /**
  * Class constructor
  */
 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $themes = api_get_themes();
     $this->_options = array();
     $this->_values = array();
     $this->addOption('--', '');
     // no theme select
     for ($i = 0; $i < count($themes[0]); $i++) {
         $this->addOption($themes[1][$i], $themes[0][$i]);
     }
 }
 /**
  * This test was created to test the change to preg_split() in setValues() due
  * to the PHP 5.3 deprecation of the split() function.
  * http://bugs.weblite.ca/view.php?id=809
  */
 function testPregSplit()
 {
     $select = new HTML_QuickForm_select('test', 'Test', array('a1' => 'Tom', 'b2' => 'Dick', 'c3' => 'Harry'));
     $select->setMultiple(true);
     $select->setSelected('a1');
     $this->assertEquals(array(0 => 'a1'), $select->getSelected(), 'setSelected failed to select value.');
     $select->setSelected('a1, c3');
     $this->assertEquals(array(0 => 'a1', 1 => 'c3'), $select->getSelected(), 'setSelectedFailed to select double value.');
 }
Пример #7
0
 /**
  * Class constructor
  */
 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $languages = api_get_languages();
     $this->_options = array();
     $this->_values = array();
     foreach ($languages as $iso => $name) {
         if ($iso == api_get_setting('language.platform_language')) {
             $this->addOption($name, $iso, array('selected' => 'selected'));
         } else {
             $this->addOption($name, $iso);
         }
     }
 }
Пример #8
0
 /**
  * Returns HTML for select form element.
  *
  * @return string
  */
 function toHtml(){
     $html = '';
     if ($this->getMultiple()) {
         // Adding an hidden field forces the browser to send an empty data even though the user did not
         // select any element. This value will be cleaned up in self::exportValue() as it will not be part
         // of the select options.
         $html .= '<input type="hidden" name="'.$this->getName().'" value="_qf__force_multiselect_submission">';
     }
     if ($this->_hiddenLabel){
         $this->_generateId();
         $html .= '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.$this->getLabel().'</label>';
     }
     $html .= parent::toHtml();
     return $html;
 }
Пример #9
0
 /**
  * Class constructor
  */
 function SelectLanguage($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $languages = api_get_languages();
     $this->_options = array();
     $this->_values = array();
     foreach ($languages['name'] as $index => $name) {
         if ($languages['folder'][$index] == api_get_setting('platformLanguage')) {
             $this->addOption($name, $languages['folder'][$index], array('selected' => 'selected'));
         } else {
             $this->addOption($name, $languages['folder'][$index]);
         }
     }
 }
Пример #10
0
 /**
  * Class constructor
  */
 function HTML_QuickForm_Select_Theme($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     if (!isset($attributes['class'])) {
         //todo this was comment due a bug in infocours.php with jquery-ui
         //$attributes['class'] = 'chzn-select';
     }
     parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $themes = api_get_themes();
     $this->_options = array();
     $this->_values = array();
     $this->addOption('--', '');
     // no theme select
     for ($i = 0; $i < count($themes[0]); $i++) {
         $this->addOption($themes[1][$i], $themes[0][$i]);
     }
 }
Пример #11
0
 /**
  * Class constructor
  */
 function HTML_QuickForm_Select_Language($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     if (!isset($attributes['class'])) {
         $attributes['class'] = 'chzn-select';
     }
     parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $languages = api_get_languages();
     $this->_options = array();
     $this->_values = array();
     foreach ($languages['name'] as $index => $name) {
         if ($languages['folder'][$index] == api_get_setting('platformLanguage')) {
             $this->addOption($name, $languages['folder'][$index], array('selected' => 'selected'));
         } else {
             $this->addOption($name, $languages['folder'][$index]);
         }
     }
 }
Пример #12
0
 /**
  * Class constructor
  */
 function HTML_QuickForm_Select_Language($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     if (!isset($attributes['class'])) {
         $attributes['class'] = 'chzn-select';
     }
     parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
     // Get all languages
     $languages = api_get_languages();
     $this->_options = array();
     $this->_values = array();
     $platformLanguage = Container::getTranslator()->getLocale();
     foreach ($languages as $language) {
         if ($language['isocode'] == $platformLanguage) {
             $this->addOption($language['english_name'], $language['isocode'], array('selected' => 'selected'));
         } else {
             $this->addOption($language['english_name'], $language['isocode']);
         }
     }
 }
Пример #13
0
 function toHtml()
 {
     $retval = '';
     if ($this->_hiddenLabel) {
         $this->_generateId();
         $retval = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
     } else {
         $retval = parent::toHtml();
     }
     if (!empty($this->_link)) {
         if (!empty($this->_linkreturn) && is_array($this->_linkreturn)) {
             $appendchar = '?';
             if (strstr($this->_link, '?')) {
                 $appendchar = '&amp;';
             }
             foreach ($this->_linkreturn as $key => $val) {
                 $this->_link .= $appendchar . "{$key}={$val}";
                 $appendchar = '&amp;';
             }
         }
         $retval .= '<a style="margin-left: 5px" href="' . $this->_link . '">' . $this->_linklabel . '</a>';
     }
     return $retval;
 }
/** listefiche() - Ajoute un element de type liste deroulante correspondant a un autre type de fiche au formulaire
*
* @param    mixed   L'objet QuickForm du formulaire
* @param    mixed   Le tableau des valeurs des differentes option pour l'element liste
* @param    string  Type d'action pour le formulaire : saisie, modification, vue,... saisie par defaut
* @return   void
*/
function listefiche(&$formtemplate, $tableau_template, $mode, $valeurs_fiche)
{
    if ($mode == 'saisie') {
        $bulledaide = '';
        if (isset($tableau_template[10]) && $tableau_template[10] != '') {
            $bulledaide = ' <img class="tooltip_aide" title="' . htmlentities($tableau_template[10]) . '" src="tools/bazar/presentation/images/aide.png" width="16" height="16" alt="image aide" />';
        }
        $val_type = baz_valeurs_formulaire($tableau_template[1]);
        $tab_result = baz_requete_recherche_fiches('', 'alphabetique', $tableau_template[1], $val_type["bn_type_fiche"]);
        $select[0] = BAZ_CHOISIR;
        foreach ($tab_result as $fiche) {
            $valeurs_fiche = json_decode($fiche[0], true);
            $valeurs_fiche = array_map('utf8_decode', $valeurs_fiche);
            $select[$valeurs_fiche['id_fiche']] = $valeurs_fiche['bf_titre'];
        }
        $option = array('id' => $tableau_template[0] . $tableau_template[1] . $tableau_template[6]);
        if (isset($valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != '') {
            $def = $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]];
        } else {
            $def = $tableau_template[5];
        }
        require_once 'HTML/QuickForm/select.php';
        $select = new HTML_QuickForm_select($tableau_template[0] . $tableau_template[1] . $tableau_template[6], $tableau_template[2] . $bulledaide, $select, $option);
        if ($tableau_template[4] != '') {
            $select->setSize($tableau_template[4]);
        }
        $select->setMultiple(0);
        $select->setValue($def);
        $formtemplate->addElement($select);
        if (isset($tableau_template[8]) && $tableau_template[8] == 1 && $resultat->numRows() > 0) {
            $formtemplate->addRule($tableau_template[0] . $tableau_template[1] . $tableau_template[6], $tableau_template[2] . ' obligatoire', 'required', '', 'client');
        }
    } elseif ($mode == 'requete') {
        if (isset($valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != 0) {
            return array($tableau_template[0] . $tableau_template[1] . $tableau_template[6] => $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]);
        }
    } elseif ($mode == 'formulaire_recherche') {
        if ($tableau_template[9] == 1) {
            $tab_result = baz_requete_recherche_fiches('', $tri = 'alphabetique', $tableau_template[1], '');
            $select[0] = BAZ_INDIFFERENT;
            foreach ($tab_result as $fiche) {
                $valeurs_fiche = json_decode($fiche[0], true);
                $valeurs_fiche = array_map('utf8_decode', $valeurs_fiche);
                $select[$valeurs_fiche['id_fiche']] = $valeurs_fiche['bf_titre'];
            }
            $option = array('id' => $tableau_template[0] . $tableau_template[1] . $tableau_template[6]);
            require_once 'HTML/QuickForm/select.php';
            $select = new HTML_QuickForm_select($tableau_template[0] . $tableau_template[1] . $tableau_template[6], $tableau_template[2], $select, $option);
            if ($tableau_template[4] != '') {
                $select->setSize($tableau_template[4]);
            }
            $select->setMultiple(0);
            $formtemplate->addElement($select);
        }
    } elseif ($mode == 'html') {
        $html = '';
        if (isset($valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != '') {
            if ($tableau_template[3] == 'fiche') {
                $html = baz_voir_fiche(0, $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]);
            } else {
                $html = '<div class="BAZ_rubrique  BAZ_rubrique_' . $GLOBALS['_BAZAR_']['class'] . '">' . "\n" . '<span class="BAZ_label ' . $tableau_template[2] . '_rubrique">' . $tableau_template[2] . '&nbsp;:</span>' . "\n";
                $html .= '<span class="BAZ_texte BAZ_texte_' . $GLOBALS['_BAZAR_']['class'] . ' ' . $tableau_template[2] . '_description">';
                $url_voirfiche = clone $GLOBALS['_BAZAR_']['url'];
                $url_voirfiche->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_CONSULTER);
                $url_voirfiche->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE);
                $url_voirfiche->addQueryString('wiki', $_GET['wiki'] . '/iframe');
                $url_voirfiche->addQueryString('id_fiche', $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]);
                $html .= '<a href="' . str_replace('&', '&amp;', $url_voirfiche->getUrl()) . '" class="voir_fiche ouvrir_overlay" title="Voir la fiche ' . $res[0] . '" rel="#overlay">' . $res[0] . '</a></span>' . "\n" . '</div>' . "\n";
            }
        }
        return $html;
    }
}
/** liste() - Ajoute un élément de type liste déroulante au formulaire
 *
 * @param    mixed   L'objet QuickForm du formulaire
 * @param    mixed   Le tableau des valeurs des différentes option pour l'élément liste
 * @param    string  Type d'action pour le formulaire : saisie, modification, vue,... saisie par défaut
 * @return   void
 */
function liste(&$formtemplate, $tableau_template, $mode, $valeurs_fiche)
{
    if ($mode == 'saisie') {
        $valliste = baz_valeurs_liste($tableau_template[1]);
        if ($valliste) {
            $bulledaide = '';
            if (isset($tableau_template[10]) && $tableau_template[10] != '') {
                $bulledaide = ' &nbsp;&nbsp;<img class="tooltip_aide" title="' . htmlentities($tableau_template[10], ENT_QUOTES, TEMPLATES_DEFAULT_CHARSET) . '" src="tools/bazar/presentation/images/aide.png" width="16" height="16" alt="image aide" />';
            }
            $select_html = '<div class="control-group form-group">' . "\n" . '<label class="control-label col-sm-3">' . "\n";
            if (isset($tableau_template[8]) && $tableau_template[8] == 1) {
                $select_html .= '<span class="symbole_obligatoire">*&nbsp;</span>' . "\n";
            }
            $select_html .= $tableau_template[2] . $bulledaide . ' : </label>' . "\n" . '<div class="controls col-sm-9">' . "\n" . '<select';
            $select_attributes = '';
            if ($tableau_template[4] != '' && $tableau_template[4] > 1) {
                $select_attributes .= ' multiple="multiple" size="' . $tableau_template[4] . '"';
                $selectnametab = '[]';
            } else {
                $selectnametab = '';
            }
            $select_attributes .= ' class="form-control" id="' . $tableau_template[0] . $tableau_template[1] . $tableau_template[6] . '" name="' . $tableau_template[0] . $tableau_template[1] . $tableau_template[6] . $selectnametab . '"';
            if (isset($tableau_template[8]) && $tableau_template[8] == 1) {
                $select_attributes .= ' required="required"';
            }
            $select_html .= $select_attributes . '>' . "\n";
            if (isset($valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != '') {
                $def = $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]];
            } else {
                $def = $tableau_template[5];
            }
            if ($def == '' && ($tableau_template[4] == '' || $tableau_template[4] <= 1) || $def == 0) {
                $select_html .= '<option value="" selected="selected">' . _t('BAZ_CHOISIR') . '</option>' . "\n";
            }
            if (is_array($valliste['label'])) {
                foreach ($valliste['label'] as $key => $label) {
                    $select_html .= '<option value="' . $key . '"';
                    if ($def != '' && $key == $def) {
                        $select_html .= ' selected="selected"';
                    }
                    $select_html .= '>' . $label . '</option>' . "\n";
                }
            }
            $select_html .= "</select>\n</div>\n</div>\n";
            $formtemplate->addElement('html', $select_html);
        }
    } elseif ($mode == 'formulaire_recherche') {
        //on affiche la liste sous forme de liste deroulante
        if ($tableau_template[9] == 1) {
            $valliste = baz_valeurs_liste($tableau_template[1]);
            $select[0] = _t('BAZ_INDIFFERENT');
            if (is_array($valliste['label'])) {
                $select = $select + $valliste['label'];
            }
            $option = array('id' => $tableau_template[0] . $tableau_template[1] . $tableau_template[6], 'class' => 'form-control');
            require_once BAZ_CHEMIN . 'libs/vendor/HTML/QuickForm/select.php';
            $select = new HTML_QuickForm_select($tableau_template[0] . $tableau_template[1] . $tableau_template[6], $tableau_template[2], $select, $option);
            if ($tableau_template[4] != '') {
                $select->setSize($tableau_template[4]);
            }
            $select->setMultiple(0);
            $nb = isset($_REQUEST[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) ? $_REQUEST[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] : 0;
            $select->setValue($nb);
            $formtemplate->addElement($select);
        }
        //on affiche la liste sous forme de checkbox
        if ($tableau_template[9] == 2) {
            $valliste = baz_valeurs_liste($tableau_template[1]);
            require_once BAZ_CHEMIN . 'libs/vendor/HTML/QuickForm/checkbox.php';
            $i = 0;
            $optioncheckbox = array('class' => 'checkbox');
            foreach ($valliste['label'] as $id => $label) {
                if ($i == 0) {
                    $tab_chkbox = $tableau_template[2];
                } else {
                    $tab_chkbox = '&nbsp;';
                }
                $checkbox[$i] =& HTML_QuickForm::createElement('checkbox', $id, $tab_chkbox, $label, $optioncheckbox);
                $i++;
            }
            $squelette_checkbox =& $formtemplate->defaultRenderer();
            $squelette_checkbox->setElementTemplate('<fieldset class="bazar_fieldset">' . "\n" . '<legend>{label}' . '<!-- BEGIN required --><span class="symbole_obligatoire">&nbsp;*</span><!-- END required -->' . "\n" . '</legend>' . "\n" . '{element}' . "\n" . '</fieldset> ' . "\n" . "\n", $tableau_template[0] . $tableau_template[1] . $tableau_template[6]);
            $squelette_checkbox->setGroupElementTemplate("\n" . '<div class="checkbox">' . "\n" . '{element}' . "\n" . '</div>' . "\n", $tableau_template[0] . $tableau_template[1] . $tableau_template[6]);
            $formtemplate->addGroup($checkbox, $tableau_template[0] . $tableau_template[1] . $tableau_template[6], $tableau_template[2], "\n");
        }
    } elseif ($mode == 'requete_recherche') {
        if ($tableau_template[9] == 1 && isset($_REQUEST[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $_REQUEST[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != 0) {
            /*return ' AND bf_id_fiche IN (SELECT bfvt_ce_fiche FROM '.BAZ_PREFIXE.'fiche_valeur_texte WHERE bfvt_id_element_form="'.$tableau_template[0].$tableau_template[1].$tableau_template[6].'" AND bfvt_texte="'.$_REQUEST[$tableau_template[0].$tableau_template[1].$tableau_template[6]].'") ';*/
        }
    } elseif ($mode == 'html') {
        $html = '';
        if (isset($valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]) && $valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]] != '') {
            $valliste = baz_valeurs_liste($tableau_template[1]);
            if (isset($valliste["label"][$valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]])) {
                $html = '<div class="BAZ_rubrique" data-id="' . $tableau_template[0] . $tableau_template[1] . $tableau_template[6] . '">' . "\n" . '<span class="BAZ_label">' . $tableau_template[2] . '&nbsp;:</span>' . "\n" . '<span class="BAZ_texte">' . "\n" . $valliste["label"][$valeurs_fiche[$tableau_template[0] . $tableau_template[1] . $tableau_template[6]]] . "\n" . '</span>' . "\n" . '</div> <!-- /.BAZ_rubrique -->' . "\n";
            }
        }
        return $html;
    }
}
Пример #16
0
 /**
  * Initialises form element with loaded options
  * @param string $elementName Element name
  * @param string $elementLabel Text for element's <label> tag
  * @param array $options Initially selected options within the list
  * @param array(string => string) $attributes HTML attributes for the element
  * @version 2011071401
  * @since 2011071401
  */
 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
 }
Пример #17
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    function toHtml()
    {
        $html = api_get_asset('select2/dist/js/select2.min.js');
        $iso = api_get_language_isocode(api_get_interface_language());
        $languageCondition = '';
        if (file_exists(api_get_path(SYS_PATH) . "web/assets/select2/dist/js/i18n/{$iso}.js")) {
            $html .= api_get_asset("select2/dist/js/i18n/{$iso}.js");
            $languageCondition = "language: '{$iso}',";
        }
        $html .= api_get_css(api_get_path(WEB_PATH) . 'web/assets/select2/dist/css/select2.min.css');
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $width = 'element';
        $givenWidth = '100%';
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $id = $this->getAttribute('id');
        if (empty($id)) {
            $id = $this->getAttribute('name');
            $this->setAttribute('id', $id);
        }
        $html .= <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('id')}').select2({
                        {$languageCondition}
                        placeholder: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        ajax: {
                            url: '{$this->getAttribute('url')}',
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $this->removeAttribute('formatResult');
        $this->removeAttribute('minimumInputLength');
        $this->removeAttribute('placeholder');
        $this->removeAttribute('class');
        $this->removeAttribute('url');
        $this->setAttribute('style', 'width: 100%;');
        return parent::toHtml() . $html;
    }
Пример #18
0
 /**
  * Loads options from different types of data sources
  *
  * This method overloaded parent method of select element, to allow
  * loading options with fancy attributes.
  *
  * @param mixed &$options Options source currently supports assoc array or DB_result
  * @param mixed $param1   (optional) See function detail
  * @param mixed $param2   (optional) See function detail
  * @param mixed $param3   (optional) See function detail
  * @param mixed $param4   (optional) See function detail
  *
  * @access     public
  * @since      version 1.5.0 (2009-02-15)
  * @return     PEAR_Error|NULL on error and TRUE on success
  * @throws     PEAR_Error
  * @see        loadArray()
  */
 function load(&$options, $param1 = null, $param2 = null, $param3 = null, $param4 = null)
 {
     if (is_array($options)) {
         $ret = $this->loadArray($options, $param1);
     } else {
         $ret = parent::load($options, $param1, $param2, $param3, $param4);
     }
     return $ret;
 }
Пример #19
0
 /**
  * Adds a new OPTION to the SELECT
  *
  * @param     string    $text       Display text for the OPTION
  * @param     string    $value      Value for the OPTION
  * @param     mixed     $attributes Either a typical HTML attribute string 
  *                                  or an associative array
  * @since     1.0
  * @access    public
  * @return    void
  */
 static function addOption($text, $value, $attributes = null)
 {
     if (null === $attributes) {
         $attributes = array('value' => $value);
     } else {
         $attributes = self::_parseAttributes($attributes);
         if (isset($attributes['selected'])) {
             // the 'selected' attribute will be set in toHtml()
             self::_removeAttr('selected', $attributes);
             if (is_null(self::$_values)) {
                 self::$_values = array($value);
             } elseif (!in_array($value, self::$_values)) {
                 self::$_values[] = $value;
             }
         }
         self::_updateAttrArray($attributes, array('value' => $value));
     }
     self::$_options[] = array('text' => $text, 'attr' => $attributes);
 }
Пример #20
0
 /**
  * Class constructor
  */
 function SelectAjax($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, $options, $attributes);
 }
Пример #21
0
 function toHtml()
 {
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     //		$commUtil = new Common_Util();
     $lastPicker = $_REQUEST[$this->_multiname . "PICKER"];
     //$commUtil->request($this->_multiname."PICKER");
     //		$out .= "<script src='/Html/JS/multichooser.js' language='Javascript' type='text/Javascript'></script>\n";
     $out .= "<table>";
     if ($this->_usePicker) {
         //$pickerVals = array("0"=>"Please Select...");
         $pickerVals = array();
         $optionArray = array();
         foreach ($this->_pickerOptions as $label => $options) {
             $pickerVals[] = $label;
             $optionArray[] = $options;
         }
         $elementName = $this->_multiname;
         $out .= "<tr><td colspan='4'><Br><Br>\n";
         $out .= "<script type='text/javascript'>";
         $out .= "var PickerData{$elementName} = [[]";
         foreach ($this->_pickerOptions as $labelSet => $optionSet) {
             $lableArr = explode(',', $labelSet);
             $lableKey = $lableArr[1];
             $out .= ",";
             //'".$lableKey."'
             $first = 1;
             if (sizeof($optionSet)) {
                 foreach ($optionSet as $value => $label) {
                     if ($first == 1) {
                         $first = 0;
                     } else {
                         $out .= ",";
                     }
                     $label = preg_replace("/\\'/", "\\'", $label);
                     $out .= "['{$lableKey}', '{$value}','{$label}']";
                 }
             } else {
                 $out .= "[]";
             }
             $out .= "\n";
         }
         $out .= "];\n";
         $out .= "</script>";
         $out .= "<b>" . $this->_pickerLabel . "</b>&nbsp;";
         $pickerValsArr = array();
         for ($index = 0; $index < sizeof($pickerVals); $index++) {
             $array_element = explode(',', $pickerVals[$index]);
             $key = $array_element[1];
             $value = $array_element[0];
             $pickerValsArr[$key] = $value;
         }
         $picker = new HTML_QuickForm_select($elementName . "PICKER", "", $pickerValsArr, $attributes . " id='{$elementName}PICKER' onchange=\"multichooserPick('{$elementName}')\"");
         $picker->setSize(1);
         $picker->setSelected($lastPicker);
         $out .= $picker->toHtml();
         $out .= "</td></tr>\n";
     }
     $out .= "<tr><td>";
     if ($this->_autoComplete) {
         $out .= $this->txt->toHtml() . "<br>";
     }
     $out .= "<b>" . $this->_fromLabel . "</b><br>";
     $out .= $this->_fromBox->toHtml();
     $out .= "</td><td>";
     $out .= $this->_addButton->toHtml();
     $out .= "<br>";
     $out .= $this->_remButton->toHtml();
     $out .= "</td><td>";
     $out .= "<b>" . $this->_toLabel . "</b><br>";
     $out .= $this->_inBox->toHtml();
     $out .= "</td></tr></table>\n";
     $out .= $this->_hidden->toHtml();
     $out .= "<script type='text/javascript'>document.getElementById('" . $this->_multiname . "').value = '" . $this->_hidden->getValue() . "';</script>";
     return $out;
 }
Пример #22
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    public function toHtml()
    {
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $width = 'element';
        $givenWidth = '100%';
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $id = $this->getAttribute('id');
        if (empty($id)) {
            $id = $this->getAttribute('name');
            $this->setAttribute('id', $id);
        }
        //$iso = Container
        $url = $this->getAttribute('url');
        $iso = api_get_language_isocode();
        $languageCondition = "language: '{$iso}',";
        if (!$url) {
            $url = $this->getAttribute('url_function');
        } else {
            $url = "'{$url}'";
        }
        $html = <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('id')}').select2({
                        {$languageCondition}
                        placeholder: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        ajax: {
                            url: {$url},
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $this->removeAttribute('formatResult');
        $this->removeAttribute('minimumInputLength');
        $this->removeAttribute('placeholder');
        $this->removeAttribute('class');
        $this->removeAttribute('url');
        $this->removeAttribute('url_function');
        $this->setAttribute('style', 'width: 100%;');
        return parent::toHtml() . $html;
    }
Пример #23
0
 /**
  * Class constructor
  */
 function HTML_QuickForm_Select_Ajax($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes);
 }
Пример #24
0
 /**
 * Accepts a renderer.  Overload select in case we'd like to see the 
 * checkboxes/radio buttons in a group when renderering with another
 * renderer.
 *
 * This function was copied from HTML_QuickForm_group::accept() and
 * modified for use with this class.
 *
 * @param  HTML_QuickForm_Renderer $renderer the QF renderer
 * @param  bool                    $require  whether a group is required
 * @param  string                  $error    an error message associated with
                                            a group
 * @see    HTML_QuickForm_group::accept()
 * @access public
 * @return void
 */
 function accept(&$renderer, $required = false, $error = null)
 {
     // if not asked to act like a group, then pass off to regular accept method
     if ($this->_type != 'group') {
         return parent::accept($renderer, $required, $error);
     }
     $this->_separator = null;
     $this->_appendName = null;
     $this->_required = array();
     // Beginning of code from HTML_QuickForm_group::accept()
     // ---8<---
     //$this->_createElementsIfNotExist();
     $renderer->startGroup($this, $required, $error);
     $name = $this->getName();
     // --->8---
     // use our method to get the elements instead
     $this->_elements = $this->getElements();
     // ---8<---
     foreach (array_keys($this->_elements) as $key) {
         $element =& $this->_elements[$key];
         if ($this->_appendName) {
             $elementName = $element->getName();
             if (isset($elementName)) {
                 $element->setName($name . '[' . (strlen($elementName) ? $elementName : $key) . ']');
             } else {
                 $element->setName($name);
             }
         }
         $required = !$element->isFrozen() && in_array($element->getName(), $this->_required);
         $element->accept($renderer, $required);
         // restore the element's name
         if ($this->_appendName) {
             $element->setName($elementName);
         }
     }
     $renderer->finishGroup($this);
     // --->8---
 }