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