function user_has_permission

7.x misc.inc user_has_permission($permission = "", $account = NULL)
6.x misc.inc user_has_permission($permission = "", $account = NULL)
5.x misc.inc user_has_permission($permission, $account = NULL)

Returns TRUE or FALSE if the logged in user has access based on the permission supplied.

Parameters

String $permission:

97 calls to user_has_permission()
admin.courses.inc in modules/admin/admin.courses.inc
admin.degrees.inc in modules/admin/admin.degrees.inc
admin.groups.inc in modules/admin/admin.groups.inc
admin.module in modules/admin/admin.module
The administrative configurations for FlightPath.
admin_display_main in modules/admin/admin.module
This is the "main" page for the admin module. It's what the user first sees when the click to go to the Admin page.

... See full list

File

includes/misc.inc, line 3153
This file contains misc functions for FlightPath

Code

function user_has_permission($permission = "", $account = NULL) {
  global $user;

  if ($account == NULL) {
    $account = $user;
  }
  //fpm("checking permission $permission");

  if ($account == NULL) {
    // The account is STILL null, so return FALSE.
    // Most likely anonymous user.
    return FALSE;
  }

  // If the user is admin (id == 1) then they always have access.
  if ($account->id == 1) {
    return TRUE;
  }

  if (!isset($account->permissions) || !is_array($account->permissions)) {
    return FALSE; // not set up yet; anonymous user most likely.
  }

  // Otherwise, simply check their permissions array.
  if (in_array($permission, $account->permissions)) {
    return TRUE;
  }


  return FALSE;

}