You are here

function signup_save_node in Signup 6.2

Same name and namespace in other branches
  1. 5.2 signup.module \signup_save_node()
  2. 6 includes/node_form.inc \signup_save_node()
  3. 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

signup_nodeapi()

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);

    // Copy the signup panes defaults to the new node.
    db_query("INSERT INTO {signup_panes} (nid, pane_id, callback, weight) SELECT %d, pane_id, callback, weight FROM {signup_panes} WHERE nid = 0", $node->nid);
  }
  $node = node_load($node->nid);
  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),
    )));
  }
}