You are here

function autologout_settings_validate in Automated Logout 6.4

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

Settings validation.

File

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

Code

function autologout_settings_validate($form, &$form_state) {
  $max_timeout = $form_state['values']['autologout_max_timeout'];
  $role_timeout = _autologout_get_role_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 than %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,
    )));
  }
}