Mercurial > hg > fapweb
annotate pages/vote.inc.php @ 709:1a9005eafb37
Change some element names.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Nov 2014 00:28:42 +0200 |
parents | 114b77baf1c2 |
children | 27f7f437d7d1 |
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")) | |
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"); |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
32 |
358
0244aeeab6e7
Use GET for error parameter.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
33 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
|
34 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
35 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
36 "<h1>Voting system login failed</h1>\n". |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
37 "<p class=\"notice\">\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
38 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
39 switch ($error) |
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 1: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
42 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
|
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 2: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
46 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
|
47 break; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
48 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
49 case 3: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
50 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
51 "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
|
52 "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
|
53 break; |
672 | 54 |
55 default: | |
56 echo | |
57 "Undefined error occured."; | |
58 break; | |
304
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 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
61 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
62 "</p>\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
63 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
64 else |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
65 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
66 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
67 "<h1>Voting system</h1>\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
68 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
69 |
68 | 70 echo |
709 | 71 "<div class=\"voteLogin\">\n". |
72 " ".stGetFormStart("vote", "usrlogin.php"). | |
110 | 73 " ".stGetFormHiddenInput("mode", "vote")."\n". |
74 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
75 " Enter your vote key:\n". | |
248
8d46f1358233
Add autofocus in vote login as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
76 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". |
110 | 77 " ".stGetFormSubmitInput("login", "Login")."\n". |
709 | 78 " </form>\n". |
79 "</div>\n"; | |
32 | 80 } |
81 else | |
110 | 82 if (($mode = stGetSessionItem("mode")) == "vote") |
32 | 83 { |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
84 stCommonAJAX("usrajax.php", "usrlogout.php", TRUE); |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
85 ?> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
86 <script type="text/javascript"> |
68 | 87 |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
88 function updateVote(eid, value) |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
89 { |
330 | 90 var msuccess = function(txt) |
91 { | |
92 } | |
93 | |
94 var mfail = function(txt) | |
95 { | |
343
e799da13c0f3
Rename messageBox() to jsMessageBox().
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
96 jsMessageBox("Something went wrong. :("); |
330 | 97 } |
98 | |
342
3175ec252c73
Rename sendPOSTRequest() to jsSendPOSTRequest().
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
99 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
|
100 return false; |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
101 } |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
102 |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
103 </script> |
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
104 <? |
68 | 105 // Try fetching previously stored votes |
106 $sql = stPrepareSQL( | |
302
828fc30e3c94
Some work on vote backend stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
107 "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
|
108 stGetSessionItem("key_id")); |
32 | 109 |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
110 $votes = array(); |
68 | 111 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
112 { |
68 | 113 foreach ($res as $vote) |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
114 $votes[$vote["entry_id"]] = $vote["value"]; |
68 | 115 } |
0 | 116 |
68 | 117 // Output voting system HTML |
118 echo | |
276 | 119 "<h1>Voting system</h1>\n". |
120 stGetFormStart("vote", "usrajax.php"). | |
121 " ".stGetFormHiddenInput("mode", "done")."\n". | |
122 " ".stGetFormHiddenInput("action", "submit")."\n". | |
123 stGetVoteButton(); | |
32 | 124 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
125 foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0") as $compo) |
68 | 126 { |
667
4fdb61f40946
Fixes to voting page. Some SQL fields had been left unrenamed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
598
diff
changeset
|
127 $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
|
128 $nentries = stFetchSQLColumn("SELECT COUNT(*) ".$esql); |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
129 if ($nentries > 0) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
130 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
131 echo |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
132 " <table class=\"vote\">\n". |
667
4fdb61f40946
Fixes to voting page. Some SQL fields had been left unrenamed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
598
diff
changeset
|
133 " <tr><th colspan=\"".($compo["show_authors"] ? "3" : "2")."\">".chentities($compo["name"])."</th></tr>\n". |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
134 " <tr>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
135 " <th class=\"vshown\">#</th>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
136 " <th class=\"vtitle\">Title</th>\n". |
667
4fdb61f40946
Fixes to voting page. Some SQL fields had been left unrenamed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
598
diff
changeset
|
137 ($compo["show_authors"] ? " <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
|
138 " "; |
0 | 139 |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
140 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
|
141 { |
708 | 142 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
|
143 } |
708 | 144 echo |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
145 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
146 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
147 $row = 0; |
598
ba84d8e35d6b
Do not count entries that have been flagged as disqualified.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
148 foreach (stExecSQL("SELECT * ".$esql) as $entry) |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
149 { |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
150 $eid = $entry["id"]; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
151 echo |
295 | 152 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". |
153 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". | |
154 " <td class=\"vtitle\">".$entry["name"]."</td>\n". | |
667
4fdb61f40946
Fixes to voting page. Some SQL fields had been left unrenamed, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
598
diff
changeset
|
155 ($compo["show_authors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : ""). |
295 | 156 " "; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
157 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
158 $val = isset($votes[$eid]) ? $votes[$eid] : 0; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
159 |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
160 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
|
161 { |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
162 $nid = "ve".$eid."_".$i; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
163 echo |
708 | 164 " <td class=\"vvalue\">". |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
165 "<input type=\"radio\" id=\"".$nid. |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
166 "\" name=\"ventry".$eid."\" value=\"".$i."\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
167 "onClick=\"updateVote(".$eid.",".$i.")\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
168 ($val == $i ? "checked=\"checked\" ": "")."/>". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
169 "<label for=\"".$nid."\"></label>". |
708 | 170 "</td>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
171 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
172 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
173 echo |
295 | 174 " </tr>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
175 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
176 $row++; |
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 echo |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
179 " </table>\n"; |
68 | 180 } |
181 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
182 |
68 | 183 echo |
225 | 184 stGetVoteButton(). |
185 "</form>\n"; | |
68 | 186 } |
187 else | |
110 | 188 if ($mode == "done") |
68 | 189 { |
190 // Voting finished | |
226
548a106b3f5b
Use setting instead of hardcoded text.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
191 echo stGetSetting("voteFinishedText"); |
325 | 192 echo "<p>Or perhaps <a href=\"vote\">vote again!</a></p>\n"; |
68 | 193 stSessionEnd(SESS_USER); |
0 | 194 } |
110 | 195 ?> |