Mercurial > hg > fapweb
view vote.inc.php @ 107:6e076b3630a0
Cleanup the code a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 21 Oct 2013 22:47:29 +0300 |
parents | 0f00192e64af |
children | ff511f5351df |
line wrap: on
line source
<? $sessionType = "user"; $userKeyLen = stGetSetting("userKeyLength"); // 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"; $status = -1; } else if (stUserSessionAuth()) { $status = stGetSessionItem("status"); stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system"); } else $status = 0; if ($status == 0) { echo "<h1>Voting system</h1>\n". stGetFormStart("vote", "usrlogin.php"). " ".stGetFormHiddenInput("mode", "key")."\n". " ".stGetFormHiddenInput("goto", "vote")."\n". " <div class=\"votectrl\">\n". " Enter your vote key:\n". " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n". " ".stGetFormSubmitInput("login", "Login")."\n". " </div>\n". "</form>\n"; } else if ($status == 1) { stGetCompoList(TRUE, TRUE); // Try fetching previously stored votes $sql = stPrepareSQL( "SELECT * FROM votes WHERE voter_id=%d", stGetSessionItem("voter_id")); if (($res = stExecSQL($sql)) !== false) { foreach ($res as $vote) { stSetSessionItem("entry".$vote["entry_id"], $vote["value"]); } } // Output voting system HTML echo "<h1>Voting system</h1>\n". stGetFormStart("vote", "vsubmit.php"). " ".stGetFormHiddenInput("mode", "vote")."\n". " ".stGetFormHiddenInput("goto", "vote")."\n". " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n"; foreach ($compos as $id => $compo) if (count($compo["entries"]) > 0) { echo " <table class=\"vote\">\n". " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n". " <tr>\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 ($compo["entries"] as $eid => $entry) { echo " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". " <td class=\"vtitle\">".$entry["name"]."</td>\n". ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : ""). " "; for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) { $name = "entry".$eid; echo "<td class=\"vvalue\">". stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). "</td>"; } echo "\n". " </tr>\n"; $row++; } echo " </table>\n"; } echo " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n". "</form>\n"; } else if ($status == 2) { // Voting finished echo "<h1>Yay, you have voted!</h1>\n". "<p>Now go FAP some more! And make a demo about it.</p>"; stSessionEnd(SESS_USER); } ?>