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