Mercurial > hg > fapweb
annotate vote.inc.php @ 126:71c35d5302c2
More work on cleanups, and AJAX modularization.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Oct 2013 17:00:49 +0300 |
parents | 9a52fa9d4ecc |
children | 6b71472cda77 |
rev | line source |
---|---|
0 | 1 <? |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
2 $sessionType = "user"; |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
3 require "majax.php"; |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
4 $userKeyLen = stGetSetting("userKeyLength"); |
32 | 5 |
110 | 6 |
7 function stGetVoteButton() | |
8 { | |
9 return | |
10 "<div class=\"votectrl\">". | |
11 stGetFormSubmitInput("vote", "Submit votes!", "return false"). | |
12 "</div>\n"; | |
13 } | |
14 | |
0 | 15 // Check if voting is enabled |
16 if (!stChkSetting("allowVoting")) | |
17 { | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
18 echo |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
19 "<h1>Sorry, voting disabled!</h1>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
20 "<p>Voting functionality not available at this time.</p>\n"; |
0 | 21 } |
22 else | |
110 | 23 if (!stUserSessionAuth(FALSE)) |
0 | 24 { |
110 | 25 // Perform authentication if we are not in session already |
68 | 26 echo |
110 | 27 "<h1>Voting system</h1>\n". |
28 (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : ""). | |
29 stGetFormStart("vote", "usrlogin.php"). | |
30 " ".stGetFormHiddenInput("mode", "vote")."\n". | |
31 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
32 " <div class=\"votectrl\">\n". | |
33 " Enter your vote key:\n". | |
34 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\"")."\n". | |
35 " ".stGetFormSubmitInput("login", "Login")."\n". | |
36 " </div>\n". | |
37 "</form>\n"; | |
32 | 38 } |
39 else | |
110 | 40 if (($mode = stGetSessionItem("mode")) == "vote") |
32 | 41 { |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
42 stCommonAJAX("usrajax.php", "usrlogout.php", TRUE); |
68 | 43 stGetCompoList(TRUE, TRUE); |
44 | |
45 // Try fetching previously stored votes | |
46 $sql = stPrepareSQL( | |
47 "SELECT * FROM votes WHERE voter_id=%d", | |
79 | 48 stGetSessionItem("voter_id")); |
32 | 49 |
68 | 50 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
51 { |
68 | 52 foreach ($res as $vote) |
53 { | |
54 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]); | |
55 } | |
56 } | |
0 | 57 |
68 | 58 // Output voting system HTML |
59 echo | |
60 "<h1>Voting system</h1>\n". | |
110 | 61 stGetFormStart("vote", "usrvote.php"). |
68 | 62 " ".stGetFormHiddenInput("mode", "vote")."\n". |
63 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
64 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". | |
110 | 65 stGetVoteButton(); |
32 | 66 |
68 | 67 foreach ($compos as $id => $compo) |
68 if (count($compo["entries"]) > 0) | |
69 { | |
0 | 70 echo |
68 | 71 " <table class=\"vote\">\n". |
72 " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n". | |
73 " <tr>\n". | |
74 " <th class=\"vtitle\">Title</th>\n". | |
75 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). | |
76 " "; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
77 |
68 | 78 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
79 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
80 echo |
68 | 81 "<th class=\"vvalue\">".$i."</th>"; |
82 } | |
83 echo "\n". | |
84 " </tr>\n"; | |
85 | |
86 $row = 0; | |
87 foreach ($compo["entries"] as $eid => $entry) | |
88 { | |
89 echo | |
90 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". | |
117
9a52fa9d4ecc
Show 'show_id' in the vote sheet as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
91 " <td class=\"show_id\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". |
68 | 92 " <td class=\"vtitle\">".$entry["name"]."</td>\n". |
93 ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : ""). | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
94 " "; |
0 | 95 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
96 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
97 { |
68 | 98 $name = "entry".$eid; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
99 echo |
68 | 100 "<td class=\"vvalue\">". |
101 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). | |
102 "</td>"; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
103 } |
68 | 104 |
105 echo | |
106 "\n". | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
107 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
108 |
68 | 109 $row++; |
110 } | |
111 echo | |
112 " </table>\n"; | |
113 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
114 |
68 | 115 echo |
110 | 116 stGetVoteButton(). |
68 | 117 "</form>\n"; |
118 } | |
119 else | |
110 | 120 if ($mode == "done") |
68 | 121 { |
122 // Voting finished | |
123 echo "<h1>Yay, you have voted!</h1>\n". | |
124 "<p>Now go FAP some more! And make a demo about it.</p>"; | |
125 stSessionEnd(SESS_USER); | |
0 | 126 } |
110 | 127 ?> |