You are here

function smtp_admin_settings in SMTP Authentication Support 7.2

Same name and namespace in other branches
  1. 5 smtp.module \smtp_admin_settings()
  2. 6 smtp.module \smtp_admin_settings()
  3. 7 smtp.admin.inc \smtp_admin_settings()

Administrative settings.

1 string reference to 'smtp_admin_settings'
smtp_menu in ./smtp.module
Implements hook_menu().

File

./smtp.admin.inc, line 11
Administrative page code for the smtp module.

Code

function smtp_admin_settings() {
  if (variable_get('smtp_on', 0)) {
    drupal_set_message(t('SMTP.module is active.'));
  }
  else {
    drupal_set_message(t('SMTP.module is INACTIVE.'));
  }
  $logging = variable_get('smtp_debugging', SMTP_LOGGING_ERRORS);
  $form['onoff'] = array(
    '#type' => 'fieldset',
    '#title' => t('Install options'),
  );
  $form['onoff']['smtp_on'] = array(
    '#type' => 'radios',
    '#title' => t('Turn this module on or off'),
    '#default_value' => variable_get('smtp_on', FALSE),
    '#options' => array(
      1 => t('On'),
      0 => t('Off'),
    ),
    '#description' => t('To uninstall this module you must turn it off here first.'),
  );
  $form['onoff']['smtp_deliver'] = array(
    '#type' => 'radios',
    '#title' => t('Turn on delivery of emails'),
    '#default_value' => variable_get('smtp_deliver', TRUE),
    '#options' => array(
      1 => t('On'),
      0 => t('Off'),
    ),
    '#description' => t('With this option turned off, email messages will be queued up and processed as normal, but not actually delivered. This option should only be used for testing purposes.'),
  );
  $form['onoff']['smtp_queue'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send mail by queue'),
    '#default_value' => variable_get('smtp_queue', FALSE),
    '#description' => t('Mails will be sent by drupal queue api.'),
  );
  $form['onoff']['smtp_queue_fail'] = array(
    '#type' => 'checkbox',
    '#title' => t('Retry sending mail on error.'),
    '#default_value' => variable_get('smtp_queue_fail', FALSE),
    '#description' => t('Mails will be added to the queue and sent by drupal queue api.'),
  );
  $form['providers'] = array(
    '#type' => 'fieldset',
    '#title' => t('Providers'),
  );

  // Create the providers list
  $providers = variable_get('smtp_providers', array());
  if (count($providers) != 0) {
    $rows = array();
    $options = array();
    foreach ($providers as $provider) {
      $rows[] = array(
        $provider['machine_name'],
        l(t('edit'), 'admin/config/system/smtp/provider/' . $provider['machine_name'] . '/edit', array(
          'class' => 'btn',
        )),
        l(t('delete'), 'admin/config/system/smtp/provider/' . $provider['machine_name'] . '/delete', array(
          'class' => 'btn',
        )),
      );
      $options[$provider['machine_name']] = $provider['machine_name'];
    }
    $form['providers']['provider_default'] = array(
      '#type' => 'select',
      '#title' => t('Default provider'),
      '#description' => t('Mails will be sent by the selected provider when no selection criterias are satisfied.'),
      '#default_value' => variable_get('smtp_default_provider', 'none'),
      '#options' => array_merge(array(
        'none' => 'None',
      ), $options),
    );
    $form['providers']['table'] = array(
      '#theme' => 'table',
      '#header' => array(
        t('machine name'),
        '',
      ),
      '#rows' => $rows,
      '#attributes' => array(
        'class' => array(
          'table-class',
        ),
      ),
      '#empty' => t('Your table is empty'),
    );
  }
  else {
    $form['providers']['message'] = array(
      '#markup' => '<div>' . t('Please add a SMTP provider') . '</div>',
    );
  }
  $form['providers']['new'] = array(
    '#theme' => 'link',
    '#text' => t('Add provider'),
    '#path' => 'admin/config/system/smtp/provider/add',
    '#options' => array(
      'attributes' => array(
        'class' => array(
          'btn',
        ),
      ),
      'html' => FALSE,
    ),
  );
  $form['criterias'] = array(
    '#type' => 'fieldset',
    '#title' => t('Selection criterias'),
    '#description' => t('Selection criterias are used to select different providers for different situations.') . '<br>' . t('Criterias will be tested in the order they appear in this table (lowest weight first). The provider selected for the first satisfied criteria will be used.'),
    '#tree' => TRUE,
  );
  $form['criterias']['table'] = array(
    '#theme' => 'smtp_table',
    '#header' => array(
      t('Provider'),
      t('Criteria'),
      array(
        'data' => t('Operations'),
        'colspan' => 2,
      ),
      t('Weight'),
    ),
    '#attributes' => array(
      'class' => array(
        'btn',
      ),
      'id' => 'smtp-selection-criterias-table',
    ),
    '#empty' => t('No selection criterias defined yet.'),
  );
  $criterias = smtp_list_selection_criterias();
  foreach ($criterias as $cid => $criteria) {
    $form['criterias']['table'][$cid] = array(
      '#attributes' => array(
        'class' => array(
          'draggable',
        ),
      ),
    );
    $form['criterias']['table'][$cid]['provider'] = array(
      '#markup' => check_plain($criteria['provider']),
    );
    $form['criterias']['table'][$cid]['criteria'] = array(
      '#theme' => 'smtp_selection_criteria',
      '#criteria' => $criteria,
    );
    $form['criterias']['table'][$cid]['edit'] = array(
      '#theme' => 'link',
      '#text' => t('edit'),
      '#path' => 'admin/config/system/smtp/criteria/' . $criteria['cid'] . '/edit',
      '#options' => array(
        'attributes' => array(
          'class' => array(
            'btn',
          ),
        ),
        'html' => FALSE,
      ),
    );
    $form['criterias']['table'][$cid]['delete'] = array(
      '#theme' => 'link',
      '#text' => t('delete'),
      '#path' => 'admin/config/system/smtp/criteria/' . $criteria['cid'] . '/delete',
      '#options' => array(
        'attributes' => array(
          'class' => array(
            'btn',
          ),
        ),
        'html' => FALSE,
      ),
    );
    $form['criterias']['table'][$cid]['weight'] = array(
      '#type' => 'textfield',
      '#title' => t('Weight'),
      '#title_display' => 'invisible',
      '#element_validate' => array(
        'element_validate_integer',
      ),
      '#attributes' => array(
        'class' => array(
          'smtp-selection-criteria-weight',
        ),
      ),
      '#size' => 3,
      '#required' => TRUE,
      '#default_value' => $criteria['weight'],
    );
  }
  $form['#attached']['drupal_add_tabledrag'][] = array(
    'smtp-selection-criterias-table',
    'order',
    'sibling',
    'smtp-selection-criteria-weight',
  );
  $form['criterias']['new'] = array(
    '#theme' => 'link',
    '#text' => t('Add selection criteria'),
    '#path' => 'admin/config/system/smtp/criteria/add',
    '#options' => array(
      'attributes' => array(
        'class' => array(
          'btn',
        ),
      ),
      'html' => FALSE,
    ),
  );
  $form['client'] = array(
    '#type' => 'fieldset',
    '#title' => t('SMTP client settings'),
  );
  $form['client']['smtp_client_hostname'] = array(
    '#type' => 'textfield',
    '#title' => t('Hostname'),
    '#default_value' => variable_get('smtp_client_hostname', ''),
    '#description' => t('The hostname to use in the Message-Id and Received headers, and as the default HELO string. Leave blank for using %server_name.', array(
      '%server_name' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain',
    )),
  );
  $form['client']['smtp_client_helo'] = array(
    '#type' => 'textfield',
    '#title' => t('HELO'),
    '#default_value' => variable_get('smtp_client_helo', ''),
    '#description' => t('The SMTP HELO/EHLO of the message. Defaults to hostname (see above).'),
  );
  $form['email_test'] = array(
    '#type' => 'fieldset',
    '#title' => t('Send test e-mail'),
  );
  $form['email_test']['smtp_test_address'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address to send a test e-mail to'),
    '#default_value' => '',
    '#description' => t('Type in an address to have a test e-mail sent there.'),
  );
  $form['debugging'] = array(
    '#type' => 'fieldset',
    '#title' => t('Debugging and logging'),
  );
  $logging_options = array(
    SMTP_LOGGING_ALL => t('Log everything'),
    SMTP_LOGGING_ERRORS => t('Errors only'),
    SMTP_LOGGING_NONE => t('No logging'),
  );
  $form['debugging']['smtp_debugging'] = array(
    '#type' => 'select',
    '#title' => t('Logging'),
    '#options' => $logging_options,
    '#default_value' => $logging,
    '#description' => t('Choose the appropriate log level. "Log everything" will log errors and informational messages when an email is sent. "Errors only" will only create a log entry when sending failed. "No logging" will disable all logging for this module.'),
  );
  $form['email_test']['smtp_reroute_address'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address to reroute all emails to'),
    '#default_value' => variable_get('smtp_reroute_address', ''),
    '#description' => t('All emails sent by the site will be rerouted to this email address; use with caution.'),
  );
  $form['debugging']['maillog'] = array(
    '#type' => 'fieldset',
    '#title' => t('Maillog integration'),
  );
  if (!module_exists('maillog')) {
    $form['debugging']['maillog']['#description'] = t('Installing the <a href="@url">Maillog module</a> also allows keeping copies of all emails sent through the site.', array(
      '@url' => 'https://www.drupal.org/project/maillog',
    ));
  }
  else {
    $form['debugging']['maillog']['#description'] = t('The <a href="@url">Maillog module</a> is installed, it can also be used to keep copies of all emails sent through the site.', array(
      '@url' => url('admin/config/development/maillog'),
    ));
    $form['debugging']['maillog']['maillog_log'] = array(
      '#type' => 'checkbox',
      '#title' => t("Create table entries in maillog table for each e-mail."),
      '#default_value' => variable_get('maillog_log', TRUE),
    );
    $form['debugging']['maillog']['maillog_devel'] = array(
      '#type' => 'checkbox',
      '#title' => t("Display the e-mails on page using devel module (if enabled)."),
      '#default_value' => variable_get('maillog_devel', TRUE),
      '#disabled' => !module_exists('devel'),
    );
  }
  $form['#submit'][] = 'smtp_admin_settings_form_submit';
  $form = system_settings_form($form);
  $form['#submit'][] = 'smtp_admin_settings_submit_post_system_settings';
  return $form;
}