Subversion Repositories Applications.papyrus

Rev

Rev 1637 | 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
// +------------------------------------------------------------------------------------------------------+
1652 alexandre_ 22
// CVS : $Id: inscription.class.php,v 1.29 2007-10-12 10:01:53 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
1652 alexandre_ 34
*@version       $Revision: 1.29 $ $Date: 2007-10-12 10:01:53 $
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
     */
146
    function construitFormulaire($url)
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') {
1550 alexandre_ 210
				$requete_defaut = 'select a_longitude, a_latitude from annuaire where a_id='.$GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID);
211
				$resultat_defaut = $GLOBALS['ins_db']->query($requete_defaut);
212
				$ligne = $resultat_defaut->fetchRow(DB_FETCHMODE_OBJECT) ;
213
				if ($ligne->a_latitude != '' && $ligne->a_longitude != '') {
1490 neiluj 214
					$script .= '
1550 alexandre_ 215
							point = new GLatLng('.$ligne->a_latitude.', '.$ligne->a_longitude.');
1490 neiluj 216
							marker = new GMarker(point, {draggable: true});
217
							map.addOverlay(marker);' ;
218
				}
219
			}
220
		    $script .= 'geocoder = new GClientGeocoder();
1550 alexandre_ 221
	    };' .
222
	    		'}
1420 alexandre_ 223
	    function showAddress() {
1467 alexandre_ 224
	      var adress_1 = document.getElementById("a_adresse1").value ;
1604 alexandre_ 225
	      if (document.getElementById("a_adresse2")) ' .
226
	      '	var adress_2 = document.getElementById("a_adresse2").value ;' .
227
	      ' else var adress_2 = "";
1467 alexandre_ 228
	      var ville = document.getElementById("a_ville").value ;
229
	      var cp = document.getElementById("a_code_postal").value ;
1550 alexandre_ 230
	      if (document.getElementById("a_ce_pays").type == "select-one") {
231
	      	var selectIndex = document.getElementById("a_ce_pays").selectedIndex;
232
	      	var pays = document.getElementById("a_ce_pays").options[selectIndex].text ;
233
	      } else {
234
	      	var pays = document.getElementById("a_ce_pays").value;
235
	      }
1420 alexandre_ 236
 
237
	      var address = adress_1 + \' \' + adress_2 + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
238
	      if (geocoder) {
239
	        geocoder.getLatLng(
240
	          address,
241
	          function(point) {
242
	            if (!point) {
243
	              alert(address + " not found");
244
	            } else {
245
	              map.setCenter(point, 13);
246
	              var marker = new GMarker(point, {draggable: true});
247
	              GEvent.addListener(marker, "dragend", function () {
248
	      coordMarker = marker.getPoint() ;
249
	      var lat = document.getElementById("latitude");
250
	      var lon = document.getElementById("longitude");
251
		  lat.value = coordMarker.lat();
252
	      lon.value = coordMarker.lng();
253
	    });
254
 
255
	              map.addOverlay(marker);
256
	              setLatLonForm(marker)
257
	              marker.openInfoWindowHtml(address+ "'.INS_GOOGLE_MSG.'");
258
	            }
259
	          }
260
	        );
261
	      }
262
	    }
263
	    function setLatLonForm(marker) {
264
	      coordMarker = marker.getPoint() ;
265
	      var lat = document.getElementById("latitude");
266
	      var lon = document.getElementById("longitude");
267
		  lat.value = coordMarker.lat();
268
	      lon.value = coordMarker.lng();
269
	    }
270
	    ';
1467 alexandre_ 271
 
272
		// Mise en place du systeme de template du bazar
273
		include_once GEN_CHEMIN_API.'/formulaire/formulaire.fonct.inc.php';
274
		$tableau= formulaire_valeurs_template_champs($GLOBALS['ins_config']['ic_inscription_template']);
275
 
276
		if (isset ($_REQUEST['action']) && $_REQUEST['action']=='modifier') {
277
			//Ajout des valeurs par defaut
278
			$requete_defaut = 'select * from annuaire where a_id='.$GLOBALS['AUTH']->getAuthData(INS_CHAMPS_ID);
279
			$resultat_defaut = $GLOBALS['ins_db']->query($requete_defaut);
280
			$valeurs_par_defaut = $resultat_defaut->fetchRow(DB_FETCHMODE_ASSOC);
281
 
282
			for ($i=0; $i<count($tableau); $i++) {
283
				if ( $tableau[$i]['type']=='liste' || $tableau[$i]['type']=='checkbox' ) {
284
					if (is_int ($tableau[$i]['nom_bdd'])) $def=$tableau[$i]['type'].$tableau[$i]['nom_bdd'];
285
							else $def = $tableau[$i]['nom_bdd'];
286
				}
287
				elseif ( $tableau[$i]['type']=='texte' || $tableau[$i]['type']=='textelong' ||
288
							$tableau[$i]['type']=='listedatedeb' || $tableau[$i]['type']=='listedatefin' ||
1625 alexandre_ 289
							 $tableau[$i]['type']=='champs_mail' || $tableau[$i]['type']=='champs_cache'
1637 alexandre_ 290
							 || $tableau[$i]['type']=='lien_internet' || $tableau[$i]['type']=='newsletter') {
1652 alexandre_ 291
					$def=$tableau[$i]['nom_bdd'];
1467 alexandre_ 292
				} elseif ($tableau[$i]['type']=='carte_google') {
293
					$def = 'carte_google';
294
					$valeurs_par_defaut[$def] = array ('latitude' => $valeurs_par_defaut[$tableau[$i]['limite1']],
295
												'longitude' => $valeurs_par_defaut[$tableau[$i]['limite2']]);
296
					GEN_stockerCodeScript($script);
1585 alexandre_ 297
					// On ajoute l attribut load a la balise body
298
					GEN_AttributsBody('onload', 'load()');
1467 alexandre_ 299
				}
300
				$tableau[$i]['type']($this, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
301
			                         $tableau[$i]['limite2'], $valeurs_par_defaut[$def], $tableau[$i]['table_source'],
302
			                         $tableau[$i]['obligatoire']) ;
303
			}
304
		}
305
		else {
306
			for ($i=0; $i<count($tableau); $i++) {
307
				if ($tableau[$i]['type'] == 'carte_google') {
308
					GEN_stockerCodeScript($script);
1585 alexandre_ 309
					// On ajoute l attribut load a la balise body
310
					GEN_AttributsBody('onload', 'load()');
1467 alexandre_ 311
				}
312
				$tableau[$i]['type']($this, $tableau[$i]['nom_bdd'], $tableau[$i]['label'], $tableau[$i]['limite1'],
313
			                         $tableau[$i]['limite2'], $tableau[$i]['defaut'], $tableau[$i]['table_source'], $tableau[$i]['obligatoire']) ;
314
			 }
315
		}
316
 
317
        $debut = inscription::getTemplate(INS_TEMPLATE_TITRE_FORMULAIRE, $GLOBALS['ins_config']['ic_id_inscription'])."\n";
318
        $this->addElement('html', $debut);
1637 alexandre_ 319
 
1467 alexandre_ 320
        // on fait un groupe avec les boutons pour les mettres sur la meme ligne
321
        $boutons[] = &HTML_QuickForm::createElement('button', 'annuler', INS_ANNULER, array ("onclick" => "javascript:document.location.href='".$url."'",
322
        												'id' => 'annuler', 'class' => 'bouton'));
323
        $boutons[] = &HTML_QuickForm::createElement('submit', 'valider', INS_VALIDER, array ('id' => 'valider', 'class' =>'bouton'));
324
        $this->addGroup($boutons, 'groupe_bouton', '', "\n");
325
 
326
        if (isset ($GLOBALS['ins_config']['ic_google_key']) && $GLOBALS['ins_config']['ic_google_key'] != '') {
327
        	GEN_stockerFichierScript('googleMapScript', $GLOBALS['ins_config']['ic_google_key']);
328
 
329
 
330
 
331
 
332
        }
448 ddelon 333
    } // end of member function construitFormulaire
334
 
335
    /** Modifie le formulaire pour l'adapter au cas des structures
336
     *
337
     *
338
     * @return void
339
     * @access public
340
     */
341
    function formulaireStructure()
342
    {
1467 alexandre_ 343
        /*
448 ddelon 344
        $this->removeElement('nom', false) ;
603 florian 345
        $this->removeElement('prenom') ;
448 ddelon 346
        $this->removeElement('email', false) ;
1467 alexandre_ 347
        $this->removeElement('telephone', false) ;
348
        $nom_structure = & HTML_QuickForm::createElement('text', 'nom', INS_NOM_STRUCTURE) ;
349
        $this->insertElementBefore($nom_structure, 'mot_de_passe') ;
350
 
448 ddelon 351
        $mail = & HTML_QuickForm::createElement('text', 'email', INS_MAIL_STRUCTURE) ;
352
        $this->insertElementBefore($mail, 'mot_de_passe') ;
1467 alexandre_ 353
 
603 florian 354
        $this->addRule('nom', INS_NOM_REQUIS, 'required', '', 'client') ;
1467 alexandre_ 355
        /*
603 florian 356
        $sigle_structure = & HTML_QuickForm::createElement('text', 'sigle_structure', INS_SIGLE_DE_LA_STRUCTURE) ;
357
        $this->insertElementBefore($sigle_structure, 'email') ;
1467 alexandre_ 358
        */
359
        // not required
360
        //$this->addRule('sigle_structure', INS_SIGLE_REQUIS, 'required', '', 'client') ;
361
 
362
        // what's this ?
363
        //$num_agrement = & HTML_QuickForm::createElement('text', 'num_agrement', INS_NUM_AGREMENT) ;
364
        //$this->insertElementBefore($num_agrement, 'email') ;
365
        /*
366
        $telephone = & HTML_QuickForm::createElement('text', 'telephone', INS_TELEPHONE_STRUCTURE) ;
367
        $this->insertElementBefore($telephone, 'lettre') ;
368
        $fax = & HTML_QuickForm::createElement('text', 'fax', INS_FAX_STRUCTURE) ;
369
        $this->insertElementBefore($fax, 'lettre') ;
370
 
603 florian 371
        $this->removeElement('site', false) ;
448 ddelon 372
        $site_structure = & HTML_QuickForm::createElement('text', 'site', INS_SITE_STRUCTURE) ;
373
        $this->insertElementBefore($site_structure, 'lettre') ;
1467 alexandre_ 374
 
375
        // bloc contact
376
        $coord = & HTML_QuickForm::createElement('html', '<tr><td colspan="2"><strong>'.INS_COORD_CONTACT.'</strong></td></tr>') ;
377
        $nom = & HTML_QuickForm::createElement('text', 'nom_contact', INS_NOM_CONTACT) ;
378
        $prenom = & HTML_QuickForm::createElement('text', 'prenom_contact', INS_PRENOM_CONTACT) ;
379
        $poste = & HTML_QuickForm::createElement('text', 'poste_contact', INS_POSTE_CONTACT) ;
380
        $tel = & HTML_QuickForm::createElement('text', 'tel_contact', INS_TEL_CONTACT) ;
381
		$this->insertElementBefore($coord, 'lettre') ;
382
		$this->insertElementBefore($nom, 'lettre') ;
383
		$this->insertElementBefore($prenom, 'lettre') ;
384
		$this->insertElementBefore($poste, 'lettre') ;
385
		$this->insertElementBefore($tel, 'lettre') ;
386
        */
387
        $separateur = & HTML_QuickForm::createElement('html', '<tr><td colspan="2"><hr /></td></tr>') ;
388
        $this->insertElementBefore($separateur, 'lettre') ;
389
 
390
        //$fax = & HTML_QuickForm::createElement('text', 'fax', INS_FAX) ;
391
        //$image = & HTML_QuickForm::createElement('file', 'image', INS_LOGO_OU_IMAGE) ;
392
 
393
		//$this->insertElementBefore($image, 'lettre') ;
394
		//$this->setMaxFileSize(150000); //logo de 150 ko maximum
395
 
448 ddelon 396
        $this->removeElement('est_structure', false) ;
603 florian 397
        $this->addElement('hidden', 'est_structure', 1) ;
398
        $this->addElement('hidden', 'form_structure', 1) ;
1430 alexandre_ 399
 
448 ddelon 400
    }
401
    /**
402
     *
403
     *
404
     * @return string
405
     * @access public
406
     */
407
    function toHTML( )
408
    {
409
        $res = HTML_QuickForm::toHTML() ;
410
        return $res ;
411
    } // end of member function toHTML
412
}
413
 
1298 neiluj 414
?>