You are here

function simplenews_scheduler_submit in Simplenews Scheduler 7

Same name and namespace in other branches
  1. 8 simplenews_scheduler.module \simplenews_scheduler_submit()
  2. 6.2 simplenews_scheduler.module \simplenews_scheduler_submit()
  3. 2.0.x simplenews_scheduler.module \simplenews_scheduler_submit()

Additional submit handler for the node_tab_send_form of simplenews.

1 string reference to 'simplenews_scheduler_submit'
simplenews_scheduler_form_simplenews_node_tab_send_form_alter in ./simplenews_scheduler.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function simplenews_scheduler_submit($form, &$form_state) {
  $scheduler = $form_state['simplenews_scheduler'];
  $nid = $form_state['values']['nid'];
  $node = node_load($nid);

  // Get Scheduler values from Simplenews.
  $send = $form_state['values']['simplenews']['send'];
  $stoptype = $form_state['values']['simplenews']['scheduler']['stoptype'];
  $start_date = strtotime($form_state['values']['simplenews']['scheduler']['start_date']);
  $stop_date = $stoptype == 1 ? strtotime($form_state['values']['simplenews']['scheduler']['stop_date']) : 0;
  $record = array(
    'nid' => $nid,
    'activated' => $send == SIMPLENEWS_COMMAND_SEND_SCHEDULE ? 1 : 0,
    'send_interval' => $form_state['values']['simplenews']['scheduler']['interval'],
    'interval_frequency' => $form_state['values']['simplenews']['scheduler']['frequency'],
    'start_date' => $start_date,
    'stop_type' => $stoptype,
    'stop_date' => $stop_date,
    'stop_edition' => $form_state['values']['simplenews']['scheduler']['stop_edition'],
    'php_eval' => $form_state['values']['simplenews']['scheduler']['php_eval'],
    'title' => $form_state['values']['simplenews']['scheduler']['title'],
  );

  // For a new scheduler, add the next_run time
  // and also for the old deactivated.
  if (!isset($scheduler['next_run']) || isset($scheduler['activated']) && $scheduler['activated'] == 0) {
    $record['next_run'] = $start_date;

    // reset last run, so next run will be calculated properly
    $record['last_run'] = 0;
  }

  // Update scheduler record.
  db_merge('simplenews_scheduler')
    ->key(array(
    'nid' => $nid,
  ))
    ->fields($record)
    ->execute();
  drupal_set_message(t('Newsletter Schedule preferences have been saved.'));
}