annotate vote.inc.php @ 32:36392d1d6b5f

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2012 11:14:05 +0200
parents b27204653615
children 7bdf89601ba0
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 <?
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
2 $sessionType = "vote";
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
3
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 // Check if voting is enabled
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 if (!stChkSetting("allowVoting"))
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 {
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
7 echo
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
8 "<h1>Sorry, voting disabled!</h1>\n".
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
9 "<p>Voting functionality not available at this time.</p>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 else
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
12 if (stUserSessionAuth())
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 {
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
14 $authState = "ok";
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
15 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
16 else
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
17 {
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
18
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
19 $authState = "login";
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
20 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
21
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
22
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
23 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
24 $status = stGetSubmitStatus();
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
25
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
26 stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
27
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
28 if ($status == 1)
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
29 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
30 $showAuthors = stGetSetting("showVoteAuthors");
24
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
31 stGetCompoList(TRUE, TRUE);
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
33 // Try fetching previously stored votes
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
34 $sql = stPrepareSQL(
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
35 "SELECT * FROM votes WHERE voter_id=%d",
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
36 stGetSessionItem("user_id"));
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 if (($res = stExecSQL($sql)) !== false)
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
39 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
40 foreach ($res as $vote)
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
41 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
42 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
43 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
44 }
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
45
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 echo
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
47 "<h1>Voting system</h1>\n".
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
48 stGetFormStart("vote", "vsubmit.php").
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
49 " ".stGetFormHiddenInput("mode", "vote")."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
50 " ".stGetFormHiddenInput("goto", "vote")."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
51 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
52 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
53
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
54 foreach ($compos as $id => $compo)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
55 if (count($compo["entries"]) > 0)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
56 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
57 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
58 " <table class=\"vote\">\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
59 " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
60 " <tr>\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
61 " <th class=\"vtitle\">Title</th>\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
62 ($showAuthors ? " <th class=\"vauthor\">Author</th>\n" : "").
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
63 " ";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
65 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
66 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
67 echo
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
68 "<th class=\"vvalue\">".$i."</th>";
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
69 }
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
70 echo "\n".
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
71 " </tr>\n";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
72
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
73 $row = 0;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
74 foreach ($compo["entries"] as $eid => $entry)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
75 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
76 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
77 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
78 " <td class=\"vtitle\">".$entry["name"]."</td>\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
79 ($showAuthors ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
80 " ";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
81
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
82 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
83 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
84 $name = "entry".$eid;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
85 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
86 "<td class=\"vvalue\">".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
87 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
88 "</td>";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
89 }
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
90
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
91 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
92 "\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
93 " </tr>\n";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
94
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
95 $row++;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
96 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
98 " </table>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
102 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
103 "</form>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 else
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
106 if ($status == 2)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 {
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
108 echo "<h1>Yay, you have voted!</h1>\n".
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
109 "<p>Now go FAP some more! And make a demo about it.</p>";
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
110 stSessionEnd(TRUE);
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 ?>