Subversion Repositories Applications.papyrus

Rev

Rev 979 | Go to most recent revision | Details | Compare with Previous | 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
// +------------------------------------------------------------------------------------------------------+
1081 florian 22
// CVS : $Id: inscription.class.php,v 1.15 2006-12-01 13:23:16 florian Exp $
448 ddelon 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
1081 florian 34
*@version       $Revision: 1.15 $ $Date: 2006-12-01 13:23:16 $
448 ddelon 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                            ENTETE du PROGRAMME                                       |
40
// +------------------------------------------------------------------------------------------------------+
41
 
895 alexandre_ 42
require_once PAP_CHEMIN_RACINE.'api/pear/HTML/QuickForm.php' ;
448 ddelon 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 ;
603 florian 56
        $requete = 'SHOW TABLES';
448 ddelon 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
        }
471 alexandre_ 66
        return $this->raiseError('La table gen_i18n_pays n\'est pas présente dans la base de donnée !') ;
448 ddelon 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
	    }
776 alexandre_ 78
	    $requete = 'select '.INS_CHAMPS_ID_PAYS.', '.INS_CHAMPS_LABEL_PAYS.' from '.INS_TABLE_PAYS
79
							.' where '.INS_CHAMPS_I18N_PAYS.'="'.$i18n.'"';
448 ddelon 80
	    $resultat = $this->_db->query($requete) ;
81
 
82
	    if (DB::isError($resultat)) {
83
		    die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
84
	    }
85
	    if ($resultat->numRows() == 0) {
86
		    return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
87
	    }
88
	    $retour = array() ;
89
	    while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
90
		    $retour[$ligne[INS_CHAMPS_ID_PAYS]] = $ligne[INS_CHAMPS_LABEL_PAYS] ;
91
	    }
92
	    return $retour ;
93
    }
673 alexandre_ 94
 
95
    /** Renvoie le nom d'un pays traduit dans la langue passé en paramètre
96
     *
97
     *  @param  string  une chaine de type i18n ou une chaine code iso langue (fr_FR ou fr ou FR)
98
     * @return  un tableau contenant en clé, le code iso du pays, en majuscule et en valeur le nom du pays traduit
99
     */
100
    function getNomPays($codeIso, $i18n = INS_LANGUE_DEFAUT) {
101
	    if (strlen($i18n) == 2) {
102
		    $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
103
	    }
104
	    $requete = 'select '.INS_CHAMPS_LABEL_PAYS.' from '.INS_TABLE_PAYS.
105
							' where '.INS_CHAMPS_I18N_PAYS.'="'.$i18n.'" and '.
106
							INS_CHAMPS_ID_PAYS.'="'.$codeIso.'"';
895 alexandre_ 107
	    $resultat = $this->_db->query($requete) ;
108
 
673 alexandre_ 109
	    if (DB::isError($resultat)) {
110
		    die ("Echec de la requete : $requete<br />".$resultat->getMessage()) ;
111
	    }
112
	    if ($resultat->numRows() == 0) {
113
		    return $this->raiseError('Le code fourni ne correspond à aucun pays ou n\'est pas dans la table!') ;
114
	    }
115
	    $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC) ;
116
	    return $ligne[INS_CHAMPS_LABEL_PAYS] ;
117
    }
448 ddelon 118
}
119
 
120
class HTML_formulaireInscription extends HTML_Quickform {
121
 
122
 
123
    /**
124
     *  Constructeur
125
     *
126
     * @param string formName Le nom du formulaire
127
     * @param string method Méthode post ou get
128
     * @param string action L'action du formulaire.
129
     * @param int target La cible.
130
     * @param Array attributes Les attributs HTML en plus.
131
     * @param bool trackSubmit ??
132
     * @return void
133
     * @access public
134
     */
135
 
136
    function HTML_formulaireInscription( $formName,  $method = "post",  $action,  $target = "_self",  $attributes,  $trackSubmit = false ) {
137
        HTML_Quickform::HTML_Quickform($formName, $method, $action, $target, $attributes, $trackSubmit) ;
138
    }
139
 
140
    /**
141
     *
142
     *
143
     * @return void
144
     * @access public
145
     */
146
    function construitFormulaire($url)
147
    {
979 florian 148
		$squelette =& $this->defaultRenderer();
149
   		$squelette->setFormTemplate("\n".'<form {attributes}>'."\n".'<table style="border:0;width:100%;">'."\n".'{content}'."\n".'</table>'."\n".'</form>'."\n");
150
    	$squelette->setElementTemplate( '<tr>'."\n".
151
										'<td style="font-size:12px;width:140px;text-align:right;">'."\n".'{label}'.
152
										'<!-- BEGIN required --><span class="symbole_obligatoire">&nbsp;*</span><!-- END required -->'."\n".
153
										' :</td>'."\n".
154
										'<td style="text-align:left;padding:5px;"> '."\n".'{element}'."\n".
155
										'<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n".
156
										'</td>'."\n".
157
										'</tr>'."\n");
158
  	  	$squelette->setElementTemplate( '<tr><td colspan="2" style="font-size:12px;text-align:left;">{label}{element}</td></tr>'."\n", 'lettre');
159
        $squelette->setElementTemplate( '<tr><td colspan="2" style="font-size:12px;text-align:left;">{label}{element}</td></tr>'."\n", 'visible');
160
        $squelette->setElementTemplate( '<tr><td colspan="2" class="bouton" id="bouton_annuler">{label}{element}</td></tr>'."\n", 'groupe_bouton');
161
        $squelette->setGroupTemplate('<tr><td colspan="2">{content}</td></tr>'."\n", 'groupe_bouton');
162
        $squelette->setRequiredNoteTemplate("\n".'<tr>'."\n".'<td colspan="2" class="symbole_obligatoire">* {requiredNote}</td></tr>'."\n");
163
		//Traduction de champs requis
633 florian 164
		$this->setRequiredNote(INS_CHAMPS_REQUIS) ;
165
		$this->setJsWarnings(INS_ERREUR_SAISIE,INS_VEUILLEZ_CORRIGER);
979 florian 166
 
603 florian 167
        $debut = '<h2>'.INS_AJOUT_MEMBRE.'</h2>'."\n";
168
        $this->addElement('html', $debut);
448 ddelon 169
        $this->addElement('text', 'email', INS_EMAIL) ;
170
        $this->addRule('email', INS_EMAIL_REQUIS, 'required','', 'client') ;
979 florian 171
        $this->addRule('email', INS_MAIL_INCORRECT, 'email', '', 'client') ;
471 alexandre_ 172
        $this->addElement('password', 'mot_de_passe', INS_MOT_DE_PASSE, array('size' => '10')) ;
173
        $this->addElement('password', 'mot_de_passe_repete', INS_REPETE_MOT_DE_PASSE, array('size' => '10')) ;
448 ddelon 174
        $this->addRule('mot_de_passe', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
175
        $this->addRule('mot_de_passe_repete', INS_MOT_DE_PASSE_REQUIS, 'required', '', 'client') ;
176
        $this->addRule(array ('mot_de_passe', 'mot_de_passe_repete'), INS_MOTS_DE_PASSE_DIFFERENTS, 'compare', '', 'client') ;
177
        $this->addElement('text', 'nom', INS_NOM) ;
603 florian 178
        $this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
179
        $this->addElement('text', 'prenom', INS_PRENOM) ;
180
        $this->addRule('prenom', INS_PRENOM_REQUIS, 'required', '', 'client') ;
448 ddelon 181
        $this->addElement('text', 'adresse_1', INS_ADRESSE_1) ;
182
        $this->addElement('text', 'adresse_2', INS_ADRESSE_2) ;
183
        $this->addElement('text', 'cp', INS_CODE_POSTAL) ;
184
        $this->addRule('cp', INS_CODE_POSTAL_REQUIS, 'required', '', 'client') ;
603 florian 185
        $this->addElement('text', 'ville', INS_VILLE) ;
186
        // L'élément pays est construit à partir du tableau liste_pays
187
        $liste_pays = new ListeDePays($GLOBALS['ins_db']) ;
188
        $this->addElement('select', 'pays', INS_PAYS, $liste_pays->getListePays(INS_LANGUE_DEFAUT)) ;
189
        $this->addElement('text', 'telephone', INS_TELEPHONE, array('size' => '12')) ;
190
        $this->addElement('text', 'fax', INS_FAX, array('size' => '12')) ;
191
        $this->addElement('text', 'site', INS_SITE_INTERNET) ;
1081 florian 192
        $this->addElement('file', 'image', INS_LOGO_OU_IMAGE) ;
193
		$this->setMaxFileSize(150000); //logo de 15ko maximum
603 florian 194
        if (INS_CHAMPS_LETTRE != '') $this->addElement('checkbox', 'lettre',INS_LETTRE, '<br />') ;
195
        $this->addElement('checkbox', 'visible',INS_VISIBLE, '<br />') ;
196
        $this->addElement('hidden', 'est_structure', 0) ;
895 alexandre_ 197
        $defauts=array ('lettre'=>1,'pays'=>'FR');
198
        $this->setDefaults($defauts);
448 ddelon 199
        // on fait un groupe avec les boutons pour les mettres sur la même ligne
979 florian 200
        $boutons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'",
201
        												'id' => 'annuler', 'class' => 'bouton'));
202
        $boutons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER, array ('id' => 'valider', 'class' =>'bouton'));
203
        $this->addGroup($boutons, 'groupe_bouton', '', "\n");
448 ddelon 204
    } // end of member function construitFormulaire
205
 
206
    /** Modifie le formulaire pour l'adapter au cas des structures
207
     *
208
     *
209
     * @return void
210
     * @access public
211
     */
212
    function formulaireStructure()
213
    {
214
        $this->removeElement('nom', false) ;
603 florian 215
        $this->removeElement('prenom') ;
448 ddelon 216
        $this->removeElement('email', false) ;
217
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
218
        $this->insertElementBefore($mail, 'mot_de_passe') ;
603 florian 219
        $nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
220
        $this->insertElementBefore($nom_structure, 'email') ;
221
        $this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
222
        $sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_DE_LA_STRUCTURE) ;
223
        $this->insertElementBefore($sigle_structure, 'email') ;
448 ddelon 224
        $this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
603 florian 225
        $num_agrement = & HTML_QuickForm::createElement('text', 'num_agrement', INS_NUM_AGREMENT) ;
226
        $this->insertElementBefore($num_agrement, 'email') ;
227
        $this->removeElement('site', false) ;
448 ddelon 228
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
229
        $this->insertElementBefore($site_structure, 'lettre') ;
230
        $this->removeElement('est_structure', false) ;
603 florian 231
        $this->addElement('hidden', 'est_structure', 1) ;
232
        $this->addElement('hidden', 'form_structure', 1) ;
448 ddelon 233
    }
234
    /**
235
     *
236
     *
237
     * @return string
238
     * @access public
239
     */
240
    function toHTML( )
241
    {
242
        $res = HTML_QuickForm::toHTML() ;
243
        return $res ;
244
    } // end of member function toHTML
245
}
246
 
247
?>