You are here

function regcode_code_validate in Registration codes 7

Same name and namespace in other branches
  1. 8 regcode.module \regcode_code_validate()
  2. 7.2 regcode.module \regcode_code_validate()

Validate a regcode.

Parameters

string $regcode: The regcode alphanumeric code.

Return value

bool|int|object An error code, or the loaded regcode.

3 calls to regcode_code_validate()
regcode_code_consume in ./regcode.module
Consume a regcode and attribute it to a user.
regcode_code_element_validate in ./regcode.module
Validate the content of the code-field on user registration.
regcode_voucher_profiletab_form_validate in regcode_voucher/regcode_voucher.module
Validate handler for regcode_voucher_admin_form().

File

./regcode.module, line 424
Main functionality and hooks of regcode module.

Code

function regcode_code_validate($regcode) {

  // Load the code.
  $code = regcode_load_single(NULL, array(
    'code' => trim($regcode),
  ));

  // Check validity.
  if ($code === FALSE) {
    return REGCODE_VALIDITY_NOTEXISTING;
  }
  if ($code->uses >= $code->maxuses && $code->maxuses !== '0') {
    return REGCODE_VALIDITY_TAKEN;
  }
  if (!$code->is_active) {
    return REGCODE_VALIDITY_NOTAVAILABLE;
  }
  if (!empty($code->begins) && $code->begins > REQUEST_TIME) {
    return REGCODE_VALIDITY_NOTAVAILABLE;
  }
  if (!empty($code->expires) && $code->expires < REQUEST_TIME) {
    return REGCODE_VALIDITY_EXPIRED;
  }
  return $code;
}