You are here

function signup_nodeapi in Signup 6

Same name and namespace in other branches
  1. 5.2 signup.module \signup_nodeapi()
  2. 5 signup.module \signup_nodeapi()
  3. 6.2 signup.module \signup_nodeapi()

Implementation of hook_nodeapi().

Related topics

File

./signup.module, line 752
The Signup module (http://drupal.org/project/signup) manages replies to nodes. In particular, it's good for event management. Signup supports sending reminder emails and automatically closing signups for nodes with a start time, via the Event…

Code

function signup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      module_load_include('inc', 'signup', 'includes/node_form');
      signup_save_node($node, $op);
      break;
    case 'delete':

      // Clean up the signup tables for the deleted node.
      db_query("DELETE FROM {signup} WHERE nid = %d", $node->nid);
      db_query("DELETE FROM {signup_log} WHERE nid = %d", $node->nid);
      break;
    case 'load':

      // Check for a signup for this node.
      // If it's a new node, load the defaults.
      $result = db_query("SELECT * FROM {signup} WHERE nid = %d", $node->nid ? $node->nid : 0);
      $signup = db_fetch_object($result);

      // Load signup data for both new nodes w/ enabled node types,
      // and any existing nodes that are already signup enabled.
      if (!$node->nid && variable_get('signup_node_default_state_' . $node->type, 'disabled') == 'enabled_on' || $node->nid && !empty($signup)) {
        $node->signup = 1;
        $node->signup_forwarding_email = $signup->forwarding_email;
        $node->signup_send_confirmation = $signup->send_confirmation;
        $node->signup_confirmation_email = $signup->confirmation_email;
        $node->signup_send_reminder = $signup->send_reminder;
        $node->signup_reminder_days_before = $signup->reminder_days_before;
        $node->signup_reminder_email = $signup->reminder_email;
        $node->signup_close_signup_limit = $signup->close_signup_limit;
        $node->signup_status = $signup->status;
        $node->signup_user_reg_form = $signup->user_reg_form;
        if ($node->nid) {
          $node->signup_total = db_result(db_query("SELECT COUNT(*) FROM {signup_log} WHERE nid = %d", $node->nid));
          $node->signup_effective_total = db_result(db_query("SELECT SUM(count_towards_limit) FROM {signup_log} WHERE nid = %d", $node->nid));
        }
      }
      else {
        $node->signup = 0;
      }
      break;
    case 'view':

      // If this is a signup node, figure out what (if anything) to print.
      // Only include any of this if we're trying to view the node as
      // a page, not during the view from comment validation, etc.
      if ($page && _signup_needs_output($node)) {
        $info_location = variable_get('signup_form_location', 'node');
        $list_location = variable_get('signup_display_signup_user_list', 'embed-view');
        if ($info_location == 'node' || $list_location == 'embed-view') {
          module_load_include('inc', 'signup', 'includes/node_output');
        }
        if ($info_location == 'node') {
          $signup_info = _signup_node_output($node);
          if (!empty($signup_info)) {
            if (module_exists('content')) {

              // Due to a bug in CCK (http://drupal.org/node/363456), we need
              // to call this function twice to ensure we get the real value.
              // The bug is present when you first enable the setting to
              // display in the node instead of a separate tab, or when you
              // first upgrade to the version that contains this code.
              content_extra_field_weight($node->type, 'signup_node_info');
              $weight = content_extra_field_weight($node->type, 'signup_node_info');
            }
            else {
              $weight = variable_get('signup_info_node_weight_' . $node->type, 10);
            }
            $node->content['signup'] = array(
              '#value' => $signup_info,
              '#weight' => $weight,
            );
          }
        }
        if ($list_location == 'embed-view') {
          $signup_list = signup_user_list_output($node);
          if (!empty($signup_list)) {
            if (module_exists('content')) {

              // Call this twice to work-around a bug in CCK (#363456).
              content_extra_field_weight($node->type, 'signup_node_list');
              $weight = content_extra_field_weight($node->type, 'signup_node_list');
            }
            else {
              $weight = variable_get('signup_list_node_weight_' . $node->type, 11);
            }
            $node->content['signup_list'] = array(
              '#value' => $signup_list,
              '#weight' => $weight,
            );
          }
        }
      }
      break;
  }
}