Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpermission.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpermission.php 7133 2001-09-10 23:00:02Z fh $
5 //
6 // Definition of eZPermission class
7 //
8 // Created on: <27-Sep-2000 08:05:56 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
92 // include_once( "ezuser/classes/ezmodule.php" );
93 // include_once( "ezuser/classes/ezuser.php" );
94 // include_once( "ezuser/classes/ezusergroup.php" );
95
96 class eZPermission
97 {
104 function __construct( $id="" )
105 {
106 if ( $id != "" )
107 {
108 $this->ID = $id;
109 $this->get( $this->ID );
110 }
111 }
112
116 function store()
117 {
118 $db =& eZDB::globalDatabase();
119 $dbError = false;
120 $ret = false;
121 $value_array = array();
122 $db->begin( );
123
124 $name = addslashes( $this->Name );
125
126 if ( ( $this->ModuleID != "" ) && ( $this->ModuleID != 0 ) )
127 {
128 $db->array_query( $value_array, "SELECT * FROM eZUser_Permission
129 WHERE Name='$name' AND ModuleID='$this->ModuleID'" );
130 if ( count( $value_array ) == 0 )
131 {
132 $db->lock( "eZUser_Permission" );
133
134 $nextID = $db->nextID( "eZUser_Permission", "ID" );
135
136 $ret = true;
137 if ( !isset( $this->ID ) )
138 {
139 $db->query( "INSERT INTO eZUser_Permission ( ID, Name, ModuleID )
140 VALUES
141 ( '$nextID', '$name', '$this->ModuleID' " );
142
143 $this->ID = $nextID;
144 }
145 else
146 {
147 $db->query( "UPDATE eZUser_Permission SET
148 Name='$name',
149 ModuleID='$this->ModuleID'
150 WHERE ID='$this->ID'" );
151 }
152 }
153 }
154
155 $db->unlock();
156
157 if ( $dbError == true )
158 $db->rollback( );
159 else
160 $db->commit();
161
162 return $ret;
163 }
164
169 function delete()
170 {
171 $db =& eZDB::globalDatabase();
172
173 if ( isset( $this->ID ) )
174 {
175 $db->query( "DELETE FROM eZUser_GroupPermissionLink WHERE PermissionID='$this->ID'" );
176
177 $db->query( "DELETE FROM eZUser_Permission WHERE ID='$this->ID'" );
178 }
179
180 return true;
181 }
182
188 function get( $id=-1 )
189 {
190 $db =& eZDB::globalDatabase();
191
192 $ret = false;
193
194 if ( $id != "" )
195 {
196 $db->array_query( $permission_array, "SELECT * FROM eZUser_Permission WHERE ID='$id'" );
197 if ( count( $permission_array ) > 1 )
198 {
199 die( "Error: Permission's with the same ID was found in the database. This shouldent happen." );
200 }
201 else if ( count( $permission_array ) == 1 )
202 {
203 $this->ID = $permission_array[0][$db->fieldName("ID")];
204 $this->Name = $permission_array[0][$db->fieldName("Name")];
205 $this->ModuleID = $permission_array[0][$db->fieldName("ModuleID")];
206 $ret = true;
207 }
208
209 $this->State_ = "Coherent";
210 }
211 else
212 {
213 $this->State_ = "Dirty";
214 }
215 return $ret;
216 }
217
221 function getAllByModule( $module )
222 {
223 if ( is_a( $module, "eZModule" ) )
224 {
225 $db =& eZDB::globalDatabase();
226
227 $moduleID = $module->id();
228
229 $return_array = array();
230 $permission_array = array();
231
232 $query ="SELECT ID,Name FROM eZUser_Permission
233 WHERE ModuleID='$moduleID'
234 ORDER BY Name";
235
236 $db->array_query( $permission_array, $query );
237
238 for ( $i=0; $i < count( $permission_array ); $i++ )
239 {
240 $return_array[$i] = new eZPermission( $permission_array[$i][$db->fieldName("ID")], 0 );
241 }
242
243 return $return_array;
244 }
245 }
246
250 function getAll( )
251 {
252 $db =& eZDB::globalDatabase();
253
254 $return_array = array();
255 $permission_array = array();
256
257 $db->array_query( $permission_array, "SELECT ID FROM eZUser_Permission" );
258
259 for ( $i=0; $i < count( $permission_array ); $i++ )
260 {
261 $return_array[$i] = new eZPermission( $permission_array[$i][$db->fieldName("ID")], 0 );
262 }
263
264 return $return_array;
265 }
266
267
268
272 function id()
273 {
274 return $this->ID;
275 }
276
280 function name()
281 {
282 if ( $this->State_ == "Dirty" )
283 $this->get( $this->ID );
284 return $this->Name;
285 }
286
292 function module()
293 {
294 $ret = false;
295 $module = new eZModule( );
296
297 if ( $module->get( $this->ModuleID ) )
298 {
299 $ret = $module;
300 }
301
302 return $module;
303 }
304
305
309 function setName( $value )
310 {
311 $this->Name = $value;
312 }
313
319 function setModule( $module )
320 {
321 $ret = false;
322 if ( is_a( $module, "eZModule" ) )
323 {
324 $this->ModuleID = $module->id();
325 $ret = true;
326 }
327 return $ret;
328 }
329
337 function setEnabled( $group, $value )
338 {
339 $ret = false;
340
341 if ( is_a( $group, "eZUserGroup" ) )
342 {
343 $db =& eZDB::globalDatabase();
344 $dbError = false;
345 $db->begin( );
346
347
348 $groupID = $group->id();
349
350 if ( $value )
351 {
352 $isEnabled = "1";
353 }
354 else
355 {
356 $isEnabled = "0";
357 }
358
359 $db->array_query( $value_array, "SELECT ID FROM eZUser_GroupPermissionLink
360 WHERE PermissionID='$this->ID' AND GroupID='$groupID'" );
361 if ( count( $value_array ) == 1 )
362 {
363 $valueID = $value_array[0][$db->fieldName("ID")];
364 $res = $db->query( "UPDATE eZUser_GroupPermissionLink SET
365 IsEnabled='$isEnabled' WHERE ID='$valueID'
366 " );
367 }
368 else
369 {
370 $db->lock( "eZUser_GroupPermissionLink" );
371
372 $nextID = $db->nextID( "eZUser_GroupPermissionLink", "ID" );
373
374 $res = $db->query( "INSERT INTO eZUser_GroupPermissionLink
375 ( ID, PermissionID, GroupID, IsEnabled )
376 VALUES
377 ( '$nextID', '$this->ID', '$groupID', '$isEnabled' )" );
378 }
379
380 if ( $res == false )
381 $dbError = true;
382 else
383 $ret = true;
384
385 $db->unlock();
386
387 if ( $dbError == true )
388 $db->rollback( );
389 else
390 $db->commit();
391
392 }
393
394 return $ret;
395 }
396
402 function isEnabled( $group )
403 {
404 $ret = false;
405 if ( is_a( $group, "eZUserGroup" ) )
406 {
407 $db =& eZDB::globalDatabase();
408
409 $groupID = $group->id();
410
411
412 $db->array_query( $value_array, "SELECT * FROM eZUser_GroupPermissionLink
413 WHERE PermissionID='$this->ID' AND GroupID='$groupID'" );
414 if ( count( $value_array ) == 1 )
415 {
416 if ( $value_array[0][$db->fieldName("IsEnabled")] == "1" )
417 {
418 $ret = true;
419 }
420 }
421 }
422 return $ret;
423 }
424
430 static public function checkPermission( $user, $moduleName, $permissionName )
431 {
432 $value_array = array();
433 $module = new eZModule();
434 $module = $module->exists( $moduleName );
435
436 if ( !is_a( $user, "eZUser" ) )
437 return false;
438
439 if ( $user->hasRootAccess() )
440 return true;
441
442 $ret = false;
443
444 if ( $module )
445 {
446 $db =& eZDB::globalDatabase();
447
448 $moduleID = $module->id();
449
450 $test = "SELECT * FROM eZUser_Permission WHERE Name='$permissionName' AND ModuleID='$moduleID'";
451
452 $db->array_query( $value_array, "SELECT * FROM eZUser_Permission
453 WHERE Name='$permissionName' AND ModuleID='$moduleID'", true );
454
455 if ( count( $value_array ) == 1 )
456 {
457 $permission = new eZPermission();
458 $permission->get( $value_array[0][$db->fieldName( "ID" )] );
459
460 if ( is_a( $user, "eZUser" ) )
461 {
462 $group = new eZUserGroup();
463 $groupArray = $group->getByUser( $user );
464 foreach ( $groupArray as $group )
465 {
466 if ( $permission->isEnabled( $group ) )
467 {
468 $ret = true;
469 break;
470 }
471 }
472 }
473 }
474 }
475 return $ret;
476 }
477
478
479 var $ID;
480 var $Name;
481 var $ModuleID;
482
484 var $State_;
485 }
486
487 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$groupArray
$groupArray
Definition: admin/useredit.php:452
$test
$test
Definition: checkout.php:109
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZModule
Definition: ezmodule.php:54
eZPermission
Definition: ezpermission.php:97
eZPermission\__construct
__construct( $id="")
Definition: ezpermission.php:104
eZPermission\name
name()
Definition: ezpermission.php:280
eZPermission\$State_
$State_
Indicates the state of the object. In regard to database information.
Definition: ezpermission.php:484
eZPermission\$ModuleID
$ModuleID
Definition: ezpermission.php:481
eZPermission\store
store()
Definition: ezpermission.php:116
eZPermission\setName
setName( $value)
Definition: ezpermission.php:309
eZPermission\id
id()
Definition: ezpermission.php:272
eZPermission\setModule
setModule( $module)
Definition: ezpermission.php:319
eZPermission\$ID
$ID
Definition: ezpermission.php:479
eZPermission\isEnabled
isEnabled( $group)
Definition: ezpermission.php:402
eZPermission\module
module()
Definition: ezpermission.php:292
eZPermission\setEnabled
setEnabled( $group, $value)
Definition: ezpermission.php:337
eZPermission\getAllByModule
getAllByModule( $module)
Definition: ezpermission.php:221
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZPermission\$Name
$Name
Definition: ezpermission.php:480
eZPermission\getAll
getAll()
Definition: ezpermission.php:250
eZUserGroup
Definition: ezusergroup.php:66
$module
$module
Definition: classes/admin/linkselect.php:219
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$permission
$permission
Definition: eventedit.php:315
$db
$db
Definition: ezarticle/user/authorlist.php:53
$groupID
$groupID
Definition: ezgroupeventcalendar/user/dayview.php:90
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.