You are here

function uc_roles_user_validate in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_roles/uc_roles.module \uc_roles_user_validate()

Implements hook_user_validate().

1 call to uc_roles_user_validate()
uc_roles_user in uc_roles/uc_roles.module
Implements hook_user().

File

uc_roles/uc_roles.module, line 411

Code

function uc_roles_user_validate(&$edit, &$account, $category) {

  // Validate the amount of time for the expiration.
  if (!empty($edit['new_role']) && $category == 'account') {
    if (intval($edit['new_role_add_qty']) < 1) {
      form_set_error('new_role_add_qty', t('The expiration length must be a positive integer'));
    }
  }

  // Validate adjusted expirations.
  if (isset($edit['table'])) {
    foreach ((array) $edit['table'] as $rid => $value) {

      // We don't validate if nothing was actually selected, the role, or the
      // expiration is removed.
      if ($value['qty'] == 0 || $value['remove'] == 1 || !$edit['roles'][$rid]) {
        continue;
      }
      $qty = $value['qty'];
      $qty *= $value['polarity'] == 'add' ? 1 : -1;
      $new_expiration = _uc_roles_get_expiration($qty, $value['granularity'], $value['expiration']);
      if (time() > $new_expiration) {
        form_set_error('qty', t("The new expiration date, %date, has already occurred.", array(
          '%date' => format_date($new_expiration, 'small'),
        )));
      }
    }
  }
}