Subversion Repositories Applications.bazar

Rev

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