You are here

function _signup_node_output in Signup 5.2

Same name and namespace in other branches
  1. 6.2 includes/node_output.inc \_signup_node_output()
  2. 6 includes/node_output.inc \_signup_node_output()
  3. 7 includes/node_output.inc \_signup_node_output()

Generate all the signup-related output for a given node.

Because of the global setting to control if the signup details and form appear at the bottom of the node or on a separate tab, this function is shared by multiple callers.

@todo This needs to be much more theme-friendly.

Parameters

$node: The fully loaded node object.

$type: The kind of output would we render: can be either 'node' or 'tab'.

Return value

The fully rendered HTML for all signup-related forms and info.

See also

signup_nodeapi()

signup_node_tab()

3 calls to _signup_node_output()
signup_nodeapi in ./signup.module
Implementation of hook_nodeapi().
signup_node_tab in ./signup.module
signup_panels_content_signup_form in panels/content_types/signup_form.inc
Render a pane of the 'signup form' content type.

File

./signup.module, line 851
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_node_output($node, $type = 'node') {
  global $user;
  $output = theme('signup_node_output_header', $node);

  // The node has been closed for signups, and the user has
  // signup permissions.  Let them know it's closed.
  if (!$node->signup_status) {
    if (user_access('sign up for content')) {
      $current_signup = '';

      // If they're logged in and already signed up, show their current
      // signup info and give them the option to cancel.
      if ($user->uid) {
        $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
        if (db_num_rows($result)) {
          $signup_info = db_fetch_object($result);
          $current_signup = _signup_print_current_signup($node, $signup_info);
        }
      }
      $output .= theme('signup_signups_closed', $node, $current_signup);
    }
  }
  else {
    $fieldset = $type == 'node' ? TRUE : FALSE;
    if ($user->uid == 0) {

      // This is an anonymous user.
      if (user_access('sign up for content')) {

        // If they can signup, render the anonymous sigup form.
        $output .= drupal_get_form('signup_form', $node, 'anon', $fieldset);
      }
      else {

        // If not, then display the appropriate login/register link if the
        // default authenticated user role can signup.
        $anon_login_text = '';
        $signup_roles = user_roles(FALSE, 'sign up for content');
        if (!empty($signup_roles[DRUPAL_AUTHENTICATED_RID])) {
          $token_array = array(
            '!login' => l(t('login'), 'user/login', array(), drupal_get_destination()),
            '!register' => l(t('register'), 'user/register', array(), drupal_get_destination()),
            '%node_type' => node_get_types('name', $node->type),
          );
          if (variable_get('user_register', 1) == 0) {
            $anon_login_text = t('Please !login to sign up for this %node_type.', $token_array);
          }
          else {
            $anon_login_text = t('Please !login or !register to sign up for this %node_type.', $token_array);
          }
        }
        $output .= theme('signup_anonymous_user_login_text', $anon_login_text);
      }
    }
    else {

      // An authenticated user.
      // See if the user is already signed up for this node.
      $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
      $signup_info = NULL;
      if (db_num_rows($result) == 0) {

        // Not yet signed up
        if (user_access('sign up for content')) {

          // User has permission to do so, so give them the form.
          $output .= drupal_get_form('signup_form', $node, 'auth', $fieldset);
        }
      }
      else {

        // Already signed up, display their info.
        $signup_info = db_fetch_object($result);
        $output .= _signup_print_current_signup($node, $signup_info);
      }
    }
  }

  // How should the list of signed-up users be displayed, if at all?
  $display_list = variable_get('signup_display_signup_user_list', 'signup');

  // If the user has the view signups perm and the admin decides to display
  // the list at the bottom of the page, display the current signups.
  if (user_access('view all signups')) {
    if ($display_list == 'signup') {

      // Admin wants the hard-coded signup listing.
      $registered_query = db_query("SELECT u.uid, u.name, s.signup_time, s.form_data FROM {signup_log} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.nid = %d AND u.uid <> 0", $node->nid);
      $registered_signups = array();
      while ($signed_up_user = db_fetch_object($registered_query)) {
        $registered_signups[] = $signed_up_user;
      }
      $anon_query = db_query("SELECT * FROM {signup_log} WHERE nid = %d AND uid = 0", $node->nid);
      $anon_signups = array();
      while ($signed_up_user = db_fetch_object($anon_query)) {
        $anon_signups[] = $signed_up_user;
      }
      $output .= theme('signup_user_list', $node, $registered_signups, $anon_signups);
    }
    elseif ($display_list == 'embed-view' && module_exists('views')) {
      $view_name = variable_get('signup_user_list_view_name', 'signup_user_list');
      $view_type = variable_get('signup_user_list_view_type', 'embed');
      $view = views_get_view($view_name);
      $args = array(
        $node->nid,
      );
      $output .= views_build_view($view_type, $view, $args);
    }

    // Otherwise, they're on their own, and either don't want it displayed at
    // all, or they want to handle where/how it's displayed via views.
  }
  return $output;
}