function advpoll_cancel in Advanced Poll 5
Same name and namespace in other branches
- 6.3 advpoll.admin.inc \advpoll_cancel()
- 6 advpoll.admin.inc \advpoll_cancel()
- 6.2 advpoll.admin.inc \advpoll_cancel()
Callback for canceling a vote.
1 string reference to 'advpoll_cancel'
- advpoll_menu in ./
advpoll.module - Implementation of hook_menu().
File
- ./
advpoll.module, line 1370 - Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.
Code
function advpoll_cancel($nid) {
global $user;
$nid = arg(2);
if ($nid && ($node = node_load(array(
'nid' => $nid,
)))) {
if (isset($node->type) && $node->voted && _advpoll_is_active($node)) {
if ($user->uid && count($user_vote = votingapi_get_user_votes('advpoll', $node->nid)) > 0) {
votingapi_unset_vote('advpoll', $node->nid, $user->uid);
}
else {
$host = $_SERVER['HTTP_X_FORWARDED_FOR'] ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
db_query("DELETE FROM {votingapi_vote} WHERE content_id = %d and hostname = '%s' AND uid = 0", $node->nid, $host);
votingapi_recalculate_results('advpoll', $nid);
}
$mode = _advpoll_get_mode($node->type);
$function = 'advpoll_cancel_' . $mode;
if (function_exists($function)) {
$function($node, $user_vote);
}
drupal_set_message(t('Your vote was canceled.'));
}
else {
drupal_set_message(t('You are not allowed to cancel an invalid choice.'), 'error');
}
drupal_goto('node/' . $nid);
}
else {
drupal_not_found();
}
}