You are here

function ad_owners_adaccess in Advertisement 6.3

Same name and namespace in other branches
  1. 6 owners/ad_owners.module \ad_owners_adaccess()
  2. 6.2 owners/ad_owners.module \ad_owners_adaccess()
  3. 7 owners/ad_owners.module \ad_owners_adaccess()

Determine whether the ad owner has a given privilege.

Parameters

$ad: Node object or aid of advertisement.

$permission: Special Ad owners permission which should be checked (such as 'manage owners')

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

File

owners/ad_owners.module, line 223
Enhances the ad module to support ad owners.

Code

function ad_owners_adaccess($ad, $permission, $account = NULL) {
  global $user;
  static $permissions = array();
  if (!isset($account)) {
    $account = $user;
  }
  $aid = 0;
  if (isset($ad)) {
    if (is_numeric($ad)) {
      $aid = $ad;
    }
    else {
      if (is_object($ad) && isset($ad->nid)) {
        $aid = $ad->nid;
      }
    }
  }
  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)));
  }
  $access = '';
  if (is_array($permission)) {
    foreach ($permission as $perm) {
      $access |= in_array($perm, $permissions[$aid][$account->uid]);
    }
  }
  else {
    $access = in_array($permission, $permissions[$aid][$account->uid]);
  }
  return $access;
}