00001 <?php
00002
00003
00012 function poll_page() {
00013
00014 $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");
00015
00016 $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n INNER JOIN {poll} p ON n.nid = p.nid WHERE n.status = 1');
00017 $result = pager_query($sql, 15, 0, $count_sql);
00018 $output = '<ul>';
00019 while ($node = db_fetch_object($result)) {
00020 $output .= '<li>' . l($node->title, "node/$node->nid") . ' - ' . format_plural($node->votes, '1 vote', '@count votes') . ' - ' . ($node->active ? t('open') : t('closed')) . '</li>';
00021 }
00022 $output .= '</ul>';
00023 $output .= theme("pager", NULL, 15);
00024 return $output;
00025 }
00026
00030 function poll_votes($node) {
00031 drupal_set_title(check_plain($node->title));
00032 $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.');
00033
00034 $header[] = array('data' => t('Visitor'), 'field' => 'u.name');
00035 $header[] = array('data' => t('Vote'), 'field' => 'pv.chorder');
00036 $header[] = array('data' => t('Vote'), 'field' => 'pc.weight');
00037
00038 $result = pager_query("SELECT pv.chid, pv.uid, pv.hostname, u.name FROM {poll_votes} pv INNER JOIN {poll_choices} pc ON pv.chid = pc.chid LEFT JOIN {users} u ON pv.uid = u.uid WHERE pv.nid = %d". tablesort_sql($header), 20, 0, NULL, $node->nid);
00039 $rows = array();
00040 while ($vote = db_fetch_object($result)) {
00041 $rows[] = array(
00042 $vote->name ? theme('username', $vote) : check_plain($vote->hostname),
00043 check_plain($node->choice[$vote->chid]['chtext']));
00044 }
00045 $output .= theme('table', $header, $rows);
00046 $output .= theme('pager', NULL, 20, 0);
00047 return $output;
00048 }
00049
00053 function poll_results($node) {
00054 drupal_set_title(check_plain($node->title));
00055 $node->show_results = TRUE;
00056 return node_show($node, 0);
00057 }