Mercurial > hg > fapweb
changeset 739:17820305bc77
Clean up vote handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 19 Nov 2014 04:42:24 +0200 |
parents | 249cba787da0 |
children | 5ab73121c0d6 |
files | usrajax.php |
diffstat | 1 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/usrajax.php Wed Nov 19 03:14:03 2014 +0200 +++ b/usrajax.php Wed Nov 19 04:42:24 2014 +0200 @@ -37,6 +37,15 @@ } +function stCheckVoteValue($id, &$value) +{ + return + stChkRequestItem($id, $value, + array(CHK_TYPE, VT_INT, "Invalid entry vote value data."), + array(CHK_RANGE, VT_INT, array(stGetSetting("voteMin"), stGetSetting("voteMax")), "Invalid vote value, not in range.")); +} + + // // Initialize // @@ -60,8 +69,6 @@ stReloadSettings(); $voteKeyId = stGetSessionItem("key_id"); -$voteMin = stGetSetting("voteMin"); -$voteMax = stGetSetting("voteMax"); // @@ -78,9 +85,7 @@ else if (stChkRequestItem("entry_id", $entry_id, array(CHK_TYPE, VT_INT, "Invalid data.")) && - stChkRequestItem("vote", $vote, - array(CHK_TYPE, VT_INT, "Invalid data."), - array(CHK_RANGE, VT_INT, array($voteMin, $voteMax), "Invalid vote value."))) + stCheckVoteValue("vote", $vote)) { // Check if the entry_id is actually valid stDBBeginTransaction(); @@ -106,10 +111,10 @@ stDBBeginTransaction(); foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) { - $value = stGetRequestItem("ventry".$entry["id"], 0); - if (!stUpdateVote($voteKeyId, $entry["id"], $value)) + if (stCheckVoteValue("ventry".$entry["id"], $value)) { - stError("Could not set vote for compo #".$compo["id"].", entry #".$entry["id"]); + if (!stUpdateVote($voteKeyId, $entry["id"], $value)) + stError("Could not set vote for compo #".$compo["id"].", entry #".$entry["id"]); } } stDBCommitTransaction(); @@ -128,7 +133,7 @@ break; default: - stSetStatus(404, "Not Found"); + stSetStatus(902, "Not Found"); break; }