| 1 |
<?php
|
| 2 |
// $Id: node_admin.inc,v 1.6 2009/01/14 17:36:11 dww Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Code related to the signup administration tab on each node.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Print the signup administration tab for a single node.
|
| 12 |
*/
|
| 13 |
function signup_node_admin_page($node) {
|
| 14 |
drupal_set_title(check_plain($node->title));
|
| 15 |
|
| 16 |
// Administrative table to control signups for this node.
|
| 17 |
// We only want this if we're not in the middle of confirming a bulk
|
| 18 |
// operation on the signup details table. Even though directly inspecting
|
| 19 |
// POST is almost always a bad idea, in this case, we're not using or
|
| 20 |
// displaying any of the data at all. We're just making a cosmetic decision
|
| 21 |
// based on if it's a certain kind of POST...
|
| 22 |
if (empty($_POST['operation'])) {
|
| 23 |
module_load_include('inc', 'signup', 'includes/node_admin_summary');
|
| 24 |
$signup_node_admin_summary_form = drupal_get_form('signup_node_admin_summary_form', $node);
|
| 25 |
}
|
| 26 |
else {
|
| 27 |
// We're either dealing with a validation error or on a confirm form, so
|
| 28 |
// don't render the summary form at all.
|
| 29 |
$signup_node_admin_summary_form = '';
|
| 30 |
}
|
| 31 |
|
| 32 |
// Signup details table, including cancel checkboxes.
|
| 33 |
$display_list = variable_get('signup_display_signup_admin_list', 'signup');
|
| 34 |
if ($display_list == 'signup') {
|
| 35 |
$signup_node_admin_details_form = drupal_get_form('signup_node_admin_details_form', $node);
|
| 36 |
}
|
| 37 |
elseif ($display_list == 'embed-view' && module_exists('views')) {
|
| 38 |
$signup_view = _signup_get_admin_list_view();
|
| 39 |
$signup_view_parts = explode(':', $signup_view);
|
| 40 |
$view_name = $signup_view_parts[0];
|
| 41 |
$view_display = $signup_view_parts[1];
|
| 42 |
$view = views_get_view($view_name);
|
| 43 |
$view->override_path = 'node/%/signups/admin';
|
| 44 |
$view_args = array($node->nid);
|
| 45 |
$signup_node_admin_details_form = $view->preview($view_display, $view_args);
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
// They don't want the administrative user list at all.
|
| 49 |
$signup_node_admin_details_form = '';
|
| 50 |
}
|
| 51 |
|
| 52 |
return theme('signup_node_admin_page', $node, $signup_node_admin_summary_form, $signup_node_admin_details_form);
|
| 53 |
}
|
| 54 |
|
| 55 |
function signup_node_admin_details_form(&$form_state, $node) {
|
| 56 |
unset($_SESSION['signup_cancel_multiple_users']);
|
| 57 |
$form = array();
|
| 58 |
|
| 59 |
// Prepare a table header that allows sorting on name and signup time.
|
| 60 |
$header = array(
|
| 61 |
theme('table_select_header_cell'),
|
| 62 |
array('data' => t('Name'), 'field' => 'u.name', 'sort' => 'asc'),
|
| 63 |
array('data' => t('Signup time'), 'field' => 's.signup_time'),
|
| 64 |
array('data' => t('Extra information')),
|
| 65 |
array('data' => t('Attendance'), 'field' => 's.attended'),
|
| 66 |
);
|
| 67 |
|
| 68 |
$sql = "SELECT u.uid, u.name, s.* FROM {signup_log} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.nid = %d";
|
| 69 |
$sql .= tablesort_sql($header);
|
| 70 |
$result = db_query($sql, $node->nid);
|
| 71 |
|
| 72 |
// Loop through the users, unserializing their user data.
|
| 73 |
while ($signed_up_user = db_fetch_object($result)) {
|
| 74 |
// The "username" to print is different for anon signups and registered
|
| 75 |
// user signups. For registered users, provide a link to the user profile
|
| 76 |
// For anon, use the user's email address as the name.
|
| 77 |
if ($signed_up_user->uid == 0) {
|
| 78 |
$username = check_plain($signed_up_user->anon_mail);
|
| 79 |
}
|
| 80 |
else {
|
| 81 |
$username = theme('username', $signed_up_user);
|
| 82 |
}
|
| 83 |
$key = $signed_up_user->sid;
|
| 84 |
$users[$key] = '';
|
| 85 |
$form['username'][$key] = array('#value' => $username);
|
| 86 |
$form['signup_date'][$key] = array('#value' => format_date($signed_up_user->signup_time, variable_get('signup_date_format', 'small')));
|
| 87 |
$form['signup_form_data'][$key] = array('#value' => theme('signup_custom_data', unserialize($signed_up_user->form_data)));
|
| 88 |
$form['attended'][$key] = array('#value' => theme('signup_attended_text', $signed_up_user->attended));
|
| 89 |
}
|
| 90 |
if (empty($users)) {
|
| 91 |
$form['no_users'] = array('#value' => t('No users have signed up for this %node_type.', array('%node_type' => node_get_types('name', $node->type))));
|
| 92 |
}
|
| 93 |
else {
|
| 94 |
$form['nid'] = array(
|
| 95 |
'#type' => 'hidden',
|
| 96 |
'#value' => $node->nid,
|
| 97 |
);
|
| 98 |
$form['users'] = array('#type' => 'checkboxes', '#options' => $users);
|
| 99 |
$form['operation'] = array(
|
| 100 |
'#type' => 'select',
|
| 101 |
'#options' => array(
|
| 102 |
'attend_yes' => t('Mark as attended'),
|
| 103 |
'attend_no' => t('Mark as did not attend'),
|
| 104 |
),
|
| 105 |
);
|
| 106 |
if (user_access('cancel signups')) {
|
| 107 |
$form['operation']['#options']['cancel'] = t('Cancel signup');
|
| 108 |
}
|
| 109 |
|
| 110 |
$form['submit'] = array(
|
| 111 |
'#type' => 'submit',
|
| 112 |
'#value' => t('Update'),
|
| 113 |
'#submit' => array('signup_node_admin_multiple_submit'),
|
| 114 |
'#validate' => array('signup_node_admin_multiple_validate'),
|
| 115 |
);
|
| 116 |
$form['#header'] = $header;
|
| 117 |
}
|
| 118 |
return $form;
|
| 119 |
}
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Validate handler for updating multiple signups via node/N/signups.
|
| 123 |
*/
|
| 124 |
function signup_node_admin_multiple_validate($form, &$form_state) {
|
| 125 |
$users = array_filter($form_state['values']['users']);
|
| 126 |
if (empty($users)) {
|
| 127 |
form_set_error('', t('No users selected.'));
|
| 128 |
}
|
| 129 |
}
|
| 130 |
|
| 131 |
/**
|
| 132 |
* Submit handler for updating multiple signups via node/N/signups.
|
| 133 |
*
|
| 134 |
* If the operation is non-destructive (recording attendance), do the deed.
|
| 135 |
* For cancelling multiple users, this just saves the selected users into
|
| 136 |
* SESSION and redirects to a confirm form which is registered at
|
| 137 |
* node/N/signups/confirm.
|
| 138 |
*/
|
| 139 |
function signup_node_admin_multiple_submit($form, &$form_state) {
|
| 140 |
$users = array_filter($form_state['values']['users']);
|
| 141 |
switch ($form_state['values']['operation']) {
|
| 142 |
case 'cancel':
|
| 143 |
if (user_access('cancel signups')) {
|
| 144 |
$_SESSION['signup_cancel_multiple_users'] = $users;
|
| 145 |
$form_state['redirect'] = 'node/'. $form_state['values']['nid'] .'/signups/confirm';
|
| 146 |
return;
|
| 147 |
}
|
| 148 |
else {
|
| 149 |
drupal_set_message(t('You do not have permission to cancel signups.'), 'error');
|
| 150 |
return;
|
| 151 |
}
|
| 152 |
|
| 153 |
case 'attend_yes':
|
| 154 |
$attend = 1;
|
| 155 |
break;
|
| 156 |
|
| 157 |
case 'attend_no':
|
| 158 |
$attend = 0;
|
| 159 |
break;
|
| 160 |
|
| 161 |
}
|
| 162 |
$placeholders = db_placeholders($users);
|
| 163 |
db_query("UPDATE {signup_log} SET attended = %d WHERE sid IN ($placeholders)", array($attend) + $users);
|
| 164 |
}
|
| 165 |
|
| 166 |
/**
|
| 167 |
* Builds the confirm form when canceling multiple signups from node/N/signups.
|
| 168 |
*/
|
| 169 |
function signup_cancel_multiple_confirm(&$form_state, $node) {
|
| 170 |
$form = array();
|
| 171 |
$form['nid'] = array(
|
| 172 |
'#type' => 'hidden',
|
| 173 |
'#value' => $node->nid,
|
| 174 |
);
|
| 175 |
$form['users'] = array(
|
| 176 |
'#prefix' => '<ul>',
|
| 177 |
'#suffix' => '</ul>',
|
| 178 |
'#tree' => TRUE,
|
| 179 |
);
|
| 180 |
$placeholders = db_placeholders($_SESSION['signup_cancel_multiple_users']);
|
| 181 |
$query = db_query("SELECT u.name, u.uid, s.* FROM {signup_log} s INNER JOIN {users} u ON s.uid = u.uid WHERE s.sid IN (". $placeholders .")", $_SESSION['signup_cancel_multiple_users']);
|
| 182 |
while ($signup = db_fetch_object($query)) {
|
| 183 |
$key = $signup->sid;
|
| 184 |
if ($signup->uid) {
|
| 185 |
$label = theme('username', $signup);
|
| 186 |
}
|
| 187 |
else {
|
| 188 |
$label = t('Anonymous signup: %anon_mail', array('%anon_mail' => $signup->anon_mail));
|
| 189 |
}
|
| 190 |
$form['users'][$key] = array(
|
| 191 |
'#type' => 'hidden',
|
| 192 |
'#value' => $key,
|
| 193 |
'#prefix' => '<li>',
|
| 194 |
'#suffix' => $label ."</li>\n",
|
| 195 |
);
|
| 196 |
}
|
| 197 |
$form['#submit'][] = 'signup_cancel_multiple_confirm_submit';
|
| 198 |
return confirm_form(
|
| 199 |
$form,
|
| 200 |
t('Are you sure you want to cancel signups for these users?'),
|
| 201 |
'node/'. $node->nid .'/signups',
|
| 202 |
t('This action cannot be undone.'),
|
| 203 |
t('Cancel signups'), t('Keep signups')
|
| 204 |
);
|
| 205 |
}
|
| 206 |
|
| 207 |
/**
|
| 208 |
* Submit handler for the confirm form to cancel multiple signups.
|
| 209 |
*/
|
| 210 |
function signup_cancel_multiple_confirm_submit($form, &$form_state) {
|
| 211 |
$nid = $form_state['values']['nid'];
|
| 212 |
if (user_access('cancel signups')) {
|
| 213 |
foreach ($form_state['values']['users'] as $key) {
|
| 214 |
signup_cancel_signup($key);
|
| 215 |
}
|
| 216 |
}
|
| 217 |
else {
|
| 218 |
drupal_set_message(t('You do not have permission to cancel signups.'), 'error');
|
| 219 |
}
|
| 220 |
$form_state['redirect'] = 'node/'. $nid .'/signups';
|
| 221 |
unset($_SESSION['signup_cancel_multiple_users']);
|
| 222 |
}
|
| 223 |
|