You are here

function ad_adaccess in Advertisement 5

Same name and namespace in other branches
  1. 6 ad.module \ad_adaccess()

Determine whether the user has a given privilege.

11 calls to ad_adaccess()
ad_form in ./ad.module
Drupal _form hook.
ad_html_node_form in html/ad_html.module
Adapi helper function for displaying a node form.
ad_image_adapi in image/ad_image.module
Adapi implementation.
ad_menu in ./ad.module
Implementation of hook_menu().
ad_notify_confirm_delete_validate in notify/ad_notify.module
Validate that the selected notification can be deleted.

... See full list

File

./ad.module, line 1617
An advertising system for Drupal powered websites.

Code

function ad_adaccess($aid, $string, $account = NULL) {
  global $user;
  static $permissions = array();
  if (is_null($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;
  }
  if (!isset($permissions[$aid][$account->uid])) {
    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $account->uid));
    $permissions[$aid][$account->uid] = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
  }
  return in_array("{$string}", $permissions[$aid][$account->uid]);
}