Subversion Repositories Applications.papyrus

Rev

Rev 1652 | 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
// +------------------------------------------------------------------------------------------------------+
1683 alexandre_ 22
// CVS : $Id: inscription.class.php,v 1.30 2007-11-08 09:29:36 alexandre_tb Exp $
448 ddelon 23
/**
24
* Inscription
25
*
1430 alexandre_ 26
* Un module d'inscription, en general ce code est specifique a
448 ddelon 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
1683 alexandre_ 34
*@version       $Revision: 1.30 $ $Date: 2007-11-08 09:29:36 $
448 ddelon 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                            ENTETE du PROGRAMME                                       |
40
// +------------------------------------------------------------------------------------------------------+
41
 
1344 alexandre_ 42
require_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm.php' ;
448 ddelon 43
 
1344 alexandre_ 44
class ListeDePays extends PEAR{
448 ddelon 45
 
46
    var $_db ;
47
    /** Constructeur
1430 alexandre_ 48
     *  Verifie l'existance de la table gen_pays_traduction
448 ddelon 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
        }
1430 alexandre_ 66
        return $this->raiseError('La table gen_i18n_pays n\'est pas presente dans la base de donnee !') ;
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)
1430 alexandre_ 72
     * @return  un tableau contenant en cle, le code iso du pays, en majuscule et en valeur le nom du pays traduit
448 ddelon 73
     */
74
    function getListePays($i18n) {
75
	    if (strlen($i18n) == 2) {
76
		    $i18n = strtolower($i18n)."-".strtoupper($i18n) ;
77
	    }
1298 neiluj 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) {
1430 alexandre_ 86
		    return $this->raiseError('Le code fourni ne correspond a aucun pays ou n\'est pas dans la table!') ;
448 ddelon 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)
1430 alexandre_ 98
     * @return  un tableau contenant en cle, le code iso du pays, en majuscule et en valeur le nom du pays traduit
673 alexandre_ 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.
1298 neiluj 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) {
1430 alexandre_ 113
		    return $this->raiseError('Le code fourni ne correspond a aucun pays ou n\'est pas dans la table!') ;
673 alexandre_ 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
1430 alexandre_ 127
     * @param string method Methode post ou get
448 ddelon 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
     */
1683 alexandre_ 146
    function construitFormulaire($url, $id_utilisateur = '')
448 ddelon 147
    {
1298 neiluj 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');
1637 alexandre_ 160
 
1298 neiluj 161
        $squelette->setElementTemplate( '<tr><td colspan="2" class="bouton" id="bouton_annuler">{label}{element}</td></tr>'."\n", 'groupe_bouton');
162
        $squelette->setGroupTemplate('<tr><td colspan="2">{content}</td></tr>'."\n", 'groupe_bouton');
163
        $squelette->setRequiredNoteTemplate("\n".'<tr>'."\n".'<td colspan="2" class="symbole_obligatoire">* {requiredNote}</td></tr>'."\n");
164
		//Traduction de champs requis
165
		$this->setRequiredNote(INS_CHAMPS_REQUIS) ;
166
		$this->setJsWarnings(INS_ERREUR_SAISIE,INS_VEUILLEZ_CORRIGER);
1467 alexandre_ 167
 
168
		$script = '
1420 alexandre_ 169
	        // Variables globales
170
	        var map = null;
171
	    	var geocoder = null;
172
			var lat = document.getElementById("latitude");
173
	        var lon = document.getElementById("longitude");
174
 
175
	        function load() {
176
	        if (GBrowserIsCompatible()) {
177
	          map = new GMap2(document.getElementById("map"));
178
	          map.addControl(new GSmallMapControl());
179
			  map.addControl(new GMapTypeControl());
180
			  map.addControl(new GScaleControl());
181
			  map.enableContinuousZoom();
182
 
1652 alexandre_ 183
			  // On centre la carte
184
			  center = new GLatLng('.INS_GOOGLE_CENTRE_LAT.', '.INS_GOOGLE_CENTRE_LON.');
185
	          map.setCenter(center, '.INS_GOOGLE_ALTITUDE.');
1420 alexandre_ 186
			  //marker = new GMarker(center, {draggable: true}) ;
187
	          GEvent.addListener(map, "click", function(marker, point) {
188
	  		    if (marker) {
189
	    	      map.removeOverlay(marker);
190
	    	      var lat = document.getElementById("latitude");
191
	              var lon = document.getElementById("longitude");
192
	    	      lat.value = "";
193
	              lon.value = "";
194
			    } else {
195
			      // On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude
196
			      marker = new GMarker(point, {draggable: true}) ;
197
			      GEvent.addListener(marker, "dragend", function () {
198
	                coordMarker = marker.getPoint() ;
199
	                var lat = document.getElementById("latitude");
200
	                var lon = document.getElementById("longitude");
201
		            lat.value = coordMarker.lat();
202
	                lon.value = coordMarker.lng();
203
	              });
204
		          map.addOverlay(marker);
205
		          setLatLonForm(marker);
206
	  		    }
207
	        });' ;
1490 neiluj 208
 
209
			if($_REQUEST['action'] == 'modifier') {
1683 alexandre_ 210
				if ($GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID) != '') {
211
					$id_utilisateur = $GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID) ;
212
				}
213
				$requete_defaut = 'select a_longitude, a_latitude from annuaire where a_id='.$id_utilisateur;
1550 alexandre_ 214
				$resultat_defaut = $GLOBALS['ins_db']->query($requete_defaut);
215
				$ligne = $resultat_defaut->fetchRow(DB_FETCHMODE_OBJECT) ;
216
				if ($ligne->a_latitude != '' && $ligne->a_longitude != '') {
1490 neiluj 217
					$script .= '
1550 alexandre_ 218
							point = new GLatLng('.$ligne->a_latitude.', '.$ligne->a_longitude.');
1490 neiluj 219
							marker = new GMarker(point, {draggable: true});
220
							map.addOverlay(marker);' ;
221
				}
222
			}
223
		    $script .= 'geocoder = new GClientGeocoder();
1550 alexandre_ 224
	    };' .
225
	    		'}
1420 alexandre_ 226
	    function showAddress() {
1467 alexandre_ 227
	      var adress_1 = document.getElementById("a_adresse1").value ;
1604 alexandre_ 228
	      if (document.getElementById("a_adresse2")) ' .
229
	      '	var adress_2 = document.getElementById("a_adresse2").value ;' .
230
	      ' else var adress_2 = "";
1467 alexandre_ 231
	      var ville = document.getElementById("a_ville").value ;
232
	      var cp = document.getElementById("a_code_postal").value ;
1550 alexandre_ 233
	      if (document.getElementById("a_ce_pays").type == "select-one") {
234
	      	var selectIndex = document.getElementById("a_ce_pays").selectedIndex;
235
	      	var pays = document.getElementById("a_ce_pays").options[selectIndex].text ;
236
	      } else {
237
	      	var pays = document.getElementById("a_ce_pays").value;
238
	      }
1420 alexandre_ 239
 
240
	      var address = adress_1 + \' \' + adress_2 + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
241
	      if (geocoder) {
242
	        geocoder.getLatLng(
243
	          address,
244
	          function(point) {
245
	            if (!point) {
246
	              alert(address + " not found");
247
	            } else {
248
	              map.setCenter(point, 13);
249
	              var marker = new GMarker(point, {draggable: true});
250
	              GEvent.addListener(marker, "dragend", function () {
251
	      coordMarker = marker.getPoint() ;
252
	      var lat = document.getElementById("latitude");
253
	      var lon = document.getElementById("longitude");
254
		  lat.value = coordMarker.lat();
255
	      lon.value = coordMarker.lng();
256
	    });
257
 
258
	              map.addOverlay(marker);
259
	              setLatLonForm(marker)
260
	              marker.openInfoWindowHtml(address+ "'.INS_GOOGLE_MSG.'");
261
	            }
262
	          }
263
	        );
264
	      }
265
	    }
266
	    function setLatLonForm(marker) {
267
	      coordMarker = marker.getPoint() ;
268
	      var lat = document.getElementById("latitude");
269
	      var lon = document.getElementById("longitude");
270
		  lat.value = coordMarker.lat();
271
	      lon.value = coordMarker.lng();
272
	    }
273
	    ';
1467 alexandre_ 274
 
275
		// Mise en place du systeme de template du bazar
276
		include_once GEN_CHEMIN_API.'/formulaire/formulaire.fonct.inc.php';
277
		$tableau= formulaire_valeurs_template_champs($GLOBALS['ins_config']['ic_inscription_template']);
278
 
279
		if (isset ($_REQUEST['action']) && $_REQUEST['action']=='modifier') {
280
			//Ajout des valeurs par defaut
1683 alexandre_ 281
			if ($GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID) != '') {
282
				$id_utilisateur = $GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID) ;
283
			}
284
			$requete_defaut = 'select * from annuaire where a_id='.$id_utilisateur;
1467 alexandre_ 285
			$resultat_defaut = $GLOBALS['ins_db']->query($requete_defaut);
286
			$valeurs_par_defaut = $resultat_defaut->fetchRow(DB_FETCHMODE_ASSOC);
287
 
288
			for ($i=0; $i<count($tableau); $i++) {
289
				if ( $tableau[$i]['type']=='liste' || $tableau[$i]['type']=='checkbox' ) {
290
					if (is_int ($tableau[$i]['nom_bdd'])) $def=$tableau[$i]['type'].$tableau[$i]['nom_bdd'];
291
							else $def = $tableau[$i]['nom_bdd'];
292
				}
293
				elseif ( $tableau[$i]['type']=='texte' || $tableau[$i]['type']=='textelong' ||
294
							$tableau[$i]['type']=='listedatedeb' || $tableau[$i]['type']=='listedatefin' ||
1625 alexandre_ 295
							 $tableau[$i]['type']=='champs_mail' || $tableau[$i]['type']=='champs_cache'
1637 alexandre_ 296
							 || $tableau[$i]['type']=='lien_internet' || $tableau[$i]['type']=='newsletter') {
1652 alexandre_ 297
					$def=$tableau[$i]['nom_bdd'];
1467 alexandre_ 298
				} elseif ($tableau[$i]['type']=='carte_google') {
299
					$def = 'carte_google';
300
					$valeurs_par_defaut[$def] = array ('latitude' => $valeurs_par_defaut[$tableau[$i]['limite1']],
301
												'longitude' => $valeurs_par_defaut[$tableau[$i]['limite2']]);
302
					GEN_stockerCodeScript($script);
1585 alexandre_ 303
					// On ajoute l attribut load a la balise body
304
					GEN_AttributsBody('onload', 'load()');
1467 alexandre_ 305
				}
306
				$tableau[$i]['type']($this, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
307
			                         $tableau[$i]['limite2'], $valeurs_par_defaut[$def], $tableau[$i]['table_source'],
308
			                         $tableau[$i]['obligatoire']) ;
309
			}
310
		}
311
		else {
312
			for ($i=0; $i<count($tableau); $i++) {
313
				if ($tableau[$i]['type'] == 'carte_google') {
314
					GEN_stockerCodeScript($script);
1585 alexandre_ 315
					// On ajoute l attribut load a la balise body
316
					GEN_AttributsBody('onload', 'load()');
1467 alexandre_ 317
				}
318
				$tableau[$i]['type']($this, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
319
			                         $tableau[$i]['limite2'], $tableau[$i]['defaut'], $tableau[$i]['table_source'], $tableau[$i]['obligatoire']) ;
320
			 }
321
		}
322
 
323
        $debut = inscription::getTemplate(INS_TEMPLATE_TITRE_FORMULAIRE, $GLOBALS['ins_config']['ic_id_inscription'])."\n";
324
        $this->addElement('html', $debut);
1637 alexandre_ 325
 
1467 alexandre_ 326
        // on fait un groupe avec les boutons pour les mettres sur la meme ligne
327
        $boutons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'",
328
        												'id' => 'annuler', 'class' => 'bouton'));
329
        $boutons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER, array ('id' => 'valider', 'class' =>'bouton'));
330
        $this->addGroup($boutons, 'groupe_bouton', '', "\n");
331
 
332
        if (isset ($GLOBALS['ins_config']['ic_google_key']) && $GLOBALS['ins_config']['ic_google_key'] != '') {
333
        	GEN_stockerFichierScript('googleMapScript', $GLOBALS['ins_config']['ic_google_key']);
334
 
335
 
336
 
337
 
338
        }
448 ddelon 339
    } // end of member function construitFormulaire
340
 
341
    /** Modifie le formulaire pour l'adapter au cas des structures
342
     *
343
     *
344
     * @return void
345
     * @access public
346
     */
347
    function formulaireStructure()
348
    {
1467 alexandre_ 349
        /*
448 ddelon 350
        $this->removeElement('nom', false) ;
603 florian 351
        $this->removeElement('prenom') ;
448 ddelon 352
        $this->removeElement('email', false) ;
1467 alexandre_ 353
        $this->removeElement('telephone', false) ;
354
        $nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
355
        $this->insertElementBefore($nom_structure, 'mot_de_passe') ;
356
 
448 ddelon 357
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
358
        $this->insertElementBefore($mail, 'mot_de_passe') ;
1467 alexandre_ 359
 
603 florian 360
        $this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
1467 alexandre_ 361
        /*
603 florian 362
        $sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_DE_LA_STRUCTURE) ;
363
        $this->insertElementBefore($sigle_structure, 'email') ;
1467 alexandre_ 364
        */
365
        // not required
366
        //$this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
367
 
368
        // what's this ?
369
        //$num_agrement = & HTML_QuickForm::createElement('text', 'num_agrement', INS_NUM_AGREMENT) ;
370
        //$this->insertElementBefore($num_agrement, 'email') ;
371
        /*
372
        $telephone = & HTML_QuickForm::createElement('text', 'telephone', INS_TELEPHONE_STRUCTURE) ;
373
        $this->insertElementBefore($telephone, 'lettre') ;
374
        $fax = & HTML_QuickForm::createElement('text', 'fax', INS_FAX_STRUCTURE) ;
375
        $this->insertElementBefore($fax, 'lettre') ;
376
 
603 florian 377
        $this->removeElement('site', false) ;
448 ddelon 378
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
379
        $this->insertElementBefore($site_structure, 'lettre') ;
1467 alexandre_ 380
 
381
        // bloc contact
382
        $coord = & HTML_QuickForm::createElement('html', '<tr><td colspan="2"><strong>'.INS_COORD_CONTACT.'</strong></td></tr>') ;
383
        $nom = & HTML_QuickForm::createElement('text', 'nom_contact', INS_NOM_CONTACT) ;
384
        $prenom = & HTML_QuickForm::createElement('text', 'prenom_contact', INS_PRENOM_CONTACT) ;
385
        $poste = & HTML_QuickForm::createElement('text', 'poste_contact', INS_POSTE_CONTACT) ;
386
        $tel = & HTML_QuickForm::createElement('text', 'tel_contact', INS_TEL_CONTACT) ;
387
		$this->insertElementBefore($coord, 'lettre') ;
388
		$this->insertElementBefore($nom, 'lettre') ;
389
		$this->insertElementBefore($prenom, 'lettre') ;
390
		$this->insertElementBefore($poste, 'lettre') ;
391
		$this->insertElementBefore($tel, 'lettre') ;
392
        */
393
        $separateur = & HTML_QuickForm::createElement('html', '<tr><td colspan="2"><hr /></td></tr>') ;
394
        $this->insertElementBefore($separateur, 'lettre') ;
395
 
396
        //$fax = & HTML_QuickForm::createElement('text', 'fax', INS_FAX) ;
397
        //$image = & HTML_QuickForm::createElement('file', 'image', INS_LOGO_OU_IMAGE) ;
398
 
399
		//$this->insertElementBefore($image, 'lettre') ;
400
		//$this->setMaxFileSize(150000); //logo de 150 ko maximum
401
 
448 ddelon 402
        $this->removeElement('est_structure', false) ;
603 florian 403
        $this->addElement('hidden', 'est_structure', 1) ;
404
        $this->addElement('hidden', 'form_structure', 1) ;
1430 alexandre_ 405
 
448 ddelon 406
    }
407
    /**
408
     *
409
     *
410
     * @return string
411
     * @access public
412
     */
413
    function toHTML( )
414
    {
415
        $res = HTML_QuickForm::toHTML() ;
416
        return $res ;
417
    } // end of member function toHTML
418
}
419
 
1298 neiluj 420
?>