You are here

function mass_contact_mail_page in Mass Contact 5

Same name and namespace in other branches
  1. 5.2 mass_contact.module \mass_contact_mail_page()
  2. 6 mass_contact.module \mass_contact_mail_page()
  3. 7 mass_contact.page.inc \mass_contact_mail_page()
1 string reference to 'mass_contact_mail_page'
mass_contact_site_page in ./mass_contact.module
mail page

File

./mass_contact.module, line 332
Enables mass contact form to selected roles.

Code

function mass_contact_mail_page() {
  global $user;
  $result = db_query('SELECT cid, category, selected FROM {mass_contact} ORDER BY weight, category');
  while ($category = db_fetch_object($result)) {
    $categories[$category->cid] = $category->category;
    if ($category->selected) {
      $default_category = $category->cid;
    }
  }
  if (count($categories) > 0) {
    $form['#attributes'] = array(
      'enctype' => "multipart/form-data",
    );
    $form['#token'] = $user->name . $user->mail;
    $form['contact_information'] = array(
      '#value' => filter_xss_admin(variable_get('mass_contact_form_information', t('Send an email message using the contact form below.'))),
    );
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Your name'),
      '#maxlength' => 255,
      '#default_value' => $user->uid ? $user->name : '',
      '#required' => TRUE,
    );
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('Your e-mail address'),
      '#maxlength' => 255,
      '#default_value' => $user->uid ? $user->mail : '',
      '#required' => TRUE,
    );
    $form['subject'] = array(
      '#type' => 'textfield',
      '#title' => t('Subject'),
      '#maxlength' => 255,
      '#required' => TRUE,
    );

    // If there is more than one category available and no default category has been selected,
    // prepend a default placeholder value.
    if (!isset($default_category)) {
      $categories = array(
        t('--'),
      ) + $categories;
    }
    $form['cid'] = array(
      '#type' => 'select',
      '#title' => t('Category'),
      '#default_value' => $default_category,
      '#options' => $categories,
      '#required' => TRUE,
    );
    if (variable_get('mass_contact_optout_d', 1) == 1) {

      // allow to override or respect opt-outs if admin, otherwise use default
      if (user_access('administer site configuration')) {
        $form['optout'] = array(
          '#type' => 'checkbox',
          '#title' => t('Respect user opt-outs'),
          '#default_value' => 1,
        );
      }
      else {
        $form['optout'] = array(
          '#type' => 'hidden',
          '#default_value' => 1,
        );
      }
    }
    $form['message'] = array(
      '#type' => 'textarea',
      '#title' => t('Message'),
      '#required' => TRUE,
    );
    if (user_access('send mass contact attachments')) {
      $form['attachment'] = array(
        '#type' => 'file',
        '#title' => t('Attachment'),
        '#size' => 40,
      );
    }
    $form['html'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send as HTML'),
      '#default_value' => variable_get('mass_contact_HTML_d', 0),
    );
    $form['bcc'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send as Bcc (hide recipients)'),
      '#default_value' => variable_get('mass_contact_bcc_d', 1),
    );
    if (user_access('choose whether to archive mass contact messages')) {
      $form['nodecc'] = array(
        '#type' => 'checkbox',
        '#title' => t('Save a copy as a node'),
        '#default_value' => variable_get('mass_contact_nodecc_d', 1),
      );
    }
    else {
      $form['nodecc'] = array(
        '#type' => 'hidden',
        '#default_value' => variable_get('mass_contact_nodecc_d', 1),
      );
    }
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Send e-mail'),
    );
  }
  else {
    $form['error'] = array(
      '#value' => '<p><b>' . t('You must create at least one category before using this form.' . '</b>'),
    );
  }
  if (user_access('administer site configuration')) {
    $form['tasklist'] = array(
      '#type' => 'fieldset',
      '#title' => t('Related tasks'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#prefix' => '<p>',
    );
    $form['tasklist']['list'] = array(
      '#value' => '<p>' . t('1. <a href="/admin/build/mass_contact/add">Add a category</a><br/>2. <a href="/admin/build/mass_contact">View categories</a><br/>3. <a href="/admin/build/mass_contact/settings">Configure the module</a><br/>4. <a href="/admin/user/access#module-mass_contact">Set permissions</a><br />5. <a href="/mass_contact">Send mass e-mail</a><br />6. <a href="/admin/help/mass_contact">Help</a>') . '</p>',
    );
  }
  return $form;
}