You are here

function ad_owners_add in Advertisement 5

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

Add an owner to an ad.

4 calls to ad_owners_add()
ad_nodeapi in ./ad.module
Drupal _nodeapi hook.
ad_operations_callback in ./ad.module
Callback function for admin mass approving ads. TODO: Update activated and expired when appropriate. TODO: Publish/unpublish nodes when appropriate.
ad_owners_add_form_submit in ./ad.module
ad_owners_overview in ./ad.module
TODO: Make this themeable. TODO: Group permissions by module. TODO: Allow modules to define default value for permission.

File

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

Code

function ad_owners_add($aid, $uid, $permissions = array()) {
  $node = node_load($aid);
  if ($GLOBALS['db_type'] == 'pgsql') {
    db_query('START TRANSACTION;');
  }
  else {

    // MySQL, MySQLi
    db_query('LOCK TABLES {ad_owners} WRITE');
  }
  if (!db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $uid, $aid))) {
    db_query('INSERT INTO {ad_owners} (aid, uid) VALUES(%d, %d)', $aid, $uid);
    $rc = db_affected_rows() ? 1 : 0;
    if (!$permissions) {
      $permissions = variable_get('ad_' . $node->adtype . '_default_permissions', array(
        'access statistics',
        'access click history',
        'manage status',
      ));
    }
    $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $uid));
    if ($GLOBALS['db_type'] == 'pgsql') {
      db_query('START TRANSACTION;');
    }
    else {

      // MySQL, MySQLi
      db_query('LOCK TABLES {ad_permissions} WRITE');
    }
    db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $oid);
    db_query("INSERT INTO {ad_permissions} VALUES(%d, '%s')", $oid, implode('|,|', $permissions));
    module_invoke_all('adowners', 'add', $node, array(
      'oid' => $oid,
      'uid' => $uid,
      'aid' => $aid,
    ));
  }
  if ($GLOBALS['db_type'] == 'pgsql') {
    db_query('COMMIT;');
  }
  else {

    // MySQL, MySQLi
    db_query('UNLOCK TABLES');
  }
  return $rc;
}