web/drupal/modules/poll/poll.pages.inc
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: poll.pages.inc,v 1.4 2007/12/14 09:50:41 goba Exp $
       
     3 
       
     4 /**
       
     5  * @file
       
     6  * User page callbacks for the poll module.
       
     7  */
       
     8 
       
     9 /**
       
    10  * Menu callback to provide a simple list of all polls available.
       
    11  */
       
    12 function poll_page() {
       
    13   // List all polls.
       
    14   $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");
       
    15   // Count all polls for the pager.
       
    16   $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid WHERE n.status = 1');
       
    17   $result = pager_query($sql, 15, 0, $count_sql);
       
    18   $output = '<ul>';
       
    19   while ($node = db_fetch_object($result)) {
       
    20     $output .= '<li>'. l($node->title, "node/$node->nid") .' - '. format_plural($node->votes, '1 vote', '@count votes') .' - '. ($node->active ? t('open') : t('closed')) .'</li>';
       
    21   }
       
    22   $output .= '</ul>';
       
    23   $output .= theme("pager", NULL, 15);
       
    24   return $output;
       
    25 }
       
    26 
       
    27 /**
       
    28  * Callback for the 'votes' tab for polls you can see other votes on
       
    29  */
       
    30 function poll_votes($node) {
       
    31   drupal_set_title(check_plain($node->title));
       
    32   $output = t('This table lists all the recorded votes for this poll. If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.');
       
    33 
       
    34   $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
       
    35   $header[] = array('data' => t('Vote'), 'field' => 'pv.chorder');
       
    36 
       
    37   $result = pager_query("SELECT pv.chorder, pv.uid, pv.hostname, u.name FROM {poll_votes} pv LEFT JOIN {users} u ON pv.uid = u.uid WHERE pv.nid = %d". tablesort_sql($header), 20, 0, NULL, $node->nid);
       
    38   $rows = array();
       
    39   while ($vote = db_fetch_object($result)) {
       
    40     $rows[] = array(
       
    41       $vote->name ? theme('username', $vote) : check_plain($vote->hostname),
       
    42       check_plain($node->choice[$vote->chorder]['chtext']));
       
    43   }
       
    44   $output .= theme('table', $header, $rows);
       
    45   $output .= theme('pager', NULL, 20, 0);
       
    46   return $output;
       
    47 }
       
    48 
       
    49 /**
       
    50  * Callback for the 'results' tab for polls you can vote on
       
    51  */
       
    52 function poll_results($node) {
       
    53   drupal_set_title(check_plain($node->title));
       
    54   $node->show_results = TRUE;
       
    55   return node_show($node, 0);
       
    56 }