annotate vote.inc.php @ 126:71c35d5302c2

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