Mercurial > hg > fapweb
view pages/vote.inc.php @ 1088:4f132374df75
Fix a 10L.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 26 Jan 2017 00:48:34 +0200 |
parents | 4c76b4994414 |
children | 95b74632cfe2 |
line wrap: on
line source
<?php // // FAPWeb - Simple Web-based Demoparty Management System // Competition voting page // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) // $sessionType = "user"; function stGetVoteButton() { return " <div class=\"voteControls\">\n". " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n". " </div>\n"; } function stVoteLoginForm() { $userKeyLen = stGetSetting("userKeyLength"); return "<div class=\"voteLogin\">\n". " ".stGetFormStart("vote", "usrlogin.php"). " ".stGetFormHiddenInput("mode", "vote")."\n". " ".stGetFormHiddenInput("goto", "vote")."\n". " Enter your vote key:\n". " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". " ".stGetFormSubmitInput("login", "Login")."\n". " </form>\n". "</div>\n"; } // Check if voting is enabled if (!stChkSetting("allowVoting")) echo stGetSetting("votingDisabled"); else if (!stUserSessionAuth(FALSE)) { // Perform authentication if we are not in session already 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; default: echo "Undefined error occured."; break; } echo "</p>\n"; } else { echo "<h1>Voting system</h1>\n"; } echo stVoteLoginForm(); } else if (($mode = stGetSessionItem("mode")) == "vote") { ?> <noscript> <div class="notice">If your browser supports JavaScript, enable it for smoother voting experience.</div> </noscript> <script type="text/javascript" src="usrajax.js.php"></script> <?php // 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". " ".stGetFormHiddenInput("onerror", "noauthvote")."\n". stGetVoteButton(); foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0 ORDER BY id") as $compo) { $esql = stPrepareSQL("FROM entries WHERE (flags & %d)=0 AND compo_id=%d", EFLAG_DISQUALIFIED, $compo["id"]); $nentries = stFetchSQLColumn("SELECT COUNT(*) ".$esql); if ($nentries > 0) { echo " <table class=\"vote\">\n". " <tr>\n". " <th class=\"vshown\">#</th>\n". " <th class=\"vcompo\">".chentities($compo["name"])."</th>\n"; for ($i = stGetSetting("voteMax"); $i >= stGetSetting("voteMin"); $i--) { echo " <th class=\"vvalue\">".$i."</th>\n"; } echo " </tr>\n"; $row = 0; foreach (stExecSQL("SELECT * ".$esql." ORDER BY show_id ASC") 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=\"ventry\">\n". " <div class=\"vpreview\">"; stPrintPreviewElements($compo, $entry); echo "</div>\n". " <div class=\"vinfo\">". "<span class=\"vtitle\">".$entry["name"]."</span>". ($compo["show_authors"] ? "<span class=\"vby\"> by </span><span class=\"vauthor\">".$entry["author"]."</span>" : ""). "</div>\n". " </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>\n"; } echo " </tr>\n"; $row++; } echo " </table>\n"; } } echo stGetVoteButton(). "</form>\n"; } else if ($mode == "done") { // Voting finished successfully echo stGetSetting("voteFinishedText"); stSessionEnd(SESS_USER); } else if ($mode == "error") { // Error cases in session, when using form submit echo "<h1>Voting system error</h1>\n". "<ul class=\"notice\">\n"; foreach (stGetSessionItem("error") as $msg) echo " <li>".chentities($msg)."</li>\n"; echo "</ul>\n". stVoteLoginForm(); stSessionEnd(SESS_USER); } ?>