You are here

function views_send_confirm_form in Views Send 7

Same name and namespace in other branches
  1. 8 views_send.module \views_send_confirm_form()

Multistep form callback for the "confirm" step. Allows the user to preview the whole message before sending it.

2 string references to 'views_send_confirm_form'
views_send_form_back_submit in ./views_send.module
Submit handler that handles back buttons.
views_send_form_submit in ./views_send.module
Submit handler for all steps of the Views Send multistep form.

File

./views_send.module, line 473
The Views Send module.

Code

function views_send_confirm_form($form, &$form_state, $view, $output) {
  drupal_set_title(t('Review and confirm the message that is about to be sent'));

  // Values entered in the "config" step.
  $configuration = $form_state['configuration'];
  if (!VIEWS_SEND_MIMEMAIL && $configuration['views_send_message']['format'] != 'plain_text') {
    drupal_set_message(t("Only plain text is supported in the message. Any HTML will be converted to text. If you want to format the message with HTML, you'll have to install and enable the !mimemail, !swiftmailer or !mandrill module.", array(
      '!mimemail' => '<a href="https://www.drupal.org/project/mimemail">Mime Mail</a>',
      '!swiftmailer' => '<a href="https://www.drupal.org/project/swiftmailer">Swift Mailer</a>',
      '!mandrill' => '<a href="https://www.drupal.org/project/mandrill">Mandrill</a>',
    )));
  }

  // From: parts.
  $from_mail = trim($configuration['views_send_from_mail']);
  $from_name = trim($configuration['views_send_from_name']);
  $form['#attributes']['class'] = array(
    'views-send-preview',
  );
  $form['from'] = array(
    '#type' => 'item',
    '#title' => t('From'),
    '#markup' => '<div class="views-send-preview-value">' . check_plain(_views_send_format_address($from_mail, $from_name, FALSE)) . '</div>',
  );

  // To: parts. (Mail is mandatory, name is optional.)
  $recipients = array();
  if (!empty($configuration['views_send_to_name'])) {
    $to_name_field = $configuration['views_send_tokens'][$configuration['views_send_to_name']];
  }
  else {
    $to_name_field = false;
    $to_name = '';
  }
  $to_mail_field = $configuration['views_send_tokens'][$configuration['views_send_to_mail']];
  foreach ($form_state['selection'] as $row_id) {
    if ($to_name_field) {
      $to_name = _views_send_get_field_value_from_views_row($view, $row_id, $to_name_field, 'plain_text');
    }
    $mail_addresses = _views_send_get_field_value_from_views_row($view, $row_id, $to_mail_field, 'mail');
    foreach ($mail_addresses as $mail_address) {
      $recipients[] = check_plain(_views_send_format_address($mail_address, $to_name, FALSE));
    }
  }
  $form['to'] = array(
    '#type' => 'item',
    '#title' => t('To'),
    '#markup' => '<div id="views-send-preview-to" class="views-send-preview-value">' . implode(', ', $recipients) . '</div>',
  );
  $form['subject'] = array(
    '#type' => 'item',
    '#title' => t('Subject'),
    '#markup' => '<div class="views-send-preview-value">' . check_plain($configuration['views_send_subject']) . '</div>',
  );
  $form['message'] = array(
    '#type' => 'item',
    '#title' => t('Message'),
    '#markup' => '<div id="views-send-preview-message" class="views-send-preview-value">' . check_markup($configuration['views_send_message']['value'], $configuration['views_send_message']['format']) . '</div>',
  );
  $headers = array();
  foreach (_views_send_headers($configuration['views_send_receipt'], $configuration['views_send_priority'], $configuration['views_send_from_mail'], $configuration['views_send_headers']) as $key => $value) {
    $headers[] = check_plain($key . ': ' . $value);
  }
  $form['headers'] = array(
    '#type' => 'item',
    '#title' => t('Headers'),
    '#markup' => '<div id="views-send-preview-headers" class="views-send-preview-value">' . implode('<br />', $headers) . '</div>',
  );
  if (VIEWS_SEND_MIMEMAIL && !empty($configuration['views_send_attachments']) && user_access('attachments with views_send')) {
    foreach ($configuration['views_send_attachments'] as $attachment) {
      $attachments[] = check_plain($attachment['filename']);
    }
    $form['attachments'] = array(
      '#type' => 'item',
      '#title' => t('Attachments'),
      '#markup' => '<div id="views-send-preview-attachments" class="views-send-preview-value">' . implode('<br />', $attachments) . '</div>',
    );
  }
  $query = drupal_get_query_parameters($_GET, array(
    'q',
  ));
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 999,
  );
  $form['actions']['back'] = array(
    '#type' => 'submit',
    '#value' => t('Go back'),
    '#submit' => array(
      'views_send_form_back_submit',
    ),
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
    '#submit' => array(
      'views_send_form_submit',
    ),
    '#suffix' => l(t('Cancel'), $view
      ->get_url(), array(
      'query' => $query,
    )),
  );
  return $form;
}