Mercurial > hg > fapweb
annotate pages/vote.inc.php @ 988:7d7bd913649c
Order the compos on vote page.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Nov 2014 18:28:50 +0200 |
parents | c1738ee91f6a |
children | 3714c6c53529 |
rev | line source |
---|---|
0 | 1 <? |
151 | 2 // |
571
ce11ea112a65
Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
3 // FAPWeb - Simple Web-based Demoparty Management System |
151 | 4 // Competition voting page |
565 | 5 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) |
151 | 6 // |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
7 $sessionType = "user"; |
384
357b81e39ab3
Rename majax.php -> majax.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
358
diff
changeset
|
8 require_once "majax.inc.php"; |
32 | 9 |
110 | 10 |
11 function stGetVoteButton() | |
12 { | |
13 return | |
709 | 14 " <div class=\"voteControls\">\n". |
326 | 15 " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n". |
16 " </div>\n"; | |
110 | 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")) | |
789
24bbd1f89794
Add few new settings, bump database version.
Matti Hamalainen <ccr@tnsp.org>
parents:
786
diff
changeset
|
22 echo stGetSetting("votingDisabled"); |
0 | 23 else |
110 | 24 if (!stUserSessionAuth(FALSE)) |
0 | 25 { |
110 | 26 // Perform authentication if we are not in session already |
190 | 27 $userKeyLen = stGetSetting("userKeyLength"); |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
28 |
358
0244aeeab6e7
Use GET for error parameter.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
29 if (($error = stGetRequestItem("error", 0, TRUE)) != 0) |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
30 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
31 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
32 "<h1>Voting system login failed</h1>\n". |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
33 "<p class=\"notice\">\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
34 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
35 switch ($error) |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
36 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
37 case 1: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
38 echo "The votekey does not exist. Please try again."; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
39 break; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
40 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
41 case 2: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
42 echo "There was an error in the system. Contact an administrator."; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
43 break; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
44 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
45 case 3: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
46 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
47 "The votekey is not yet activated, try again later. If ". |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
48 "you are certain that it should be working now, go pester an organizer."; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
49 break; |
672 | 50 |
51 default: | |
52 echo | |
53 "Undefined error occured."; | |
54 break; | |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
55 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
56 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
57 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
58 "</p>\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
59 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
60 else |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
61 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
62 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
63 "<h1>Voting system</h1>\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
64 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
65 |
68 | 66 echo |
709 | 67 "<div class=\"voteLogin\">\n". |
68 " ".stGetFormStart("vote", "usrlogin.php"). | |
110 | 69 " ".stGetFormHiddenInput("mode", "vote")."\n". |
70 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
71 " Enter your vote key:\n". | |
248
8d46f1358233
Add autofocus in vote login as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
72 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". |
110 | 73 " ".stGetFormSubmitInput("login", "Login")."\n". |
709 | 74 " </form>\n". |
75 "</div>\n"; | |
32 | 76 } |
77 else | |
110 | 78 if (($mode = stGetSessionItem("mode")) == "vote") |
32 | 79 { |
731
4ac3d5f07178
Remove function argument that no longer exists.
Matti Hamalainen <ccr@tnsp.org>
parents:
730
diff
changeset
|
80 stCommonAJAX("usrajax.php", "usrlogout.php"); |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
81 ?> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
82 <script type="text/javascript"> |
68 | 83 |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
84 function updateVote(eid, value) |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
85 { |
330 | 86 var msuccess = function(txt) |
87 { | |
88 } | |
89 | |
90 var mfail = function(txt) | |
91 { | |
786 | 92 jsMessageBox("<h1>Ooops, an error occured</h2><p>Something went wrong, votes might not be submitted. :(</p>"); |
330 | 93 } |
94 | |
342
3175ec252c73
Rename sendPOSTRequest() to jsSendPOSTRequest().
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
95 jsSendPOSTRequest("action=set&entry_id="+eid+"&vote="+value, msuccess, mfail); |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
96 return false; |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
97 } |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
98 |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
99 </script> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
100 <? |
68 | 101 // Try fetching previously stored votes |
102 $sql = stPrepareSQL( | |
302
828fc30e3c94
Some work on vote backend stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
103 "SELECT entry_id,value FROM votes WHERE key_id=%d", |
828fc30e3c94
Some work on vote backend stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
104 stGetSessionItem("key_id")); |
32 | 105 |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
106 $votes = array(); |
68 | 107 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
108 { |
68 | 109 foreach ($res as $vote) |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
110 $votes[$vote["entry_id"]] = $vote["value"]; |
68 | 111 } |
0 | 112 |
68 | 113 // Output voting system HTML |
114 echo | |
276 | 115 "<h1>Voting system</h1>\n". |
116 stGetFormStart("vote", "usrajax.php"). | |
117 " ".stGetFormHiddenInput("mode", "done")."\n". | |
118 " ".stGetFormHiddenInput("action", "submit")."\n". | |
789
24bbd1f89794
Add few new settings, bump database version.
Matti Hamalainen <ccr@tnsp.org>
parents:
786
diff
changeset
|
119 " ".stGetFormHiddenInput("onerror", "noauthvote")."\n". |
276 | 120 stGetVoteButton(); |
32 | 121 |
988
7d7bd913649c
Order the compos on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
972
diff
changeset
|
122 foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0 ORDER BY id") as $compo) |
68 | 123 { |
972 | 124 $esql = stPrepareSQL("FROM entries WHERE (flags & %d)=0 AND compo_id=%d", EFLAG_DISQUALIFIED, $compo["id"]); |
598
ba84d8e35d6b
Do not count entries that have been flagged as disqualified.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
125 $nentries = stFetchSQLColumn("SELECT COUNT(*) ".$esql); |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
126 if ($nentries > 0) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
127 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
128 echo |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
129 " <table class=\"vote\">\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
130 " <tr>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
131 " <th class=\"vshown\">#</th>\n". |
726 | 132 " <th class=\"vcompo\">".chentities($compo["name"])."</th>\n"; |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
133 for ($i = stGetSetting("voteMax"); $i >= stGetSetting("voteMin"); $i--) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
134 { |
708 | 135 echo " <th class=\"vvalue\">".$i."</th>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
136 } |
708 | 137 echo |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
138 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
139 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
140 $row = 0; |
972 | 141 foreach (stExecSQL("SELECT * ".$esql." ORDER BY show_id ASC") as $entry) |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
142 { |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
143 $eid = $entry["id"]; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
144 echo |
295 | 145 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". |
146 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". | |
712 | 147 " <td class=\"ventry\">\n". |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
148 " <div class=\"vpreview\">"; |
712 | 149 |
774
d6668b73bb01
Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents:
732
diff
changeset
|
150 stPrintPreviewElements($compo, $entry); |
721
69a829f687a9
Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents:
712
diff
changeset
|
151 |
712 | 152 echo |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
153 "</div>\n". |
712 | 154 " <div class=\"vinfo\">". |
155 "<span class=\"vtitle\">".$entry["name"]."</span>". | |
156 ($compo["show_authors"] ? "<span class=\"vby\"> by </span><span class=\"vauthor\">".$entry["author"]."</span>" : ""). | |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
157 "</div>\n". |
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
158 " </td>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
159 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
160 $val = isset($votes[$eid]) ? $votes[$eid] : 0; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
161 |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
162 for ($i = stGetSetting("voteMax"); $i >= stGetSetting("voteMin"); $i--) |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
163 { |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
164 $nid = "ve".$eid."_".$i; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
165 echo |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
166 " <td class=\"vvalue\">". |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
167 "<input type=\"radio\" id=\"".$nid. |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
168 "\" name=\"ventry".$eid."\" value=\"".$i."\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
169 "onClick=\"updateVote(".$eid.",".$i.")\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
170 ($val == $i ? "checked=\"checked\" ": "")."/>". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
171 "<label for=\"".$nid."\"></label>". |
708 | 172 "</td>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
173 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
174 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
175 echo |
295 | 176 " </tr>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
177 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
178 $row++; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
179 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
180 echo |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
181 " </table>\n"; |
68 | 182 } |
183 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
184 |
68 | 185 echo |
225 | 186 stGetVoteButton(). |
187 "</form>\n"; | |
68 | 188 } |
189 else | |
110 | 190 if ($mode == "done") |
68 | 191 { |
192 // Voting finished | |
226
548a106b3f5b
Use setting instead of hardcoded text.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
193 echo stGetSetting("voteFinishedText"); |
68 | 194 stSessionEnd(SESS_USER); |
0 | 195 } |
110 | 196 ?> |