コード例 #1
0
 /**
  * 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.');
 }
コード例 #2
0
/** 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;
    }
}
コード例 #3
0
/** 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;
    }
}