function poll_cancel

You are here

7 poll.module poll_cancel($form, &$form_state)
5 poll.module poll_cancel(&$node)
6 poll.module poll_cancel($form, &$form_state)

Callback for canceling a vote

1 string reference to 'poll_cancel'
poll_menu in modules/poll/poll.module
Implementation of hook_menu().

File

modules/poll/poll.module, line 557
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_cancel(&$node) {
  global $user;

  $nid = arg(2);
  if ($node = node_load($nid)) {
    if ($node->type == 'poll' && $node->allowvotes == FALSE) {
      if ($user->uid) {
        db_query('DELETE FROM {poll_votes} WHERE nid = %d and uid = %d', $node->nid, $user->uid);
      }
      else {
        db_query("DELETE FROM {poll_votes} WHERE nid = %d and hostname = '%s'", $node->nid, $_SERVER['REMOTE_ADDR']);
      }

      // Subtract from the votes.
      db_query("UPDATE {poll_choices} SET chvotes = chvotes - 1 WHERE nid = %d AND chorder = %d", $node->nid, $node->vote);
      $node->allowvotes = TRUE;
      $node->choice[$node->vote]['chvotes']--;
      drupal_set_message(t('Your vote was canceled.'));
    }
    else {
      drupal_set_message(t("You are not allowed to cancel an invalid poll choice."), 'error');
    }
    drupal_goto('node/' . $nid);
  }
  else {
    drupal_not_found();
  }
}