Mercurial > hg > fapweb
annotate results.inc.php @ 94:6edd7d623eab
Start adding votekey modes code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Oct 2013 20:28:58 +0300 |
parents | b75f99a8973c |
children | eecac02579c4 |
rev | line source |
---|---|
0 | 1 <? |
62
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
2 $useASCII = stGetSetting("showResultsASCII"); |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
3 $showResults = stGetSetting("showResults"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
4 $showAuthors = stGetSetting("showResAuthors"); |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
5 |
23 | 6 function stChop($str, $len) |
7 { | |
8 if (strlen($str) > $len) | |
9 $s = substr($str, 0, $len - 3)."..."; | |
10 else | |
11 $s = $str; | |
12 return sprintf("%-".$len."s", $s); | |
13 } | |
14 | |
15 | |
4 | 16 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
|
17 |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
18 // 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
|
19 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
|
20 { |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
21 if (!$showResults) |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
22 echo "<p>Results hidden from normal users.</p>"; |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
23 if (!$showAuthors) |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
24 echo "<p>Entry authors hidden from normal users.</p>"; |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
25 |
101cde58b267
Add a new setting for ASCII vs. HTML table output for compo results.
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
26 $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
|
27 } |
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 |
4 | 30 if (!$showResults) |
0 | 31 { |
4 | 32 echo "<p>Sorry, no results available! Nothing to see here, move along.</p>"; |
33 } | |
34 else | |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
35 if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE) |
4 | 36 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
37 if ($useASCII) echo "<pre>\n"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
38 foreach ($res as $compo) |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
39 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
40 $sqlConds = $sqlJoins = ""; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
41 switch (stGetSetting("voteKeyMode")) |
4 | 42 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
43 case VOTE_FREELY: |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
44 break; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
45 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
46 case VOTE_ACTIVATE: |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
47 $sqlConds = "AND votekeys.active<>0 "; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
48 break; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
49 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
50 case VOTE_ASSIGN: |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
51 $sqlJoins = "LEFT JOIN attendees ON votekeys.voter_id=attendees.id "; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
52 break; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
53 } |
4 | 54 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
55 $sql = |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
56 "SELECT entries.*,SUM(votes.value) AS votesum ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
57 "FROM entries ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
58 "LEFT JOIN votes ON entries.id=votes.entry_id ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
59 "LEFT JOIN votekeys ON votekeys.id=votes.voter_id ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
60 $sqlJoins. |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
61 "WHERE entries.compo_id=".$compo["id"]." ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
62 $sqlConds. |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
63 "GROUP BY votes.entry_id ". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
64 "ORDER BY votesum DESC"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
65 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
66 if (($fres = stExecSQL($sql)) !== FALSE) |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
67 { |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
68 if ($useASCII) |
4 | 69 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
70 echo "<b> ".$compo["name"]." </b>\n"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
71 echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n"; |
23 | 72 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
73 $index = 0; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
74 $prev = FALSE; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
75 foreach ($fres as $entry) |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
76 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
77 if ($entry["votesum"] != $prev || $index == 0) |
4 | 78 { |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
79 $index++; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
80 printf("%3d.", $index); |
4 | 81 } |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
82 else |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
83 echo " "; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
84 $prev = $entry["votesum"]; |
4 | 85 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
86 printf(" %s by %s (%d pts)\n", |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
87 chentities(stChop($entry["name"], 30)), |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
88 chentities(stChop($showAuthors ? $entry["author"] : "-", 30)), |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
89 $entry["votesum"]); |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
90 |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
91 } |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
92 echo "\n\n"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
93 } |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
94 else |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
95 { |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
96 echo "<h2>".$compo["name"]."</h2>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
97 "<table class=\"attendees\" style=\"width: 80%;\">\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
98 " <tr>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
99 " <th style=\"width: 1%;\">#</th>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
100 " <th style=\"width: 3%;\">Points</th>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
101 " <th>Name</th>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
102 " <th>Author</th>\n". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
103 " </tr>\n"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
104 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
105 $index = 0; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
106 foreach ($fres as $entry) |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
107 { |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
108 if ($entry["votesum"] != $prev) |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
109 $index++; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
110 $prev = $entry["votesum"]; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
111 echo |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
112 "<tr>". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
113 "<td>#".$index."</td>". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
114 "<td>".$entry["votesum"]."</td>". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
115 "<td>".chentities($entry["name"])."</td>". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
116 "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>". |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
117 "</tr>\n"; |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
118 } |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
119 |
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
120 echo "</table>\n"; |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
121 } |
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
122 } |
0 | 123 } |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
79
diff
changeset
|
124 if ($useASCII) echo "</pre>\n"; |
0 | 125 } |
126 ?> |