You are here

function signup_admin_page in Signup 5

Same name and namespace in other branches
  1. 5.2 signup.module \signup_admin_page()
  2. 6.2 includes/admin.signup_administration.inc \signup_admin_page()
  3. 6 includes/admin.signup_administration.inc \signup_admin_page()
  4. 7 includes/admin.signup_administration.inc \signup_admin_page()

Prints the admin signup overview page located at admin/content/signup

1 string reference to 'signup_admin_page'
signup_menu in ./signup.module
Implementation of hook_menu().

File

./signup.module, line 710

Code

function signup_admin_page() {
  drupal_add_css(drupal_get_path('module', 'signup') . '/signup.css');
  $output = drupal_get_form('signup_filter_status_form');
  $type = $_SESSION['signup_status_filter'];

  // Add optional SQL to the query if the event module is enabled.
  $has_event = module_exists('event');
  $event_select = $has_event ? ', e.event_start, e.timezone' : '';
  $event_join = $has_event ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
  if ($type == 'open') {
    $where = ' WHERE s.completed = 0';
  }
  elseif ($type == 'closed') {
    $where = ' WHERE s.completed = 1';
  }
  else {
    $where = '';
  }
  $header = array(
    array(
      'data' => t('Event'),
      'field' => 'n.title',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Signups'),
      'field' => 'count',
    ),
    array(
      'data' => t('Operations'),
    ),
  );

  // If event.module enabled, add event start time to table
  if ($has_event) {
    $header = array_merge(array(
      array(
        'data' => t('Start'),
        'field' => 'e.event_start',
      ),
    ), $header);
  }

  // Pull all open signup nodes, and start the creation of the table.
  $sql = "SELECT n.nid, n.title, s.completed{$event_select},\n          COUNT(s_l.nid) AS count\n          FROM {signup} s INNER JOIN {node} n ON n.nid = s.nid\n          LEFT JOIN {signup_log} s_l ON s.nid = s_l.nid {$event_join}";
  $sql .= $where;
  $sql .= " GROUP BY n.nid, n.title, s.completed{$event_select}";
  $sql .= tablesort_sql($header);
  $sql = db_rewrite_sql($sql);
  $sql_count = "SELECT COUNT(s.nid) FROM {signup} s";
  $sql_count .= $where;
  $sql_count = db_rewrite_sql($sql_count, 's');
  $result = pager_query($sql, 25, 0, $sql_count);

  // Loop through the signup nodes, pull the number of signups for
  // each, and create the summary table.
  while ($signup_event = db_fetch_object($result)) {
    $row = array();
    if ($has_event) {

      // Must include this here as event module doesn't include timezone
      // support on all page requests.
      require_once drupal_get_path('module', 'event') . '/event_timezones.inc';
      $offset = $signup_event->event_start ? event_get_offset($signup_event->timezone, $signup_event->event_start) : '';
      $row[] = $signup_event->event_start ? _event_date(variable_get('signup_date_string', 'D, M jS, g:i A'), $signup_event->event_start, $offset) : '';
    }
    $row[] = l($signup_event->title, "node/{$signup_event->nid}");
    $row[] = $signup_event->count;
    $op_links = l(t('View Signups'), "node/{$signup_event->nid}/signups");
    $op_links .= '<br />';
    if ($signup_event->completed) {
      if (!arg(2)) {
        $op_links .= '<em>' . t('Closed: ') . '</em>';
      }
      $op_links .= l(t('Open Event'), "opensignup/{$signup_event->nid}/" . arg(2));
    }
    else {
      if (!arg(2)) {
        $op_links .= '<em>' . t('Open: ') . '</em>';
      }
      $op_links .= l(t('Close Event'), "closesignup/{$signup_event->nid}/" . arg(2));
    }
    $row[] = $op_links;
    $rows[] = $row;
  }
  $output .= theme('table', $header, $rows, array(
    'style' => 'width:100%',
  ));
  $pager = theme('pager', NULL, 25, 0);
  if (!empty($pager)) {
    $output .= $pager;
  }
  return $output;
}