You are here

function simplenews_node_tab_send_form_submit in Simplenews 6.2

Same name and namespace in other branches
  1. 7.2 includes/simplenews.admin.inc \simplenews_node_tab_send_form_submit()
  2. 7 includes/simplenews.admin.inc \simplenews_node_tab_send_form_submit()

Simplenews tab form submit callback

File

./simplenews.module, line 479
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_node_tab_send_form_submit($form, &$form_state) {

  // Get the node
  $values = $form_state['values'];
  $node = node_load($values['nid']);
  $s_status = SIMPLENEWS_STATUS_SEND_NOT;
  if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_NOW) {
    $s_status = SIMPLENEWS_STATUS_SEND_PENDING;
  }
  $values['simplenews']['s_status'] = $s_status;

  // Is this a multilingual newsletter ?
  // When this node is selected for translation all translation of this node
  // will be sent too.
  // All translated nodes will receive the same send states (priority, confirmation, format).
  if (module_exists('translation') && translation_supported_type($node->type) && $node->tnid != 0) {
    if ($translations = translation_node_get_translations($node->tnid)) {
      foreach ($translations as $translation) {

        // translation_node_get_translation() only returns nid, title and language
        // For consistency, we load the full node
        $translation = node_load($translation->nid);
        simplenews_newsletter_update($translation, $values['simplenews']);
      }
    }
    else {
      simplenews_newsletter_update($node, $values['simplenews']);
    }
  }
  else {
    simplenews_newsletter_update($node, $values['simplenews']);
  }

  // Update $node before send
  $node->simplenews = _simplenews_flatten_array($values['simplenews']);

  // Send newsletter or test newsletter
  module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
  if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_NOW) {

    // Send newsletter to all subscribers
    simplenews_send_node($node);
  }
  elseif ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_TEST) {

    // Send test newsletter to test address(es)
    simplenews_send_test($node);
  }
}