2 // $Id: node_admin.inc,v 1.1.2.3 2008/12/20 06:31:27 dww Exp $
7 * Code related to the signup administration tab on each node.
11 * Print the signup administration tab for a single node.
13 function signup_node_admin_page($node) {
14 drupal_set_title(check_plain($node->title));
16 // Administrative table to control signups for this node.
17 module_load_include('inc', 'signup', 'includes/node_admin_summary');
18 $signup_node_admin_summary_form = drupal_get_form('signup_node_admin_summary_form', $node);
20 // Signup details table, including cancel checkboxes.
21 $signup_node_admin_details_form = drupal_get_form('signup_node_admin_details_form', $node);
23 return theme('signup_node_admin_page', $node, $signup_node_admin_summary_form, $signup_node_admin_details_form);
26 function signup_node_admin_details_form(&$form_state, $node) {
27 unset($_SESSION['signup_cancel_multiple_users']);
30 // Prepare a table header that allows sorting on name and signup time.
32 theme('table_select_header_cell'),
33 array('data' => t('Name'), 'field' => 'u.name', 'sort' => 'asc'),
34 array('data' => t('Signup time'), 'field' => 's.signup_time'),
35 array('data' => t('Extra information')),
36 array('data' => t('Attendance'), 'field' => 's.attended'),
39 $sql = "SELECT u.uid, u.name, s.* FROM {signup_log} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.nid = %d";
40 $sql .= tablesort_sql($header);
41 $result = db_query($sql, $node->nid);
43 // Loop through the users, unserializing their user data.
44 while ($signed_up_user = db_fetch_object($result)) {
45 // The "username" to print is different for anon signups and registered
46 // user signups. For registered users, provide a link to the user profile
47 // For anon, use the user's email address as the name.
48 if ($signed_up_user->uid == 0) {
49 $username = check_plain($signed_up_user->anon_mail);
52 $username = theme('username', $signed_up_user);
54 $key = $signed_up_user->sid;
56 $form['username'][$key] = array('#value' => $username);
57 $form['signup_date'][$key] = array('#value' => format_date($signed_up_user->signup_time, variable_get('signup_date_format', 'small')));
58 $form['signup_form_data'][$key] = array('#value' => theme('signup_custom_data', unserialize($signed_up_user->form_data)));
59 $form['attended'][$key] = array('#value' => theme('signup_attended_text', $signed_up_user->attended));
62 $form['no_users'] = array('#value' => t('No users have signed up for this %node_type.', array('%node_type' => node_get_types('name', $node->type))));
67 '#value' => $node->nid,
69 $form['users'] = array('#type' => 'checkboxes', '#options' => $users);
70 $form['operation'] = array(
73 'attend_yes' => t('Mark as attended'),
74 'attend_no' => t('Mark as did not attend'),
77 if (user_access('cancel signups')) {
78 $form['operation']['#options']['cancel'] = t('Cancel signup');
81 $form['submit'] = array(
83 '#value' => t('Update'),
84 '#submit' => array('signup_node_admin_multiple_submit'),
85 '#validate' => array('signup_node_admin_multiple_validate'),
87 $form['#header'] = $header;
93 * Validate handler for updating multiple signups via node/N/signups.
95 function signup_node_admin_multiple_validate($form, &$form_state) {
96 $users = array_filter($form_state['values']['users']);
98 form_set_error('', t('No users selected.'));
103 * Submit handler for updating multiple signups via node/N/signups.
105 * If the operation is non-destructive (recording attendance), do the deed.
106 * For cancelling multiple users, this just saves the selected users into
107 * SESSION and redirects to a confirm form which is registered at
108 * node/N/signups/confirm.
110 function signup_node_admin_multiple_submit($form, &$form_state) {
111 $users = array_filter($form_state['values']['users']);
112 switch ($form_state['values']['operation']) {
114 if (user_access('cancel signups')) {
115 $_SESSION['signup_cancel_multiple_users'] = $users;
116 $form_state['redirect'] = 'node/'. $form_state['values']['nid'] .'/signups/confirm';
120 drupal_set_message(t('You do not have permission to cancel signups.'), 'error');
133 $placeholders = db_placeholders($users);
134 db_query("UPDATE {signup_log} SET attended = %d WHERE sid IN ($placeholders)", array($attend) + $users);
138 * Builds the confirm form when canceling multiple signups from node/N/signups.
140 function signup_cancel_multiple_confirm(&$form_state, $node) {
142 $form['nid'] = array(
144 '#value' => $node->nid,
146 $form['users'] = array(
148 '#suffix' => '</ul>',
151 $placeholders = db_placeholders($_SESSION['signup_cancel_multiple_users']);
152 $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']);
153 while ($signup = db_fetch_object($query)) {
156 $label = theme('username', $signup);
159 $label = t('Anonymous signup: %anon_mail', array('%anon_mail' => $signup->anon_mail));
161 $form['users'][$key] = array(
165 '#suffix' => $label ."</li>\n",
168 $form['#submit'][] = 'signup_cancel_multiple_confirm_submit';
171 t('Are you sure you want to cancel signups for these users?'),
172 'node/'. $node->nid .'/signups',
173 t('This action cannot be undone.'),
174 t('Cancel signups'), t('Keep signups')
179 * Submit handler for the confirm form to cancel multiple signups.
181 function signup_cancel_multiple_confirm_submit($form, &$form_state) {
182 $nid = $form_state['values']['nid'];
183 if (user_access('cancel signups')) {
184 foreach ($form_state['values']['users'] as $key) {
185 signup_cancel_signup($key);
189 drupal_set_message(t('You do not have permission to cancel signups.'), 'error');
191 $form_state['redirect'] = 'node/'. $nid .'/signups';
192 unset($_SESSION['signup_cancel_multiple_users']);