Subversion Repositories Applications.bazar

Rev

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

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