Mercurial > hg > fapweb
changeset 316:54dfab6ba12c
Work on voting.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 27 Nov 2013 05:07:48 +0200 |
parents | 100d9f7f9dde |
children | cacd5ceed4ab |
files | usrajax.php |
diffstat | 1 files changed, 26 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/usrajax.php Wed Nov 27 03:45:18 2013 +0200 +++ b/usrajax.php Wed Nov 27 05:07:48 2013 +0200 @@ -9,39 +9,28 @@ require_once "msite.inc.php"; require_once "msession.inc.php"; - // -// "Submit" one vote into the database +// Update one vote (prevalidated) // -function stSubmitOneVote($voter_id, $entry_id, $vote) +function stUpdateVote($key_id, $entry_id, $vote) { - // Check if the entry_id is actually valid - $sql = stPrepareSQL("SELECT * FROM entries WHERE id=%d", $entry_id); - if (($entry = stFetchSQL($sql)) === false) - return FALSE; - - // Check if the compo is valid for the entry - $sql = stPrepareSQL("SELECT * FROM compos WHERE id=%d", $entry["compo_id"]); - if (($compo = stFetchSQL($sql)) === false || $compo["voting"] == 0) - return FALSE; - // Check if the vote already exists - $sql = stPrepareSQL("SELECT id FROM votes WHERE voter_id=%d AND entry_id=%d", - $voter_id, $entry_id); + $sql = stPrepareSQL("SELECT id FROM votes WHERE key_id=%d AND entry_id=%d", + $key_id, $entry_id); if (($res = stFetchSQLColumn($sql)) === false) { // Didn't exist, insert it $sql = stPrepareSQL( - "INSERT INTO votes (voter_id,entry_id,value) VALUES (%d,%d,%d)", - $voter_id, $entry_id, $vote); + "INSERT INTO votes (key_id,entry_id,value) VALUES (%d,%d,%d)", + $key_id, $entry_id, $vote); } else { // Existed, thusly update $sql = stPrepareSQL( - "UPDATE votes SET value=%d WHERE voter_id=%d AND entry_id=%d", - $vote, $voter_id, $eid); + "UPDATE votes SET value=%d WHERE key_id=%d AND entry_id=%d", + $vote, $key_id, $eid); } return stExecSQL($sql); @@ -91,7 +80,17 @@ array(CHK_TYPE, VT_INT, "Invalid data."), array(CHK_RANGE, VT_INT, array($voteMin, $voteMax), "Invalid vote value."))) { - // Check if voting is enabled on the compo and voter is valid + // Check if the entry_id is actually valid + $sql = stPrepareSQL("SELECT * FROM entries WHERE id=%d", $entry_id); + if (($entry = stFetchSQL($sql)) !== false) + { + // Check if the compo is valid for the entry + $sql = stPrepareSQL("SELECT * FROM compos WHERE id=%d", $entry["compo_id"]); + if (($compo = stFetchSQL($sql)) !== false && $compo["voting"] != 0) + { + stUpdateVote($voteKeyId, $entry_id, $vote); + } + } } break; @@ -100,6 +99,13 @@ stError("Voting is not enabled."); else { + foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0") as $compo) + { + $cid = $compo["id"]; + foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$cid) as $entry) + { + } + } } break;