Mercurial > hg > fapweb
annotate vote.inc.php @ 98:0f00192e64af
Obey userKeyLength site setting here when printing voting login.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Oct 2013 20:30:37 +0300 |
parents | b75f99a8973c |
children | ff511f5351df |
rev | line source |
---|---|
0 | 1 <? |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
2 $sessionType = "user"; |
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
3 $userKeyLen = stGetSetting("userKeyLength"); |
32 | 4 |
0 | 5 // Check if voting is enabled |
6 if (!stChkSetting("allowVoting")) | |
7 { | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
8 echo |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
9 "<h1>Sorry, voting disabled!</h1>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
10 "<p>Voting functionality not available at this time.</p>\n"; |
68 | 11 |
12 $status = -1; | |
0 | 13 } |
14 else | |
32 | 15 if (stUserSessionAuth()) |
0 | 16 { |
68 | 17 $status = stGetSessionItem("status"); |
18 stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system"); | |
19 } else | |
20 $status = 0; | |
21 | |
22 | |
23 if ($status == 0) | |
24 { | |
25 echo | |
26 "<h1>Voting system</h1>\n". | |
27 stGetFormStart("vote", "usrlogin.php"). | |
28 " ".stGetFormHiddenInput("mode", "key")."\n". | |
29 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
30 " <div class=\"votectrl\">\n". | |
31 " Enter your vote key:\n". | |
98
0f00192e64af
Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
32 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n". |
68 | 33 " ".stGetFormSubmitInput("login", "Login")."\n". |
34 " </div>\n". | |
35 "</form>\n"; | |
32 | 36 } |
37 else | |
68 | 38 if ($status == 1) |
32 | 39 { |
68 | 40 stGetCompoList(TRUE, TRUE); |
41 | |
42 // Try fetching previously stored votes | |
43 $sql = stPrepareSQL( | |
44 "SELECT * FROM votes WHERE voter_id=%d", | |
79 | 45 stGetSessionItem("voter_id")); |
32 | 46 |
68 | 47 if (($res = stExecSQL($sql)) !== false) |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
48 { |
68 | 49 foreach ($res as $vote) |
50 { | |
51 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]); | |
52 } | |
53 } | |
0 | 54 |
68 | 55 // Output voting system HTML |
56 echo | |
57 "<h1>Voting system</h1>\n". | |
58 stGetFormStart("vote", "vsubmit.php"). | |
59 " ".stGetFormHiddenInput("mode", "vote")."\n". | |
60 " ".stGetFormHiddenInput("goto", "vote")."\n". | |
61 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". | |
62 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n"; | |
32 | 63 |
68 | 64 foreach ($compos as $id => $compo) |
65 if (count($compo["entries"]) > 0) | |
66 { | |
0 | 67 echo |
68 | 68 " <table class=\"vote\">\n". |
69 " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n". | |
70 " <tr>\n". | |
71 " <th class=\"vtitle\">Title</th>\n". | |
72 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). | |
73 " "; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
74 |
68 | 75 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
|
76 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
77 echo |
68 | 78 "<th class=\"vvalue\">".$i."</th>"; |
79 } | |
80 echo "\n". | |
81 " </tr>\n"; | |
82 | |
83 $row = 0; | |
84 foreach ($compo["entries"] as $eid => $entry) | |
85 { | |
86 echo | |
87 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". | |
88 " <td class=\"vtitle\">".$entry["name"]."</td>\n". | |
89 ($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
|
90 " "; |
0 | 91 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
92 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
|
93 { |
68 | 94 $name = "entry".$eid; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
95 echo |
68 | 96 "<td class=\"vvalue\">". |
97 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). | |
98 "</td>"; | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
99 } |
68 | 100 |
101 echo | |
102 "\n". | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
103 " </tr>\n"; |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
104 |
68 | 105 $row++; |
106 } | |
107 echo | |
108 " </table>\n"; | |
109 } | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
110 |
68 | 111 echo |
112 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n". | |
113 "</form>\n"; | |
114 } | |
115 else | |
116 if ($status == 2) | |
117 { | |
118 // Voting finished | |
119 echo "<h1>Yay, you have voted!</h1>\n". | |
120 "<p>Now go FAP some more! And make a demo about it.</p>"; | |
121 stSessionEnd(SESS_USER); | |
0 | 122 } |
123 ?> |