function signup_save_node in Signup 6
Same name and namespace in other branches
- 5.2 signup.module \signup_save_node()
- 6.2 includes/node_form.inc \signup_save_node()
- 7 includes/node_form.inc \signup_save_node()
Save signup-related information when a node is created or edited.
This is a helper function invoked via signup_nodeapi(). If signups are disabled, the record from {signup} (if any) is cleared. If the signup administrator editing the node decided to remove all signup data, all the records from the {signup_log} table for this node are also removed. This function is also responsible for testing if the node has a start time and if the autoclose period has already begun, in which case signups are closed. If a new node is being saved, or an existing node is updated and is newly-enabled for signups, the site-wide default signup settings are copied into a record in the {signup} table for this node so that the node is properly signup-enabled (these settings can be changed by visiting the "Settings" subtab under the "Signups" tab at node/N/signups/settings).
Parameters
$node: The node object given to signup_nodeapi().
$op: The hook_nodeapi() operation, either 'insert' or 'update'.
Return value
Nothing, this function is expected to update the database.
See also
1 call to signup_save_node()
- signup_nodeapi in ./
signup.module - Implementation of hook_nodeapi().
File
- includes/
node_form.inc, line 34 - Signup-related code needed while editing a node.
Code
function signup_save_node($node, $op) {
// See if a user is editing a node and disables signups for it.
if ($op == 'update' && isset($node->signup_enabled)) {
switch ($node->signup_enabled) {
case 2:
// Disabled, and delete {signup_log}, too
db_query("DELETE FROM {signup_log} WHERE nid = %d", $node->nid);
// No break, fall through and remove from {signup} too.
case 0:
// Disabled, but leave {signup_log} alone
db_query("DELETE FROM {signup} WHERE nid = %d", $node->nid);
// We're done.
return;
}
}
// If the form is configured to have signups enabled, or the form doesn't
// include that information at all but the node type defaults to have
// signups enabled (which would happen if a user without signup admin
// permission created a node that defaulted to have signups enabled based on
// the node type), see if we need to insert a new record into the {signup}
// table for this node using the site-wide defaults.
$needs_defaults = FALSE;
if (isset($node->signup_enabled) && $node->signup_enabled == 1 || !isset($node->signup_enabled) && variable_get('signup_node_default_state_' . $node->type, 'disabled') == 'enabled_on') {
if ($op == 'insert') {
$needs_defaults = TRUE;
}
else {
// Updating -- see if we already have a record for this node.
$has_record = db_result(db_query("SELECT nid FROM {signup} WHERE nid = %d", $node->nid));
$needs_defaults = empty($has_record);
}
}
if ($needs_defaults) {
$values = db_fetch_array(db_query("SELECT forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email FROM {signup} WHERE nid = 0"));
$values[] = $node->nid;
db_query("INSERT INTO {signup} (forwarding_email, send_confirmation, confirmation_email, close_signup_limit, send_reminder, reminder_days_before, reminder_email, nid) VALUES ('%s', %d, '%s', %d, %d, %d, '%s', %d)", $values);
}
db_query("UPDATE {signup} SET user_reg_form = %d WHERE nid = %d", $node->signup_user_reg, $node->nid);
$node = node_load($node->nid);
// We clear CCK's cache for this node due to an edge case bug:
// http://drupal.org/node/605594.
if (module_exists('content')) {
cache_clear_all('content:' . $node->nid . ':' . $node->vid, content_cache_tablename());
}
if (_signup_node_completed($node) && !empty($node->signup_status)) {
// If this is an time-based node, and it's already past the close in
// advance time (e.g. someone just changed the node start time), and
// signups are still open, close them now.
signup_close_signup($node->nid);
drupal_set_message(t('%node_type start time is already past the signup close-in-advance time, signups now closed.', array(
'%node_type' => node_get_types('name', $node->type),
)));
}
}