Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
access.class.php
Go to the documentation of this file.
00001 <?php
00046 class access {
00047 
00058         public static function check($class=null, $pids=null, $opts=null) {
00059 
00060                 $registry = registry::instance();
00061                 
00062                 $user = $registry->user;
00063 
00064                 if($class == 'public_view') {
00065                         $class = 'main';
00066                         $pids = $registry->public_view_privilege;
00067                 }
00068                 elseif($class == 'private_view') {
00069                         $class = 'main';
00070                         $pids = $registry->private_view_privilege;
00071                 }
00072                 elseif($class == 'admin_view') {
00073                         $class = 'main';
00074                         $pids = $registry->admin_view_privilege;
00075                 }
00076                 elseif($class == 'admin') {
00077                         $class = 'main';
00078                         $pids = $registry->admin_privilege;
00079                 }
00080 
00081                 $user_privileges = array();
00082                 foreach(explode(",", $user->groups) as $ugid) {
00083                         $ug = new group($ugid);
00084                         if($ug->privileges) {
00085                                 foreach(explode(",", $ug->privileges) as $gpid) {
00086                                         $p = new privilege($gpid);
00087                                         $user_privileges[$p->class][] = $p->class_id;
00088                                 }
00089                         }
00090                 }
00091                 if(!is_array($pids)) $pids = array($pids);
00092 
00093                 $access = false;
00094                 foreach($pids as $pid) {
00095                         if((isset($user_privileges[$class]) && in_array($pid, $user_privileges[$class])) || 
00096                                 (isset($user_privileges['main']) && in_array($registry->admin_privilege, $user_privileges['main']))) {
00097                                 $access = true;
00098                                 break;
00099                         }
00100                 }
00101 
00102                 if(!$access && gOpt($opts, 'exitOnFailure')) {
00103                     header("Location: ".$registry->router->linkHref('noaccess', null));
00104                     exit();
00105                 }
00106                 return $access;
00107 
00108         }
00109 
00116         public static function hasGroup($group_ids) {
00117         
00118                 $registry = registry::instance();
00119 
00120                 $user = $registry->user;
00121 
00122                 foreach($group_ids as $group_id) {
00123                         if(preg_match("#\b".preg_quote($group_id)."\b#", $user->groups)) return true;
00124                 }
00125 
00126                 return false;
00127 
00128         }
00129 
00130 
00131 }
00132 
00133 ?>