diff msite.inc.php @ 792:b42b23073209

Improve printing of results with more options (in the admin interface).
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 21 Nov 2014 21:42:47 +0200
parents 7735f97b2bbf
children 589cb2d88332
line wrap: on
line diff
--- a/msite.inc.php	Fri Nov 21 16:19:15 2014 +0200
+++ b/msite.inc.php	Fri Nov 21 21:42:47 2014 +0200
@@ -69,6 +69,13 @@
 
 
 //
+// Results output flags
+//
+define("RFLAG_NORMAL", 0);
+define("RFLAG_DISQUALIFIED", 1);
+define("RFLAG_HIDDEN_COMPOS", 2);
+
+//
 // Competition types
 //
 define("COMPO_NORMAL", 0);          // Normal voting compo, points determine placement
@@ -457,7 +464,7 @@
 }
 
 
-function stGetCompoResultsSQL($mode, $compo)
+function stGetCompoResultsSQL($mode, $compo, $flags)
 {
   //
   // Act based on competition type
@@ -524,16 +531,16 @@
 
   return $sql." ".
     "WHERE entries.compo_id=".$compo["id"]." ".
-    "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0 ".
+    (($flags & RFLAG_DISQUALIFIED) ? "" : "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0 ").
     $extra;
 }
 
 
-function stGetCompoResults()
+function stGetCompoResults($flags)
 {
   $voteKeyMode = stGetSetting("voteKeyMode");
   $out = array();
-  $sql = "SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC";
+  $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC";
   if (($res = stExecSQL($sql)) === false)
     return $out;
 
@@ -543,13 +550,13 @@
     // Check if there are any entries for it
     $sql =
       "SELECT COUNT(*) FROM entries ".
-      "WHERE compo_id=".$compo["id"]." ".
-      "AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0";
+      "WHERE compo_id=".$compo["id"].
+      (($flags & RFLAG_DISQUALIFIED) ? "" : " AND (entries.flags & ".EFLAG_DISQUALIFIED.")=0");
 
     if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0)
     {
       // Get voting results by mode
-      $sql = stGetCompoResultsSQL($voteKeyMode, $compo);
+      $sql = stGetCompoResultsSQL($voteKeyMode, $compo, $flags);
 
       $out[$compo["id"]] = $compo;
       $out[$compo["id"]]["results"] = array();
@@ -580,20 +587,26 @@
 
   $out = sprintf("  %s", $html ? chentities($name) : $name);
 
+  // Author?
   if ($showAuthor)
     $out .= sprintf("  by  %s", $html ? chentities($author) : $author);
 
+  // Points?
   if ($points !== FALSE)
     $out .= sprintf(" (%d pts)", $points);
 
+  // Add disqualified flag etc.
+  if ($entry["flags"] & EFLAG_DISQUALIFIED)
+    $out .= " [DISQ]";
+
   return $out."\n";
 }
 
 
-function stGetCompoResultsASCIIStr($html)
+function stGetCompoResultsASCIIStr($html, $flags)
 {
   $out = "";
-  foreach (stGetCompoResults() as $compo)
+  foreach (stGetCompoResults($flags) as $compo)
   {
     // Output compo title / header
     if ($html)