function regcode_save in Registration codes 6.2
Same name and namespace in other branches
- 8 regcode.module \regcode_save()
- 7.2 regcode.module \regcode_save()
- 7 regcode.module \regcode_save()
Save given code array to a record in the db
@todo Remove the $terms parameter and put it in the object
Parameters
$code object A code object (required fields are code,:
$terms array An array of terms to associate this tag with:
$action int Action to perform when saving the code::
Return value
bool TRUE if the code was saved
3 calls to regcode_save()
- regcode_admin_create_submit in ./
regcode.admin.php - Process creation form
- regcode_dynamic_user in regcode_dynamic/
regcode_dynamic.module - Implementation of hook_user().
- regcode_ie_admin_import_submit in regcode_ie/
regcode_ie.module - Process import form
File
- ./
regcode.module, line 457
Code
function regcode_save($code, $terms = array(), $action = REGCODE_MODE_REPLACE) {
// Sanity check
if (empty($code) || empty($code->code)) {
return FALSE;
}
// Insert mode
if ($action == REGCODE_MODE_REPLACE) {
db_query("DELETE FROM {regcode} WHERE code = '%s'", $code->code);
}
// Insert
$sql = "INSERT INTO {regcode} (created,begins,expires,code,is_active,maxuses)\n VALUES (%d, %s, %s, '%s', %d, %s)";
$result = db_query($sql, time(), empty($code->begins) ? 'NULL' : (int) $code->begins, empty($code->expires) ? 'NULL' : (int) $code->expires, check_plain($code->code), isset($code->is_active) ? $code->is_active : 1, isset($code->maxuses) ? (int) $code->maxuses : 1);
// Add tags
if (count($terms)) {
$rid = db_last_insert_id('regcode', 'rid');
foreach ($terms as $term) {
db_query('INSERT INTO {regcode_term} (rid, tid) VALUES (%d, %d)', $rid, $term);
}
}
return $result;
}