Subversion Repositories Applications.bazar

Rev

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

Rev 228 Rev 269
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.6 2007-04-20 09:58:06 neiluj Exp $
22
// CVS : $Id: bazar.class.php,v 1.7 2007-07-04 09:59:09 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.6 $
30
*@version       $Revision: 1.7 $
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
 
-
 
38
define ('BAZ_DROIT_SUPER_ADMINISTRATEUR', 0);
-
 
39
define ('BAZ_DROIT_ADMINISTRATEUR', 2);
37
 
40
define ('BAZ_DROIT_REDACTEUR', 1);
38
 
41
 
39
// +------------------------------------------------------------------------------------------------------+
42
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
43
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
44
// +------------------------------------------------------------------------------------------------------+
-
 
45
 
42
 
46
include_once PAP_CHEMIN_API_PEAR.'PEAR.php';
43
 
47
 
44
class Administrateur_bazar {
48
class Administrateur_bazar {
45
 
49
 
46
	var $_auth ;
50
	var $_auth ;
47
	
51
	
48
	/**
52
	/**
49
	 * Identifiant de l'utilisateur
53
	 * Identifiant de l'utilisateur
50
	 */
54
	 */
51
	
55
	
52
	var $_id_utilisateur ;
56
	var $_id_utilisateur ;
53
 
57
 
54
	/**
58
	/**
55
	 * 	Vaut true si l'utilisateur est un administrateur
59
	 * 	Vaut true si l'utilisateur est un administrateur
56
	 */
60
	 */
57
	var $_isSuperAdmin ;
61
	var $_isSuperAdmin ;
58
	
62
	
59
	/**	Constructeur
63
	/**	Constructeur
60
	 * 
64
	 * 
61
	 * @param	object Un objet authentification
65
	 * @param	object Un objet authentification
62
	 * @return void
66
	 * @return void
63
	 * 
67
	 * 
64
	 */
68
	 */
65
	 
69
	 
66
	 function Administrateur_bazar (&$AUTH) {
70
	 function Administrateur_bazar (&$AUTH) {
67
	 	$this->_auth = $AUTH ;
71
	 	$this->_auth = $AUTH ;
68
	 	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) ;
69
	 }	
73
	 }	
70
	
74
	
71
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
75
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
72
	 * 
76
	 * 
73
	 */
77
	 */
74
	function isSuperAdmin() {
78
	function isSuperAdmin() {
75
		
79
		
76
		if(empty($this->_id_utilisateur)) 
80
		if(empty($this->_id_utilisateur)) 
77
			return FALSE;
81
			return FALSE;
78
		
82
		
79
		// 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
80
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
84
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
81
		
85
		
82
		// On court-circuite si l'utilisateur n'est pas logué
86
		// On court-circuite si l'utilisateur n'est pas logué
83
		if (!$this->_auth->getAuth()) return false ;
87
		if (!$this->_auth->getAuth()) return false ;
84
		
88
		
85
		// Sinon on interroge la base
89
		// Sinon on interroge la base
86
		$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='.
87
	 				$this->_id_utilisateur.
91
	 				$this->_id_utilisateur.
88
	           		' AND bd_niveau_droit=0';
92
	           		' AND bd_niveau_droit=0';
89
 
93
 
90
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
94
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
91
		if (DB::isError($resultat)) {
95
		if (DB::isError($resultat)) {
92
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
96
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
93
		}
97
		}
94
		if ($resultat->numRows() != 0) {
98
		if ($resultat->numRows() != 0) {
95
			$this->_isSuperAdmin = true ;
99
			$this->_isSuperAdmin = true ;
96
		} else {
100
		} else {
97
			$this->_isSuperAdmin = false ;	
101
			$this->_isSuperAdmin = false ;	
98
		}
102
		}
99
		return $this->_isSuperAdmin;
103
		return $this->_isSuperAdmin;
100
	}
104
	}
101
	
105
	
102
	/**	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é
103
	 * 
107
	 * 
104
	 * @param interger type_annonce	Le type de l'annonce
108
	 * @param interger type_annonce	Le type de l'annonce
105
	 * 
109
	 * 
106
	 */
110
	 */
107
	 
111
	 
108
	function isAdmin($id_nature) {
112
	function isAdmin($id_nature) {
109
		// on court-circuite si l'utilisateur n'est pas logué
113
		// on court-circuite si l'utilisateur n'est pas logué
110
		if (!$this->_auth->getAuth()) return false ;
114
		if (!$this->_auth->getAuth()) return false ;
111
		
115
		
112
		return $this->_requeteDroit ($id_nature, 2) ;
116
		return $this->_requeteDroit ($id_nature, 2) ;
113
	}
117
	}
114
	
118
	
115
	/**	isRedacteur() - Renvoie true si l'utilisateur est rédacteur du type de fiche spécifié
119
	/**	isRedacteur() - Renvoie true si l'utilisateur est rédacteur du type de fiche spécifié
116
	 * 
120
	 * 
117
	 */
121
	 */
118
	
122
	
119
	function isRedacteur($id_nature) {
123
	function isRedacteur($id_nature) {
120
		return $this->_requeteDroit ($id_nature, 1) ;
124
		return $this->_requeteDroit ($id_nature, 1) ;
121
	}
125
	}
122
	
126
	
123
	/** _requeteDroit() - fait une requete sur la table bazar_droit
127
	/** _requeteDroit() - fait une requete sur la table bazar_droit
124
	 * 
128
	 * 
125
	 */
129
	 */
126
	
130
	
127
	function _requeteDroit ($id_nature, $niveau) {
131
	function _requeteDroit ($id_nature, $niveau) {
128
		
132
		
129
		if(empty($this->_id_utilisateur)) 
133
		if(empty($this->_id_utilisateur)) 
130
			return false;
134
			return false;
131
			
135
			
132
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
136
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
133
					.$this->_id_utilisateur.
137
					.$this->_id_utilisateur.
134
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
138
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
135
 
139
 
136
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
140
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
137
		if (DB::isError($resultat)) {
141
		if (DB::isError($resultat)) {
138
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
142
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
139
		}
143
		}
140
		if ($resultat->numRows() != 0) {
144
		if ($resultat->numRows() != 0) {
141
			return true ;
145
			return true ;
142
		}
146
		}
143
		return false ;
147
		return false ;
144
	}
148
	}
145
}
149
}
146
 
150
 
147
class Utilisateur_bazar extends Administrateur_bazar {
151
class Utilisateur_bazar extends Administrateur_bazar {
148
	
152
	
149
	function Utilisateur_bazar($id_utilisateur) {
153
	function Utilisateur_bazar($id_utilisateur) {
150
		$this->_id_utilisateur = $id_utilisateur ;		
154
		$this->_id_utilisateur = $id_utilisateur ;		
151
	}	
155
	}	
152
	
156
	
153
	function isAdmin($id_nature) {
157
	function isAdmin($id_nature) {
154
		return $this->_requeteDroit ($id_nature, 2) ;
158
		return $this->_requeteDroit ($id_nature, 2) ;
155
	}
159
	}
156
	
160
	
157
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
161
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
158
	 * 
162
	 * 
159
	 */
163
	 */
160
	function isSuperAdmin() {
164
	function isSuperAdmin() {
161
		
165
		
162
		if(empty($this->_id_utilisateur)) 
166
		if(empty($this->_id_utilisateur)) 
163
			return false;
167
			return false;
164
			
168
			
165
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
169
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
166
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
170
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
167
		
171
		
168
		// Sinon on interroge la base
172
		// Sinon on interroge la base
169
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
173
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
170
	 				$this->_id_utilisateur.
174
	 				$this->_id_utilisateur.
171
	           		' AND bd_niveau_droit=0';
175
	           		' AND bd_niveau_droit=0';
172
 
176
 
173
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
177
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
174
		if (DB::isError($resultat)) {
178
		if (DB::isError($resultat)) {
175
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
179
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
176
		}
180
		}
177
		if ($resultat->numRows() != 0) {
181
		if ($resultat->numRows() != 0) {
178
			$this->_isSuperAdmin = true ;
182
			$this->_isSuperAdmin = true ;
179
		} else {
183
		} else {
180
			$this->_isSuperAdmin = false ;	
184
			$this->_isSuperAdmin = false ;	
181
		}
185
		}
182
		return $this->_isSuperAdmin;
186
		return $this->_isSuperAdmin;
183
	}
187
	}
184
	
188
	
185
}
189
}
-
 
190
 
-
 
191
 
-
 
192
 
-
 
193
 
-
 
194
class bazar extends PEAR {
-
 
195
	
-
 
196
	/**
-
 
197
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type 
-
 
198
	 * 					de fiche passe en parametre
-
 
199
	 * 
-
 
200
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
-
 
201
	 * 	@param integer L identifiant de la nature
-
 
202
	 */
-
 
203
	function getMailAdmin($id_nature) {
-
 
204
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
-
 
205
				'where bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit="'.BAZ_DROIT_ADMINISTRATEUR.'"' .
-
 
206
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
-
 
207
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
-
 
208
		if (DB::isError($resultat)) $this->raiseError();
-
 
209
		$tableau_mail = array();
-
 
210
		if ($resultat->numRows() == 0) return false;
-
 
211
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
-
 
212
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
-
 
213
		}
-
 
214
		return $tableau_mail;
-
 
215
	}
-
 
216
}
-
 
217
 
186
/* +--Fin du code ----------------------------------------------------------------------------------------+
218
/* +--Fin du code ----------------------------------------------------------------------------------------+
187
*
219
*
188
* $Log: not supported by cvs2svn $
220
* $Log: not supported by cvs2svn $
-
 
221
* Revision 1.6  2007/04/20 09:58:06  neiluj
-
 
222
* correction bug $this->_id_utilisateur
-
 
223
*
189
* Revision 1.5  2007/04/11 08:30:12  neiluj
224
* Revision 1.5  2007/04/11 08:30:12  neiluj
190
* remise en état du CVS...
225
* remise en état du CVS...
191
*
226
*
192
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
227
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
193
* Mise  en majuscule de select
228
* Mise  en majuscule de select
194
*
229
*
195
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
230
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
196
* ajout de la classe Administrateur_bazar
231
* ajout de la classe Administrateur_bazar
197
*
232
*
198
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
233
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
199
* changement dans les id des droit
234
* changement dans les id des droit
200
* 0 => super administrateur
235
* 0 => super administrateur
201
* 1 => redacteur
236
* 1 => redacteur
202
* 2 => administrateur
237
* 2 => administrateur
203
*
238
*
204
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
239
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
205
* version initiale
240
* version initiale
206
*
241
*
207
* +-- Fin du code ----------------------------------------------------------------------------------------+
242
* +-- Fin du code ----------------------------------------------------------------------------------------+
208
*/
243
*/
209
?>
244
?>