? advpoll_eligible.patch
Index: advpoll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/advpoll.module,v
retrieving revision 1.21.2.47
diff -u -p -r1.21.2.47 advpoll.module
--- advpoll.module	30 Jul 2007 21:30:25 -0000	1.21.2.47
+++ advpoll.module	5 Aug 2007 15:53:59 -0000
@@ -1024,7 +1024,7 @@ function advpoll_view($node, $teaser = F
       '#value' => drupal_get_form('advpoll_voting_'. $mode .'_form', $node, $teaser, $page),
     );
   }
-  else if (!$node->voted && arg(2) != 'results' && $node->active && ($eligible = advpoll_eligible($node))) {
+  else if (!$node->voted && arg(2) != 'results' && $node->active) {
     // User hasn't voted and we're not on the results tab
     $node->content['poll'] = array(
       '#weight' => 1,
@@ -1040,13 +1040,7 @@ function advpoll_view($node, $teaser = F
     }
   }
   else {
-    if (isset($eligible) && !$eligible) {
-      $node->content['message'] = array(
-        '#weight' => -1,
-        '#value' => t('You are not eligible to vote in this poll.'),
-      );
-    }
-    // Show results only if the user has voted or poll is closed
+    // Show results (the user has voted or poll is closed).
     $node->content['poll'] = array(
       '#weight' => 1,
       '#value' => advpoll_view_results($node, $teaser, $page)
Index: modes/binary.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/modes/binary.inc,v
retrieving revision 1.7.2.20
diff -u -p -r1.7.2.20 binary.inc
--- modes/binary.inc	30 Jul 2007 21:30:25 -0000	1.7.2.20
+++ modes/binary.inc	5 Aug 2007 15:53:59 -0000
@@ -74,7 +74,16 @@ function advpoll_voting_binary_form(&$no
     );
   }
 
+  // Disable button and display message for non-eligible users.
+  if (!advpoll_eligible($node)) {
+    global $user;
+    $form['vote']['#disabled'] = TRUE;
+    $login_message = t('<a href="@login">Login</a> to vote in this poll.', array('@login' => url('user/login', drupal_get_destination())));
+    $form['vote']['#suffix'] = ($user->uid ? t('You are not eligible to vote in this poll.') : $login_message);
+  }
+  
   $form['#action'] = url('node/'. $node->nid);
+  
   return $form;
 }
 
@@ -175,6 +184,18 @@ function advpoll_voting_binary_form_vali
   $node = node_load($form_values['nid']);
   $ajax = $form_values['ajax'];
   $ok = TRUE;
+  
+  // Check if user is eligible to vote
+  if (!advpoll_eligible($node)) {
+    $msg = t('You are not allowed to vote in this poll.');
+    if ($ajax) {
+      $errors[] = $msg;
+    }
+    else {
+      form_set_error('choice[', $msg);
+    }
+    $ok = FALSE;
+  }
 
   // Check if user has already voted
   list($voted, $cancel_vote) = _advpoll_user_voted($node->nid);
Index: modes/ranking.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advpoll/modes/ranking.inc,v
retrieving revision 1.8.2.24
diff -u -p -r1.8.2.24 ranking.inc
--- modes/ranking.inc	30 Jul 2007 21:30:25 -0000	1.8.2.24
+++ modes/ranking.inc	5 Aug 2007 15:53:59 -0000
@@ -85,7 +85,16 @@ function advpoll_voting_ranking_form(&$n
     );
   }
 
+  // Disable button and display message for non-eligible users.
+  if (!advpoll_eligible($node)) {
+    global $user;
+    $form['vote']['#disabled'] = TRUE;
+    $login_message = t('<a href="@login">Login</a> to vote in this poll.', array('@login' => url('user/login', drupal_get_destination())));
+    $form['vote']['#suffix'] = ($user->uid ? t('You are not eligible to vote in this poll.') : $login_message);
+  }
+  
   $form['#action'] = url('node/'. $node->nid);
+  
   return $form;
 }
 
@@ -611,6 +620,18 @@ function advpoll_voting_ranking_form_val
   $node = node_load($form_values['nid']);
   $ajax = $form_values['ajax'];
   $ok = TRUE;
+  
+  // Check if user is eligible to vote
+  if (!advpoll_eligible($node)) {
+    $msg = t('You are not allowed to vote in this poll.');
+    if ($ajax) {
+      $errors[] = $msg;
+    }
+    else {
+      form_set_error('choice[', $msg);
+    }
+    $ok = FALSE;
+  }
 
   // Check if user has already voted
   list($voted, $cancel_vote) = _advpoll_user_voted($node->nid);
