function _advpoll_vote_response in Advanced Poll 6.3
Same name and namespace in other branches
- 5 advpoll.module \_advpoll_vote_response()
- 6 advpoll.module \_advpoll_vote_response()
- 6.2 advpoll.module \_advpoll_vote_response()
2 calls to _advpoll_vote_response()
- advpoll_voting_binary_form_submit in modes/
binary.inc - Registers the vote as a key for this node using votingapi_set_vote().
- advpoll_voting_ranking_form_submit in modes/
ranking.inc - Implementation of the vote hook for the runoff module.
File
- ./
advpoll.module, line 1325 - Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.
Code
function _advpoll_vote_response($node, $form_state) {
$advpollSettings = variable_get('advpoll_settings', array());
$msg = !empty($advpollSettings['vote_registered']) ? $advpollSettings['vote_registered'] : t('Your vote was registered.');
$votingMode = $advpollSettings['voting_mode'];
$displayResults = _advpoll_check_settings($node);
// Ajax response
if ($form_state['values']['ajax']) {
// Do not show results (there are cases where people can vote but shouldn't see a result
// but should still see the poll with appropriate messaging
// Unset the array of choices so duplicates aren't shown.
unset($node->choice);
// Get all choices from database. This is necessary to get information about
// newly submitted write-in choices.
$result = db_query('SELECT cid, weight, label, writein FROM {advpoll_choices} WHERE nid = %d ORDER BY weight', $node->nid);
while ($choice = db_fetch_array($result)) {
$node->choice[$choice['cid']] = $choice;
}
// Update the number of choices.
$node->choices = count($node->choice);
// Get updated total number of votes from database.
$result = db_query("SELECT value FROM {votingapi_cache} WHERE content_type = 'advpoll' AND content_id = %d AND tag = '_advpoll' AND function = 'total_votes'", $node->nid);
if ($cache = db_fetch_object($result)) {
$node->votes = $cache->value;
}
else {
$node->votes = 0;
}
list($node->voted, $node->cancel_vote) = _advpoll_user_voted($node->nid);
$ajax_output = '';
if (user_access('show vote results')) {
$ajax_output .= advpoll_view_results($node, NULL, NULL);
}
elseif (user_access('cancel own vote') && !$votingMode) {
$ajax_output .= _advpoll_show_cancel_form($node);
}
// Remove linebreaks as they will break jQuery's insert-HTML methods.
$ajax_output = str_replace("\n", '', $ajax_output);
drupal_set_header('Content-Type: text/plain; charset=utf-8');
print drupal_to_js(array(
'statusMsgs' => '<div class="messages status">' . $msg . '</div>',
'response' => $ajax_output,
));
exit;
}
else {
drupal_set_message($msg);
}
}