Mercurial > hg > fapweb
annotate vote.inc.php @ 190:a14663f6497d
Cosmetic.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 09 Nov 2013 14:58:24 +0200 |
parents | 8df523e6326a |
children | 2b39068c4968 |
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". | |
40 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\"")."\n". | |
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); |
68 | 49 stGetCompoList(TRUE, TRUE); |
50 | |
51 // Try fetching previously stored votes | |
52 $sql = stPrepareSQL( | |
53 "SELECT * FROM votes WHERE voter_id=%d", | |
79 | 54 stGetSessionItem("voter_id")); |
32 | 55 |
68 | 56 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
57 { |
68 | 58 foreach ($res as $vote) |
59 { | |
60 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]); | |
61 } | |
62 } | |
0 | 63 |
68 | 64 // Output voting system HTML |
65 echo | |
66 "<h1>Voting system</h1>\n". | |
110 | 67 stGetFormStart("vote", "usrvote.php"). |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
68 " ".stGetFormHiddenInput("mode", "done")."\n". |
68 | 69 " ".stGetFormHiddenInput("goto", "vote")."\n". |
110 | 70 stGetVoteButton(); |
32 | 71 |
68 | 72 foreach ($compos as $id => $compo) |
73 if (count($compo["entries"]) > 0) | |
74 { | |
0 | 75 echo |
68 | 76 " <table class=\"vote\">\n". |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
77 " <tr><th colspan=\"".($compo["showAuthors"] ? "3" : "2")."\">".chentities($compo["name"])."</th></tr>\n". |
68 | 78 " <tr>\n". |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
79 " <th class=\"vshown\">#</th>\n". |
68 | 80 " <th class=\"vtitle\">Title</th>\n". |
81 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). | |
82 " "; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
83 |
68 | 84 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
|
85 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
86 echo |
68 | 87 "<th class=\"vvalue\">".$i."</th>"; |
88 } | |
89 echo "\n". | |
90 " </tr>\n"; | |
91 | |
92 $row = 0; | |
93 foreach ($compo["entries"] as $eid => $entry) | |
94 { | |
95 echo | |
96 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". | |
127
6b71472cda77
A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
97 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n". |
68 | 98 " <td class=\"vtitle\">".$entry["name"]."</td>\n". |
99 ($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
|
100 " "; |
0 | 101 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
102 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
|
103 { |
68 | 104 $name = "entry".$eid; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
105 echo |
68 | 106 "<td class=\"vvalue\">". |
107 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). | |
108 "</td>"; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
109 } |
68 | 110 |
111 echo | |
112 "\n". | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
113 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
114 |
68 | 115 $row++; |
116 } | |
117 echo | |
118 " </table>\n"; | |
119 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
120 |
68 | 121 echo |
110 | 122 stGetVoteButton(). |
68 | 123 "</form>\n"; |
124 } | |
125 else | |
110 | 126 if ($mode == "done") |
68 | 127 { |
128 // Voting finished | |
129 echo "<h1>Yay, you have voted!</h1>\n". | |
130 "<p>Now go FAP some more! And make a demo about it.</p>"; | |
131 stSessionEnd(SESS_USER); | |
0 | 132 } |
110 | 133 ?> |