You are here

function prod_check_settings_form_validate in Production check & Production monitor 6

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

Validation for settings form.

File

includes/prod_check.admin.inc, line 398

Code

function prod_check_settings_form_validate($form, &$form_state) {
  if (!empty($form_state['ahah_submission'])) {
    return;
  }

  // Had to add CSS again here since it was lost on form errors. Weird, doesn't
  // seem logical...
  $base = drupal_get_path('module', 'prod_check');
  drupal_add_css($base . '/css/prod-check.css');
  drupal_add_js($base . '/js/jquery.equalheights.js', 'module', 'header');
  drupal_add_js($base . '/js/jquery.maskedinput.min.js', 'module', 'header');
  drupal_add_js($base . '/js/prod-check.js', 'module', 'header');
  if (module_exists('dblog')) {
    if (!is_numeric($form_state['values']['prod_check_dblog_php_threshold'])) {
      form_set_error('prod_check_dblog_php_threshold', t('The PHP error threshold should be numeric!'));
    }
  }
  if ($form_state['values']['prod_check_enable_xmlrpc']) {
    if (empty($form_state['values']['prod_check_xmlrpc_key'])) {
      form_set_error('prod_check_xmlrpc_key', t('When enabling the XPLRPC API, you <strong>must</strong> enter an API key!'));
    }
  }
  if (!empty($form_state['values']['prod_check_module_list_time'])) {

    // This check in case JavaScript is not enabled / malfunctioning.
    if (strpos($form_state['values']['prod_check_module_list_time'], ':') != 2) {
      form_set_error('prod_check_module_list_time', t('Time must be input in 24 hour format: HH:MM!'));
    }
    else {
      $time = explode(':', $form_state['values']['prod_check_module_list_time']);
      if (intval($time[0]) > 23) {
        form_set_error('prod_check_module_list_time', t('Hours must range from 00 (midnight) to 23!'));
      }
      if (intval($time[1]) > 59) {
        form_set_error('prod_check_module_list_time', t('Minutes must range from 00 to 59!'));
      }
    }
  }
  if (!is_numeric($form_state['values']['prod_check_apc_expunge'])) {
    form_set_error('prod_check_apc_expunge', t('APC/OPcache Cache full count threshold should be numeric!'));
  }
  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;
        }
      }
    }
    if (empty($checks)) {
      form_set_error('monitor_settings', t('When enabling Nagios support, you <strong>must</strong> tick at least one of the checkboxes!'));
    }
    if (!empty($form_state['values']['prod_check_nagios_takeover'])) {

      // Path can only contain alphanumeric chars, dash and underscore.
      if (!preg_match('/^[a-zA-Z0-9\\-_]*$/', $form_state['values']['prod_check_nagios_takeover'])) {
        form_set_error('prod_check_nagios_takeover', t('The takover path can only contain alphanumeric characters, dash and underscore.'));
      }
      elseif (strtolower($form_state['values']['prod_check_nagios_takeover']) == 'nagios') {
        form_set_error('prod_check_nagios_takeover', t('The path should be different than the default Nagios module path!'));
      }
    }
  }
}