view results.inc.php @ 5:76c3b89d7b11

Improve voting, clean up the code, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Dec 2012 08:08:58 +0200
parents 934ab7d8c244
children d76020022881
line wrap: on
line source

<?
$text = TRUE;
$showResults = stGetSetting("showResults");
$showAuthors = stGetSetting("showResAuthors");

echo "<h1>Results</h1>\n";
if (!$showResults)
{
  echo "<p>Sorry, no results available! Nothing to see here, move along.</p>";
}
else
{
  if (($res = stExecSQL("SELECT * FROM compos WHERE enabled<>0 ORDER BY name DESC")) !== FALSE)
  {
    if ($text) echo "<pre>\n";
    foreach ($res as $compo)
    {
      $sql =
        "SELECT entries.*,SUM(votes.value) AS votesum ".
        "FROM entries LEFT JOIN votes ON entries.id=votes.entry_id ".
        "WHERE entries.compo_id=".$compo["id"]." ".
        "GROUP BY votes.entry_id ".
        "ORDER BY votesum DESC";

      if (($fres = stExecSQL($sql)) !== FALSE)
      {
        if ($text)
        {
          echo "<b> ".$compo["name"]." </b>\n";
          echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";

          $index = 1;
          foreach ($fres as $entry)
          {
            printf("%3s.  %-35s  by  %-25s (%d pts)\n",
              $index,
              chentities($entry["name"]),
              ($showAuthors ? chentities($entry["author"]) : "-"),
              $entry["votesum"]);
            $index++;
          }
          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 = 1;
          foreach ($fres as $entry)
          {
            echo
              "<tr>".
              "<td>#".$index."</td>".
              "<td>".$entry["votesum"]."</td>".
              "<td>".chentities($entry["name"])."</td>".
              "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>".
              "</tr>\n";
            $index++;
          }

          echo "</table>\n";
        }
      }
    }
    if ($text) echo "</pre>\n";
  }
}
?>