Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // hasPermission()
- // Parameters:
- // $permissions: can be either a scalar or an array of values from permissions.id (1=User, 2=Admin usually in US)
- // $user_id: allows to ask for a given user; if not provided the current user will be assumed
- // $allow_master_user: user_id=1 (Admin) is a "special" user in US - under normal circumstances this user is part
- // of ALL permission groups
- // Return value:
- // return TRUE if the specified user is in (one of) the permission groups
- // return FALSE otherwise
- function hasPermission($permissions, $user_id=null, $allow_master_user=true) {
- global $user;
- $db = DB::getInstance();
- // decide which user_id we're working on
- if (!$user_id)
- $user_id = $user->data()->id; // self
- //Grant access if master user
- if ($allow_master_user && $user_id == 1)
- return true;
- foreach((array)$permissions as $perm){
- #echo "DEBUG: Looking for user_id=$user_id and perm=$perm<br />\n";
- $query = $db->query("SELECT id FROM user_permission_matches WHERE user_id = ? AND permission_id = ?",array($user_id,$perm));
- if ($query->count() > 0) {
- #echo "DEBUG: count=".$query->count()."<br />\n";
- return true;
- }
- }
- return false;
- }
- function checkPermissions($permissions) {
- return hasPermissions($permissions[0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement