Subversion Repositories Applications.bazar

Rev

Rev 269 | Rev 317 | 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
// +------------------------------------------------------------------------------------------------------+
308 alexandre_ 22
// CVS : $Id: bazar.class.php,v 1.8 2007-10-01 10:35:14 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
308 alexandre_ 30
*@version       $Revision: 1.8 $
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) {
308 alexandre_ 124
		if (isset($GLOBALS['droit_depot']) && $GLOBALS['droit_depot'] == 3) return true;
99 alexandre_ 125
		return $this->_requeteDroit ($id_nature, 1) ;
91 alexandre_ 126
	}
127
 
128
	/** _requeteDroit() - fait une requete sur la table bazar_droit
129
	 *
130
	 */
131
 
132
	function _requeteDroit ($id_nature, $niveau) {
228 neiluj 133
 
134
		if(empty($this->_id_utilisateur))
135
			return false;
136
 
205 jp_milcent 137
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='
110 alexandre_ 138
					.$this->_id_utilisateur.
91 alexandre_ 139
	           		' AND bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit='.$niveau;
140
 
141
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
142
		if (DB::isError($resultat)) {
143
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
144
		}
145
		if ($resultat->numRows() != 0) {
146
			return true ;
147
		}
148
		return false ;
149
	}
150
}
151
 
110 alexandre_ 152
class Utilisateur_bazar extends Administrateur_bazar {
153
 
154
	function Utilisateur_bazar($id_utilisateur) {
155
		$this->_id_utilisateur = $id_utilisateur ;
156
	}
157
 
158
	function isAdmin($id_nature) {
159
		return $this->_requeteDroit ($id_nature, 2) ;
160
	}
161
 
162
	/**	isSuperAdmin () - Renvoie true si l'utilisateur est un super administrateur
163
	 *
164
	 */
165
	function isSuperAdmin() {
228 neiluj 166
 
167
		if(empty($this->_id_utilisateur))
168
			return false;
169
 
110 alexandre_ 170
		// On court-circuite si la question a déjà été posé pour ne pas refaire la requete
171
		if (isset ($this->_isSuperAdmin)) return $this->_isSuperAdmin ;
172
 
173
		// Sinon on interroge la base
205 jp_milcent 174
		$requete = 'SELECT bd_niveau_droit FROM bazar_droits WHERE bd_id_utilisateur='.
110 alexandre_ 175
	 				$this->_id_utilisateur.
176
	           		' AND bd_niveau_droit=0';
177
 
178
		$resultat = $GLOBALS['_BAZAR_']['db']->query ($requete) ;
179
		if (DB::isError($resultat)) {
180
			die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
181
		}
182
		if ($resultat->numRows() != 0) {
183
			$this->_isSuperAdmin = true ;
184
		} else {
185
			$this->_isSuperAdmin = false ;
186
		}
187
		return $this->_isSuperAdmin;
188
	}
189
 
190
}
269 alexandre_ 191
 
192
 
193
 
194
 
195
class bazar extends PEAR {
196
 
197
	/**
198
	 * 	getMailAdmin	Renvoie un tableau de mail des administrateurs du type
199
	 * 					de fiche passe en parametre
200
	 *
201
	 * 	@global DB Un objet DB de PEAR $GLOBALS['_BAZAR_']['db']
202
	 * 	@param integer L identifiant de la nature
203
	 */
204
	function getMailAdmin($id_nature) {
205
		$requete = 'select '.BAZ_CHAMPS_EMAIL.' from '.BAZ_ANNUAIRE.', bazar_droits ' .
206
				'where bd_id_nature_offre="'.$id_nature.'" and bd_niveau_droit="'.BAZ_DROIT_ADMINISTRATEUR.'"' .
207
						' and '.BAZ_CHAMPS_ID.'= bd_id_utilisateur';
208
		$resultat = $GLOBALS['_BAZAR_']['db']->query($requete);
209
		if (DB::isError($resultat)) $this->raiseError();
210
		$tableau_mail = array();
211
		if ($resultat->numRows() == 0) return false;
212
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
213
			array_push ($tableau_mail, $ligne[BAZ_CHAMPS_EMAIL]) ;
214
		}
215
		return $tableau_mail;
216
	}
217
}
218
 
91 alexandre_ 219
/* +--Fin du code ----------------------------------------------------------------------------------------+
220
*
221
* $Log: not supported by cvs2svn $
308 alexandre_ 222
* Revision 1.7  2007-07-04 09:59:09  alexandre_tb
223
* ajout de la classe bazar, premices d une structuration du code
224
*
269 alexandre_ 225
* Revision 1.6  2007/04/20 09:58:06  neiluj
226
* correction bug $this->_id_utilisateur
227
*
228 neiluj 228
* Revision 1.5  2007/04/11 08:30:12  neiluj
229
* remise en état du CVS...
230
*
205 jp_milcent 231
* Revision 1.3.2.1  2007/03/07 16:49:21  jp_milcent
232
* Mise  en majuscule de select
233
*
234
* Revision 1.3  2006/03/29 13:05:12  alexandre_tb
235
* ajout de la classe Administrateur_bazar
236
*
110 alexandre_ 237
* Revision 1.2  2006/02/09 11:06:12  alexandre_tb
238
* changement dans les id des droit
239
* 0 => super administrateur
240
* 1 => redacteur
241
* 2 => administrateur
242
*
99 alexandre_ 243
* Revision 1.1  2006/02/07 11:08:06  alexandre_tb
244
* version initiale
245
*
91 alexandre_ 246
* +-- Fin du code ----------------------------------------------------------------------------------------+
247
*/
248
?>