Mercurial > hg > fapweb
annotate pages/vote.inc.php @ 1085:01783161eeb2
Fix usr and adm ajax and voting.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 25 Jan 2017 22:39:42 +0200 |
parents | 7e497188e4c6 |
children | 4c76b4994414 |
rev | line source |
---|---|
1075 | 1 <?php |
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 |
1001 | 5 // (C) Copyright 2012-2015 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"; |
32 | 8 |
110 | 9 |
10 function stGetVoteButton() | |
11 { | |
12 return | |
709 | 13 " <div class=\"voteControls\">\n". |
326 | 14 " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n". |
15 " </div>\n"; | |
110 | 16 } |
17 | |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
18 |
0 | 19 // Check if voting is enabled |
20 if (!stChkSetting("allowVoting")) | |
789
24bbd1f89794
Add few new settings, bump database version.
Matti Hamalainen <ccr@tnsp.org>
parents:
786
diff
changeset
|
21 echo stGetSetting("votingDisabled"); |
0 | 22 else |
110 | 23 if (!stUserSessionAuth(FALSE)) |
0 | 24 { |
110 | 25 // Perform authentication if we are not in session already |
190 | 26 $userKeyLen = stGetSetting("userKeyLength"); |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
27 |
358
0244aeeab6e7
Use GET for error parameter.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
28 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
|
29 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
30 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
31 "<h1>Voting system login failed</h1>\n". |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
32 "<p class=\"notice\">\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
33 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
34 switch ($error) |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
35 { |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
36 case 1: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
37 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
|
38 break; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
39 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
40 case 2: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
41 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
|
42 break; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
43 |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
44 case 3: |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
45 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
46 "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
|
47 "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
|
48 break; |
672 | 49 |
50 default: | |
51 echo | |
52 "Undefined error occured."; | |
53 break; | |
304
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
54 } |
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 echo |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
57 "</p>\n"; |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
58 } |
7181350076c1
Change how user login errors are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
302
diff
changeset
|
59 else |
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 "<h1>Voting system</h1>\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 |
68 | 65 echo |
709 | 66 "<div class=\"voteLogin\">\n". |
67 " ".stGetFormStart("vote", "usrlogin.php"). | |
110 | 68 " ".stGetFormHiddenInput("mode", "vote")."\n". |
69 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
70 " Enter your vote key:\n". | |
248
8d46f1358233
Add autofocus in vote login as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
71 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". |
110 | 72 " ".stGetFormSubmitInput("login", "Login")."\n". |
709 | 73 " </form>\n". |
74 "</div>\n"; | |
32 | 75 } |
76 else | |
110 | 77 if (($mode = stGetSessionItem("mode")) == "vote") |
32 | 78 { |
285
4c00e9cbb84e
Work on the voting interface.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
79 ?> |
999
3714c6c53529
Add helpful notice for people who have JavaScript disabled while voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
988
diff
changeset
|
80 <noscript> |
3714c6c53529
Add helpful notice for people who have JavaScript disabled while voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
988
diff
changeset
|
81 <div class="notice">If your browser supports JavaScript, enable it for smoother voting experience.</div> |
3714c6c53529
Add helpful notice for people who have JavaScript disabled while voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
988
diff
changeset
|
82 </noscript> |
1085
01783161eeb2
Fix usr and adm ajax and voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1075
diff
changeset
|
83 <script type="text/javascript" src="usrajax.js.php"></script> |
1075 | 84 <?php |
68 | 85 // Try fetching previously stored votes |
86 $sql = stPrepareSQL( | |
302
828fc30e3c94
Some work on vote backend stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
87 "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
|
88 stGetSessionItem("key_id")); |
32 | 89 |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
90 $votes = array(); |
68 | 91 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
92 { |
68 | 93 foreach ($res as $vote) |
221
2b39068c4968
Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
94 $votes[$vote["entry_id"]] = $vote["value"]; |
68 | 95 } |
0 | 96 |
68 | 97 // Output voting system HTML |
98 echo | |
276 | 99 "<h1>Voting system</h1>\n". |
100 stGetFormStart("vote", "usrajax.php"). | |
101 " ".stGetFormHiddenInput("mode", "done")."\n". | |
102 " ".stGetFormHiddenInput("action", "submit")."\n". | |
789
24bbd1f89794
Add few new settings, bump database version.
Matti Hamalainen <ccr@tnsp.org>
parents:
786
diff
changeset
|
103 " ".stGetFormHiddenInput("onerror", "noauthvote")."\n". |
276 | 104 stGetVoteButton(); |
32 | 105 |
988
7d7bd913649c
Order the compos on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
972
diff
changeset
|
106 foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0 ORDER BY id") as $compo) |
68 | 107 { |
972 | 108 $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
|
109 $nentries = stFetchSQLColumn("SELECT COUNT(*) ".$esql); |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
110 if ($nentries > 0) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
111 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
112 echo |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
113 " <table class=\"vote\">\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
114 " <tr>\n". |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
115 " <th class=\"vshown\">#</th>\n". |
726 | 116 " <th class=\"vcompo\">".chentities($compo["name"])."</th>\n"; |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
117 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
|
118 { |
708 | 119 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
|
120 } |
708 | 121 echo |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
122 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
123 |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
124 $row = 0; |
972 | 125 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
|
126 { |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
127 $eid = $entry["id"]; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
128 echo |
295 | 129 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". |
130 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". | |
712 | 131 " <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
|
132 " <div class=\"vpreview\">"; |
712 | 133 |
774
d6668b73bb01
Modularize preview HTML stuff into a function stPrintPreviewElements().
Matti Hamalainen <ccr@tnsp.org>
parents:
732
diff
changeset
|
134 stPrintPreviewElements($compo, $entry); |
721
69a829f687a9
Preliminary work for entry previews.
Matti Hamalainen <ccr@tnsp.org>
parents:
712
diff
changeset
|
135 |
712 | 136 echo |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
137 "</div>\n". |
712 | 138 " <div class=\"vinfo\">". |
139 "<span class=\"vtitle\">".$entry["name"]."</span>". | |
140 ($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
|
141 "</div>\n". |
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
142 " </td>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
143 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
144 $val = isset($votes[$eid]) ? $votes[$eid] : 0; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
145 |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
146 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
|
147 { |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
148 $nid = "ve".$eid."_".$i; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
149 echo |
729
0d064dcef03e
Vote page layout adjustments and add missing </td> tag for entries.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
150 " <td class=\"vvalue\">". |
333
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
151 "<input type=\"radio\" id=\"".$nid. |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
152 "\" name=\"ventry".$eid."\" value=\"".$i."\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
153 "onClick=\"updateVote(".$eid.",".$i.")\" ". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
154 ($val == $i ? "checked=\"checked\" ": "")."/>". |
018817535fab
Make voting more visually pleasant(?).
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
155 "<label for=\"".$nid."\"></label>". |
708 | 156 "</td>\n"; |
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 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
159 echo |
295 | 160 " </tr>\n"; |
242
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
161 |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
162 $row++; |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
163 } |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
164 echo |
c52ca3a89989
Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
165 " </table>\n"; |
68 | 166 } |
167 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
168 |
68 | 169 echo |
225 | 170 stGetVoteButton(). |
171 "</form>\n"; | |
68 | 172 } |
173 else | |
110 | 174 if ($mode == "done") |
68 | 175 { |
176 // Voting finished | |
226
548a106b3f5b
Use setting instead of hardcoded text.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
177 echo stGetSetting("voteFinishedText"); |
68 | 178 stSessionEnd(SESS_USER); |
0 | 179 } |
110 | 180 ?> |