| 1 |
<?php
|
| 2 |
// $Id: admin.signup_administration.inc,v 1.2 2009/07/22 22:00:06 dww Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Code related to the Signup administration page (admin/content/signup).
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Print the admin signup overview page located at admin/content/signup.
|
| 12 |
*/
|
| 13 |
function signup_admin_page() {
|
| 14 |
drupal_add_css(drupal_get_path('module', 'signup') .'/signup.css');
|
| 15 |
$filter_status_form = drupal_get_form('signup_filter_status_form');
|
| 16 |
$signup_admin_form = drupal_get_form('signup_admin_form');
|
| 17 |
return theme('signup_admin_page', $filter_status_form, $signup_admin_form);
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Form builder for the signup status filter on the signup administration page.
|
| 22 |
*/
|
| 23 |
function signup_filter_status_form(&$form_state) {
|
| 24 |
$options = array(
|
| 25 |
'all' => t('All'),
|
| 26 |
'open' => t('Open'),
|
| 27 |
'closed' => t('Closed'),
|
| 28 |
);
|
| 29 |
if (empty($_SESSION['signup_status_filter'])) {
|
| 30 |
$_SESSION['signup_status_filter'] = 'all';
|
| 31 |
}
|
| 32 |
$form['filter'] = array(
|
| 33 |
'#type' => 'select',
|
| 34 |
'#title' => t('Filter by signup status'),
|
| 35 |
'#options' => $options,
|
| 36 |
'#default_value' => $_SESSION['signup_status_filter'],
|
| 37 |
);
|
| 38 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Filter'));
|
| 39 |
// $form['#redirect'] = FALSE;
|
| 40 |
return $form;
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Submit handler for the status filter on the signup administration page.
|
| 45 |
*/
|
| 46 |
function signup_filter_status_form_submit($form, &$form_state) {
|
| 47 |
$_SESSION['signup_status_filter'] = $form_state['values']['filter'];
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Form builder for the main form on the signup administration page.
|
| 52 |
*/
|
| 53 |
function signup_admin_form($form_state) {
|
| 54 |
// Figure out if the current user has permission to use signup broadcast.
|
| 55 |
$access_broadcast = user_access('email all signed up users');
|
| 56 |
|
| 57 |
$header = array(
|
| 58 |
array('data' => t('Title'), 'field' => 'n.title', 'sort' => 'asc'),
|
| 59 |
array('data' => t('Signups'), 'field' => 'signup_total'),
|
| 60 |
array('data' => t('Limit'), 'field' => 'signup_close_signup_limit'),
|
| 61 |
array('data' => t('Status'), 'field' => 'signup_status'),
|
| 62 |
array('data' => t('Operations')),
|
| 63 |
);
|
| 64 |
|
| 65 |
$start_column = signup_admin_form_header();
|
| 66 |
if (!empty($start_column)) {
|
| 67 |
array_unshift($header, $start_column);
|
| 68 |
}
|
| 69 |
|
| 70 |
list($sql, $sql_count) = signup_admin_form_sql();
|
| 71 |
|
| 72 |
$form['header']['#value'] = $header;
|
| 73 |
|
| 74 |
$sql .= tablesort_sql($header);
|
| 75 |
|
| 76 |
$result = pager_query($sql, 25, 0, $sql_count);
|
| 77 |
|
| 78 |
// Loop through the signup nodes, and generate our form elements
|
| 79 |
while ($signup_node = db_fetch_object($result)) {
|
| 80 |
$row = array();
|
| 81 |
if (!empty($start_column)) {
|
| 82 |
$row['start'] = signup_admin_form_extra($signup_node);
|
| 83 |
}
|
| 84 |
|
| 85 |
// Instead of duplicating the logic from the node/N/signups admin
|
| 86 |
// form, we just call that form builder here and lift the elements
|
| 87 |
// we need directly from that.
|
| 88 |
module_load_include('inc', 'signup', 'includes/node_admin_summary');
|
| 89 |
$node_admin_form = signup_node_admin_summary_form(array(), $signup_node);
|
| 90 |
$row['title'] = array(
|
| 91 |
'#type' => 'markup',
|
| 92 |
'#value' => l($signup_node->title, "node/$signup_node->nid"),
|
| 93 |
);
|
| 94 |
$row['status'] = $node_admin_form['status'];
|
| 95 |
unset($row['status']['#title']);
|
| 96 |
$row['total'] = array(
|
| 97 |
'#type' => 'markup',
|
| 98 |
'#value' => $signup_node->signup_total,
|
| 99 |
);
|
| 100 |
$row['limit'] = $node_admin_form['limit'];
|
| 101 |
unset($row['limit']['#title']);
|
| 102 |
$op_links = l(t('View signups'), "node/$signup_node->nid/signups");
|
| 103 |
if ($access_broadcast) {
|
| 104 |
$op_links .= '<br />';
|
| 105 |
$options['attributes']['title'] = t('Send an email message to all users who signed up.');
|
| 106 |
$op_links .= l(t('Signup broadcast'), "node/$signup_node->nid/signups/broadcast", $options);
|
| 107 |
}
|
| 108 |
$row['operations'] = array(
|
| 109 |
'#type' => 'markup',
|
| 110 |
'#value' => $op_links,
|
| 111 |
);
|
| 112 |
$form['nids'][$signup_node->nid] = $row;
|
| 113 |
}
|
| 114 |
$form['#tree'] = TRUE;
|
| 115 |
$form['submit'] = array(
|
| 116 |
'#type' => 'submit',
|
| 117 |
'#value' => t('Update'),
|
| 118 |
);
|
| 119 |
return $form;
|
| 120 |
}
|
| 121 |
|
| 122 |
function signup_admin_form_header() {
|
| 123 |
if (module_exists('date')) {
|
| 124 |
// If we're using CCK date, we can't sort since the date field used for
|
| 125 |
// each content type can come from different tables.
|
| 126 |
return array('data' => t('Start'), 'field' => NULL);
|
| 127 |
}
|
| 128 |
elseif (module_exists('event')) {
|
| 129 |
// If we've got event, but not date, we can sort by e.event_start.
|
| 130 |
return array('data' => t('Start'), 'field' => 'e.event_start');
|
| 131 |
}
|
| 132 |
// If we've got no scheduling backend at all, there's no start time column.
|
| 133 |
return array();
|
| 134 |
}
|
| 135 |
|
| 136 |
function signup_admin_form_extra($signup_node) {
|
| 137 |
return array(
|
| 138 |
'#type' => 'markup',
|
| 139 |
'#value' => signup_format_date($signup_node),
|
| 140 |
);
|
| 141 |
}
|
| 142 |
|
| 143 |
function signup_admin_form_sql() {
|
| 144 |
$admin_common_sql = array(
|
| 145 |
'primary' => '{node} n',
|
| 146 |
'fields' => array(
|
| 147 |
'n.nid',
|
| 148 |
'n.title',
|
| 149 |
'n.type',
|
| 150 |
's.status AS signup_status',
|
| 151 |
'COUNT(s_l.nid) AS signup_total',
|
| 152 |
's.close_signup_limit AS signup_close_signup_limit',
|
| 153 |
),
|
| 154 |
'group_by' => array(
|
| 155 |
'n.nid',
|
| 156 |
'n.title',
|
| 157 |
'signup_status',
|
| 158 |
'signup_close_signup_limit',
|
| 159 |
),
|
| 160 |
'joins' => array(
|
| 161 |
'INNER JOIN {signup} s ON s.nid = n.nid',
|
| 162 |
'LEFT JOIN {signup_log} s_l ON s.nid = s_l.nid',
|
| 163 |
),
|
| 164 |
);
|
| 165 |
|
| 166 |
$type = $_SESSION['signup_status_filter'];
|
| 167 |
if ($type == 'open') {
|
| 168 |
$filter_status = 1;
|
| 169 |
}
|
| 170 |
elseif ($type == 'closed') {
|
| 171 |
$filter_status = 0;
|
| 172 |
}
|
| 173 |
if (isset($filter_status)) {
|
| 174 |
$admin_common_sql['where'] = array("s.status = $filter_status");
|
| 175 |
}
|
| 176 |
|
| 177 |
// Get the right query elements from the currently installed backend
|
| 178 |
$admin_sql = array();
|
| 179 |
foreach (signup_content_types() as $type) {
|
| 180 |
$admin_sql = array_merge_recursive($admin_sql, signup_admin_sql($type));
|
| 181 |
}
|
| 182 |
|
| 183 |
// Build the main query.
|
| 184 |
$sql = _signup_build_query($admin_common_sql, $admin_sql);
|
| 185 |
|
| 186 |
// Construct the proper pager query using just the WHERE clauses (if any).
|
| 187 |
$all_fragments = array_merge_recursive($admin_common_sql, $admin_sql);
|
| 188 |
$sql_count = "SELECT COUNT(s.nid) FROM {signup} s";
|
| 189 |
if (!empty($all_fragments['where'])) {
|
| 190 |
$sql_count .= ' WHERE '. implode(' AND ', $all_fragments['where']);
|
| 191 |
}
|
| 192 |
|
| 193 |
return array(db_rewrite_sql($sql), db_rewrite_sql($sql_count, 's'));
|
| 194 |
}
|
| 195 |
|
| 196 |
function signup_admin_form_submit($form, &$form_state) {
|
| 197 |
module_load_include('inc', 'signup', 'includes/node_admin_summary');
|
| 198 |
foreach ($form_state['values']['nids'] as $nid => $values) {
|
| 199 |
$values['nid'] = $nid;
|
| 200 |
$temp_state['values'] = $values;
|
| 201 |
signup_node_admin_summary_form_submit($form, $temp_state);
|
| 202 |
}
|
| 203 |
}
|
| 204 |
|