You are here

function simplenews_scheduler_nodeapi in Simplenews Scheduler 6.2

Same name and namespace in other branches
  1. 5 simplenews_scheduler.module \simplenews_scheduler_nodeapi()
  2. 6 simplenews_scheduler.module \simplenews_scheduler_nodeapi()

Implementation of hook_nodeapi().

File

./simplenews_scheduler.module, line 279
Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.

Code

function simplenews_scheduler_nodeapi(&$node, $op) {
  if (in_array($node->type, variable_get('simplenews_content_types', array(
    'simplenews',
  )))) {
    switch ($op) {
      case 'load':
        if (isset($node->nid)) {
          $result = db_query("SELECT * FROM {simplenews_scheduler} WHERE nid = %d", $node->nid);
          $row = db_fetch_array($result);
          if ($row) {
            $node->simplenews_scheduler = $row;
          }
          else {

            // Maybe this was an edition that has been sent?
            $result = db_query("SELECT * FROM {simplenews_scheduler_editions} WHERE eid = %d", $node->nid);
            $row = db_fetch_array($result);
            if ($row) {
              $node->simplenews_scheduler_edition = $row;
            }
          }
        }
        break;
      case 'delete':

        // erase the record from the scheduler table so it does not try to send
        db_query("DELETE FROM {simplenews_scheduler} WHERE nid = %d", $node->nid);
        break;
      case 'view':

        // leaving this out until we figure out a nicer UI for showing this.
        // this should be letting you know that you are viewing a generated newsletter, not the original

        /*  if(isset($node->simplenews_scheduler_edition)) {
               drupal_set_message(t('You have been redirected to the original newsletter'));
               drupal_goto('node/'.$node->simplenews_scheduler_edition['pid'].'/simplenews');
             }
            */
        break;
    }
  }
}