Mercurial > hg > fapweb
view vote.inc.php @ 248:8d46f1358233
Add autofocus in vote login as well.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 24 Nov 2013 00:24:38 +0200 |
parents | c52ca3a89989 |
children | 92698b090c35 |
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.php"; function stGetVoteButton() { return "<div class=\"votectrl\">". stGetFormSubmitInput("vote", "Submit votes!", "return false"). "</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"); echo "<h1>Voting system</h1>\n". (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : ""). 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); stGetCompoList(TRUE, TRUE); // Try fetching previously stored votes $sql = stPrepareSQL( "SELECT entry_id,value FROM votes WHERE voter_id=%d", stGetSessionItem("voter_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("voteMin"); $i <= stGetSetting("voteMax"); $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("voteMin"); $i <= stGetSetting("voteMax"); $i++) { echo "<td class=\"vvalue\">". stGetFormRadioButtonInput( "entry".$eid, "", "", $i, ($i == $val), "onClick=\"updateVote(".$eid.",".$i.")\""). "</td>"; } echo "\n". " </tr>\n"; $row++; } echo " </table>\n"; } } echo stGetVoteButton(). "</form>\n"; } else if ($mode == "done") { // Voting finished echo stGetSetting("voteFinishedText"); stSessionEnd(SESS_USER); } ?>