You are here

function simplenews_scheduler_nodeapi in Simplenews Scheduler 5

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

File

./simplenews_scheduler.module, line 112

Code

function simplenews_scheduler_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if (is_numeric($node->nid) && ($op == 'insert' || $op == 'update') && $node->type == 'simplenews') {
    db_query("DELETE FROM {simplenews_scheduler} WHERE `snid` = %d", $node->nid);
    if ($_POST['send'] == 3) {
      $sched_start = strtotime(check_plain($_POST['interval_start']));
      db_query("INSERT INTO {simplenews_scheduler} (snid, sched_interval, sched_start) VALUES (%d, '%s', %d)", $node->nid, check_plain($_POST['send_interval']), $sched_start);
    }
  }
  if ($node->type == 'simplenews' && $op == 'load') {
    $result = db_query("SELECT * FROM {simplenews_scheduler} WHERE `snid` = %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 `edition_snid` = %d", $node->nid);
      $row = db_fetch_array($result);
      if ($result) {
        $node->simplenews_scheduler_edition = $row;
      }
    }
  }
}