Commit: 218cb889d56571bc041eda4d7e095597139174bf Author: Jacob Bednarz <[email protected]> Sat, 3 Jan 2015 20:21:40 +1000 Parents: 90b07aee49ea4227c82f80a0136e21695126633b Branches: master
Link: http://git.php.net/?p=web/bugs.git;a=commitdiff;h=218cb889d56571bc041eda4d7e095597139174bf Log: Make duplicate votes update previous votes Instead of ignoring duplicate votes this allows the votes to be updated which will allow users to update if they vote incorrectly initially. Changed paths: M www/bug.php M www/vote.php Diff: diff --git a/www/bug.php b/www/bug.php index 4f73455..a340e49 100644 --- a/www/bug.php +++ b/www/bug.php @@ -602,7 +602,7 @@ switch ($thanks) display_bug_success('You have successfully unsubscribed.'); break; case 10: - display_bug_success('You have already voted on this bug.'); + display_bug_success('Your vote has been updated.'); break; default: diff --git a/www/vote.php b/www/vote.php index 536ff55..3ffa35e 100644 --- a/www/vote.php +++ b/www/vote.php @@ -60,22 +60,37 @@ $bug_check = $dbh->prepare("SELECT bug, ip FROM bugdb_votes WHERE bug = ? AND ip ->execute(array($id, $ip)) ->fetchRow(); -if (!empty($bug_check)) { - // Let the user know they have already voted. - redirect("bug.php?id=$id&thanks=10"); -} +if (empty($bug_check)) { + // If the user vote isn't found, create one. + $dbh->prepare(" + INSERT INTO bugdb_votes (bug, ip, score, reproduced, tried, sameos, samever) + VALUES ( + {$id}, {$ip}, {$score}, " . + ($reproduced == 1 ? "1," : "0,") . + ($reproduced != 2 ? "1," : "0,") . + ($reproduced ? "$sameos," : "NULL,") . + ($reproduced ? "$samever" : "NULL") . + ')' + )->execute(); -// add the vote -$dbh->prepare(" - INSERT INTO bugdb_votes (bug,ip,score,reproduced,tried,sameos,samever) - VALUES ( - {$id}, {$ip}, {$score}, " . - ($reproduced == 1 ? "1," : "0,") . - ($reproduced != 2 ? "1," : "0,") . - ($reproduced ? "$sameos," : "NULL,") . - ($reproduced ? "$samever" : "NULL") . - ')' -)->execute(); + // redirect to the bug page (which will display the success message) + redirect("bug.php?id=$id&thanks=6"); +} else { + // As the user has already voted, just update their existing vote. + $dbh->prepare("UPDATE bugdb_votes + SET score = ?, reproduced = ? , tried = ?, sameos = ?, samever = ? + WHERE bug = ? AND ip = ?") + ->execute(array( + $score, + ($reproduced == 1 ? "1," : "0,"), + ($reproduced != 2 ? "1," : "0,"), + ($reproduced ? "$sameos," : "NULL,"), + ($reproduced ? "$samever" : "NULL"), + $id, + $ip + )); -// redirect to the bug page (which will display the success message) -redirect("bug.php?id=$id&thanks=6"); + // Let the user know they have already voted and the existing vote will be + // updated. + redirect("bug.php?id=$id&thanks=10"); +} -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
