You are here

function _signup_current_user_signup in Signup 7

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

Helper function to generate the output for the current user's signup.

2 calls to _signup_current_user_signup()
signup_current_user_signup_page in ./signup.module
Page callback for displaying a signup form.
_signup_node_output in includes/node_output.inc
Generate all the signup-related output for a given node.

File

includes/node_output.inc, line 37
Code used to generate singup-related output when viewing nodes.

Code

function _signup_current_user_signup($node, $type = 'node') {
  global $user;
  $output = '';
  $fieldset = $type == 'node' && !variable_get('signup_ignore_default_fields', 0) ? TRUE : FALSE;

  // 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) {
        $signup = db_query("SELECT sl.*, n.title, u.name FROM {signup_log} sl INNER JOIN {node} n ON sl.nid = n.nid INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.uid = :uid AND sl.nid = :nid", array(
          ':uid' => $user->uid,
          ':nid' => $node->nid,
        ))
          ->fetchObject();
        if (!empty($signup)) {
          $current_signup = _signup_render_signup_edit_form($signup, $type);
        }
      }
      $output .= theme('signup_signups_closed', array(
        'node' => $node,
        'current_signup' => $current_signup,
      ));
    }
  }
  else {
    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.
        module_load_include('inc', 'signup', 'includes/signup_form');
        $form = drupal_get_form('signup_form', $node, 'anon', $fieldset);
        $output .= drupal_render($form);
      }
      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(
              'query' => drupal_get_destination(),
            )),
            '!register' => l(t('register'), 'user/register', array(
              'query' => drupal_get_destination(),
            )),
            '%node_type' => node_type_get_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', array(
          'anon_login_text' => $anon_login_text,
        ));
      }
    }
    else {

      // An authenticated user.
      // See if the user is already signed up for this node.
      $signup = db_query("SELECT sl.*, n.title, u.name, u.mail FROM {signup_log} sl INNER JOIN {node} n ON sl.nid = n.nid INNER JOIN {users} u ON sl.uid = u.uid WHERE sl.uid = :uid AND sl.nid = :nid", array(
        ':uid' => $user->uid,
        ':nid' => $node->nid,
      ))
        ->fetchObject();
      if (empty($signup)) {

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

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

        // Already signed up, display their info.
        $output .= _signup_render_signup_edit_form($signup, $type);
      }
    }
  }
  return $output;
}