poll_vote
- Versions
- 4.6 – 5
poll_vote(&$node)- 6 – 7
poll_vote($form, &$form_state)
Callback for processing a vote
Code
modules/poll.module, line 403
<?php
function poll_vote(&$node) {
global $user;
$nid = arg(1);
if ($node = node_load($nid)) {
$edit = $_POST['edit'];
$choice = $edit['choice'];
$vote = $_POST['vote'];
if (isset($choice) && isset($node->choice[$choice])) {
if ($node->allowvotes) {
// Mark the user or host as having voted.
if ($user->uid) {
db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $node->nid, $user->uid);
}
else {
db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $node->nid, $_SERVER['REMOTE_ADDR']);
}
// Add one to the votes.
db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $choice);
$node->allowvotes = FALSE;
$node->choice[$choice]['chvotes']++;
cache_clear_all();
drupal_set_message(t('Your vote was recorded.'));
}
else {
drupal_set_message(t("You're not allowed to vote on this poll."), 'error');
}
}
else {
drupal_set_message(t("You didn't specify a valid poll choice."), 'error');
}
drupal_goto('node/'. $nid);
}
else {
drupal_not_found();
}
}
?>Login or register to post comments 