You are here

function smtp_admin_provider_delete in SMTP Authentication Support 7.2

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

File

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

Code

function smtp_admin_provider_delete($form, $form_state, $machine_name) {
  $providers = variable_get('smtp_providers', array());
  $machine_name = check_plain($machine_name);

  // Check if the provider exists
  if (empty($providers[$machine_name])) {
    drupal_set_message(t("There isn't a provider called :machine_name", array(
      ':machine_name' => $machine_name,
    )), 'error');
    drupal_goto('admin/config/system/smtp');
  }

  // Allows user to select an action if there are selection criterias for this provider
  $criterias = smtp_list_selection_criterias($machine_name);
  if ($criterias) {
    $form['criterias_option'] = array(
      '#type' => 'radios',
      '#title' => t('There are selection criterias using this provider. What would you like to do?'),
      '#options' => array(
        'delete' => t('Delete selection criterias for this provider'),
      ),
      '#default_value' => 'delete',
      '#required' => TRUE,
    );
    $replace_options = array();
    foreach ($providers as $provider) {
      if ($provider['machine_name'] != $machine_name) {
        $replace_options[$provider['machine_name']] = $provider['name'];
      }
    }

    // Allows user to replace provider if there are others configured
    if ($replace_options) {
      $form['criterias_option']['#options']['replace'] = t('Replace selection criterias\' provider by another');
      $default_provider = variable_get('smtp_default_provider', '');
      $form['criterias_replace'] = array(
        '#type' => 'select',
        '#title' => t('Select a provider to be used for replacement'),
        '#options' => $replace_options,
        '#default_value' => $default_provider != $machine_name ? $default_provider : NULL,
        '#states' => array(
          'visible' => array(
            ':input[name="criterias_option"]' => array(
              'value' => 'replace',
            ),
          ),
        ),
      );
    }
  }
  $form['machine_name'] = array(
    '#type' => 'value',
    '#value' => $machine_name,
  );
  return confirm_form($form, "Are you sure that you want to delete the provider " . $machine_name . "?", 'admin/config/system/smtp');
}