You are here

function ad_permission_nodeapi in Advertisement 5.2

Drupal _nodeapi hook.

File

permission/ad_permission.module, line 72
Provide granular permissions for advertisements.

Code

function ad_permission_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case 'insert':
    case 'update':
      ad_permission_owners_add($node->nid, $node->uid);
      ad_permission_create_hostid($node->uid);
      break;
    case 'delete':

      // Clean up ad_permissions and any other per-ad tables.
      $result = db_query('SELECT oid, uid FROM {ad_owners} WHERE aid = %d', $node->nid);
      while ($id = db_fetch_object($result)) {
        db_query('DELETE FROM {ad_permissions} WHERE oid = %d', $id->oid);
        $owner = user_load(array(
          'uid' => $id->uid,
        ));

        // Tell plug-in modules to clean up.
        module_invoke_all('adowners', 'remove', $id->oid, $owner);
      }
      db_query('DELETE FROM {ad_owners} WHERE aid = %d', $node->nid);
      break;
  }
}