Mercurial > hg > fapweb
annotate results.inc.php @ 472:1eabbd70cd25
Add skipping button.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Dec 2013 22:28:23 +0200 |
parents | cd2fbd5e0b1a |
children | c63c7f98147a |
rev | line source |
---|---|
0 | 1 <? |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
2 // |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
3 // FAPWeb Simple Demoparty System |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
4 // Competition results page |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
6 // |
62
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
7 $useASCII = stGetSetting("showResultsASCII"); |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
8 $showResults = stGetSetting("showResults"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
9 $showAuthors = stGetSetting("showResAuthors"); |
327 | 10 $voteKeyMode = stGetSetting("voteKeyMode"); |
11 | |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 |
166
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
13 function stGetNumberSuffix($val) |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
14 { |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
15 switch ($val) |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
16 { |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
17 case 1: return "st"; |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
18 case 2: return "nd"; |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
19 case 3: return "rd"; |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
20 case 4: case 5: case 6: |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
21 case 7: case 8: case 9: return "th"; |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
22 default: return "th"; |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
23 } |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
24 } |
c73217c35864
Add function for getting number suffix.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
25 |
23 | 26 |
4 | 27 echo "<h1>Results</h1>\n"; |
62
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
28 |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
29 // Show everything for the admin session |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
30 if (stAdmSessionAuth()) |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
31 { |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
32 if (!$showResults) |
327 | 33 echo "<p class=\"notice\">Results hidden from normal users.</p>"; |
62
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
34 if (!$showAuthors) |
327 | 35 echo "<p class=\"notice\">Entry authors hidden from normal users.</p>"; |
62
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
36 |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
37 $showResults = $showAuthors = TRUE; |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
38 } |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
39 |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
40 |
4 | 41 if (!$showResults) |
0 | 42 { |
4 | 43 echo "<p>Sorry, no results available! Nothing to see here, move along.</p>"; |
44 } | |
45 else | |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
46 if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE) |
4 | 47 { |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
48 // For each compo that has been set visible |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
49 foreach ($res as $compo) |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 { |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
51 // Check if there are any entries for it |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
52 $sql = |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
53 "SELECT COUNT(*) FROM entries ". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
54 "WHERE compo_id=".$compo["id"]; |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
55 |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
56 if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0) |
4 | 57 { |
327 | 58 // Get voting results by mode |
59 switch ($voteKeyMode) | |
60 { | |
61 case VOTE_FREELY: | |
62 $sql = | |
63 "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ". | |
64 "LEFT JOIN votes ON votes.entry_id=entries.id ". | |
334
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
65 "WHERE entries.compo_id=".$compo["id"]; |
327 | 66 break; |
4 | 67 |
327 | 68 case VOTE_ACTIVATE: |
69 $sql = | |
334
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
70 "SELECT entries.*, ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
71 "(SELECT SUM(votes.value) FROM votes ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
72 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
73 "WHERE votes.entry_id=entries.id AND votekeys.active<>0) ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
74 "AS votesum ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
75 "FROM entries ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
76 "WHERE entries.compo_id=".$compo["id"]; |
327 | 77 break; |
78 | |
79 case VOTE_ASSIGN: | |
80 $sql = | |
81 "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ". | |
82 "LEFT JOIN votes ON votes.entry_id=entries.id ". | |
83 "LEFT JOIN attendees ON votes.key_id=attendees.key_id ". | |
84 "WHERE entries.compo_id=".$compo["id"]." ". | |
334
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
85 "AND attendees.key_id<>0"; |
335
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
86 |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
87 $sql = |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
88 "SELECT entries.*, ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
89 "(SELECT SUM(votes.value) FROM votes ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
90 "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
91 "LEFT JOIN attendees ON votekeys.id=attendees.key_id ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
92 "WHERE votes.entry_id=entries.id AND attendees.key_id<>0) ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
93 "AS votesum ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
94 "FROM entries ". |
cd2fbd5e0b1a
Fix the assigned key results calculation as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
95 "WHERE entries.compo_id=".$compo["id"]; |
327 | 96 break; |
97 } | |
98 | |
334
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
99 $sql .= " ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
100 "GROUP BY entries.id ". |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
101 "ORDER BY votesum DESC"; |
a02422200eca
Work on fixing results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
102 |
327 | 103 // List results |
104 $prev = FALSE; | |
105 $index = 0; | |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
106 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
107 if ($useASCII) |
4 | 108 { |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
109 echo |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
110 "<pre>\n". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
111 "<b> ".chentities($compo["name"])." </b>\n". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
112 str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n"; |
23 | 113 |
327 | 114 foreach (stExecSQL($sql) as $entry) |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
115 { |
327 | 116 if ($entry["votesum"] !== $prev) |
4 | 117 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
118 $index++; |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
119 printf("%3d%s.", $index, stGetNumberSuffix($index)); |
4 | 120 } |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
121 else |
327 | 122 echo " -''-"; |
4 | 123 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
124 printf(" %s by %s (%d pts)\n", |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
125 chentities(stStrChop($entry["name"], 30)), |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
126 chentities(stStrChop($showAuthors ? $entry["author"] : "-", 30)), |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
127 $entry["votesum"]); |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
128 |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
129 $prev = $entry["votesum"]; |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
130 } |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
131 echo "\n\n</pre>\n"; |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
132 } |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
133 else |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
134 { |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
135 echo |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
136 "<h2>".chentities($compo["name"])."</h2>\n". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
137 "<table class=\"attendees\" style=\"width: 80%;\">\n". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
138 " <tr>\n". |
328
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
139 " <th style=\"width: 5%;\">#</th>\n". |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
140 " <th>Name</th>\n". |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
141 " <th>Author</th>\n". |
328
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
142 " <th style=\"width: 3%;\">Points</th>\n". |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
143 " </tr>\n"; |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
144 |
327 | 145 foreach (stExecSQL($sql) as $entry) |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
146 { |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
147 if ($entry["votesum"] != $prev) |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
148 $index++; |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
149 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
150 echo |
328
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
151 " <tr>". |
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
152 " <td>".$index."</td>". |
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
153 " <td>".chentities($entry["name"])."</td>". |
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
154 " <td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>". |
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
155 " <td>".$entry["votesum"]."</td>". |
6dd62c3204aa
Improve HTML table output of results.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
156 " </tr>\n"; |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
157 |
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
158 $prev = $entry["votesum"]; |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
159 } |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
160 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
161 echo "</table>\n"; |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
162 } |
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
163 } |
0 | 164 } |
165 } | |
167
1e16a71323de
Some work on results display.
Matti Hamalainen <ccr@tnsp.org>
parents:
166
diff
changeset
|
166 |
0 | 167 ?> |