Subversion Repositories Applications.bazar

Rev

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

Rev 110 Rev 205
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.3 2006-03-29 13:05:12 alexandre_tb Exp $
22
// CVS : $Id: bazar.class.php,v 1.4 2007-03-08 15:12:13 jp_milcent 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.3 $
30
*@version       $Revision: 1.4 $
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
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
75
		// 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 ;
76
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
77
		
77
		
78
		// On court-circuite si l'utilisateur n'est pas loggué
78
		// On court-circuite si l'utilisateur n'est pas loggué
79
		if (!$this->_auth->getAuth()) return false ;
79
		if (!$this->_auth->getAuth()) return false ;
80
		
80
		
81
		// Sinon on interroge la base
81
		// Sinon on interroge la base
82
		$requete = 'select bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
82
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
83
	 				$this->_id_utilisateur.
83
	 				$this->_id_utilisateur.
84
	           		' AND bd_niveau_droit=0';
84
	           		' AND bd_niveau_droit=0';
85
 
85
 
86
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
86
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
87
		if (DB::isError($resultat)) {
87
		if (DB::isError($resultat)) {
88
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
88
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
89
		}
89
		}
90
		if ($resultat->numRows() != 0) {
90
		if ($resultat->numRows() != 0) {
91
			$this->_isSuperAdmin = true ;
91
			$this->_isSuperAdmin = true ;
92
		} else {
92
		} else {
93
			$this->_isSuperAdmin = false ;	
93
			$this->_isSuperAdmin = false ;	
94
		}
94
		}
95
		return $this->_isSuperAdmin;
95
		return $this->_isSuperAdmin;
96
	}
96
	}
97
	
97
	
98
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
98
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
99
	 * 
99
	 * 
100
	 * @param interger type_annonce	Le type de l'annonce
100
	 * @param interger type_annonce	Le type de l'annonce
101
	 * 
101
	 * 
102
	 */
102
	 */
103
	 
103
	 
104
	function isAdmin($id_nature) {
104
	function isAdmin($id_nature) {
105
		// on court-circuite si l'utilisateur n'est pas loggué
105
		// on court-circuite si l'utilisateur n'est pas loggué
106
		if (!$this->_auth->getAuth()) return false ;
106
		if (!$this->_auth->getAuth()) return false ;
107
		
107
		
108
		return $this->_requeteDroit ($id_nature, 2) ;
108
		return $this->_requeteDroit ($id_nature, 2) ;
109
	}
109
	}
110
	
110
	
111
	/**	isRedacteur() - Renvoie true si l'utilisateur est rédacteur du type de fiche spécifié
111
	/**	isRedacteur() - Renvoie true si l'utilisateur est rédacteur du type de fiche spécifié
112
	 * 
112
	 * 
113
	 */
113
	 */
114
	
114
	
115
	function isRedacteur($id_nature) {
115
	function isRedacteur($id_nature) {
116
		return $this->_requeteDroit ($id_nature, 1) ;
116
		return $this->_requeteDroit ($id_nature, 1) ;
117
	}
117
	}
118
	
118
	
119
	/** _requeteDroit() - fait une requete sur la table bazar_droit
119
	/** _requeteDroit() - fait une requete sur la table bazar_droit
120
	 * 
120
	 * 
121
	 */
121
	 */
122
	
122
	
123
	function _requeteDroit ($id_nature, $niveau) {
123
	function _requeteDroit ($id_nature, $niveau) {
124
		$requete = 'select bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
124
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
125
					.$this->_id_utilisateur.
125
					.$this->_id_utilisateur.
126
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
126
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
127
 
127
 
128
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
128
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
129
		if (DB::isError($resultat)) {
129
		if (DB::isError($resultat)) {
130
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
130
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
131
		}
131
		}
132
		if ($resultat->numRows() != 0) {
132
		if ($resultat->numRows() != 0) {
133
			return true ;
133
			return true ;
134
		}
134
		}
135
		return false ;
135
		return false ;
136
	}
136
	}
137
}
137
}
138
 
138
 
139
class Utilisateur_bazar extends Administrateur_bazar {
139
class Utilisateur_bazar extends Administrateur_bazar {
140
	
140
	
141
	function Utilisateur_bazar($id_utilisateur) {
141
	function Utilisateur_bazar($id_utilisateur) {
142
		$this->_id_utilisateur = $id_utilisateur ;		
142
		$this->_id_utilisateur = $id_utilisateur ;		
143
	}	
143
	}	
144
	
144
	
145
	function isAdmin($id_nature) {
145
	function isAdmin($id_nature) {
146
		return $this->_requeteDroit ($id_nature, 2) ;
146
		return $this->_requeteDroit ($id_nature, 2) ;
147
	}
147
	}
148
	
148
	
149
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
149
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
150
	 * 
150
	 * 
151
	 */
151
	 */
152
	function isSuperAdmin() {
152
	function isSuperAdmin() {
153
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
153
		// 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 ;
154
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
155
		
155
		
156
		// Sinon on interroge la base
156
		// Sinon on interroge la base
157
		$requete = 'select bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
157
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
158
	 				$this->_id_utilisateur.
158
	 				$this->_id_utilisateur.
159
	           		' AND bd_niveau_droit=0';
159
	           		' AND bd_niveau_droit=0';
160
 
160
 
161
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
161
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
162
		if (DB::isError($resultat)) {
162
		if (DB::isError($resultat)) {
163
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
163
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
164
		}
164
		}
165
		if ($resultat->numRows() != 0) {
165
		if ($resultat->numRows() != 0) {
166
			$this->_isSuperAdmin = true ;
166
			$this->_isSuperAdmin = true ;
167
		} else {
167
		} else {
168
			$this->_isSuperAdmin = false ;	
168
			$this->_isSuperAdmin = false ;	
169
		}
169
		}
170
		return $this->_isSuperAdmin;
170
		return $this->_isSuperAdmin;
171
	}
171
	}
172
	
172
	
173
}
173
}
174
/* +--Fin du code ----------------------------------------------------------------------------------------+
174
/* +--Fin du code ----------------------------------------------------------------------------------------+
175
*
175
*
176
* $Log: not supported by cvs2svn $
176
* $Log: not supported by cvs2svn $
-
 
177
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
-
 
178
* Mise  en majuscule de select
-
 
179
*
-
 
180
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
-
 
181
* ajout de la classe Administrateur_bazar
-
 
182
*
177
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
183
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
178
* changement dans les id des droit
184
* changement dans les id des droit
179
* 0 => super administrateur
185
* 0 => super administrateur
180
* 1 => redacteur
186
* 1 => redacteur
181
* 2 => administrateur
187
* 2 => administrateur
182
*
188
*
183
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
189
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
184
* version initiale
190
* version initiale
185
*
191
*
186
* +-- Fin du code ----------------------------------------------------------------------------------------+
192
* +-- Fin du code ----------------------------------------------------------------------------------------+
187
*/
193
*/
188
?>
194
?>