You are here

function purge_users_config_form_validate in Auto Purge Users 7

Same name and namespace in other branches
  1. 7.2 purge_users.pages.inc \purge_users_config_form_validate()

Validation function for purge user config form.

File

./purge_users.pages.inc, line 242
Purge users module config form file.

Code

function purge_users_config_form_validate($form, &$form_state) {
  if (!isset($form_state['storage']['confirm'])) {
    $never_login_value = $form_state['values']['purge_users_user_never_lastlogin_value'];
    $never_login_period = $form_state['values']['purge_users_user_never_lastlogin_period'];
    $login_value = $form_state['values']['purge_users_user_lastlogin_value'];
    $login_period = $form_state['values']['purge_users_user_lastlogin_period'];
    $inactive_value = $form_state['values']['purge_users_user_inactive_value'];
    $inactive_period = $form_state['values']['purge_users_user_inactive_period'];
    $block_value = $form_state['values']['purge_users_user_blocked_value'];
    $block_period = $form_state['values']['purge_users_user_blocked_period'];
    $enable_blocked = $form_state['values']['purge_users_enabled_blocked_users'];
    $never_enable_loggedin = $form_state['values']['purge_users_enabled_never_loggedin_users'];
    $enable_loggedin = $form_state['values']['purge_users_enabled_loggedin_users'];
    $enable_inactive = $form_state['values']['purge_users_enabled_inactive_users'];

    // Validate text field to only contain numeric values.
    if ($never_login_value != '' && !is_numeric($never_login_value)) {
      form_set_error('purge_users_user_never_lastlogin_value', t('Interval must be a number.'));
    }
    if ($login_value != '' && !is_numeric($login_value)) {
      form_set_error('purge_users_user_lastlogin_value', t('Interval must be a number.'));
    }
    if ($inactive_value != '' && !is_numeric($inactive_value)) {
      form_set_error('purge_users_user_inactive_value', t('Interval must be a number.'));
    }
    if ($block_value != '' && !is_numeric($block_value)) {
      form_set_error('purge_users_user_blocked_value', t('Interval must be a number.'));
    }

    // Validate to set purge period more than 10 days.
    if ($never_login_period == 'days' && !empty($never_login_value) && $never_login_value <= 10) {
      form_set_error('purge_users_user_never_lastlogin_value', t('Purge period should be more than 10 days.'));
    }
    if ($login_period == 'days' && !empty($login_value) && $login_value <= 10) {
      form_set_error('purge_users_user_lastlogin_value', t('Purge period should be more than 10 days.'));
    }
    if ($inactive_period == 'days' && !empty($inactive_value) && $inactive_value <= 10) {
      form_set_error('purge_users_user_inactive_value', t('Purge period should be more than 10 days.'));
    }
    if ($block_period == 'days' && !empty($block_value) && $block_value <= 10) {
      form_set_error('purge_users_user_blocked_value', t('Purge period should be more than 10 days.'));
    }

    // Make sure one of the fieldset is checked.
    if ($never_enable_loggedin == 0 && $enable_loggedin == 0 && $enable_inactive == 0 && $enable_blocked == 0) {
      form_set_error('Enable fieldset', t('Please enable one of the Conditions:  Not logged in users, Inactive users or Blocked users.'));
    }

    // Check if value field is not empty.
    if ($never_enable_loggedin == 1 && empty($never_login_value)) {
      form_set_error('purge_users_user_never_lastlogin_value', t('Interval should not be empty.'));
    }
    if ($enable_loggedin == 1 && empty($login_value)) {
      form_set_error('purge_users_user_lastlogin_value', t('Interval should not be empty.'));
    }
    if ($enable_inactive == 1 && empty($inactive_value)) {
      form_set_error('purge_users_user_inactive_value', t('Interval should not be empty.'));
    }
    if ($enable_blocked == 1 && empty($block_value)) {
      form_set_error('purge_users_user_blocked_value', t('Interval should not be empty.'));
    }
  }
}