You are here

function ad_access in Advertisement 7.2

Same name and namespace in other branches
  1. 5.2 ad.module \ad_access()
  2. 5 ad.module \ad_access()
  3. 6.3 ad.module \ad_access()
  4. 6 ad.module \ad_access()
  5. 6.2 ad.module \ad_access()

Checks ad access for various operations.

Parameters

$op: The operation being performed. One of 'view', 'update', 'create' or 'delete'.

$ad: Optionally an ad to check access for or for the create operation the ad type. If nothing is given access permissions for all ads are returned.

$account: The user to check for. Leave it to NULL to check for the current user.

2 string references to 'ad_access'
ad_entity_info in ./ad.module
Implements hook_entity_info().
ad_ui_menu in ./ad_ui.module
Implements hook_menu().

File

./ad.module, line 366
Defines the core ad entity, including the entity itself, the bundle definitions (ad types), and various API functions to manage ads and interact with them through forms and autocompletes.

Code

function ad_access($op, $ad = NULL, $account = NULL) {
  global $user;
  $account = isset($account) ? $account : $user;
  if (user_access('administer ads', $account)) {
    return TRUE;
  }
  if ($op == 'view' && user_access('access ads', $account)) {
    return TRUE;
  }
  if (isset($ad) && is_string($ad) && $op == 'create' && user_access('create ' . $ad, $account)) {
    return TRUE;
  }
  if (isset($ad) && ($op == 'update' || $op == 'delete')) {
    if (user_access('edit any ' . $ad->type, $account)) {
      return TRUE;
    }

    // Others either don't have any access or must match the ad uid.
    if ($account->uid && user_access('edit own ' . $ad->type, $account) && $ad->uid == $account->uid) {
      return TRUE;
    }
  }
  return FALSE;
}