Mercurial > hg > fapweb
annotate vote.inc.php @ 295:e387d717cf46
Indentation cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 25 Nov 2013 15:40:21 +0200 |
parents | 4c00e9cbb84e |
children | 828fc30e3c94 |
rev | line source |
---|---|
0 | 1 <? |
151 | 2 // |
3 // FAPWeb Simple Demoparty System | |
4 // Competition voting page | |
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) | |
6 // | |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
7 $sessionType = "user"; |
175
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
151
diff
changeset
|
8 require_once "majax.php"; |
32 | 9 |
110 | 10 |
11 function stGetVoteButton() | |
12 { | |
13 return | |
14 "<div class=\"votectrl\">". | |
15 stGetFormSubmitInput("vote", "Submit votes!", "return false"). | |
16 "</div>\n"; | |
17 } | |
18 | |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
19 |
0 | 20 // Check if voting is enabled |
21 if (!stChkSetting("allowVoting")) | |
22 { | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
23 echo |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
24 "<h1>Sorry, voting disabled!</h1>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
25 "<p>Voting functionality not available at this time.</p>\n"; |
0 | 26 } |
27 else | |
110 | 28 if (!stUserSessionAuth(FALSE)) |
0 | 29 { |
110 | 30 // Perform authentication if we are not in session already |
190 | 31 $userKeyLen = stGetSetting("userKeyLength"); |
68 | 32 echo |
110 | 33 "<h1>Voting system</h1>\n". |
34 (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : ""). | |
35 stGetFormStart("vote", "usrlogin.php"). | |
36 " ".stGetFormHiddenInput("mode", "vote")."\n". | |
37 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
38 " <div class=\"votectrl\">\n". | |
39 " Enter your vote key:\n". | |
248
8d46f1358233
Add autofocus in vote login as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
40 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". |
110 | 41 " ".stGetFormSubmitInput("login", "Login")."\n". |
42 " </div>\n". | |
43 "</form>\n"; | |
32 | 44 } |
45 else | |
110 | 46 if (($mode = stGetSessionItem("mode")) == "vote") |
32 | 47 { |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
48 stCommonAJAX("usrajax.php", "usrlogout.php", TRUE); |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
49 ?> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
50 <script type="text/javascript"> |
68 | 51 |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
52 function updateVote(eid, value) |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
53 { |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
54 return false; |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
55 } |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
56 |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
57 </script> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
58 <? |
68 | 59 // Try fetching previously stored votes |
60 $sql = stPrepareSQL( | |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
61 "SELECT entry_id,value FROM votes WHERE voter_id=%d", |
79 | 62 stGetSessionItem("voter_id")); |
32 | 63 |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
64 $votes = array(); |
68 | 65 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
66 { |
68 | 67 foreach ($res as $vote) |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
68 $votes[$vote["entry_id"]] = $vote["value"]; |
68 | 69 } |
0 | 70 |
68 | 71 // Output voting system HTML |
72 echo | |
276 | 73 "<h1>Voting system</h1>\n". |
74 stGetFormStart("vote", "usrajax.php"). | |
75 " ".stGetFormHiddenInput("mode", "done")."\n". | |
76 " ".stGetFormHiddenInput("action", "submit")."\n". | |
77 stGetVoteButton(); | |
32 | 78 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
79 foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0") as $compo) |
68 | 80 { |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
81 $cid = $compo["id"]; |
277 | 82 $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$cid); |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
83 if ($nentries > 0) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
84 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
85 echo |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
86 " <table class=\"vote\">\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
87 " <tr><th colspan=\"".($compo["showAuthors"] ? "3" : "2")."\">".chentities($compo["name"])."</th></tr>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
88 " <tr>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
89 " <th class=\"vshown\">#</th>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
90 " <th class=\"vtitle\">Title</th>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
91 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
92 " "; |
0 | 93 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
94 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
|
95 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
96 echo |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
97 "<th class=\"vvalue\">".$i."</th>"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
98 } |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
99 echo "\n". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
100 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
101 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
102 $row = 0; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
103 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$cid) as $entry) |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
104 { |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
105 $eid = $entry["id"]; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
106 echo |
295 | 107 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". |
108 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". | |
109 " <td class=\"vtitle\">".$entry["name"]."</td>\n". | |
110 ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : ""). | |
111 " "; | |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
112 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
113 $val = isset($votes[$eid]) ? $votes[$eid] : 0; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
114 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
115 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
116 { |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
117 echo |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
118 "<td class=\"vvalue\">". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
119 stGetFormRadioButtonInput( |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
120 "entry".$eid, "", "", $i, ($i == $val), |
277 | 121 "", |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
122 "onClick=\"updateVote(".$eid.",".$i.")\""). |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
123 "</td>"; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
124 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
125 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
126 echo |
295 | 127 "\n". |
128 " </tr>\n"; | |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
129 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
130 $row++; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
131 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
132 echo |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
133 " </table>\n"; |
68 | 134 } |
135 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
136 |
68 | 137 echo |
225 | 138 stGetVoteButton(). |
139 "</form>\n"; | |
68 | 140 } |
141 else | |
110 | 142 if ($mode == "done") |
68 | 143 { |
144 // Voting finished | |
226
548a106b3f5b
Use setting instead of hardcoded text.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
145 echo stGetSetting("voteFinishedText"); |
68 | 146 stSessionEnd(SESS_USER); |
0 | 147 } |
110 | 148 ?> |