You are here

function prod_check_settings_form_submit in Production check & Production monitor 6

Same name and namespace in other branches
  1. 7 includes/prod_check.admin.inc \prod_check_settings_form_submit()

Submit for settings form.

File

includes/prod_check.admin.inc, line 470

Code

function prod_check_settings_form_submit($form, &$form_state) {
  if (!empty($form_state['ahah_submission'])) {
    return;
  }
  switch ($form_state['values']['op']) {
    case t('Force immediate module list reporting'):
      variable_set('prod_check_module_list_lastrun', -1);
      break;
    case t('Save configuration'):
      variable_set('prod_check_sitemail', $form_state['values']['prod_check_sitemail']);

      // PHP errors.
      if (module_exists('dblog')) {
        variable_set('prod_check_dblog_php', $form_state['values']['prod_check_dblog_php']);
        variable_set('prod_check_dblog_php_threshold', $form_state['values']['prod_check_dblog_php_threshold']);
      }

      // APC/OPcache.
      variable_set('prod_check_apc_expunge', $form_state['values']['prod_check_apc_expunge']);
      variable_set('prod_check_apcuser', $form_state['values']['prod_check_apcuser']);
      if (!empty($form_state['values']['prod_check_apcpass'])) {
        variable_set('prod_check_apcpass', $form_state['values']['prod_check_apcpass']);
      }
      else {
        variable_set('prod_check_apcpass', 'password');
      }
      if ($form_state['values']['prod_check_enable_xmlrpc']) {

        // Enable.
        variable_set('prod_check_enable_xmlrpc', $form_state['values']['prod_check_enable_xmlrpc']);
        variable_set('prod_check_xmlrpc_key', $form_state['values']['prod_check_xmlrpc_key']);
        variable_set('prod_check_module_list_day', $form_state['values']['prod_check_module_list_day']);
        variable_set('prod_check_module_list_time', $form_state['values']['prod_check_module_list_time']);
      }
      else {

        // Disable.
        variable_set('prod_check_enable_xmlrpc', 0);
      }

      // This is why we didn't use a system_settings_form().
      if (isset($form_state['values']['prod_check_enable_nagios']) && $form_state['values']['prod_check_enable_nagios']) {
        $checks = array();
        foreach ($form_state['values']['monitor_settings'] as $set => $data) {
          foreach ($data as $check => $value) {
            if ($value) {
              $checks[$set][] = $value;
            }
          }
        }

        // Enable.
        variable_set('prod_check_enable_nagios', $form_state['values']['prod_check_enable_nagios']);
        variable_set('prod_check_nagios_checks', $checks);

        // Check to see if we need to do a menu_rebuild.
        if (variable_get('prod_check_nagios_takeover', '') != $form_state['values']['prod_check_nagios_takeover'] || variable_get('prod_check_nagios_unique', 'default') != $form_state['values']['prod_check_nagios_unique']) {
          variable_set('prod_check_nagios_takeover', $form_state['values']['prod_check_nagios_takeover']);
          variable_set('prod_check_nagios_unique', $form_state['values']['prod_check_nagios_unique']);
          menu_rebuild();
        }
        variable_set('prod_check_nagios_verbose', $form_state['values']['prod_check_nagios_verbose']);
      }
      else {

        // Disable.
        variable_set('prod_check_enable_nagios', 0);
      }
      drupal_set_message(t('The configuration options have been saved.'));
      break;
    case t('Reset to defaults'):

      // This beats multiple variable_del() calls.
      // Don't delete prod_check_module_list_lastrun!
      db_query('DELETE FROM {variable} WHERE name LIKE "prod_check\\_%" AND name <> "prod_check_module_list_lastrun"');
      cache_clear_all('variables', 'cache');
      drupal_set_message(t('The configuration options have been reset to their default values.'));
      break;
  }
}