Subversion Repositories Applications.papyrus

Rev

Rev 293 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
310 florian 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.4 2005-03-21 16:57:30 florian 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.4 $ $Date: 2005-03-21 16:57:30 $
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_formulaireInscription( $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>{label}</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
 
79
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire"><label>{label}</label> {element}</span>', 'groupe_cp_ville') ;
80
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire"><label>{label}</label> {element}</span>', 'groupe_nom') ;
81
        $squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n");
82
 
83
	$this->addElement('html', '<br /><h2>'.INS_AJOUT_MEMBRE.'</h2><br />');
84
        $fieldset_debut =    '<fieldset>'."\n".
85
                                '<legend>'.INS_COORD_PERSO.'</legend>'."\n".
86
                                '<ul>'."\n";
87
        $this->addElement('html', $fieldset_debut);
88
        $this->addElement('text', 'email', INS_EMAIL) ;
89
        $this->addRule('email', INS_EMAIL_REQUIS, 'required','', 'client') ;
90
        $this->addRule('email', INS_MAIL_INCORRECT, 'email', '', 'client') ;
91
        $this->registerRule('doublonmail', 'callback', 'verif_doublonMail');
92
        $this->addRule('email', INS_MAIL_DOUBLE, 'doublonmail', true);
93
 
94
 
95
        // A faire, grouper les mots de passe
96
        $this->addElement('password', 'mot_de_passe', INS_MOT_DE_PASSE, array ('size' => '8')) ;
97
        $this->addElement('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE, array ('size' => '8')) ;
98
        $this->addRule('mot_de_passe', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
99
        $this->addRule('mot_de_passe_repete', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
100
        $this->addRule(array ('mot_de_passe', 'mot_de_passe_repete'), INS_MOTS_DE_PASSE_DIFFERENTS, 'compare', '', 'client') ;
101
 
102
 
103
        $nom_prenom[] = & HTML_QuickForm::createElement('text', 'nom', INS_NOM, array ('size' => '12')) ;
104
        $nom_prenom[] = & HTML_QuickForm::createElement('text', 'prenom', INS_PRENOM, array ('size' => '12')) ;
105
        $this->addGroup($nom_prenom, 'groupe_nom', '', '', false) ;
106
 
107
        if (INS_UTILISE_WIKINI) {
108
            $this->addElement('text', 'nom_wikini', INS_NOM_WIKI, array ('size' => '12')) ;
109
            $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') ;
110
            $this->registerRule('doublonwikini', 'callback', 'verif_doublonNomWiki');
111
            $this->addRule('nom_wikini', INS_NOMWIKI_DOUBLE, 'doublonwikini', true);
112
        }
113
        $this->addElement('text', 'adresse_1', INS_ADRESSE1) ;
114
        $this->addElement('text', 'adresse_2', INS_ADRESSE2) ;
115
        if (INS_CHAMPS_TELEPHONE) $this->addElement('text', 'telephone', INS_TEL, array ('size' => '12')) ;
116
        if (INS_CHAMPS_FAX) $this->addElement('text', 'fax', INS_FAX, array ('size' => '12')) ;
117
        $this->addElement('text', 'region', INS_REGION) ;
118
 
119
        $cp_ville[] = & HTML_QuickForm::createElement('text', 'cp', INS_CODE_POSTAL, array ('size' => '6')) ;
120
        $cp_ville[] = & HTML_QuickForm::createElement('text', 'ville', INS_VILLE) ;
121
        $this->addGroup($cp_ville, 'groupe_cp_ville', '', '', false) ;
122
        $this->addGroupRule('groupe_cp_ville', INS_CODE_POSTAL_REQUIS, 'required', '', 1, 'client') ;
123
 
124
            // L'élément pays est construit à partir du tableau liste_pays
125
 
126
        $this->addElement('select', 'pays', INS_PAYS, $liste_pays) ;
127
 
128
        if (INS_CHAMPS_STRUCTURE) $this->addElement('text', 'structure', INS_STRUCTURE) ;
129
 
130
        $this->addElement('text', 'site', INS_SITE_INTERNET) ;
131
 
132
           // on fait un groupe avec les boutons pour les mettres sur la même ligne
133
        $buttons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'"));
134
        $buttons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER);
135
        $this->addGroup($buttons, null, null, '&nbsp;');
136
 
137
        $fieldset_fin =    '</ul>'."\n".
138
                            '</fieldset>'."\n";
139
        $this->addElement('html', $fieldset_fin);
140
 
141
 
142
        $this->setRequiredNote(INS_CHAMPS_REQUIS) ;
143
    } // end of member function construitFormulaire
144
 
145
    /** Modifie le formulaire pour l'adapter au cas des structures
146
     *
147
     *
148
     * @return void
149
     * @access public
150
     */
151
    function formulaireStructure()
152
    {
153
        $this->removeElement('groupe_nom') ;
154
        $this->removeElement('email', false) ;
155
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
156
        $this->insertElementBefore($mail, 'mot_de_passe') ;
157
        $nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
158
        $this->insertElementBefore($nom_structure, 'email') ;
159
        $this->removeElement('site', false) ;
160
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
161
        $this->insertElementBefore($site_structure, 'pays') ;
162
        $this->addElement('hidden', 'est_structure', 1) ;
163
        $sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_STRUCTURE) ;
164
        $this->insertElementBefore($sigle_structure, 'nom') ;
165
        $this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
166
    }
167
    /**
168
     *
169
     *
170
     * @return string
171
     * @access public
172
     */
173
    function toHTML( )
174
    {
175
        $res = HTML_QuickForm::toHTML() ;
176
        return $res ;
177
    } // end of member function toHTML
178
 
179
 
180
 
181
}
182
 
183
class ListeDePays extends PEAR{
184
 
185
    var $_db ;
186
    /** Constructeur
187
     *  Vérifie l'existance de la table gen_pays_traduction
188
     *
189
     *  @param  DB  Un objet PEAR::DB
190
     * @return
191
     */
192
 
193
    function ListeDePays(&$objetDB) {
194
        $this->_db = $objetDB ;
195
        $requete = "show tables" ;
196
        $resultat = $objetDB->query($requete) ;
197
        if (DB::isError($resultat)) {
198
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
199
        }
200
        while ($ligne = $resultat->fetchRow()) {
201
            if ($ligne[0] == INS_TABLE_PAYS) {
202
                return ;
203
            }
204
        }
205
        return $this->raiseError('La table gen_pays_traduction n\'est pas présente dans la base de donnée !') ;
206
    }
207
 
208
    /** Renvoie la liste des pays traduite
209
     *
210
     *  @param  string  une chaine de type i18n ou une chaine code iso langue (fr_FR ou fr ou FR)
211
     * @return  un tableau contenant en clé, le code iso du pays, en majuscule et en valeur le nom du pays traduit
212
     */
213
 
214
    function getListePays($i18n) {
215
        if (strlen($i18n) == 2) {
216
            $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
217
        }
218
        $requete = "select ".INS_CHAMPS_ID_PAYS.", ".INS_CHAMPS_LABEL_PAYS." from ".INS_TABLE_PAYS;
219
        $resultat = $this->_db->query($requete) ;
220
        if (DB::isError($resultat)) {
221
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
222
        }
223
        if ($resultat->numRows() == 0) {
224
            return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
225
        }
226
        $retour = array() ;
227
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
228
            $retour[$ligne[INS_CHAMPS_ID_PAYS]] = $ligne[INS_CHAMPS_LABEL_PAYS];
229
        }
230
        return $retour ;
231
    }
232
}
233
 
231 alex 234
?>