Subversion Repositories Applications.bazar

Rev

Rev 225 | Rev 269 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
91 alexandre_ 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
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                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
228 neiluj 22
// CVS : $Id: bazar.class.php,v 1.6 2007-04-20 09:58:06 neiluj Exp $
91 alexandre_ 23
/**
24
*
25
*@package bazar
26
//Auteur original :
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
28
*@author        Florian Schmitt <florian@ecole-et-nature.org>
29
*@copyright     Tela-Botanica 2000-2004
228 neiluj 30
*@version       $Revision: 1.6 $
91 alexandre_ 31
// +------------------------------------------------------------------------------------------------------+
32
*/
33
 
34
// +------------------------------------------------------------------------------------------------------+
35
// |                             LES CONSTANTES DES NIVEAUX DE DROIT                                      |
36
// +------------------------------------------------------------------------------------------------------+
37
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
 
110 alexandre_ 44
class Administrateur_bazar {
91 alexandre_ 45
 
46
	var $_auth ;
110 alexandre_ 47
 
48
	/**
49
	 * Identifiant de l'utilisateur
50
	 */
51
 
52
	var $_id_utilisateur ;
91 alexandre_ 53
 
54
	/**
55
	 * 	Vaut true si l'utilisateur est un administrateur
56
	 */
57
	var $_isSuperAdmin ;
58
 
59
	/**	Constructeur
60
	 *
61
	 * @param	object Un objet authentification
62
	 * @return void
63
	 *
64
	 */
65
 
110 alexandre_ 66
	 function Administrateur_bazar (&$AUTH) {
91 alexandre_ 67
	 	$this->_auth = $AUTH ;
110 alexandre_ 68
	 	if ($AUTH->getAuth())$this->_id_utilisateur = $this->_auth->getAuthData(BAZ_CHAMPS_ID) ;
91 alexandre_ 69
	 }
70
 
71
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
72
	 *
73
	 */
74
	function isSuperAdmin() {
228 neiluj 75
 
76
		if(empty($this->_id_utilisateur))
77
			return FALSE;
78
 
91 alexandre_ 79
		// 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 ;
81
 
228 neiluj 82
		// On court-circuite si l'utilisateur n'est pas logué
91 alexandre_ 83
		if (!$this->_auth->getAuth()) return false ;
84
 
85
		// Sinon on interroge la base
205 jp_milcent 86
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
110 alexandre_ 87
	 				$this->_id_utilisateur.
91 alexandre_ 88
	           		' AND bd_niveau_droit=0';
89
 
90
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
91
		if (DB::isError($resultat)) {
92
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
93
		}
94
		if ($resultat->numRows() != 0) {
95
			$this->_isSuperAdmin = true ;
96
		} else {
97
			$this->_isSuperAdmin = false ;
98
		}
99
		return $this->_isSuperAdmin;
100
	}
101
 
102
	/**	isAdmin () - Renvoie true si l'utilisateur est administrateur du type de fiche spécifié
103
	 *
104
	 * @param interger type_annonce	Le type de l'annonce
105
	 *
106
	 */
107
 
108
	function isAdmin($id_nature) {
228 neiluj 109
		// on court-circuite si l'utilisateur n'est pas logué
91 alexandre_ 110
		if (!$this->_auth->getAuth()) return false ;
111
 
99 alexandre_ 112
		return $this->_requeteDroit ($id_nature, 2) ;
91 alexandre_ 113
	}
114
 
115
	/**	isRedacteur() - Renvoie true si l'utilisateur est rédacteur du type de fiche spécifié
116
	 *
117
	 */
118
 
119
	function isRedacteur($id_nature) {
99 alexandre_ 120
		return $this->_requeteDroit ($id_nature, 1) ;
91 alexandre_ 121
	}
122
 
123
	/** _requeteDroit() - fait une requete sur la table bazar_droit
124
	 *
125
	 */
126
 
127
	function _requeteDroit ($id_nature, $niveau) {
228 neiluj 128
 
129
		if(empty($this->_id_utilisateur))
130
			return false;
131
 
205 jp_milcent 132
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
110 alexandre_ 133
					.$this->_id_utilisateur.
91 alexandre_ 134
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
135
 
136
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
137
		if (DB::isError($resultat)) {
138
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
139
		}
140
		if ($resultat->numRows() != 0) {
141
			return true ;
142
		}
143
		return false ;
144
	}
145
}
146
 
110 alexandre_ 147
class Utilisateur_bazar extends Administrateur_bazar {
148
 
149
	function Utilisateur_bazar($id_utilisateur) {
150
		$this->_id_utilisateur = $id_utilisateur ;
151
	}
152
 
153
	function isAdmin($id_nature) {
154
		return $this->_requeteDroit ($id_nature, 2) ;
155
	}
156
 
157
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
158
	 *
159
	 */
160
	function isSuperAdmin() {
228 neiluj 161
 
162
		if(empty($this->_id_utilisateur))
163
			return false;
164
 
110 alexandre_ 165
		// 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 ;
167
 
168
		// Sinon on interroge la base
205 jp_milcent 169
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
110 alexandre_ 170
	 				$this->_id_utilisateur.
171
	           		' AND bd_niveau_droit=0';
172
 
173
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
174
		if (DB::isError($resultat)) {
175
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
176
		}
177
		if ($resultat->numRows() != 0) {
178
			$this->_isSuperAdmin = true ;
179
		} else {
180
			$this->_isSuperAdmin = false ;
181
		}
182
		return $this->_isSuperAdmin;
183
	}
184
 
185
}
91 alexandre_ 186
/* +--Fin du code ----------------------------------------------------------------------------------------+
187
*
188
* $Log: not supported by cvs2svn $
228 neiluj 189
* Revision 1.5  2007/04/11 08:30:12  neiluj
190
* remise en état du CVS...
191
*
205 jp_milcent 192
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
193
* Mise  en majuscule de select
194
*
195
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
196
* ajout de la classe Administrateur_bazar
197
*
110 alexandre_ 198
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
199
* changement dans les id des droit
200
* 0 => super administrateur
201
* 1 => redacteur
202
* 2 => administrateur
203
*
99 alexandre_ 204
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
205
* version initiale
206
*
91 alexandre_ 207
* +-- Fin du code ----------------------------------------------------------------------------------------+
208
*/
209
?>