annotate vote.inc.php @ 276:92698b090c35

Indentation cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Nov 2013 22:22:51 +0200
parents 8d46f1358233
children f20df1da0903
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 <?
151
a778629edff9 Add copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
2 //
a778629edff9 Add copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
3 // FAPWeb Simple Demoparty System
a778629edff9 Add copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
4 // Competition voting page
a778629edff9 Add copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP)
a778629edff9 Add copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
6 //
98
0f00192e64af Obey userKeyLength site setting here when printing voting login.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
7 $sessionType = "user";
175
8df523e6326a User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
8 require_once "majax.php";
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
9
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
10
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
11 function stGetVoteButton()
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 return
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
14 "<div class=\"votectrl\">".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
15 stGetFormSubmitInput("vote", "Submit votes!", "return false").
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
16 "</div>\n";
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
17 }
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
18
127
6b71472cda77 A tiny bit of work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
19
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 // Check if voting is enabled
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 if (!stChkSetting("allowVoting"))
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
23 echo
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
24 "<h1>Sorry, voting disabled!</h1>\n".
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
25 "<p>Voting functionality not available at this time.</p>\n";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 else
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
28 if (!stUserSessionAuth(FALSE))
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
30 // Perform authentication if we are not in session already
190
a14663f6497d Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
31 $userKeyLen = stGetSetting("userKeyLength");
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
32 echo
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
33 "<h1>Voting system</h1>\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
34 (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : "").
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
35 stGetFormStart("vote", "usrlogin.php").
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
36 " ".stGetFormHiddenInput("mode", "vote")."\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
37 " ".stGetFormHiddenInput("goto", "vote")."\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
38 " <div class=\"votectrl\">\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
39 " Enter your vote key:\n".
248
8d46f1358233 Add autofocus in vote login as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
40 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n".
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
41 " ".stGetFormSubmitInput("login", "Login")."\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
42 " </div>\n".
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
43 "</form>\n";
32
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 else
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
46 if (($mode = stGetSessionItem("mode")) == "vote")
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
47 {
126
71c35d5302c2 More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
48 stCommonAJAX("usrajax.php", "usrlogout.php", TRUE);
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
49 stGetCompoList(TRUE, TRUE);
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
50
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
51 // Try fetching previously stored votes
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
52 $sql = stPrepareSQL(
221
2b39068c4968 Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
53 "SELECT entry_id,value FROM votes WHERE voter_id=%d",
79
b75f99a8973c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
54 stGetSessionItem("voter_id"));
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
55
221
2b39068c4968 Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
56 $votes = array();
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
57 if (($res = stExecSQL($sql)) !== false)
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
58 {
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
59 foreach ($res as $vote)
221
2b39068c4968 Tiny bit of work on voting code.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
60 $votes[$vote["entry_id"]] = $vote["value"];
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
61 }
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
63 // Output voting system HTML
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
64 echo
276
92698b090c35 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
65 "<h1>Voting system</h1>\n".
92698b090c35 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
66 stGetFormStart("vote", "usrajax.php").
92698b090c35 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
67 " ".stGetFormHiddenInput("mode", "done")."\n".
92698b090c35 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
68 " ".stGetFormHiddenInput("action", "submit")."\n".
92698b090c35 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
69 stGetVoteButton();
32
36392d1d6b5f Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
70
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
71 foreach (stExecSQL("SELECT * FROM compos WHERE visible<>0 AND voting<>0") as $compo)
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
72 {
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
73 $cid = $compo["id"];
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
74
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
75 $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$cid));
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
76 if ($nentries > 0)
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
77 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
78 echo
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
79 " <table class=\"vote\">\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
80 " <tr><th colspan=\"".($compo["showAuthors"] ? "3" : "2")."\">".chentities($compo["name"])."</th></tr>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
81 " <tr>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
82 " <th class=\"vshown\">#</th>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
83 " <th class=\"vtitle\">Title</th>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
84 ($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
85 " ";
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
87 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
88 {
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
89 echo
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
90 "<th class=\"vvalue\">".$i."</th>";
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
91 }
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
92 echo "\n".
26
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
242
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
95 $row = 0;
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
96 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$cid) as $entry)
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
97 {
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
98 $eid = $entry["id"];
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
99 echo
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
100 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
101 " <td class=\"vshown\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
102 " <td class=\"vtitle\">".$entry["name"]."</td>\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
103 ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
104 " ";
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
105
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
106 $val = isset($votes[$eid]) ? $votes[$eid] : 0;
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
107
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
108 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
109 {
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
110 echo
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
111 "<td class=\"vvalue\">".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
112 stGetFormRadioButtonInput(
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
113 "entry".$eid, "", "", $i, ($i == $val),
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
114 "onClick=\"updateVote(".$eid.",".$i.")\"").
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
115 "</td>";
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
116 }
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
117
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
118 echo
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
119 "\n".
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
120 " </tr>\n";
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
121
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
122 $row++;
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
123 }
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
124 echo
c52ca3a89989 Some random broken work on vote page.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
125 " </table>\n";
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
126 }
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
127 }
5
76c3b89d7b11 Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
128
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
129 echo
225
1bb4f4bcb027 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
130 stGetVoteButton().
1bb4f4bcb027 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
131 "</form>\n";
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
132 }
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
133 else
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
134 if ($mode == "done")
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
135 {
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
136 // Voting finished
226
548a106b3f5b Use setting instead of hardcoded text.
Matti Hamalainen <ccr@tnsp.org>
parents: 225
diff changeset
137 echo stGetSetting("voteFinishedText");
68
3ae137411706 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
138 stSessionEnd(SESS_USER);
0
8019b357cc03 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 }
110
ff511f5351df Work on voting.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
140 ?>