annotate vote.inc.php @ 55:4fac95384753

Make visibility of entry authors per compo.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Oct 2013 09:33:06 +0300
parents 7bdf89601ba0
children 3ae137411706
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 {
24
5bc8bd5c7ecc Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
30 stGetCompoList(TRUE, TRUE);
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
32 // Try fetching previously stored votes
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
33 $sql = stPrepareSQL(
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
34 "SELECT * FROM votes WHERE voter_id=%d",
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
35 stGetSessionItem("user_id"));
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
36
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
37 if (($res = stExecSQL($sql)) !== false)
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 foreach ($res as $vote)
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
40 {
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
41 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
42 }
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
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 echo
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
46 "<h1>Voting system</h1>\n".
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
47 stGetFormStart("vote", "vsubmit.php").
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
48 " ".stGetFormHiddenInput("mode", "vote")."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
49 " ".stGetFormHiddenInput("goto", "vote")."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
50 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
51 " <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
52
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
53 foreach ($compos as $id => $compo)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
54 if (count($compo["entries"]) > 0)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
55 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
56 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
57 " <table class=\"vote\">\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
58 " <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
59 " <tr>\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
60 " <th class=\"vtitle\">Title</th>\n".
55
4fac95384753 Make visibility of entry authors per compo.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
61 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : "").
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
62 " ";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
64 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
65 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
66 echo
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
67 "<th class=\"vvalue\">".$i."</th>";
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
68 }
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
69 echo "\n".
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
70 " </tr>\n";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
71
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
72 $row = 0;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
73 foreach ($compo["entries"] as $eid => $entry)
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
74 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
75 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
76 " <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
77 " <td class=\"vtitle\">".$entry["name"]."</td>\n".
55
4fac95384753 Make visibility of entry authors per compo.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
78 ($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
79 " ";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
80
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
81 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
82 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
83 $name = "entry".$eid;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
84 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
85 "<td class=\"vvalue\">".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
86 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
87 "</td>";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
88 }
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 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
91 "\n".
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
92 " </tr>\n";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
93
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
94 $row++;
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
95 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
97 " </table>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 echo
26
7be3f8cf1f7a Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
101 " <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
102 "</form>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 else
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
105 if ($status == 2)
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 {
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
107 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
108 "<p>Now go FAP some more! And make a demo about it.</p>";
51
7bdf89601ba0 Work on session stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
109 stSessionEnd(SESS_USER);
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 ?>