Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
448 ddelon 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 2005-09-22 14:02:49 ddelon 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 $ $Date: 2005-09-22 14:02:49 $
35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                            ENTETE du PROGRAMME                                       |
40
// +------------------------------------------------------------------------------------------------------+
41
 
42
require_once 'HTML/QuickForm.php' ;
43
 
44
   class ListeDePays extends PEAR{
45
 
46
    var $_db ;
47
    /** Constructeur
48
     *  Vérifie l'existance de la table gen_pays_traduction
49
     *
50
     *  @param  DB  Un objet PEAR::DB
51
     * @return
52
     */
53
 
54
    function ListeDePays(&$objetDB) {
55
        $this->_db = $objetDB ;
56
        $requete = "show tables" ;
57
        $resultat = $objetDB->query ($requete) ;
58
        if (DB::isError ($resultat)) {
59
            die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
60
        }
61
        while ($ligne = $resultat->fetchRow()) {
62
            if ($ligne[0] == INS_TABLE_PAYS) {
63
                return ;
64
            }
65
        }
66
        return $this->raiseError('La table gen_pays_traduction n\'est pas présente dans la base de donnée !') ;
67
    }
68
 
69
    /** Renvoie la liste des pays traduite
70
     *
71
     *  @param  string  une chaine de type i18n ou une chaine code iso langue (fr_FR ou fr ou FR)
72
     * @return  un tableau contenant en clé, le code iso du pays, en majuscule et en valeur le nom du pays traduit
73
     */
74
    function getListePays($i18n) {
75
	    if (strlen($i18n) == 2) {
76
		    $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
77
	    }
78
	    $requete = 'select '.INS_CHAMPS_ID_PAYS.', '.INS_CHAMPS_LABEL_PAYS.' from '.INS_TABLE_PAYS;
79
	    $resultat = $this->_db->query($requete) ;
80
 
81
	    if (DB::isError($resultat)) {
82
		    die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
83
	    }
84
	    if ($resultat->numRows() == 0) {
85
		    return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
86
	    }
87
	    $retour = array() ;
88
	    while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
89
		    $retour[$ligne[INS_CHAMPS_ID_PAYS]] = $ligne[INS_CHAMPS_LABEL_PAYS] ;
90
	    }
91
	    return $retour ;
92
    }
93
}
94
 
95
class HTML_formulaireInscription extends HTML_Quickform {
96
 
97
 
98
    /**
99
     *  Constructeur
100
     *
101
     * @param string formName Le nom du formulaire
102
     * @param string method Méthode post ou get
103
     * @param string action L'action du formulaire.
104
     * @param int target La cible.
105
     * @param Array attributes Les attributs HTML en plus.
106
     * @param bool trackSubmit ??
107
     * @return void
108
     * @access public
109
     */
110
 
111
    function HTML_formulaireInscription( $formName,  $method = "post",  $action,  $target = "_self",  $attributes,  $trackSubmit = false ) {
112
        HTML_Quickform::HTML_Quickform($formName, $method, $action, $target, $attributes, $trackSubmit) ;
113
    }
114
 
115
    /**
116
     *
117
     *
118
     * @return void
119
     * @access public
120
     */
121
    function construitFormulaire($url)
122
    {
123
        $squelette =& $this->defaultRenderer();
124
        $squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'{content}'."\n".'</form>'."\n");
125
        $squelette->setElementTemplate( '<li class="liste_inscription">'."\n".'{label}'."\n".'{element}'."\n".
126
                                        '<!-- BEGIN required --><span class="symbole_obligatoire">*</span><!-- END required -->'."\n".
127
                                        '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
128
                                        '</li>'."\n");
129
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_mot_de_passe') ;
130
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_cp_ville') ;
131
        $squelette->setGroupElementTemplate('<span class="groupe_formulaire">{label}{element}</span>', 'groupe_nom') ;
132
        $squelette->setRequiredNoteTemplate("\n".'<p>'."\n".'<span class="symbole_obligatoire">*</span> {requiredNote}'."\n".'</p>'."\n");
133
 
134
        $fieldset_debut =    '<br /><fieldset>'."\n".
135
                                '<h2>'.INS_AJOUT_MEMBRE.'</h2>'."\n".
136
                                '<ul>'."\n";
137
        $this->addElement('html', $fieldset_debut);
138
        $this->addElement('text', 'email', INS_EMAIL) ;
139
        $this->addRule('email', INS_EMAIL_REQUIS, 'required','', 'client') ;
140
        $this->addRule('email', INS_MAIL_INCORRECT, 'email', '', 'client') ;
141
        $this->registerRule('doublonmail', 'callback', 'verif_doublonMail');
142
        $this->addRule('email', INS_MAIL_DOUBLE, 'doublonmail', true);
143
 
144
 
145
        // A faire, grouper les mots de passe
146
        $this->addElement('password', 'mot_de_passe', INS_MOT_DE_PASSE) ;
147
        $this->addElement('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE) ;
148
        $this->addRule('mot_de_passe', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
149
        $this->addRule('mot_de_passe_repete', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
150
        $this->addRule(array ('mot_de_passe', 'mot_de_passe_repete'), INS_MOTS_DE_PASSE_DIFFERENTS, 'compare', '', 'client') ;
151
        $this->addElement('text', 'nom', INS_NOM) ;
152
	$this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
153
	$this->addElement('text', 'prenom', INS_PRENOM) ;
154
	$this->addRule('prenom', INS_PRENOM_REQUIS, 'required', '', 'client') ;
155
        $this->addElement('text', 'adresse_1', INS_ADRESSE_1) ;
156
        $this->addElement('text', 'adresse_2', INS_ADRESSE_2) ;
157
        $this->addElement('text', 'cp', INS_CODE_POSTAL) ;
158
        $this->addRule('cp', INS_CODE_POSTAL_REQUIS, 'required', '', 'client') ;
159
	$this->addElement('text', 'ville', INS_VILLE) ;
160
	// L'élément pays est construit à partir du tableau liste_pays
161
	$liste_pays = new ListeDePays($GLOBALS['ins_db']) ;
162
	$this->addElement('select', 'pays', INS_PAYS, $liste_pays->getListePays(INS_LANGUE_DEFAUT)) ;
163
        $this->addElement('text', 'telephone', INS_TELEPHONE) ;
164
	$this->addElement('text', 'fax', INS_FAX) ;
165
	$this->addElement('text', 'site', INS_SITE_INTERNET) ;
166
	$this->addElement('checkbox', 'lettre',INS_LETTRE) ;
167
	$this->addElement('checkbox', 'visible',INS_VISIBLE) ;
168
	$this->addElement('hidden', 'est_structure', 0) ;
169
	$defauts=array ('lettre'=>1,'pays'=>'FR');
170
 
171
	$this->setDefaults($defauts);
172
 
173
        // on fait un groupe avec les boutons pour les mettres sur la même ligne
174
        $buttons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'"));
175
        $buttons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER);
176
        $this->addGroup($buttons, null, null, '&nbsp;');
177
        $this->setRequiredNote(INS_CHAMPS_REQUIS) ;
178
	$fieldset_fin =    '</ul></fieldset>'."\n";
179
        $this->addElement('html', $fieldset_fin);
180
    } // end of member function construitFormulaire
181
 
182
    /** Modifie le formulaire pour l'adapter au cas des structures
183
     *
184
     *
185
     * @return void
186
     * @access public
187
     */
188
    function formulaireStructure()
189
    {
190
        $this->removeElement('nom', false) ;
191
	$this->removeElement('prenom') ;
192
        $this->removeElement('email', false) ;
193
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
194
        $this->insertElementBefore($mail, 'mot_de_passe') ;
195
	$nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
196
	$this->insertElementBefore($nom_structure, 'email') ;
197
	$this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
198
	$sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_STRUCTURE) ;
199
	$this->insertElementBefore($sigle_structure, 'email') ;
200
        $this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
201
	$num_agrement = & HTML_QuickForm::createElement('text', 'num_agrement', INS_NUM_AGREMENT) ;
202
	$this->insertElementBefore($num_agrement, 'email') ;
203
	$this->removeElement('site', false) ;
204
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
205
        $this->insertElementBefore($site_structure, 'lettre') ;
206
        $this->removeElement('est_structure', false) ;
207
	$this->addElement('hidden', 'est_structure', 1) ;
208
	$this->addElement('hidden', 'form_structure', 1) ;
209
 
210
    }
211
    /**
212
     *
213
     *
214
     * @return string
215
     * @access public
216
     */
217
    function toHTML( )
218
    {
219
        $res = HTML_QuickForm::toHTML() ;
220
        return $res ;
221
    } // end of member function toHTML
222
}
223
 
224
?>