Advertisement
pbowers

Untitled

Sep 1st, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. function hasPermission($permissions, $user_id=null, $allow_master_user=true) {
  2.     global $user;
  3.     $db = DB::getInstance();
  4.  
  5.   // decide which user_id we're working on
  6.     if (!$user_id)
  7.         $user_id = $user->data()->id; // self
  8.  
  9.     //Grant access if master user
  10.     if ($allow_master_user && $user_id == 1)
  11.         return true;
  12.  
  13.     foreach((array)$permissions as $perm){
  14.         echo "DEBUG: Looking for user_id=$user_id and perm=$perm<br />\n";
  15.         $query = $db->query("SELECT id FROM user_permission_matches  WHERE user_id = ? AND permission_id = ?",array($user_id,$perm));
  16.         if ($query->count() > 0) {
  17.             echo "DEBUG: count=".$query->count()."<br />\n";
  18.             return true;
  19.         }
  20.     }
  21.     return false;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement