Subversion Repositories Applications.bazar

Rev

Rev 392 | Rev 446 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 392 Rev 398
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
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                                  |
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                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: bazar.class.php,v 1.10 2008-09-17 14:08:45 alexandre_tb Exp $
22
// CVS : $Id: bazar.class.php,v 1.11 2008-10-29 10:38:14 alexandre_tb Exp $
23
/**
23
/**
24
* 
24
* 
25
*@package bazar
25
*@package bazar
26
//Auteur original :
26
//Auteur original :
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
28
*@author        Florian Schmitt <florian@ecole-et-nature.org>
28
*@author        Florian Schmitt <florian@ecole-et-nature.org>
29
*@copyright     Tela-Botanica 2000-2004
29
*@copyright     Tela-Botanica 2000-2004
30
*@version       $Revision: 1.10 $
30
*@version       $Revision: 1.11 $
31
// +------------------------------------------------------------------------------------------------------+
31
// +------------------------------------------------------------------------------------------------------+
32
*/
32
*/
33
 
33
 
34
// +------------------------------------------------------------------------------------------------------+
34
// +------------------------------------------------------------------------------------------------------+
35
// |                             LES CONSTANTES DES NIVEAUX DE DROIT                                      |
35
// |                             LES CONSTANTES DES NIVEAUX DE DROIT                                      |
36
// +------------------------------------------------------------------------------------------------------+
36
// +------------------------------------------------------------------------------------------------------+
37
 
37
 
38
define ('BAZ_DROIT_SUPER_ADMINISTRATEUR', 0);
38
define ('BAZ_DROIT_SUPER_ADMINISTRATEUR', 0);
39
define ('BAZ_DROIT_ADMINISTRATEUR', 2);
39
define ('BAZ_DROIT_ADMINISTRATEUR', 2);
40
define ('BAZ_DROIT_REDACTEUR', 1);
40
define ('BAZ_DROIT_REDACTEUR', 1);
41
 
41
 
42
// +------------------------------------------------------------------------------------------------------+
42
// +------------------------------------------------------------------------------------------------------+
43
// |                                            ENTETE du PROGRAMME                                       |
43
// |                                            ENTETE du PROGRAMME                                       |
44
// +------------------------------------------------------------------------------------------------------+
44
// +------------------------------------------------------------------------------------------------------+
45
 
45
 
46
include_once PAP_CHEMIN_API_PEAR.'PEAR.php';
46
include_once PAP_CHEMIN_API_PEAR.'PEAR.php';
-
 
47
include_once BAZ_CHEMIN_APPLI.'bibliotheque/bazarTemplate.class.php';
47
 
48
 
48
class Administrateur_bazar {
49
class Administrateur_bazar {
49
 
50
 
50
	var $_auth ;
51
	var $_auth ;
51
	
52
	
52
	/**
53
	/**
53
	 * Identifiant de l'utilisateur
54
	 * Identifiant de l'utilisateur
54
	 */
55
	 */
55
	
56
	
56
	var $_id_utilisateur ;
57
	var $_id_utilisateur ;
57
 
58
 
58
	/**
59
	/**
59
	 * 	Vaut true si l'utilisateur est un administrateur
60
	 * 	Vaut true si l'utilisateur est un administrateur
60
	 */
61
	 */
61
	var $_isSuperAdmin ;
62
	var $_isSuperAdmin ;
62
	
63
	
63
	/**	Constructeur
64
	/**	Constructeur
64
	 * 
65
	 * 
65
	 * @param	object Un objet authentification
66
	 * @param	object Un objet authentification
66
	 * @return void
67
	 * @return void
67
	 * 
68
	 * 
68
	 */
69
	 */
69
	 
70
	 
70
	 function Administrateur_bazar (&$AUTH) {
71
	 function Administrateur_bazar (&$AUTH) {
71
	 	$this->_auth = $AUTH ;
72
	 	$this->_auth = $AUTH ;
72
	 	if ($AUTH->getAuth())$this->_id_utilisateur = $this->_auth->getAuthData(BAZ_CHAMPS_ID) ;
73
	 	if ($AUTH->getAuth())$this->_id_utilisateur = $this->_auth->getAuthData(BAZ_CHAMPS_ID) ;
73
	 }	
74
	 }	
74
	
75
	
75
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
76
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
76
	 * 
77
	 * 
77
	 */
78
	 */
78
	function isSuperAdmin() {
79
	function isSuperAdmin() {
79
		
80
		
80
		if(empty($this->_id_utilisateur)) 
81
		if(empty($this->_id_utilisateur)) 
81
			return FALSE;
82
			return FALSE;
82
		
83
		
83
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
84
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
84
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
85
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
85
		
86
		
86
		// On court-circuite si l'utilisateur n'est pas logué
87
		// On court-circuite si l'utilisateur n'est pas logué
87
		if (!$this->_auth->getAuth()) return false ;
88
		if (!$this->_auth->getAuth()) return false ;
88
		
89
		
89
		// Sinon on interroge la base
90
		// Sinon on interroge la base
90
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
91
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
91
	 				$this->_id_utilisateur.
92
	 				$this->_id_utilisateur.
92
	           		' AND bd_niveau_droit=0';
93
	           		' AND bd_niveau_droit=0';
93
 
94
 
94
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
95
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
95
		if (DB::isError($resultat)) {
96
		if (DB::isError($resultat)) {
96
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
97
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
97
		}
98
		}
98
		if ($resultat->numRows() != 0) {
99
		if ($resultat->numRows() != 0) {
99
			$this->_isSuperAdmin = true ;
100
			$this->_isSuperAdmin = true ;
100
		} else {
101
		} else {
101
			$this->_isSuperAdmin = false ;	
102
			$this->_isSuperAdmin = false ;	
102
		}
103
		}
103
		return $this->_isSuperAdmin;
104
		return $this->_isSuperAdmin;
104
	}
105
	}
105
	
106
	
106
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
107
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
107
	 * 
108
	 * 
108
	 * @param interger type_annonce	Le type de l'annonce
109
	 * @param interger type_annonce	Le type de l'annonce
109
	 * 
110
	 * 
110
	 */
111
	 */
111
	 
112
	 
112
	function isAdmin($id_nature) {
113
	function isAdmin($id_nature) {
113
		// on court-circuite si l'utilisateur n'est pas logué
114
		// on court-circuite si l'utilisateur n'est pas logué
114
		if (!$this->_auth->getAuth()) return false ;
115
		if (!$this->_auth->getAuth()) return false ;
115
		
116
		
116
		return $this->_requeteDroit ($id_nature, 2) ;
117
		return $this->_requeteDroit ($id_nature, 2) ;
117
	}
118
	}
118
	
119
	
119
	/**	isRedacteur() - Renvoie true si l'utilisateur est redacteur du type de fiche specifie
120
	/**	isRedacteur() - Renvoie true si l'utilisateur est redacteur du type de fiche specifie
120
	 * 
121
	 * 
121
	 */
122
	 */
122
	
123
	
123
	function isRedacteur($id_nature) {
124
	function isRedacteur($id_nature) {
124
		if (isset($GLOBALS['droit_depot']) && $GLOBALS['droit_depot'] == 3) return true;
125
		if (isset($GLOBALS['droit_depot']) && $GLOBALS['droit_depot'] == 3) return true;
125
		return $this->_requeteDroit ($id_nature, 1) ;
126
		return $this->_requeteDroit ($id_nature, 1) ;
126
	}
127
	}
127
	
128
	
128
	/** _requeteDroit() - fait une requete sur la table bazar_droit
129
	/** _requeteDroit() - fait une requete sur la table bazar_droit
129
	 * 
130
	 * 
130
	 */
131
	 */
131
	
132
	
132
	function _requeteDroit ($id_nature, $niveau) {
133
	function _requeteDroit ($id_nature, $niveau) {
133
		
134
		
134
		if(empty($this->_id_utilisateur)) 
135
		if(empty($this->_id_utilisateur)) 
135
			return false;
136
			return false;
136
			
137
			
137
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
138
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
138
					.$this->_id_utilisateur.
139
					.$this->_id_utilisateur.
139
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
140
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
140
 
141
 
141
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
142
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
142
		if (DB::isError($resultat)) {
143
		if (DB::isError($resultat)) {
143
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
144
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
144
		}
145
		}
145
		if ($resultat->numRows() != 0) {
146
		if ($resultat->numRows() != 0) {
146
			return true ;
147
			return true ;
147
		}
148
		}
148
		return false ;
149
		return false ;
149
	}
150
	}
150
}
151
}
151
 
152
 
152
class Utilisateur_bazar extends Administrateur_bazar {
153
class Utilisateur_bazar extends Administrateur_bazar {
153
	
154
	
154
	function Utilisateur_bazar($id_utilisateur) {
155
	function Utilisateur_bazar($id_utilisateur) {
155
		$this->_id_utilisateur = $id_utilisateur ;		
156
		$this->_id_utilisateur = $id_utilisateur ;		
156
	}	
157
	}	
157
	
158
	
158
	function isAdmin($id_nature) {
159
	function isAdmin($id_nature) {
159
		return $this->_requeteDroit ($id_nature, 2) ;
160
		return $this->_requeteDroit ($id_nature, 2) ;
160
	}
161
	}
161
	
162
	
162
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
163
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
163
	 * 
164
	 * 
164
	 */
165
	 */
165
	function isSuperAdmin() {
166
	function isSuperAdmin() {
166
		
167
		
167
		if(empty($this->_id_utilisateur)) 
168
		if(empty($this->_id_utilisateur)) 
168
			return false;
169
			return false;
169
			
170
			
170
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
171
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
171
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
172
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
172
		
173
		
173
		// Sinon on interroge la base
174
		// Sinon on interroge la base
174
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
175
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
175
	 				$this->_id_utilisateur.
176
	 				$this->_id_utilisateur.
176
	           		' AND bd_niveau_droit=0';
177
	           		' AND bd_niveau_droit=0';
177
 
178
 
178
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
179
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
179
		if (DB::isError($resultat)) {
180
		if (DB::isError($resultat)) {
180
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
181
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
181
		}
182
		}
182
		if ($resultat->numRows() != 0) {
183
		if ($resultat->numRows() != 0) {
183
			$this->_isSuperAdmin = true ;
184
			$this->_isSuperAdmin = true ;
184
		} else {
185
		} else {
185
			$this->_isSuperAdmin = false ;	
186
			$this->_isSuperAdmin = false ;	
186
		}
187
		}
187
		return $this->_isSuperAdmin;
188
		return $this->_isSuperAdmin;
188
	}
189
	}
189
	
190
	
190
}
191
}
191
 
192
 
192
 
193
 
-
 
194
 
-
 
195
define ('BAZAR_NOTIFICATION_NOUVELLE_FICHE', 1);
-
 
196
define ('BAZAR_NOTIFICATION_MODIFICATION_FICHE', 2);
193
 
197
 
194
 
198
 
195
class bazar extends PEAR {
199
class bazar extends PEAR {
196
	
200
	
197
	/**
201
	/**
198
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type 
202
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type 
199
	 * 					de fiche passe en parametre
203
	 * 					de fiche passe en parametre
200
	 * 
204
	 * 
201
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
205
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
202
	 * 	@param integer L identifiant de la nature
206
	 * 	@param integer L identifiant de la nature
203
	 */
207
	 */
204
	function getMailAdmin($id_nature) {
208
	function getMailAdmin($id_nature) {
205
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
209
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
206
				'where bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit="'.BAZ_DROIT_ADMINISTRATEUR.'"' .
210
				'where bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit="'.BAZ_DROIT_ADMINISTRATEUR.'"' .
207
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
211
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
208
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
212
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
209
		if (DB::isError($resultat)) $this->raiseError();
213
		if (DB::isError($resultat)) $this->raiseError();
210
		$tableau_mail = array();
214
		$tableau_mail = array();
211
		if ($resultat->numRows() == 0) return false;
215
		if ($resultat->numRows() == 0) return false;
212
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
216
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
213
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
217
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
214
		}
218
		}
215
		return $tableau_mail;
219
		return $tableau_mail;
216
	}
220
	}
217
	
221
	
218
	/**
222
	/**
219
	 * 	getMailAdmin	Renvoie un tableau de mail des super administrateurs  
223
	 * 	getMailAdmin	Renvoie un tableau de mail des super administrateurs  
220
	 * 
224
	 * 
221
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
225
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
222
	 */
226
	 */
223
	function getMailSuperAdmin() {
227
	function getMailSuperAdmin() {
224
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
228
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
225
				'where bd_niveau_droit="'.BAZ_DROIT_SUPER_ADMINISTRATEUR.'"' .
229
				'where bd_niveau_droit="'.BAZ_DROIT_SUPER_ADMINISTRATEUR.'"' .
226
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
230
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
227
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
231
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
228
		if (DB::isError($resultat)) $this->raiseError();
232
		if (DB::isError($resultat)) $this->raiseError();
229
		$tableau_mail = array();
233
		$tableau_mail = array();
230
		if ($resultat->numRows() == 0) return false;
234
		if ($resultat->numRows() == 0) return false;
231
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
235
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
232
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
236
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
233
		}
237
		}
234
		return $tableau_mail;
238
		return $tableau_mail;
235
	}
239
	}
-
 
240
	/**
-
 
241
	 *  notifier() envoie un message aux administrateurs
-
 
242
	 * 
-
 
243
	 * par defaut lors du depot ou de la modification d une fiche
-
 
244
	 */
-
 
245
	function notifier($type = BAZAR_NOTIFICATION_NOUVELLE_FICHE) {
-
 
246
		
-
 
247
		switch ($type) {
-
 
248
			case BAZAR_NOTIFICATION_NOUVELLE_FICHE :
-
 
249
				$id_sujet = BAZ_TEMPLATE_MAIL_NOUVELLE_FICHE_SUJET;
-
 
250
				$id_corps = BAZ_TEMPLATE_MAIL_NOUVELLE_FICHE_CORPS;
-
 
251
			break ;
-
 
252
			case BAZAR_NOTIFICATION_MODIFICATION_FICHE :
-
 
253
				$id_sujet = BAZ_TEMPLATE_MAIL_MODIFIER_FICHE_SUJET;
-
 
254
				$id_corps = BAZ_TEMPLATE_MAIL_MODIFIER_FICHE_CORPS;
-
 
255
			break;
-
 
256
		}
-
 
257
		
-
 
258
		$template = new bazarTemplate($GLOBALS['_BAZAR_']['db']);
-
 
259
		//print ('toto'.$id_sujet);
-
 
260
		$sujet = html_entity_decode($template->getTemplate($id_sujet, $GLOBALS['_BAZAR_']['langue'], $GLOBALS['_BAZAR_']['id_typeannonce']));
-
 
261
		$corps = html_entity_decode($template->getTemplate($id_corps, $GLOBALS['_BAZAR_']['langue'], $GLOBALS['_BAZAR_']['id_typeannonce']));
-
 
262
		
-
 
263
		$mails = bazar::getMailSuperAdmin($GLOBALS['_BAZAR_']['id_typeannonce']);
-
 
264
		if (is_array ($mails)) {
-
 
265
			foreach ($mails as $mail) {
-
 
266
				mail ($mail, $sujet, $corps);
-
 
267
			}
-
 
268
		}
-
 
269
	}
-
 
270
	
-
 
271
	/** Effectue une requete sur bazar_nature pour remplir diverses
-
 
272
	 * globales
-
 
273
	 * 
-
 
274
	 * @global string la globale de langue (ex fr-FR)
-
 
275
	 * @global	int $GLOBALS['_BAZAR_']['id_typeannonce']
-
 
276
	 * 
-
 
277
	 * @return mixed	true ou PEAR_Error
-
 
278
	 */
-
 
279
	function chargeNature() {
-
 
280
		
-
 
281
		$requete = 'SELECT bn_label_nature, bn_condition, bn_template, bn_commentaire, bn_appropriation, bn_image_titre, bn_image_logo';
-
 
282
		$requete .= ' FROM bazar_nature WHERE bn_id_nature = '.$GLOBALS['_BAZAR_']['id_typeannonce'];
-
 
283
		if (isset($GLOBALS['_BAZAR_']['langue'])) {
-
 
284
			$requete .= ' and bn_ce_i18n like "'.$GLOBALS['_BAZAR_']['langue'].'%"';
-
 
285
		}
-
 
286
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
-
 
287
		if (DB::isError($resultat)) {
-
 
288
			return $resultat->getMessage().$resultat->getDebugInfo() ;
-
 
289
		}
-
 
290
		$ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
-
 
291
		$GLOBALS['_BAZAR_']['typeannonce']=$ligne['bn_label_nature'];
-
 
292
		$GLOBALS['_BAZAR_']['condition']=$ligne['bn_condition'];
-
 
293
	    $GLOBALS['_BAZAR_']['template']=$ligne['bn_template'];
-
 
294
		$GLOBALS['_BAZAR_']['commentaire']=$ligne['bn_commentaire'];
-
 
295
		$GLOBALS['_BAZAR_']['appropriation']=$ligne['bn_appropriation'];
-
 
296
		$GLOBALS['_BAZAR_']['image_titre']=$ligne['bn_image_titre'];
-
 
297
		$GLOBALS['_BAZAR_']['image_logo']=$ligne['bn_image_logo'];	
-
 
298
		return true;
-
 
299
	}  
-
 
300
	/** Renvoie un element de formulaire de type select ou radio
-
 
301
	 *  au vue de filtrer les resultats du bazar
-
 
302
	 * @global	mixed	$GLOBALS['_BAZAR_']['db'] identifiant de connexion a la bd
-
 
303
	 * 
-
 
304
	 * @return string	html
-
 
305
	 */
-
 
306
	function getFiltre($numero_liste, $multiple = false, $type = 'select') {
-
 
307
		$type == 'select' ? $balise = 'select' : $balise = 'radio' ;
-
 
308
		
-
 
309
		// chargement du template
-
 
310
		$tableau_template = baz_valeurs_template($GLOBALS['_BAZAR_']['template']);
-
 
311
		
-
 
312
		$html_filtre = '<select name="bazar_filtre_'.$numero_liste.'" onchange="javascript:this.form.submit();">'."\n";
-
 
313
		
-
 
314
		// Requete dans bazar_liste_valeurs
-
 
315
		$requete = 'select blv_valeur, blv_label from bazar_liste_valeurs where blv_ce_liste="'.$numero_liste.'"';
-
 
316
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
-
 
317
		
-
 
318
		if (DB::isError($resultat)) {
-
 
319
			return $resultat->getMessage().$resultat->getDebugInfo() ;
-
 
320
		}
-
 
321
		$html_filtre .= '<option id="filtre_tous" value="*" ';
-
 
322
		if (isset($_POST['bazar_filtre_'.$numero_liste]) && '*' == $_POST['bazar_filtre_'.$numero_liste]) {
-
 
323
			$html_filtre .= 'selected="selected" ';
-
 
324
		}
-
 
325
		$html_filtre .= '>'.'Tout afficher'.'</option>';
-
 
326
		
-
 
327
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
-
 
328
			$html_filtre .= '<option class="filtre_'.$ligne->blv_valeur.'" value="'.$ligne->blv_valeur.'"';
-
 
329
			if (isset($_POST['bazar_filtre_'.$numero_liste]) && $ligne->blv_valeur == $_POST['bazar_filtre_'.$numero_liste]) {
-
 
330
				$html_filtre .= 'selected="selected" ';
-
 
331
			}
-
 
332
			$html_filtre .= '>'.$ligne->blv_label.'</option>'."\n";
-
 
333
		} 
-
 
334
		$html_filtre .= '</select>'."\n";
-
 
335
		$resultat->free();
-
 
336
		return $html_filtre;
-
 
337
	}
-
 
338
	
-
 
339
	function getFiltrePlageDeDate () {
-
 
340
		if (isset ($_POST['date_debut'])) {
-
 
341
				$defaut_debut = $_POST['date_debut'];
-
 
342
			} else {
-
 
343
				$defaut_debut = '';
-
 
344
			} 
-
 
345
			if (isset ($_POST['date_fin'])) {
-
 
346
				$defaut_fin = $_POST['date_fin'];
-
 
347
			} else {
-
 
348
				$defaut_fin = '';
-
 
349
			}
-
 
350
			$formulaire_filtre .= 'de <input type="text" readonly size="10" name="date_debut" class="inputDate" id="date_debut" value="'.$defaut_debut.'" />'; 
-
 
351
			$formulaire_filtre .= ' &agrave; <input type="text" readonly size="10" name="date_fin" class="inputDate" id="date_fin" value="'.$defaut_fin.'" />'; 
-
 
352
			$formulaire_filtre .= "\n".'<script language="javascript" type="text/javascript">' ."\n".
-
 
353
					'$(document).ready(function() { $(\'#date_debut, #date_fin\').datepicker($.extend({}, $.datepicker.regional["fr-FR"],{
-
 
354
	dateFormat:\'dd-mm-yy\',
-
 
355
	buttonImage: "client/bazar/images/cal.png", 
-
 
356
	showOn: "both",
-
 
357
	beforeShow: customRange,
-
 
358
	buttonImageOnly: true'."\n". 
-
 
359
					'}));})' ."\n".
-
 
360
'function customRange(input) { return {minDate: (input.id == "date_fin" ? $("#date_debut").datepicker("getDate") : null), 
-
 
361
        maxDate: (input.id == "date_debut" ? $("#date_fin").datepicker("getDate") : null)};}' ."\n".
-
 
362
'</script>';
-
 
363
	return $formulaire_filtre;
-
 
364
	}
-
 
365
	
-
 
366
	/** Renvoie le formulaire d un filtre
-
 
367
	 *  utile dans la carte google ou dans le calendrier
-
 
368
	 * 
-
 
369
	 * @param	string	le template avec des filtres ecrits comme {filtre liste="12"}
-
 
370
	 * @global	mixed	$GLOBALS['_BAZAR_']['url']
-
 
371
	 * @return	string html
-
 
372
	 */
-
 
373
	function getFormulaireFiltre($template) {
-
 
374
		if (preg_match_all ('/{filtre liste="([0-9]+)"}/', $template, $subpattern)) {
-
 
375
			
-
 
376
			$formulaire_filtre = '<form action="'.$GLOBALS['_BAZAR_']['url']->getURL().'" method="post">'."\n";
-
 
377
			$formulaire_filtre .= '<fieldset><legend>Filtrer : </legend>';
-
 
378
			for ($i = 0; $i <count($subpattern[1]); $i++) {
-
 
379
				$formulaire_filtre .= bazar::getFiltre($subpattern[1][$i]) ; 
-
 
380
			}
-
 
381
			$formulaire_filtre .= bazar::getFiltrePlageDeDate();
-
 
382
			$formulaire_filtre .= '<input type="submit" value="Filtrer" />';
-
 
383
			$formulaire_filtre .= '</fieldset>';
-
 
384
			$formulaire_filtre .= '</form>'."\n";
-
 
385
			$html = preg_replace ('/{filtre liste="([0-9]+)"}/', $formulaire_filtre, $template);
-
 
386
		}
-
 
387
		return $html;
-
 
388
	}
236
}
389
}
237
 
390
 
238
class Bazar_element {
391
class Bazar_element {
239
	
392
	
240
	function &factory($type, $options = false)
393
	function &factory($type, $options = false)
241
    {
394
    {
242
        
395
        
243
        if (file_exists (BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php")) include_once BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php";
396
        if (file_exists (BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php")) include_once BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php";
244
        else return PEAR::raiseError("Impossible d inclure le fichier /{$type}.php", "Impossible d inclure le fichier ".
397
        else return PEAR::raiseError("Impossible d inclure le fichier /{$type}.php", "Impossible d inclure le fichier ".
245
        							BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php<br />", null, null,
398
        							BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php<br />", null, null,
246
                                    "Impossible d inclure le fichier /{$type}.php"
399
                                    "Impossible d inclure le fichier /{$type}.php"
247
                                    , 'PEAR_Error', true);;
400
                                    , 'PEAR_Error', true);;
248
        $classname = "Bazar_{$type}";
401
        $classname = "Bazar_{$type}";
249
 
402
 
250
        if (!class_exists($classname)) {
403
        if (!class_exists($classname)) {
251
            $tmp = PEAR::raiseError(null, -2, null, null,
404
            $tmp = PEAR::raiseError(null, -2, null, null,
252
                                    "la classe $classname n'existe pas"
405
                                    "la classe $classname n'existe pas"
253
                                    , 'PEAR_Error', true);
406
                                    , 'PEAR_Error', true);
254
            return $tmp;
407
            return $tmp;
255
        }
408
        }
256
 
409
 
257
        @$obj =& new $classname($options);
410
        @$obj =& new $classname($options);
258
 
411
 
259
        return $obj;
412
        return $obj;
260
    }
413
    }
261
}
414
}
262
 
415
 
263
/* +--Fin du code ----------------------------------------------------------------------------------------+
416
/* +--Fin du code ----------------------------------------------------------------------------------------+
264
*
417
*
265
* $Log: not supported by cvs2svn $
418
* $Log: not supported by cvs2svn $
-
 
419
* Revision 1.10  2008-09-17 14:08:45  alexandre_tb
-
 
420
* merge depuis aha
-
 
421
*
266
* Revision 1.9  2007-10-10 13:27:06  alexandre_tb
422
* Revision 1.9  2007-10-10 13:27:06  alexandre_tb
267
* encodage et remplacement de die en return
423
* encodage et remplacement de die en return
268
*
424
*
269
* Revision 1.8  2007-10-01 10:35:14  alexandre_tb
425
* Revision 1.8  2007-10-01 10:35:14  alexandre_tb
270
* petit hack pour tester la presence de $GLOBALS['droit_depot'] qui indique le niveau de droit minimum pour pouvoir deposer une fiche.
426
* petit hack pour tester la presence de $GLOBALS['droit_depot'] qui indique le niveau de droit minimum pour pouvoir deposer une fiche.
271
*
427
*
272
* Revision 1.7  2007-07-04 09:59:09  alexandre_tb
428
* Revision 1.7  2007-07-04 09:59:09  alexandre_tb
273
* ajout de la classe bazar, premices d une structuration du code
429
* ajout de la classe bazar, premices d une structuration du code
274
*
430
*
275
* Revision 1.6  2007/04/20 09:58:06  neiluj
431
* Revision 1.6  2007/04/20 09:58:06  neiluj
276
* correction bug $this->_id_utilisateur
432
* correction bug $this->_id_utilisateur
277
*
433
*
278
* Revision 1.5  2007/04/11 08:30:12  neiluj
434
* Revision 1.5  2007/04/11 08:30:12  neiluj
279
* remise en état du CVS...
435
* remise en état du CVS...
280
*
436
*
281
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
437
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
282
* Mise  en majuscule de select
438
* Mise  en majuscule de select
283
*
439
*
284
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
440
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
285
* ajout de la classe Administrateur_bazar
441
* ajout de la classe Administrateur_bazar
286
*
442
*
287
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
443
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
288
* changement dans les id des droit
444
* changement dans les id des droit
289
* 0 => super administrateur
445
* 0 => super administrateur
290
* 1 => redacteur
446
* 1 => redacteur
291
* 2 => administrateur
447
* 2 => administrateur
292
*
448
*
293
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
449
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
294
* version initiale
450
* version initiale
295
*
451
*
296
* +-- Fin du code ----------------------------------------------------------------------------------------+
452
* +-- Fin du code ----------------------------------------------------------------------------------------+
297
*/
453
*/
298
?>
454
?>