You are here

function uc_roles_feature_form_validate in Ubercart 6.2

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

Validation function for the roles feature form.

See also

uc_roles_feature_form()

uc_roles_feature_form_submit()

File

uc_roles/uc_roles.module, line 794

Code

function uc_roles_feature_form_validate($form, &$form_state) {

  // Invalid quantity?
  if ($form_state['values']['expiration'] === 'abs') {
    $form_state['values']['uc_roles_expire_absolute'] = mktime(0, 0, 0, $form_state['values']['uc_roles_expire_absolute']['month'], $form_state['values']['uc_roles_expire_absolute']['day'], $form_state['values']['uc_roles_expire_absolute']['year']);
    if ($form_state['values']['uc_roles_expire_absolute'] <= time()) {
      form_set_error('uc_roles_expire_absolute', t('The specified date !date has already occurred. Please choose another.', array(
        '!date' => format_date($form_state['values']['uc_roles_expire_absolute']),
      )));
    }
  }
  else {
    if ($form_state['values']['uc_roles_expire_relative_granularity'] != 'never' && intval($form_state['values']['uc_roles_expire_relative_duration']) < 1) {
      form_set_error('uc_roles_expire_relative_duration', t('The amount of time must be a positive integer.'));
    }
  }

  // No roles?
  if (empty($form_state['values']['uc_roles_role'])) {
    form_set_error('uc_roles_role', t('You must have a role to assign. You may need to <a href="!role_url">create a new role</a> or perhaps <a href="!feature_url">set role assignment defaults</a>.', array(
      '!role_url' => url('admin/user/roles'),
      '!feature_url' => url('admin/store/settings/products/edit/features'),
    )));
  }

  // This role already set on this SKU?
  if ($product_roles = db_fetch_object(db_query("SELECT * FROM {uc_roles_products} WHERE nid = %d AND model = '%s' AND rid = %d", $form_state['values']['nid'], $form_state['values']['uc_roles_model'], $form_state['values']['uc_roles_role'])) && $form_state['values']['pfid'] == 0) {
    form_set_error('uc_roles_role', t('The combination of SKU and role already exists for this product.'));
    form_set_error('uc_roles_model', ' ');
  }
}