poll_cancel

Versions
5
poll_cancel(&$node)
6 – 7
poll_cancel($form, &$form_state)

Callback for canceling a vote

Code

modules/poll/poll.module, line 557

<?php
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();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.