/** baz_formulaire() - Renvoie le formulaire pour les saisies ou modification des fiches
 * @param   string  action du formulaire :
 *  - soit formulaire de saisie
 *  - soit sauvegarde dans la base de donnees
 *  - soit formulaire de modification
 *  - soit modification de la base de donnees
 * @param   string  url de renvois du formulaire (facultatif)
 * @param   array   valeurs de la fiche en cas de modification (facultatif)
 *
 * @return   string  HTML
 */
function baz_formulaire($mode, $url = '', $valeurs = '')
{
    $res = '';
    if ($url == '') {
        $lien_formulaire = $GLOBALS['_BAZAR_']['url'];
        $lien_formulaire->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_SAISIR);
        //Definir le lien du formulaire en fonction du mode de formulaire choisi
        if ($mode == BAZ_CHOISIR_TYPE_FICHE) {
            if ($GLOBALS['params']['vue'] == BAZ_VOIR_SAISIR && isset($_REQUEST['id_typeannonce'])) {
                $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_NOUVEAU_V);
            } else {
                $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_NOUVEAU);
            }
        }
        if ($mode == BAZ_ACTION_NOUVEAU) {
            if (isset($_REQUEST['id_typeannonce'])) {
                if (!isset($_POST['bf_titre']) || !isset($_POST['accept_condition']) && $GLOBALS['_BAZAR_']['condition'] != null) {
                    $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_NOUVEAU);
                } else {
                    $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_NOUVEAU_V);
                }
            } else {
                $mode = BAZ_CHOISIR_TYPE_FICHE;
            }
        }
        if ($mode == BAZ_ACTION_MODIFIER) {
            if (!isset($_POST['bf_titre']) || !isset($_POST['accept_condition']) && $GLOBALS['_BAZAR_']['condition'] != null) {
                $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_MODIFIER);
            } else {
                $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_MODIFIER_V);
            }
            $lien_formulaire->addQueryString('id_fiche', $valeurs['id_fiche']);
        }
        if ($mode == BAZ_ACTION_MODIFIER_V) {
            $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_MODIFIER_V);
            $lien_formulaire->addQueryString('id_fiche', $valeurs['id_fiche']);
        }
    }
    // contruction du squelette du formulaire
    $formtemplate = new HTML_QuickForm('formulaire', 'post', preg_replace('/&/', '&', $url ? $url : $lien_formulaire->getURL()));
    $squelette =& $formtemplate->defaultRenderer();
    $squelette->setFormTemplate('<form {attributes} class="form-horizontal" novalidate="novalidate">' . "\n" . '{content}' . "\n" . '</form>' . "\n");
    $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<label class="control-label col-sm-3">' . "\n" . '<!-- BEGIN required --><span class="symbole_obligatoire">*&nbsp;</span><!-- END required -->' . "\n" . '{label} :</label>' . "\n" . '<div class="controls col-sm-9"> ' . "\n" . '{element}' . "\n" . '<!-- BEGIN error --><span class="alert alert-error alert-danger">{error}</span><!-- END error -->' . "\n" . '</div>' . "\n" . '</div>' . "\n");
    $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<div class="liste_a_cocher"><strong>{label}&nbsp;{element}</strong>' . "\n" . '<!-- BEGIN required --><span class="symbole_obligatoire">&nbsp;*</span><!-- END required -->' . "\n" . '</div>' . "\n" . '</div>' . "\n", 'accept_condition');
    $squelette->setElementTemplate('<div class="form-actions form-group">' . "\n" . '<div class="col-sm-9 col-sm-offset-3">{label}{element}</div></div>' . "\n", 'groupe_boutons');
    $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<div class="control-label col-sm-3">' . "\n" . '{label} :</div>' . "\n" . '<div class="controls col-sm-9"> ' . "\n" . '{element}' . "\n" . '</div>' . "\n" . '</div>', 'select');
    $squelette->setRequiredNoteTemplate('<div class="col-sm-9 col-sm-offset-3 symbole_obligatoire">* {requiredNote}</div>' . "\n");
    //Traduction de champs requis
    $formtemplate->setRequiredNote(_t('BAZ_CHAMPS_REQUIS'));
    $formtemplate->setJsWarnings(_t('BAZ_ERREUR_SAISIE'), _t('BAZ_VEUILLEZ_CORRIGER'));
    //antispam
    $formtemplate->addElement('hidden', 'antispam', 0);
    //------------------------------------------------------------------------------------------------
    // CHOIX DU TYPE DE FICHE
    //------------------------------------------------------------------------------------------------
    if ($mode == BAZ_CHOISIR_TYPE_FICHE) {
        if (isset($_REQUEST['id_typeannonce']) && !empty($_REQUEST['id_typeannonce'])) {
            $GLOBALS['params']['idtypeannonce'] = $_REQUEST['id_typeannonce'];
            $mode = BAZ_ACTION_NOUVEAU;
        } else {
            $resultat = array();
            $tabform = baz_valeurs_tous_les_formulaires($GLOBALS['params']['categorienature'], 'html', $GLOBALS['params']['idtypeannonce']);
            foreach ($tabform as $cat => $form) {
                foreach ($form as $key => $value) {
                    $resultat[$value['bn_id_nature']] = $value;
                }
            }
            if (count($resultat) == 0) {
                $res .= '<div class="alert alert-info">' . _t('BAZ_NO_FORMS_FOUND') . '.</div>' . "\n";
            } elseif (count($resultat) == 1) {
                $ligne = reset($resultat);
                $_REQUEST['id_typeannonce'] = $ligne['bn_id_nature'];
                $GLOBALS['params']['idtypeannonce'] = $ligne['bn_id_nature'];
                $mode = BAZ_ACTION_NOUVEAU;
                //on remplace l'attribut action du formulaire par l'action adequate
                $lien_formulaire->addQueryString(BAZ_VARIABLE_ACTION, BAZ_ACTION_NOUVEAU_V);
                $formtemplate->updateAttributes(array('action' => str_replace('&amp;', '&', $lien_formulaire->getURL())));
            } else {
                $res .= '<table id="add-entry-table" class="bazar-table table table-condensed table-striped">
                    <thead>
                        <tr>
                            <th>' . _t('BAZ_FORMULAIRE') . '</th>
                            <th style="width:220px;">' . _t('BAZ_ACTIONS') . '</th>
                            <th>' . _t('BAZ_CATEGORIE') . '</th>
                        </tr>
                    </thead>
                    <tbody>' . "\n";
                foreach ($resultat as $ligne) {
                    $newurl = $GLOBALS['wiki']->href('', $GLOBALS['wiki']->GetPageTag(), BAZ_VARIABLE_VOIR . '=' . BAZ_VOIR_SAISIR . '&amp;' . BAZ_VARIABLE_ACTION . '=' . BAZ_ACTION_NOUVEAU . '&amp;id_typeannonce=' . $ligne['bn_id_nature']);
                    $res .= '<tr>
                            <td>
                                <strong>' . $ligne['bn_label_nature'] . '</strong>' . "\n" . (!empty($ligne['bn_description']) ? '<br>' . $ligne['bn_description'] : '') . '
                            </td>
                            <td>
                            <a class="btn btn-mini btn-xs btn-primary" href="' . $newurl . '">' . '<i class="glyphicon glyphicon-plus icon-plus"></i> ' . _t('BAZ_SAISIR_UNE_NOUVELLE_FICHE') . '</a>&nbsp;&nbsp;' . "\n" . '</td>
                            <td>' . $ligne['bn_type_fiche'] . '</td>
                        </tr>';
                }
                $res .= '</tbody>
                </table>' . "\n";
            }
        }
    }
    //------------------------------------------------------------------------------------------------
    // AFFICHAGE DU FORMULAIRE CORRESPONDANT AU TYPE DE FICHE CHOISI PAR L'UTILISATEUR
    //------------------------------------------------------------------------------------------------
    if ($mode == BAZ_ACTION_NOUVEAU) {
        // Affichage du modele de formulaire
        $res .= baz_afficher_formulaire_fiche('saisie', $formtemplate, $url);
    }
    //------------------------------------------------------------------------------------------------
    // CAS DE LA MODIFICATION D'UNE FICHE (FORMULAIRE DE MODIFICATION)
    //------------------------------------------------------------------------------------------------
    if ($mode == BAZ_ACTION_MODIFIER) {
        $res .= baz_afficher_formulaire_fiche('modification', $formtemplate, $url, $valeurs);
    }
    //------------------------------------------------------------------------------------------------
    // CAS DE L'AJOUT D'UNE FICHE
    //------------------------------------------------------------------------------------------------
    if ($mode == BAZ_ACTION_NOUVEAU_V) {
        if ($formtemplate->validate() && $_POST['antispam'] == 1) {
            $valeur = baz_insertion_fiche($_POST);
            // Redirection pour eviter la revalidation du formulaire
            $GLOBALS['_BAZAR_']['url']->addQueryString('message', 'ajout_ok');
            $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_CONSULTER);
            $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE);
            $GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $valeur['id_fiche']);
            header('Location: ' . $GLOBALS['_BAZAR_']['url']->getURL());
            exit;
        }
    }
    //------------------------------------------------------------------------------------------------
    // CAS DE LA MODIFICATION D'UNE FICHE (VALIDATION ET MAJ)
    //------------------------------------------------------------------------------------------------
    if ($mode == BAZ_ACTION_MODIFIER_V) {
        if ($formtemplate->validate() && $_POST['antispam'] == 1 && baz_a_le_droit('saisie_fiche', $GLOBALS['wiki']->GetPageOwner($_POST['id_fiche']))) {
            $valeur = baz_mise_a_jour_fiche($_POST);
            if ($GLOBALS['wiki']->GetPageTag() != $valeur['id_fiche']) {
                // Redirection pour eviter la revalidation du formulaire
                $GLOBALS['_BAZAR_']['url']->addQueryString('message', 'modif_ok');
                $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_VOIR, BAZ_VOIR_CONSULTER);
                $GLOBALS['_BAZAR_']['url']->addQueryString(BAZ_VARIABLE_ACTION, BAZ_VOIR_FICHE);
                $GLOBALS['_BAZAR_']['url']->addQueryString('id_fiche', $valeur['id_fiche']);
                header('Location: ' . $GLOBALS['_BAZAR_']['url']->getURL());
            } else {
                header('Location: ' . $GLOBALS['wiki']->href('', $GLOBALS['wiki']->GetPageTag()));
            }
        }
    }
    return $res;
}
Beispiel #2
0
             //contruction du squelette du formulaire
             $formtemplate = new HTML_QuickForm('formulaire', 'post', preg_replace('/&amp;/', '&', $url));
             $squelette =& $formtemplate->defaultRenderer();
             $squelette->setFormTemplate('<form {attributes} class="form-horizontal content-padded list-spacer" ' . 'novalidate="novalidate">' . "\n" . '{content}' . "\n" . '</form>');
             $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<div class="control-label col-xs-3">' . "\n" . '<!-- BEGIN required --><span class="symbole_obligatoire">*</span> <!-- END required -->' . "\n" . '{label} :</div>' . "\n" . '<div class="controls col-xs-8"> ' . "\n" . '{element}' . "\n" . '<!-- BEGIN error -->' . '<span class="alert alert-error alert-danger">{error}</span>' . '<!-- END error -->' . "\n" . '</div>' . "\n" . '</div>' . "\n");
             $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<div class="liste_a_cocher"><strong>{label}&nbsp;{element}</strong>' . "\n" . '<!-- BEGIN required -->' . '<span class="symbole_obligatoire">&nbsp;*</span>' . '<!-- END required -->' . "\n" . '</div>' . "\n" . '</div>' . "\n", 'accept_condition');
             $squelette->setElementTemplate('<div class="form-actions">{label}{element}</div>' . "\n", 'groupe_boutons');
             $squelette->setElementTemplate('<div class="control-group form-group">' . "\n" . '<div class="control-label col-xs-3">' . "\n" . '{label} :</div>' . "\n" . '<div class="controls col-xs-8"> ' . "\n" . '{element}' . "\n" . '</div>' . "\n" . '</div>', 'select');
             $squelette->setRequiredNoteTemplate("<div class=\"symbole_obligatoire\">* {requiredNote}</div>\n");
             //Traduction de champs requis
             $formtemplate->setRequiredNote(_t('BAZ_CHAMPS_REQUIS'));
             $formtemplate->setJsWarnings(_t('BAZ_ERREUR_SAISIE'), _t('BAZ_VEUILLEZ_CORRIGER'));
             //antispam
             $formtemplate->addElement('hidden', 'antispam', 1);
             // generation du formulaire
             $form = baz_afficher_formulaire_fiche('saisie', $formtemplate, $url, '', true);
             $form = preg_replace('~<div class="form-actions">.*</div>~Ui', "\n" . '<a href="#" class="btn btn-block btn-positive btn-save">' . _t('BAZ_SAVE') . '</a>', $form);
             $form = preg_replace('~<div id="map".*>~Ui', "\n" . '<div id="map">', $form);
             echo json_encode(array('html' => $form));
         }
     }
     break;
 case "forms":
     // les formulaires bazar
     $formval = baz_valeurs_formulaire($form);
     // si un seul formulaire, on cree un tableau à une entrée
     if (!empty($form)) {
         $formval = array($formval['bn_id_nature'] => $formval);
     }
     foreach ($formval as $idform => $form) {
         $i = 0;