Subversion Repositories Sites.gentiana.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
43 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: inscription.class.php,v 1.1.1.1 2005/01/03 17:27:49 alex Exp $
23
/**
24
* Inscription
25
*
26
* Un module d'inscription, en général ce code est spécifique à
27
* un site web
28
*
29
*@package inscription
30
//Auteur original :
31
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
32
//Autres auteurs :
33
*@copyright     Tela-Botanica 2000-2004
34
*@version       $Revision: 1.1.1.1 $ $Date: 2005/01/03 17:27:49 $
35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                            ENTETE du PROGRAMME                                       |
40
// +------------------------------------------------------------------------------------------------------+
41
 
42
require_once 'HTML/QuickForm.php' ;
43
 
44
class HTML_formulaireInscription extends HTML_Quickform {
45
 
46
 
47
    /**
48
     *  Constructeur
49
     *
50
     * @param string formName Le nom du formulaire
51
     * @param string method Méthode post ou get
52
     * @param string action L'action du formulaire.
53
     * @param int target La cible.
54
     * @param Array attributes Les attributs HTML en plus.
55
     * @param bool trackSubmit ??
56
     * @return void
57
     * @access public
58
     */
59
 
60
    function HTML_forumlaireInscription ( $formName,  $method = "post",  $action,  $target = "_self",  $attributes,  $trackSubmit = false ) {
61
        HTML_Quickform::HTML_Quickform($formName, $method, $action, $target, $attributes, $trackSubmit) ;
62
    }
63
 
64
    /**
65
     *
66
     *
67
     * @return void
68
     * @access public
69
     */
70
    function construitFormulaire($url, $liste_pays)
71
    {
72
        $squelette =& $this->defaultRenderer();
73
        $squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>'."\n");
74
        $squelette->setElementTemplate( '<li class="liste_inscription">'."\n".'{label}'."\n".'{element}'."\n".
75
                                        '<!-- BEGIN required --><span class="symbole_obligatoire">*</span><!-- END required -->'."\n".
76
                                        '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
77
                                        '</li>'."\n");
78
        $squelette->setGroupElementTemplate ('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_mot_de_passe') ;
79
        $squelette->setGroupElementTemplate ('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_cp_ville') ;
80
        $squelette->setGroupElementTemplate ('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_nom') ;
81
        $squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n");
82
 
83
        $fieldset_debut =    '<fieldset>'."\n".
84
                                '<legend>'.INS_AJOUT_MEMBRE.'</legend>'."\n".
85
                                '<ul>'."\n";
86
        $this->addElement('html', $fieldset_debut);
87
        $this->addElement ('text', 'email', INS_EMAIL) ;
88
        $this->addRule ('email', INS_EMAIL_REQUIS, 'required','', 'client') ;
89
        $this->addRule ('email', INS_MAIL_INCORRECT, 'email', '', 'client') ;
90
        $this->registerRule('doublonmail', 'callback', 'verif_doublonMail');
91
        $this->addRule('email', INS_MAIL_DOUBLE, 'doublonmail', true);
92
 
93
 
94
        // A faire, grouper les mots de passe
95
        $this->addElement ('password', 'mot_de_passe', INS_MOT_DE_PASSE) ;
96
        $this->addElement ('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE) ;
97
        $this->addRule ('mot_de_passe', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
98
        $this->addRule ('mot_de_passe_repete', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
99
        $this->addRule (array ('mot_de_passe', 'mot_de_passe_repete'), INS_MOTS_DE_PASSE_DIFFERENTS, 'compare', '', 'client') ;
100
 
101
 
102
        $nom_prenom[] = & HTML_QuickForm::createElement ('text', 'nom', INS_NOM) ;
103
        $nom_prenom[] = & HTML_QuickForm::createElement ('text', 'prenom', INS_PRENOM) ;
104
        $this->addGroup ($nom_prenom, 'groupe_nom', '', '', false) ;
105
 
106
        if (INS_UTILISE_WIKINI) {
107
            $this->addElement ('text', 'nom_wikini', INS_NOM_WIKI) ;
108
            $this->addRule ('nom_wikini', INS_MAUVAIS_NOM_WIKI, 'regex', '/(!?[A-Z][A-Za-z0-9]*[a-z0-9]+[A-Z][A-Za-z0-9]*)/', 'client') ;
109
            $this->registerRule('doublonwikini', 'callback', 'verif_doublonNomWiki');
110
            $this->addRule('nom_wikini', INS_NOMWIKI_DOUBLE, 'doublonwikini', true);
111
        }
112
        $this->addElement ('text', 'adresse_1', INS_ADRESSE) ;
113
        $this->addElement ('text', 'adresse_2', INS_ADRESSE) ;
114
        $this->addElement ('text', 'region', INS_REGION) ;
115
 
116
        $cp_ville[] = & HTML_QuickForm::createElement ('text', 'cp', INS_CODE_POSTAL) ;
117
        $cp_ville[] = & HTML_QuickForm::createElement ('text', 'ville', INS_VILLE) ;
118
        $this->addGroup ($cp_ville, 'groupe_cp_ville', '', '', false) ;
119
        $this->addGroupRule ('groupe_cp_ville', INS_CODE_POSTAL_REQUIS, 'required', '', 1, 'client') ;
120
 
121
            // L'élément pays est construit à partir du tableau liste_pays
122
 
123
        $this->addElement ('select', 'pays', INS_PAYS, $liste_pays) ;
124
 
125
        $this->addElement ('text', 'site', INS_SITE_INTERNET) ;
126
 
127
           // on fait un groupe avec les boutons pour les mettres sur la même ligne
128
        $buttons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'"));
129
        $buttons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER);
130
        $this->addGroup($buttons, null, null, '&nbsp;');
131
 
132
        $fieldset_fin =    '</ul>'."\n".
133
                            '</fieldset>'."\n";
134
        $this->addElement('html', $fieldset_fin);
135
 
136
 
137
        $this->setRequiredNote(INS_CHAMPS_REQUIS) ;
138
    } // end of member function construitFormulaire
139
 
140
    /** Modifie le formulaire pour l'adapter au cas des structures
141
     *
142
     *
143
     * @return void
144
     * @access public
145
     */
146
    function formulaireStructure()
147
    {
148
        $this->removeElement('groupe_nom') ;
149
        $this->removeElement('email', false) ;
150
        $mail = & HTML_QuickForm::createElement ('text', 'email', INS_MAIL_STRUCTURE) ;
151
        $this->insertElementBefore ($mail, 'mot_de_passe') ;
152
        $nom_structure = & HTML_QuickForm::createElement ('text', 'nom', INS_NOM_STRUCTURE) ;
153
        $this->insertElementBefore ($nom_structure, 'email') ;
154
        $this->removeElement ('site', false) ;
155
        $site_structure = & HTML_QuickForm::createElement ('text', 'site', INS_SITE_STRUCTURE) ;
156
        $this->insertElementBefore ($site_structure, 'pays') ;
157
        $this->addElement ('hidden', 'est_structure', 1) ;
158
        $sigle_structure = & HTML_QuickForm::createElement ('text', 'sigle_structure', INS_SIGLE_STRUCTURE) ;
159
        $this->insertElementBefore ($sigle_structure, 'nom') ;
160
        $this->addRule ('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
161
    }
162
    /**
163
     *
164
     *
165
     * @return string
166
     * @access public
167
     */
168
    function toHTML( )
169
    {
170
        $res = HTML_QuickForm::toHTML() ;
171
        return $res ;
172
    } // end of member function toHTML
173
 
174
 
175
 
176
}
177
 
178
class ListeDePays extends PEAR{
179
 
180
    var $_db ;
181
    /** Constructeur
182
     *  Vérifie l'existance de la table gen_pays_traduction
183
     *
184
     *  @param  DB  Un objet PEAR::DB
185
     * @return
186
     */
187
 
188
    function ListeDePays (&$objetDB) {
189
        $this->_db = $objetDB ;
190
        $requete = "show tables" ;
191
        $resultat = $objetDB->query ($requete) ;
192
        if (DB::isError ($resultat)) {
193
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
194
        }
195
        while ($ligne = $resultat->fetchRow()) {
196
            if ($ligne[0] == 'gen_pays_traduction') {
197
                return ;
198
            }
199
        }
200
        return $this->raiseError ('La table gen_pays_traduction n\'est pas présente dans la base de donnée !') ;
201
    }
202
 
203
    /** Renvoie la liste des pays traduite
204
     *
205
     *  @param  string  une chaine de type i18n ou une chaine code iso langue (fr_FR ou fr ou FR)
206
     * @return  un tableau contenant en clé, le code iso du pays, en majuscule et en valeur le nom du pays traduit
207
     */
208
 
209
    function getListePays ($i18n) {
210
        if (strlen($i18n) == 2) {
211
            $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
212
        }
213
        $requete = "select gpt_id_pays, gpt_nom_pays_traduit from gen_pays_traduction where gpt_id_i18n='".$i18n."'" ;
214
        $resultat = $this->_db->query ($requete) ;
215
        if (DB::isError ($resultat)) {
216
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
217
        }
218
        if ($resultat->numRows() == 0) {
219
            return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
220
        }
221
        $retour = array() ;
222
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
223
            $retour[$ligne->gpt_id_pays] = $ligne->gpt_nom_pays_traduit ;
224
        }
225
        return $retour ;
226
    }
227
}
228
 
229
?>