function poll_vote in Drupal 5
Same name and namespace in other branches
- 4 modules/poll.module \poll_vote()
- 6 modules/poll/poll.module \poll_vote()
- 7 modules/poll/poll.module \poll_vote()
Callback for processing a vote
1 call to poll_vote()
- poll_view in modules/
poll/ poll.module - Implementation of hook_view().
1 string reference to 'poll_vote'
- poll_menu in modules/
poll/ poll.module - Implementation of hook_menu().
File
- modules/
poll/ poll.module, line 512 - Enables your site to capture votes on different topics in the form of multiple choice questions.
Code
function poll_vote(&$node) {
global $user;
$nid = arg(1);
if ($node = node_load($nid)) {
$edit = $_POST;
$choice = $edit['choice'];
$vote = $_POST['vote'];
if (isset($choice) && isset($node->choice[$choice])) {
if ($node->allowvotes) {
// Record the vote by this user or host.
if ($user->uid) {
db_query('INSERT INTO {poll_votes} (nid, chorder, uid) VALUES (%d, %d, %d)', $node->nid, $choice, $user->uid);
}
else {
db_query("INSERT INTO {poll_votes} (nid, chorder, hostname) VALUES (%d, %d, '%s')", $node->nid, $choice, $_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 are not allowed to vote on this poll."), 'error');
}
}
else {
drupal_set_message(t("You did not specify a valid poll choice."), 'error');
}
drupal_goto('node/' . $nid);
}
else {
drupal_not_found();
}
}