Index: poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll.module,v
retrieving revision 1.142
diff -u -r1.142 poll.module
--- poll.module 31 Jul 2004 09:30:09 -0000      1.142
+++ poll.module 6 Aug 2004 13:50:32 -0000
@@ -41,22 +41,42 @@
   if (user_access('access content')) {
     if ($op == 'list') {
       $blocks[0]['info'] = t('Most recent poll');
+      $blocks[1]['info'] = t('Random active poll');
       return $blocks;
     }
-    else {
-      // Retrieve the latest poll.
-      $timestamp = db_result(db_query('SELECT MAX(n.created) FROM {node} n '. node_access_join_sql() ." WHERE n.type = 'poll' AND n.status = 1 AND ". node_access_where_sql() .' AND n.moderate = 0'));
-      if ($timestamp) {
-        $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'moderate' => 0, 'status' => 1));
-
-        if ($poll->nid) {
-          // poll_view() dumps the output into $poll->body.
-          poll_view($poll, 1, 0, 1);
+
+    switch ($delta) {
+      case 0:
+        // Retrieve latest poll
+        $timestamp = db_result(db_query('SELECT MAX(n.created) FROM {node} n '. node_access_join_sql() ." WHERE n.type = 'poll' AND n.status = 1 AND ". node_access_where_sql() .' AND n.moderate = 0'));
+        if ($timestamp) {
+          $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'moderate' => 0, 'status' => 1));
+
+          if ($poll->nid) {
+            // poll_view() dumps the output into $poll->body.
+            poll_view($poll, 1, 0, 1, $delta);
+          }
         }
-      }
-      $block['subject'] = t('Poll');
-      $block['content'] = $poll->body;
-      return $block;
+        $block['subject'] = t('Poll');
+        $block['content'] = $poll->body;
+        return $block;
+
+      case 1:
+        // Retrieve nid for active polls
+        $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() ." INNER JOIN {poll} p ON p.nid = n.nid WHERE n.type = 'poll' AND n.status = 1 AND ". node_access_where_sql() .' AND n.moderate = 0 AND p.active = 1'));
+        $nid = db_result($result, rand(0, db_num_rows($result) - 1));
+
+        if ($nid) {
+          $poll = node_load(array('type' => 'poll', 'nid' => $nid, 'moderate' => 0, 'status' => 1));
+
+          if ($poll->nid) {
+            // Poll_view dumps the output into $poll->body
+            poll_view($poll, 1, 0, 1, $delta);
+          }
+        }
+        $block['subject'] = t('Random Poll');
+        $block['content'] = $poll->body;
+        return $block;
     }
   }
 }
@@ -409,7 +429,7 @@
  *   An extra parameter that adapts the hook to display a block-ready
  *   rendering of the poll.
  */
-function poll_view(&$node, $teaser = FALSE, $page = FALSE, $block = FALSE) {
+function poll_view(&$node, $teaser = FALSE, $page = FALSE, $block = FALSE, $blockdelta = FALSE) {
   global $user;
   $output = '';
 
@@ -426,7 +446,7 @@
     $node->body = $node->teaser = '';
 
     $links = link_node($node, $main);
-    $links[] = l(t('older polls'), 'poll', array('title' => t('View the list of polls on this site.')));
+    $links[] = l(t($blockdelta ? 'other polls' : 'older polls'), 'poll', array('title' => t('View the list of polls on this site.')));
     if ($node->allowvotes && $block) {
       $links[] = l(t('results'), 'node/'. $node->nid .'/results', array('title' => t('View the current poll results.')));
     }
