function regcode_get_code in Registration codes 5.3
Same name and namespace in other branches
- 6 regcode.api.php \regcode_get_code()
Retrieve a particular registration code identified by given code id, or assign it to a given user
Parameters
$code: The code identifiert string
$assign_to_uid: Optional user id to assign the given code to
Return value
The data array of the code to retrieve, or a boolean result (TRUE=successfully assigned to given uid) if assign_to_uid has been given.
1 call to regcode_get_code()
- regcode_user in ./
regcode.module - Act on user account actions.
File
- ./
regcode_api.inc.php, line 58 - regcode_api.inc.php contains general low-level functions for the registration-code module, for tasks like
Code
function regcode_get_code($code, $assign_to_uid = FALSE) {
// look up and retrieve code record from DB
$code = db_fetch_array(db_query("SELECT * FROM {regcode} WHERE code = '%s'", $code));
// check validity
if (!is_array($code)) {
return REGCODE_VALIDITY_NOTEXISTING;
}
if ($code['uid']) {
return REGCODE_VALIDITY_TAKEN;
}
if (!$code['available']) {
return REGCODE_VALIDITY_NOTAVAILABLE;
}
if ($code['expire'] && $code['expire'] < $_SERVER["REQUEST_TIME"]) {
return REGCODE_VALIDITY_EXPIRED;
}
// optionally mark this code as taken for the given user uid
if ($assign_to_uid) {
if ($code['reuse']) {
$result = db_query("UPDATE {regcode} SET used_count = (used_count + 1), used = UNIX_TIMESTAMP() WHERE code = '%s'", $code['code']);
}
else {
$result = db_query("UPDATE {regcode} SET available = 0, used_count = 1, used = UNIX_TIMESTAMP(), uid = %d WHERE code = '%s'", $assign_to_uid, $code['code']);
}
}
return $code;
}