You are here

function views_send_mail_action_form in Views Send 6

Configuration form for views_send_mail action.

See also

http://drupal.org/node/172152

File

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

Code

function views_send_mail_action_form($context) {
  $display = $context['view']->name . ':' . $context['view']->current_display;
  $form = array();
  $form['display'] = array(
    '#type' => 'value',
    '#value' => $display,
  );
  $form['from'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sender'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['from']['views_send_from_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Sender\'s name'),
    '#description' => t("Enter the sender's human readable name."),
    '#default_value' => variable_get('views_send_from_name_' . $display, variable_get('site_name', '')),
    '#maxlen' => 255,
  );
  $form['from']['views_send_from_mail'] = array(
    '#type' => 'textfield',
    '#title' => t('Sender\'s e-mail'),
    '#description' => t("Enter the sender's e-mail address."),
    '#required' => TRUE,
    '#default_value' => variable_get('views_send_from_mail_' . $display, variable_get('site_mail', ini_get('sendmail_from'))),
    '#maxlen' => 255,
  );

  // The view needs to be executed, as we rely on the result set to
  // retrieve the available fields
  if (!$context['view']->executed) {
    $context['view']
      ->execute();
  }
  $fields = _views_send_get_fields_and_tokens($context['view'], 'fields');
  $tokens = _views_send_get_fields_and_tokens($context['view'], 'tokens');
  $fields_name_text = _views_send_get_fields_and_tokens($context['view'], 'fields_name_text');
  $fields_options = array_merge(array(
    '' => '<' . t('select') . '>',
  ), $fields);
  $form['views_send_tokens'] = array(
    '#type' => 'value',
    '#value' => $tokens,
  );
  $form['to'] = array(
    '#type' => 'fieldset',
    '#title' => t('Recipients'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['to']['views_send_to_name'] = array(
    '#type' => 'select',
    '#title' => t('Field used for recipient\'s name'),
    '#description' => t('Select which field from the current view will be used as recipient\'s name.'),
    '#options' => $fields_options,
    '#default_value' => variable_get('views_send_to_name_' . $display, ''),
  );
  $form['to']['views_send_to_mail'] = array(
    '#type' => 'select',
    '#title' => t('Field used for recipient\'s e-mail'),
    '#description' => t('Select which field from the current view will be used as recipient\'s e-mail.'),
    '#options' => $fields_options,
    '#default_value' => variable_get('views_send_to_mail_' . $display, ''),
    '#required' => TRUE,
  );
  $form['mail'] = array(
    '#type' => 'fieldset',
    '#title' => t('E-mail content'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['mail']['views_send_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#description' => t('Enter the e-mail\'s subject line.'),
    '#maxlen' => 255,
    '#required' => TRUE,
    '#default_value' => variable_get('views_send_subject_' . $display, ''),
  );
  $form['mail']['views_send_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#description' => t('Enter the body of the message. You can use the token replacements listed below.'),
    '#required' => TRUE,
    '#rows' => 10,
    '#default_value' => variable_get('views_send_message_' . $display, ''),
  );
  $form['mail']['format'] = _views_send_filter_form(variable_get('views_send_message_format_' . $display, VIEWS_SEND_FORMAT_PLAIN));
  $form['mail']['token'] = array(
    '#type' => 'fieldset',
    '#title' => t('Replacements'),
    '#description' => t('You can use these token replacements in Subject or Message Body.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['mail']['token']['tokens'] = array(
    '#type' => 'markup',
    '#value' => theme('views_send_token_help', $fields_name_text),
  );
  if (VIEWS_SEND_MIMEMAIL && user_access('allow attachments with views_send')) {

    // set the form encoding type
    $form['#attributes']['enctype'] = "multipart/form-data";

    // add a file upload file
    $form['mail']['views_send_attachments'] = array(
      '#type' => 'file',
      '#title' => t('Attachment'),
      '#description' => t('NB! The attached file is stored once per recipient in the database (before sending it).'),
    );
  }
  $form['additional'] = array(
    '#type' => 'fieldset',
    '#title' => t('Additional e-mail options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['additional']['views_send_priority'] = array(
    '#type' => 'select',
    '#title' => t('Priority'),
    '#options' => array(
      VIEWS_SEND_PRIORITY_NONE => t('none'),
      VIEWS_SEND_PRIORITY_HIGHEST => t('highest'),
      VIEWS_SEND_PRIORITY_HIGH => t('high'),
      VIEWS_SEND_PRIORITY_NORMAL => t('normal'),
      VIEWS_SEND_PRIORITY_LOW => t('low'),
      VIEWS_SEND_PRIORITY_LOWEST => t('lowest'),
    ),
    '#description' => t('Note that email priority is ignored by a lot of email programs.'),
    '#default_value' => variable_get('views_send_priority_' . $display, 0),
  );
  $form['additional']['views_send_receipt'] = array(
    '#type' => 'checkbox',
    '#title' => t('Request receipt'),
    '#default_value' => variable_get('views_send_receipt_' . $display, 0),
    '#description' => t('Request a Read Receipt from your e-mails. A lot of email programs ignore these so it is not a definitive indication of how many people have read your message.'),
  );
  $form['additional']['views_send_headers'] = array(
    '#type' => 'textarea',
    '#title' => t('Additional headers'),
    '#description' => t("Additional headers to be send with the message. You'll have to enter one per line. Example:<pre>Reply-To: noreply@example.com\nX-MyCustomHeader: Whatever</pre>"),
    '#rows' => 4,
    '#default_value' => variable_get('views_send_headers_' . $display, ''),
  );
  $form['views_send_remember'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remember these values for the next time a mass mail is sent. (The values are not stored per user.)'),
    '#default_value' => variable_get('views_send_remember_' . $display, FALSE),
  );
  return $form;
}