Subversion Repositories Applications.bazar

Rev

Rev 418 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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