Subversion Repositories Applications.bazar

Rev

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