Mercurial > hg > fapweb
view results.inc.php @ 120:2c594958050e
Make test vote keys "testN" where N >= 1
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Oct 2013 14:22:26 +0300 |
parents | 6edd7d623eab |
children | eecac02579c4 |
line wrap: on
line source
<? $useASCII = stGetSetting("showResultsASCII"); $showResults = stGetSetting("showResults"); $showAuthors = stGetSetting("showResAuthors"); function stChop($str, $len) { if (strlen($str) > $len) $s = substr($str, 0, $len - 3)."..."; else $s = $str; return sprintf("%-".$len."s", $s); } echo "<h1>Results</h1>\n"; // Show everything for the admin session if (stAdmSessionAuth()) { if (!$showResults) echo "<p>Results hidden from normal users.</p>"; if (!$showAuthors) echo "<p>Entry authors hidden from normal users.</p>"; $showResults = $showAuthors = TRUE; } if (!$showResults) { echo "<p>Sorry, no results available! Nothing to see here, move along.</p>"; } else if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE) { if ($useASCII) echo "<pre>\n"; foreach ($res as $compo) { $sqlConds = $sqlJoins = ""; switch (stGetSetting("voteKeyMode")) { case VOTE_FREELY: break; case VOTE_ACTIVATE: $sqlConds = "AND votekeys.active<>0 "; break; case VOTE_ASSIGN: $sqlJoins = "LEFT JOIN attendees ON votekeys.voter_id=attendees.id "; break; } $sql = "SELECT entries.*,SUM(votes.value) AS votesum ". "FROM entries ". "LEFT JOIN votes ON entries.id=votes.entry_id ". "LEFT JOIN votekeys ON votekeys.id=votes.voter_id ". $sqlJoins. "WHERE entries.compo_id=".$compo["id"]." ". $sqlConds. "GROUP BY votes.entry_id ". "ORDER BY votesum DESC"; if (($fres = stExecSQL($sql)) !== FALSE) { if ($useASCII) { echo "<b> ".$compo["name"]." </b>\n"; echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n"; $index = 0; $prev = FALSE; foreach ($fres as $entry) { if ($entry["votesum"] != $prev || $index == 0) { $index++; printf("%3d.", $index); } else echo " "; $prev = $entry["votesum"]; printf(" %s by %s (%d pts)\n", chentities(stChop($entry["name"], 30)), chentities(stChop($showAuthors ? $entry["author"] : "-", 30)), $entry["votesum"]); } echo "\n\n"; } else { echo "<h2>".$compo["name"]."</h2>\n". "<table class=\"attendees\" style=\"width: 80%;\">\n". " <tr>\n". " <th style=\"width: 1%;\">#</th>\n". " <th style=\"width: 3%;\">Points</th>\n". " <th>Name</th>\n". " <th>Author</th>\n". " </tr>\n"; $index = 0; foreach ($fres as $entry) { if ($entry["votesum"] != $prev) $index++; $prev = $entry["votesum"]; echo "<tr>". "<td>#".$index."</td>". "<td>".$entry["votesum"]."</td>". "<td>".chentities($entry["name"])."</td>". "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>". "</tr>\n"; } echo "</table>\n"; } } } if ($useASCII) echo "</pre>\n"; } ?>