Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement