diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-04-22 23:59:04 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-04-22 23:59:04 +0000 |
commit | e82edd5758b26883381f5a95c248f2c48d9b42b4 (patch) | |
tree | 608910689c6c5879af0adb8d0b285245277dc40b /modules/poll/poll.module | |
parent | 257a5b8ef52fa6c2a70aa0197cdfb2becf41d12a (diff) | |
download | brdo-e82edd5758b26883381f5a95c248f2c48d9b42b4.tar.gz brdo-e82edd5758b26883381f5a95c248f2c48d9b42b4.tar.bz2 |
- Patch #39432 by c960657, chx, Gábor Hojtsy: fixed problems with anonymous users voting.
Diffstat (limited to 'modules/poll/poll.module')
-rw-r--r-- | modules/poll/poll.module | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/modules/poll/poll.module b/modules/poll/poll.module index f118b08e2..68c4627bd 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -478,17 +478,17 @@ function poll_load($nodes) { $poll->allowvotes = FALSE; if (user_access('vote on polls') && $poll->active) { if ($user->uid) { - $result = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchObject(); + $poll->vote = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField(); + if (empty($poll->vote)) { + $poll->vote = -1; + $poll->allowvotes = TRUE; + } } - else { - $result = db_query("SELECT chid FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchObject(); - } - if ($result) { - $poll->vote = $result->chid; + elseif (!empty($_SESSION['poll_vote'][$node->nid])) { + $poll->vote = $_SESSION['poll_vote'][$node->nid]; } else { - $poll->vote = -1; - $poll->allowvotes = TRUE; + $poll->allowvotes = !db_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField(); } } foreach ($poll as $key => $value) { @@ -730,6 +730,16 @@ function poll_vote($form, &$form_state) { ->execute(); cache_clear_all(); + + if (!$user->uid) { + // The vote is recorded so the user gets the result view instead of the + // voting form when viewing the poll. Saving a value in $_SESSION has the + // convenient side effect of preventing the user from hitting the page + // cache. When anonymous voting is allowed, the page cache should only + // contain the voting form, not the results. + $_SESSION['poll_vote'][$node->nid] = $choice; + } + drupal_set_message(t('Your vote was recorded.')); // Return the user to whatever page they voted from. @@ -911,6 +921,8 @@ function poll_cancel($form, &$form_state) { ->condition('chid', $node->vote) ->execute(); + unset($_SESSION['poll_vote'][$node->nid]); + drupal_set_message(t('Your vote was cancelled.')); } |