view results.inc.php @ 58:005a02a2cc2d

Always show optionally hidden information for admin session on the results page.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Oct 2013 10:34:32 +0300
parents 5bc8bd5c7ecc
children 101cde58b267
line wrap: on
line source

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

// Show everything for the admin session
if (stAdmSessionAuth())
  $showResults = $showAuthors = TRUE;


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";
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 ($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 = 0;
          $prev = FALSE;
          foreach ($fres as $entry)
          {
            if ($entry["votesum"] != $prev)
            {
              $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 ($text) echo "</pre>\n";
  }
}
?>