view results.inc.php @ 220:db433a1d22b4

Fix test data creation.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 18 Nov 2013 01:27:52 +0200
parents 1e16a71323de
children 995400521822
line wrap: on
line source

<?
//
// FAPWeb Simple Demoparty System
// Competition results page
// (C) Copyright 2012-2013 Tecnic Software productions (TNSP)
//
$useASCII = stGetSetting("showResultsASCII");
$showResults = stGetSetting("showResults");
$showAuthors = stGetSetting("showResAuthors");

function stGetNumberSuffix($val)
{
  switch ($val)
  {
    case  1: return "st";
    case  2: return "nd";
    case  3: return "rd";
    case  4: case 5: case 6:
    case  7: case 8: case 9: return "th";
    default: return "th";
  }
}


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)
{
  // For each compo that has been set visible
  foreach ($res as $compo)
  {
    // Check if there are any entries for it
    $sql =
      "SELECT COUNT(*) FROM entries ".
      "WHERE compo_id=".$compo["id"];

    if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0)
    {
      // Get voting results
      $sql =
        "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ".
        "LEFT JOIN votes ON votes.entry_id=entries.id ".
        "WHERE entries.compo_id=".$compo["id"]." ".
        "GROUP BY entries.id ".
        "ORDER BY votesum DESC";

      $entries = stExecSQL($sql);

      if ($useASCII)
      {
        echo
          "<pre>\n".
          "<b> ".chentities($compo["name"])." </b>\n".
          str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";

        foreach ($entries as $entry)
        {
          $index = 0;
          $prev = FALSE;
          
          if ($entry["votesum"] != $prev)
          {
            $index++;
            printf("%3d%s.", $index, stGetNumberSuffix($index));
          }
          else
            echo "    ";

          printf("  %s  by  %s (%d pts)\n",
            chentities(stStrChop($entry["name"], 30)),
            chentities(stStrChop($showAuthors ? $entry["author"] : "-", 30)),
            $entry["votesum"]);

          $prev = $entry["votesum"];
        }
        echo "\n\n</pre>\n";
      }
      else
      {
        echo
          "<h2>".chentities($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++;

          echo
            "<tr>".
            "<td>".$index."</td>".
            "<td>".$entry["votesum"]."</td>".
            "<td>".chentities($entry["name"])."</td>".
            "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>".
            "</tr>\n";

          $prev = $entry["votesum"];
        }

        echo "</table>\n";
      }
    }
  }
}

?>