| 1 |
<?php
|
| 2 |
// $Id: node_output.inc,v 1.11 2009/08/03 19:58:11 dww Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Code used to generate singup-related output when viewing nodes.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Generate all the signup-related output for a given node.
|
| 12 |
*
|
| 13 |
* Because of the global setting to control if the signup details and form
|
| 14 |
* appear at the bottom of the node or on a separate tab, this function is
|
| 15 |
* shared by multiple callers.
|
| 16 |
*
|
| 17 |
* @param $node
|
| 18 |
* The fully loaded node object.
|
| 19 |
* @param $type
|
| 20 |
* The kind of output would we render: can be either 'node' or 'tab'.
|
| 21 |
*
|
| 22 |
* @return
|
| 23 |
* The fully rendered HTML for all signup-related forms and info.
|
| 24 |
*
|
| 25 |
* @see signup_nodeapi()
|
| 26 |
* @see signup_node_tab()
|
| 27 |
*
|
| 28 |
* @todo This needs to be much more theme-friendly.
|
| 29 |
*
|
| 30 |
*/
|
| 31 |
function _signup_node_output($node, $type = 'node') {
|
| 32 |
$output = theme('signup_node_output_header', $node);
|
| 33 |
$output .= _signup_current_user_signup($node, $type);
|
| 34 |
return $output;
|
| 35 |
}
|
| 36 |
|
| 37 |
/**
|
| 38 |
* Helper function to generate the output for the current user's signup.
|
| 39 |
*/
|
| 40 |
function _signup_current_user_signup($node, $type = 'node') {
|
| 41 |
global $user;
|
| 42 |
$output = '';
|
| 43 |
$fieldset = $type == 'node' ? TRUE : FALSE;
|
| 44 |
// The node has been closed for signups, and the user has
|
| 45 |
// signup permissions. Let them know it's closed.
|
| 46 |
if (!$node->signup_status) {
|
| 47 |
if (user_access('sign up for content')) {
|
| 48 |
$current_signup = '';
|
| 49 |
// If they're logged in and already signed up, show their current
|
| 50 |
// signup info and give them the option to cancel.
|
| 51 |
if ($user->uid) {
|
| 52 |
$signup = db_fetch_object(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 = %d AND sl.nid = %d", $user->uid, $node->nid));
|
| 53 |
if (!empty($signup)) {
|
| 54 |
$current_signup = _signup_render_signup_edit_form($signup, $type);
|
| 55 |
}
|
| 56 |
}
|
| 57 |
$output .= theme('signup_signups_closed', $node, $current_signup);
|
| 58 |
}
|
| 59 |
}
|
| 60 |
else {
|
| 61 |
if ($user->uid == 0) {
|
| 62 |
// This is an anonymous user.
|
| 63 |
if (user_access('sign up for content')) {
|
| 64 |
// If they can signup, render the anonymous sigup form.
|
| 65 |
module_load_include('inc', 'signup', 'includes/signup_form');
|
| 66 |
$output .= drupal_get_form('signup_form', $node, 'anon', $fieldset);
|
| 67 |
}
|
| 68 |
else {
|
| 69 |
// If not, then display the appropriate login/register link if the
|
| 70 |
// default authenticated user role can signup.
|
| 71 |
$anon_login_text = '';
|
| 72 |
$signup_roles = user_roles(FALSE, 'sign up for content');
|
| 73 |
if (!empty($signup_roles[DRUPAL_AUTHENTICATED_RID])) {
|
| 74 |
$token_array = array(
|
| 75 |
'!login' => l(t('login'), 'user/login', array('query' => drupal_get_destination())),
|
| 76 |
'!register' => l(t('register'), 'user/register', array('query' => drupal_get_destination())),
|
| 77 |
'%node_type' => node_get_types('name', $node->type),
|
| 78 |
);
|
| 79 |
if (variable_get('user_register', 1) == 0) {
|
| 80 |
$anon_login_text = t('Please !login to sign up for this %node_type.', $token_array);
|
| 81 |
}
|
| 82 |
else {
|
| 83 |
$anon_login_text = t('Please !login or !register to sign up for this %node_type.', $token_array);
|
| 84 |
}
|
| 85 |
}
|
| 86 |
$output .= theme('signup_anonymous_user_login_text', $anon_login_text);
|
| 87 |
}
|
| 88 |
}
|
| 89 |
else {
|
| 90 |
// An authenticated user.
|
| 91 |
|
| 92 |
// See if the user is already signed up for this node.
|
| 93 |
$signup = db_fetch_object(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 = %d AND sl.nid = %d", $user->uid, $node->nid));
|
| 94 |
if (empty($signup)) {
|
| 95 |
// Not yet signed up
|
| 96 |
if (user_access('sign up for content')) {
|
| 97 |
// User has permission to do so, so give them the form.
|
| 98 |
module_load_include('inc', 'signup', 'includes/signup_form');
|
| 99 |
$output .= drupal_get_form('signup_form', $node, 'auth', $fieldset);
|
| 100 |
}
|
| 101 |
}
|
| 102 |
else {
|
| 103 |
// Already signed up, display their info.
|
| 104 |
$output .= _signup_render_signup_edit_form($signup, $type);
|
| 105 |
}
|
| 106 |
}
|
| 107 |
}
|
| 108 |
return $output;
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Helper function to generate the list of users signed up for a node.
|
| 113 |
*/
|
| 114 |
function signup_user_list_output($node) {
|
| 115 |
$output = '';
|
| 116 |
|
| 117 |
// How should the list of signed-up users be displayed, if at all?
|
| 118 |
$display_list = variable_get('signup_display_signup_user_list', 'signup');
|
| 119 |
|
| 120 |
// Ensure the user has permission to view the signup list for this node.
|
| 121 |
if (_signup_menu_access($node, 'list')) {
|
| 122 |
if ($display_list == 'signup' || $display_list == 'signup-tab') {
|
| 123 |
// Admin wants the hard-coded signup listing.
|
| 124 |
$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);
|
| 125 |
$registered_signups = array();
|
| 126 |
while ($signed_up_user = db_fetch_object($registered_query)) {
|
| 127 |
$registered_signups[] = $signed_up_user;
|
| 128 |
}
|
| 129 |
$anon_query = db_query("SELECT * FROM {signup_log} WHERE nid = %d AND uid = 0", $node->nid);
|
| 130 |
$anon_signups = array();
|
| 131 |
while ($signed_up_user = db_fetch_object($anon_query)) {
|
| 132 |
$anon_signups[] = $signed_up_user;
|
| 133 |
}
|
| 134 |
$output .= theme('signup_user_list', $node, $registered_signups, $anon_signups);
|
| 135 |
}
|
| 136 |
elseif (($display_list == 'embed-view' || $display_list == 'embed-view-tab') && module_exists('views')) {
|
| 137 |
$signup_view = variable_get('signup_user_list_view', 'signup_user_list:default');
|
| 138 |
$signup_view_parts = explode(':', $signup_view);
|
| 139 |
$view_name = $signup_view_parts[0];
|
| 140 |
$view_display = $signup_view_parts[1];
|
| 141 |
$view = views_get_view($view_name);
|
| 142 |
if ($display_list == 'embed-view-tab') {
|
| 143 |
$view->override_path = 'node/%/signups/list';
|
| 144 |
}
|
| 145 |
else {
|
| 146 |
$view->override_path = 'node/%';
|
| 147 |
}
|
| 148 |
$view_args = array($node->nid);
|
| 149 |
$output .= $view->preview($view_display, $view_args);
|
| 150 |
}
|
| 151 |
// Otherwise, they're on their own, and either don't want it displayed at
|
| 152 |
// all, or they want to handle where/how it's displayed via views.
|
| 153 |
}
|
| 154 |
return $output;
|
| 155 |
}
|
| 156 |
|
| 157 |
/**
|
| 158 |
* Page handler for the optional 'signup' tab on nodes.
|
| 159 |
*
|
| 160 |
* This is only used if the site has configured the signup form and related
|
| 161 |
* output to appear on a separate tab, instead of directly embedded in the
|
| 162 |
* node.
|
| 163 |
*
|
| 164 |
* @param $node
|
| 165 |
* The node to generate a signup tab for.
|
| 166 |
*
|
| 167 |
* @return
|
| 168 |
* The contents of the signup tab.
|
| 169 |
*
|
| 170 |
* @see _signup_node_output()
|
| 171 |
*/
|
| 172 |
function signup_node_tab($node) {
|
| 173 |
drupal_set_title(check_plain($node->title));
|
| 174 |
return _signup_node_output($node, 'tab');
|
| 175 |
}
|
| 176 |
|
| 177 |
/**
|
| 178 |
* Helper function to render the form to edit your own signup.
|
| 179 |
*/
|
| 180 |
function _signup_render_signup_edit_form($signup, $type) {
|
| 181 |
$path = drupal_get_path('module', 'signup');
|
| 182 |
if ($type == 'node') {
|
| 183 |
drupal_add_css("$path/signup.css");
|
| 184 |
}
|
| 185 |
drupal_add_js("$path/js/signup_edit_form.js");
|
| 186 |
module_load_include('inc', 'signup', 'includes/signup_edit_form');
|
| 187 |
$form = drupal_get_form('signup_edit_form', $signup, $type);
|
| 188 |
$form_errors = form_get_errors() ? TRUE : FALSE;
|
| 189 |
drupal_add_js(array('signupEditFormErrors' => $form_errors), 'setting');
|
| 190 |
return $form;
|
| 191 |
}
|
| 192 |
|