Mercurial > hg > fapweb
view vsubmit.php @ 71:d74fb8cf0062
Adjust attendee output again, we're separating vote keys from there once more. Durr.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 Oct 2013 09:33:16 +0300 |
parents | 36392d1d6b5f |
children | 78893039b1f6 |
line wrap: on
line source
<? $sessionType = "vote"; require "mconfig.inc.php"; require "msite.inc.php"; function stSubmitVotes($user_id) { foreach ($compos as $id => $compo) foreach ($compo["entries"] as $eid => $entry) { $vote = stGetRequestItem("entry".$eid); $sql = stPrepareSQL("SELECT id FROM votes WHERE voter_id=%d AND entry_id=%d", $user_id, $eid); if (($res = stFetchSQLColumn($sql)) === false) { $sql = stPrepareSQL( "INSERT INTO votes (voter_id,entry_id,value) VALUES (%d,%d,%d)", $user_id, $eid, $vote); if (stExecSQL($sql) === false) return FALSE; } else { $sql = stPrepareSQL( "UPDATE votes SET value=%d WHERE voter_id=%d AND entry_id=%d", $vote, $user_id, $eid); if (stExecSQL($sql) === false) return FALSE; } } return TRUE; } // // Start of the main code // if (stStartSubmitSession("allowVoting", $sessionType)) { // Vote submission if (!$errorSet && $mode == "vote") { stSetSessionStatus(1); stGetCompoList(FALSE); // Check the submitted vote values foreach ($compos as $id => $compo) foreach ($compo["entries"] as $eid => $entry) { $name = "entry".$eid; $vote = stGetRequestItem($name); if (!$errorSet && ($vote < stGetSetting("voteMin") || $vote > stGetSetting("voteMax"))) { stError("One or more vote value was out of bounds. Trying to cheat, eh?"); $vote = 0; } stSetSessionItem($name, $vote); } if (!$errorSet) { if (stSubmitVotes($user["id"])) stSetSessionStatus(2); } } stEndSubmitSession($sessionType); } ?>