You are here

function autologout_settings_validate in Automated Logout 7.4

Same name and namespace in other branches
  1. 6.4 autologout.admin.inc \autologout_settings_validate()

Settings validation.

File

./autologout.admin.inc, line 171
Contains all admin pages, settings, and validate.

Code

function autologout_settings_validate($form, &$form_state) {
  $max_timeout = $form_state['values']['autologout_max_timeout'];

  // Validate timeouts for each role.
  foreach (user_roles(TRUE) as $key => $role) {
    if (empty($form_state['values']['autologout_role_' . $key])) {

      // Don't validate role timeouts for non enabled roles.
      continue;
    }
    $timeout = $form_state['values']['autologout_role_' . $key . '_timeout'];
    $validate = autologout_timeout_validate($timeout, $max_timeout);
    if (!$validate) {
      form_set_error('autologout_role_' . $key . '_timeout', t('%role role timeout must be an integer greater than 60, less then %max or 0 to disable autologout for that role.', array(
        '%role' => $role,
        '%max' => $max_timeout,
      )));
    }
  }
  $timeout = $form_state['values']['autologout_timeout'];

  // Validate timeout.
  if (!is_numeric($timeout) || (int) $timeout != $timeout || $timeout < 60 || $timeout > $max_timeout) {
    form_set_error('autologout_timeout', t('The timeout must be an integer greater than 60 and less then %max.', array(
      '%max' => $max_timeout,
    )));
  }

  // Validate ip address list
  $whitelisted_ip_addresses_list = explode("\n", trim($form_state['values']['autologout_whitelisted_ip_addresses']));
  foreach ($whitelisted_ip_addresses_list as $ip_address) {
    if (!empty($ip_address) && !filter_var(trim($ip_address), FILTER_VALIDATE_IP)) {
      form_set_error('whitelisted_ip_addresses', t('Whitelisted IP address list should contain only valid IP addresses, one per row'));
    }
  }
}