Subversion Repositories Applications.bazar

Rev

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

Rev 317 Rev 392
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.9 2007-10-10 13:27:06 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.9 $
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
 
47
 
48
class Administrateur_bazar {
48
class Administrateur_bazar {
49
 
49
 
50
	var $_auth ;
50
	var $_auth ;
51
	
51
	
52
	/**
52
	/**
53
	 * Identifiant de l'utilisateur
53
	 * Identifiant de l'utilisateur
54
	 */
54
	 */
55
	
55
	
56
	var $_id_utilisateur ;
56
	var $_id_utilisateur ;
57
 
57
 
58
	/**
58
	/**
59
	 * 	Vaut true si l'utilisateur est un administrateur
59
	 * 	Vaut true si l'utilisateur est un administrateur
60
	 */
60
	 */
61
	var $_isSuperAdmin ;
61
	var $_isSuperAdmin ;
62
	
62
	
63
	/**	Constructeur
63
	/**	Constructeur
64
	 * 
64
	 * 
65
	 * @param	object Un objet authentification
65
	 * @param	object Un objet authentification
66
	 * @return void
66
	 * @return void
67
	 * 
67
	 * 
68
	 */
68
	 */
69
	 
69
	 
70
	 function Administrateur_bazar (&$AUTH) {
70
	 function Administrateur_bazar (&$AUTH) {
71
	 	$this->_auth = $AUTH ;
71
	 	$this->_auth = $AUTH ;
72
	 	if ($AUTH->getAuth())$this->_id_utilisateur = $this->_auth->getAuthData(BAZ_CHAMPS_ID) ;
72
	 	if ($AUTH->getAuth())$this->_id_utilisateur = $this->_auth->getAuthData(BAZ_CHAMPS_ID) ;
73
	 }	
73
	 }	
74
	
74
	
75
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
75
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
76
	 * 
76
	 * 
77
	 */
77
	 */
78
	function isSuperAdmin() {
78
	function isSuperAdmin() {
79
		
79
		
80
		if(empty($this->_id_utilisateur)) 
80
		if(empty($this->_id_utilisateur)) 
81
			return FALSE;
81
			return FALSE;
82
		
82
		
83
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
83
		// 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 ;
84
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
85
		
85
		
86
		// On court-circuite si l'utilisateur n'est pas logué
86
		// On court-circuite si l'utilisateur n'est pas logué
87
		if (!$this->_auth->getAuth()) return false ;
87
		if (!$this->_auth->getAuth()) return false ;
88
		
88
		
89
		// Sinon on interroge la base
89
		// Sinon on interroge la base
90
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
90
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
91
	 				$this->_id_utilisateur.
91
	 				$this->_id_utilisateur.
92
	           		' AND bd_niveau_droit=0';
92
	           		' AND bd_niveau_droit=0';
93
 
93
 
94
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
94
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
95
		if (DB::isError($resultat)) {
95
		if (DB::isError($resultat)) {
96
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
96
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
97
		}
97
		}
98
		if ($resultat->numRows() != 0) {
98
		if ($resultat->numRows() != 0) {
99
			$this->_isSuperAdmin = true ;
99
			$this->_isSuperAdmin = true ;
100
		} else {
100
		} else {
101
			$this->_isSuperAdmin = false ;	
101
			$this->_isSuperAdmin = false ;	
102
		}
102
		}
103
		return $this->_isSuperAdmin;
103
		return $this->_isSuperAdmin;
104
	}
104
	}
105
	
105
	
106
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
106
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
107
	 * 
107
	 * 
108
	 * @param interger type_annonce	Le type de l'annonce
108
	 * @param interger type_annonce	Le type de l'annonce
109
	 * 
109
	 * 
110
	 */
110
	 */
111
	 
111
	 
112
	function isAdmin($id_nature) {
112
	function isAdmin($id_nature) {
113
		// on court-circuite si l'utilisateur n'est pas logué
113
		// on court-circuite si l'utilisateur n'est pas logué
114
		if (!$this->_auth->getAuth()) return false ;
114
		if (!$this->_auth->getAuth()) return false ;
115
		
115
		
116
		return $this->_requeteDroit ($id_nature, 2) ;
116
		return $this->_requeteDroit ($id_nature, 2) ;
117
	}
117
	}
118
	
118
	
119
	/**	isRedacteur() - Renvoie true si l'utilisateur est redacteur du type de fiche specifie
119
	/**	isRedacteur() - Renvoie true si l'utilisateur est redacteur du type de fiche specifie
120
	 * 
120
	 * 
121
	 */
121
	 */
122
	
122
	
123
	function isRedacteur($id_nature) {
123
	function isRedacteur($id_nature) {
124
		if (isset($GLOBALS['droit_depot']) && $GLOBALS['droit_depot'] == 3) return true;
124
		if (isset($GLOBALS['droit_depot']) && $GLOBALS['droit_depot'] == 3) return true;
125
		return $this->_requeteDroit ($id_nature, 1) ;
125
		return $this->_requeteDroit ($id_nature, 1) ;
126
	}
126
	}
127
	
127
	
128
	/** _requeteDroit() - fait une requete sur la table bazar_droit
128
	/** _requeteDroit() - fait une requete sur la table bazar_droit
129
	 * 
129
	 * 
130
	 */
130
	 */
131
	
131
	
132
	function _requeteDroit ($id_nature, $niveau) {
132
	function _requeteDroit ($id_nature, $niveau) {
133
		
133
		
134
		if(empty($this->_id_utilisateur)) 
134
		if(empty($this->_id_utilisateur)) 
135
			return false;
135
			return false;
136
			
136
			
137
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
137
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
138
					.$this->_id_utilisateur.
138
					.$this->_id_utilisateur.
139
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
139
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
140
 
140
 
141
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
141
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
142
		if (DB::isError($resultat)) {
142
		if (DB::isError($resultat)) {
143
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
143
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
144
		}
144
		}
145
		if ($resultat->numRows() != 0) {
145
		if ($resultat->numRows() != 0) {
146
			return true ;
146
			return true ;
147
		}
147
		}
148
		return false ;
148
		return false ;
149
	}
149
	}
150
}
150
}
151
 
151
 
152
class Utilisateur_bazar extends Administrateur_bazar {
152
class Utilisateur_bazar extends Administrateur_bazar {
153
	
153
	
154
	function Utilisateur_bazar($id_utilisateur) {
154
	function Utilisateur_bazar($id_utilisateur) {
155
		$this->_id_utilisateur = $id_utilisateur ;		
155
		$this->_id_utilisateur = $id_utilisateur ;		
156
	}	
156
	}	
157
	
157
	
158
	function isAdmin($id_nature) {
158
	function isAdmin($id_nature) {
159
		return $this->_requeteDroit ($id_nature, 2) ;
159
		return $this->_requeteDroit ($id_nature, 2) ;
160
	}
160
	}
161
	
161
	
162
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
162
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
163
	 * 
163
	 * 
164
	 */
164
	 */
165
	function isSuperAdmin() {
165
	function isSuperAdmin() {
166
		
166
		
167
		if(empty($this->_id_utilisateur)) 
167
		if(empty($this->_id_utilisateur)) 
168
			return false;
168
			return false;
169
			
169
			
170
		// 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
171
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
171
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
172
		
172
		
173
		// Sinon on interroge la base
173
		// Sinon on interroge la base
174
		$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='.
175
	 				$this->_id_utilisateur.
175
	 				$this->_id_utilisateur.
176
	           		' AND bd_niveau_droit=0';
176
	           		' AND bd_niveau_droit=0';
177
 
177
 
178
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
178
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
179
		if (DB::isError($resultat)) {
179
		if (DB::isError($resultat)) {
180
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
180
			return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
181
		}
181
		}
182
		if ($resultat->numRows() != 0) {
182
		if ($resultat->numRows() != 0) {
183
			$this->_isSuperAdmin = true ;
183
			$this->_isSuperAdmin = true ;
184
		} else {
184
		} else {
185
			$this->_isSuperAdmin = false ;	
185
			$this->_isSuperAdmin = false ;	
186
		}
186
		}
187
		return $this->_isSuperAdmin;
187
		return $this->_isSuperAdmin;
188
	}
188
	}
189
	
189
	
190
}
190
}
191
 
191
 
192
 
192
 
193
 
193
 
194
 
194
 
195
class bazar extends PEAR {
195
class bazar extends PEAR {
196
	
196
	
197
	/**
197
	/**
198
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type 
198
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type 
199
	 * 					de fiche passe en parametre
199
	 * 					de fiche passe en parametre
200
	 * 
200
	 * 
201
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
201
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
202
	 * 	@param integer L identifiant de la nature
202
	 * 	@param integer L identifiant de la nature
203
	 */
203
	 */
204
	function getMailAdmin($id_nature) {
204
	function getMailAdmin($id_nature) {
205
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
205
		$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.'"' .
206
				'where bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit="'.BAZ_DROIT_ADMINISTRATEUR.'"' .
207
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
207
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
208
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
208
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
209
		if (DB::isError($resultat)) $this->raiseError();
209
		if (DB::isError($resultat)) $this->raiseError();
210
		$tableau_mail = array();
210
		$tableau_mail = array();
211
		if ($resultat->numRows() == 0) return false;
211
		if ($resultat->numRows() == 0) return false;
212
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
212
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
213
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
213
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
214
		}
214
		}
215
		return $tableau_mail;
215
		return $tableau_mail;
216
	}
216
	}
-
 
217
	
-
 
218
	/**
-
 
219
	 * 	getMailAdmin	Renvoie un tableau de mail des super administrateurs  
-
 
220
	 * 
-
 
221
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
-
 
222
	 */
-
 
223
	function getMailSuperAdmin() {
-
 
224
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
-
 
225
				'where bd_niveau_droit="'.BAZ_DROIT_SUPER_ADMINISTRATEUR.'"' .
-
 
226
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
-
 
227
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
-
 
228
		if (DB::isError($resultat)) $this->raiseError();
-
 
229
		$tableau_mail = array();
-
 
230
		if ($resultat->numRows() == 0) return false;
-
 
231
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
-
 
232
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
-
 
233
		}
-
 
234
		return $tableau_mail;
-
 
235
	}
-
 
236
}
-
 
237
 
-
 
238
class Bazar_element {
-
 
239
	
-
 
240
	function &factory($type, $options = false)
-
 
241
    {
-
 
242
        
-
 
243
        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 ".
-
 
245
        							BAZ_CHEMIN_APPLI."bibliotheque/elements/{$type}.php<br />", null, null,
-
 
246
                                    "Impossible d inclure le fichier /{$type}.php"
-
 
247
                                    , 'PEAR_Error', true);;
-
 
248
        $classname = "Bazar_{$type}";
-
 
249
 
-
 
250
        if (!class_exists($classname)) {
-
 
251
            $tmp = PEAR::raiseError(null, -2, null, null,
-
 
252
                                    "la classe $classname n'existe pas"
-
 
253
                                    , 'PEAR_Error', true);
-
 
254
            return $tmp;
-
 
255
        }
-
 
256
 
-
 
257
        @$obj =& new $classname($options);
-
 
258
 
-
 
259
        return $obj;
-
 
260
    }
217
}
261
}
218
 
262
 
219
/* +--Fin du code ----------------------------------------------------------------------------------------+
263
/* +--Fin du code ----------------------------------------------------------------------------------------+
220
*
264
*
221
* $Log: not supported by cvs2svn $
265
* $Log: not supported by cvs2svn $
-
 
266
* Revision 1.9  2007-10-10 13:27:06  alexandre_tb
-
 
267
* encodage et remplacement de die en return
-
 
268
*
222
* Revision 1.8  2007-10-01 10:35:14  alexandre_tb
269
* Revision 1.8  2007-10-01 10:35:14  alexandre_tb
223
* petit hack pour tester la presence de $GLOBALS['droit_depot'] qui indique le niveau de droit minimum pour pouvoir deposer une fiche.
270
* petit hack pour tester la presence de $GLOBALS['droit_depot'] qui indique le niveau de droit minimum pour pouvoir deposer une fiche.
224
*
271
*
225
* Revision 1.7  2007-07-04 09:59:09  alexandre_tb
272
* Revision 1.7  2007-07-04 09:59:09  alexandre_tb
226
* ajout de la classe bazar, premices d une structuration du code
273
* ajout de la classe bazar, premices d une structuration du code
227
*
274
*
228
* Revision 1.6  2007/04/20 09:58:06  neiluj
275
* Revision 1.6  2007/04/20 09:58:06  neiluj
229
* correction bug $this->_id_utilisateur
276
* correction bug $this->_id_utilisateur
230
*
277
*
231
* Revision 1.5  2007/04/11 08:30:12  neiluj
278
* Revision 1.5  2007/04/11 08:30:12  neiluj
232
* remise en état du CVS...
279
* remise en état du CVS...
233
*
280
*
234
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
281
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
235
* Mise  en majuscule de select
282
* Mise  en majuscule de select
236
*
283
*
237
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
284
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
238
* ajout de la classe Administrateur_bazar
285
* ajout de la classe Administrateur_bazar
239
*
286
*
240
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
287
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
241
* changement dans les id des droit
288
* changement dans les id des droit
242
* 0 => super administrateur
289
* 0 => super administrateur
243
* 1 => redacteur
290
* 1 => redacteur
244
* 2 => administrateur
291
* 2 => administrateur
245
*
292
*
246
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
293
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
247
* version initiale
294
* version initiale
248
*
295
*
249
* +-- Fin du code ----------------------------------------------------------------------------------------+
296
* +-- Fin du code ----------------------------------------------------------------------------------------+
250
*/
297
*/
251
?>
298
?>