You are here

function advpoll_cancel in Advanced Poll 6.3

Same name and namespace in other branches
  1. 5 advpoll.module \advpoll_cancel()
  2. 6 advpoll.admin.inc \advpoll_cancel()
  3. 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.admin.inc, line 31
Page callbacks for the advpoll module.

Code

function advpoll_cancel($node) {
  global $user;
  if (isset($node->type) && $node->voted && _advpoll_is_active($node)) {
    if ($user->uid && count($user_votes = votingapi_select_votes(array(
      'content_type' => 'advpoll',
      'content_id' => $node->nid,
      'uid' => $user->uid,
    ))) > 0) {
      votingapi_delete_votes($user_votes);
    }
    else {
      $user_votes = votingapi_select_votes(array(
        'content_type' => 'advpoll',
        'content_id' => $node->nid,
        'vote_source' => ip_address(),
      ));
      votingapi_delete_votes($user_votes);
    }
    $mode = _advpoll_get_mode($node->type);
    $function = 'advpoll_cancel_' . $mode;
    if (function_exists($function)) {
      $function($node, $user_votes);
    }
    votingapi_recalculate_results('advpoll', $node->nid);
    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/' . $node->nid);
}