Mercurial > hg > fapweb
view vote.inc.php @ 472:1eabbd70cd25
Add skipping button.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Dec 2013 22:28:23 +0200 |
parents | 357b81e39ab3 |
children |
line wrap: on
line source
<? // // FAPWeb Simple Demoparty System // Competition voting page // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) // $sessionType = "user"; require_once "majax.inc.php"; function stGetVoteButton() { return " <div class=\"votectrl\">\n". " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n". " </div>\n"; } // Check if voting is enabled if (!stChkSetting("allowVoting")) { echo "<h1>Sorry, voting disabled!</h1>\n". "<p>Voting functionality not available at this time.</p>\n"; } else if (!stUserSessionAuth(FALSE)) { // Perform authentication if we are not in session already $userKeyLen = stGetSetting("userKeyLength"); if (($error = stGetRequestItem("error", 0, TRUE)) != 0) { echo "<h1>Voting system login failed</h1>\n". "<p class=\"notice\">\n"; switch ($error) { case 1: echo "The votekey does not exist. Please try again."; break; case 2: echo "There was an error in the system. Contact an administrator."; break; case 3: echo "The votekey is not yet activated, try again later. If ". "you are certain that it should be working now, go pester an organizer."; break; } echo "</p>\n"; } else { echo "<h1>Voting system</h1>\n"; } echo stGetFormStart("vote", "usrlogin.php"). " ".stGetFormHiddenInput("mode", "vote")."\n". " ".stGetFormHiddenInput("goto", "vote")."\n". " <div class=\"votectrl\">\n". " Enter your vote key:\n". " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". " ".stGetFormSubmitInput("login", "Login")."\n". " </div>\n". "</form>\n"; } else if (($mode = stGetSessionItem("mode")) == "vote") { stCommonAJAX("usrajax.php", "usrlogout.php", TRUE); ?> <script type="text/javascript"> function updateVote(eid, value) { var msuccess = function(txt) { } var mfail = function(txt) { jsMessageBox("Something went wrong. :("); } jsSendPOSTRequest("action=set&entry_id="+eid+"&vote="+value, msuccess, mfail); return false; } </script> <? // Try fetching previously stored votes $sql = stPrepareSQL( "SELECT entry_id,value FROM votes WHERE key_id=%d", stGetSessionItem("key_id")); $votes = array(); if (($res = stExecSQL($sql)) !== false) { foreach ($res as $vote) $votes[$vote["entry_id"]] = $vote["value"]; } // Output voting system HTML echo "<h1>Voting system</h1>\n". stGetFormStart("vote", "usrajax.php"). " ".stGetFormHiddenInput("mode", "done")."\n". " ".stGetFormHiddenInput("action", "submit")."\n". stGetVoteButton(); foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0") as $compo) { $cid = $compo["id"]; $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$cid); if ($nentries > 0) { echo " <table class=\"vote\">\n". " <tr><th colspan=\"".($compo["showAuthors"] ? "3" : "2")."\">".chentities($compo["name"])."</th></tr>\n". " <tr>\n". " <th class=\"vshown\">#</th>\n". " <th class=\"vtitle\">Title</th>\n". ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). " "; for ($i = stGetSetting("voteMax"); $i >= stGetSetting("voteMin"); $i--) { echo "<th class=\"vvalue\">".$i."</th>"; } echo "\n". " </tr>\n"; $row = 0; foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$cid) as $entry) { $eid = $entry["id"]; echo " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". " <td class=\"vtitle\">".$entry["name"]."</td>\n". ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : ""). " "; $val = isset($votes[$eid]) ? $votes[$eid] : 0; for ($i = stGetSetting("voteMax"); $i >= stGetSetting("voteMin"); $i--) { $nid = "ve".$eid."_".$i; echo "<td class=\"vvalue\">". "<input type=\"radio\" id=\"".$nid. "\" name=\"ventry".$eid."\" value=\"".$i."\" ". "onClick=\"updateVote(".$eid.",".$i.")\" ". ($val == $i ? "checked=\"checked\" ": "")."/>". "<label for=\"".$nid."\"></label>". "</td>"; } echo "\n". " </tr>\n"; $row++; } echo " </table>\n"; } } echo stGetVoteButton(). "</form>\n"; } else if ($mode == "done") { // Voting finished echo stGetSetting("voteFinishedText"); echo "<p>Or perhaps <a href=\"vote\">vote again!</a></p>\n"; stSessionEnd(SESS_USER); } ?>