Index: poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.231
diff -u -r1.231 poll.module
--- poll.module	4 Jun 2007 07:22:21 -0000	1.231
+++ poll.module	7 Jun 2007 09:39:55 -0000
@@ -29,7 +29,7 @@
       'arguments' => array('form' => NULL),
     ),
     'poll_results' => array(
-      'arguments' => array('title' => NULL, 'results' => NULL, 'votes' => NULL, 'links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),
+      'arguments' => array('title' => NULL, 'description' => NULL, 'results' => NULL, 'votes' => NULL, 'links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),
     ),
     'poll_bar' => array(
       'arguments' => array('title' => NULL, 'percentage' => NULL, 'votes' => NULL, 'block' => NULL),
@@ -146,6 +146,14 @@
     '#default_value' => $node->title,
     '#weight' => -1
   );
+  $form['body_filter']['body'] = array(
+    '#type' => 'textarea',
+    '#title' => check_plain($type->body_label),
+    '#default_value' => $node->body,
+    '#rows' => 5,
+    '#description' => t('Optional description for this poll, e.g. details, motivation.')
+  );
+  $form['body_filter']['format'] = filter_form($node->format);
 
   if (isset($form_state['choices'])) {
     $choices = $form_state['choices'];
@@ -234,6 +242,7 @@
 
   db_query("INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active);
 
+  $i = 0;
   foreach ($node->choice as $choice) {
     if ($choice['chtext'] != '') {
       db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice['chtext'], $choice['chvotes'], $i++);
@@ -330,7 +339,8 @@
       'module' => 'poll',
       'description' => t("A poll is a multiple-choice question which visitors can vote on."),
       'title_label' => t('Question'),
-      'has_body' => FALSE,
+      'has_body' => TRUE,
+      'body_label' => t('Description'),
     )
   );
 }
@@ -372,7 +382,10 @@
 /**
  * Generates the voting form for a poll.
  */
-function poll_view_voting($node, $block) {
+function poll_view_voting(&$form_state, $node, $block) {
+  if (!empty($node->body)) {
+    $form['description'] = array('#value' => check_markup($node->body, $node->format, FALSE));
+  }
   if ($node->choice) {
     $list = array();
     foreach ($node->choice as $i => $choice) {
@@ -395,7 +408,12 @@
  * Themes the voting form for a poll.
  */
 function theme_poll_view_voting($form) {
-  $output .= '<div class="poll">';
+  $output  = '<div class="poll">';
+  if (isset($form['description'])) {
+    $output .= '<div class="description">';
+    $output .= drupal_render($form['description']);
+    $output .= '</div>';
+  }
   $output .= '  <div class="vote-form">';
   $output .= '    <div class="choices">';
   $output .= drupal_render($form['choice']);
@@ -427,14 +445,17 @@
     }
   }
 
-  return theme('poll_results', check_plain($node->title), $poll_results, $total_votes, isset($node->links) ? $node->links : array(), $block, $node->nid, isset($node->vote) ? $node->vote : NULL);
+  return theme('poll_results', check_plain($node->title), check_markup($node->body, $node->format, FALSE), $poll_results, $total_votes, isset($node->links) ? $node->links : array(), $block, $node->nid, isset($node->vote) ? $node->vote : NULL);
 }
 
-function theme_poll_results($title, $results, $votes, $links, $block, $nid, $vote) {
+function theme_poll_results($title, $description, $results, $votes, $links, $block, $nid, $vote) {
   $output = '';
   if ($block) {
     $output .= '<div class="poll">';
     $output .= '<div class="title">'. $title .'</div>';
+    if (!empty($description)) {
+      $output .= '<div class="description">'. $description .'</div>';
+    }
     $output .= $results;
     $output .= '<div class="total">'. t('Total votes: %votes', array('%votes' => $votes)) .'</div>';
     $output .= '</div>';
@@ -442,6 +463,9 @@
   }
   else {
     $output .= '<div class="poll">';
+    if (!empty($description)) {
+      $output .= '<div class="description">'. $description .'</div>';
+    }
     $output .= $results;
     $output .= '<div class="total">'. t('Total votes: %votes', array('%votes' => $votes)) .'</div>';
     if (isset($vote) && $vote > -1 && user_access('cancel own vote')) {
@@ -522,9 +546,7 @@
   $nid = arg(1);
 
   if ($node = node_load($nid)) {
-    $edit = $_POST;
-    $choice = $edit['choice'];
-    $vote = $_POST['vote'];
+    $choice = $_POST['choice'];
 
     if (isset($choice) && isset($node->choice[$choice])) {
       if ($node->allowvotes) {
@@ -562,11 +584,10 @@
 /**
  * Callback for canceling a vote
  */
-function poll_cancel(&$node) {
+function poll_cancel($node) {
   global $user;
 
-  $nid = arg(2);
-  if ($node = node_load($nid)) {
+  if ($node = (is_object($node) ? $node : node_load($node))) {
     if ($node->type == 'poll' && $node->allowvotes == FALSE) {
       if ($user->uid) {
         db_query('DELETE FROM {poll_votes} WHERE nid = %d and uid = %d', $node->nid, $user->uid);
@@ -584,7 +605,7 @@
     else {
       drupal_set_message(t("You are not allowed to cancel an invalid poll choice."), 'error');
     }
-    drupal_goto('node/'. $nid);
+    drupal_goto('node/'. $node->nid);
   }
   else {
     drupal_not_found();
@@ -617,7 +638,7 @@
   }
 
   if (!empty($node->allowvotes) && ($block || arg(2) != 'results')) {
-    if ($_POST['op'] == t('Vote')) {
+    if (isset($_POST['op']) && $_POST['op'] == t('Vote')) {
       poll_vote($node);
     }
     $node->content['body'] = array(
