You are here

function ad_check_permission in Advertisement 7

Determine whether the user has a given privilege.

Parameters

$aid: ID of advertisement.

$permission: Permission string which should be checked (such as 'access click history')

$account: User object, which are accessing the ad or current user by default.

5 calls to ad_check_permission()
ad_activity_details in ./ad.pages.inc
ad_form in ./ad.module
Implementation of hook_form().
ad_status_array in ./ad.module
Return an array with all status values user has permission to set. A user with 'administer advertisements' permission can update any status.
theme_node_ad in ./ad.pages.inc
@file Advertisement nodes pages and forms.
_ad_html_node_form in html/ad_html.module
Adapi helper function for displaying a node form.

File

./ad.module, line 1447

Code

function ad_check_permission($aid, $string, $account = NULL) {
  global $user;
  $access = FALSE;

  // by default, check permission for current user
  if (!isset($account)) {
    $account = $user;
  }

  // user #1 has all privileges
  if ($account->uid == 1) {
    return TRUE;
  }

  // if you have administer permissions, you have all permissions
  if (user_access('administer advertisements', $account)) {
    return TRUE;
  }

  // when used in the Drupal menu, $aid may be the full ad object.
  if (is_object($aid) && isset($aid->aid)) {
    $aid = $aid->aid;
  }
  else {
    if (is_object($aid) && isset($aid->nid)) {
      $aid = $aid->nid;
    }
    else {
      if (is_object($aid)) {
        watchdog('ad', 'Invalid aid object passed into ad_permission, no aid->aid set.');
        $aid = 0;
      }
    }
  }

  // invoke ad_owners module to determine user's access
  if (module_exists('ad_owners') && function_exists('ad_owners_permission')) {
    $access = ad_owners_permission($aid, $string, $account);
  }
  else {
    if (in_array($string, array(
      'access statistics',
      'access click history',
    ))) {
      $access = TRUE;
    }
  }

  // with no ad_owners module, all other permissions are denied unless user
  // has 'administer advertisements' permission
  return $access;
}