You are here

function poll_page in Drupal 6

Same name and namespace in other branches
  1. 4 modules/poll.module \poll_page()
  2. 5 modules/poll/poll.module \poll_page()
  3. 7 modules/poll/poll.pages.inc \poll_page()

Menu callback to provide a simple list of all polls available.

1 string reference to 'poll_page'
poll_menu in modules/poll/poll.module
Implementation of hook_menu().

File

modules/poll/poll.pages.inc, line 11
User page callbacks for the poll module.

Code

function poll_page() {

  // List all polls.
  $sql = db_rewrite_sql("SELECT n.nid, n.title, p.active, n.created, SUM(c.chvotes) AS votes FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid INNER JOIN {poll_choices} c ON n.nid = c.nid WHERE n.status = 1 GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC");

  // Count all polls for the pager.
  $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid WHERE n.status = 1');
  $result = pager_query($sql, 15, 0, $count_sql);
  $output = '<ul>';
  while ($node = db_fetch_object($result)) {
    $output .= '<li>' . l($node->title, "node/{$node->nid}") . ' - ' . format_plural($node->votes, '1 vote', '@count votes') . ' - ' . ($node->active ? t('open') : t('closed')) . '</li>';
  }
  $output .= '</ul>';
  $output .= theme("pager", NULL, 15);
  return $output;
}