changeset 3:916623924bd5

More work on the party management and voting system.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Dec 2012 20:27:08 +0200
parents 50216ed31d78
children 934ab7d8c244
files ajax.php index.php results.inc.php
diffstat 3 files changed, 61 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ajax.php	Tue Dec 04 19:11:53 2012 +0200
+++ b/ajax.php	Tue Dec 04 20:27:08 2012 +0200
@@ -333,8 +333,7 @@
     }
     else
     if ($type == "entry" && stChkRequestItem("id") &&
-      stChkRequestItem("compo_id") && stChkRequestItem("name") &&
-      stChkRequestItem("author"))
+      stChkRequestItem("name") && stChkRequestItem("author"))
     {
       $sql = stPrepareSQLUpdate("entries",
         "WHERE id=".intval(stGetRequestItem("id").
--- a/index.php	Tue Dec 04 19:11:53 2012 +0200
+++ b/index.php	Tue Dec 04 20:27:08 2012 +0200
@@ -41,6 +41,9 @@
 <?
 if (stGetSetting("allowVoting", FALSE))
 echo "  <a href=\"vote\">Vote</a>\n";
+
+if (stGetSetting("showResults", FALSE))
+echo "  <a href=\"results\">Results</a>\n";
 ?>
  </div>
 </div>
--- a/results.inc.php	Tue Dec 04 19:11:53 2012 +0200
+++ b/results.inc.php	Tue Dec 04 20:27:08 2012 +0200
@@ -1,37 +1,66 @@
 <?
 echo "<h1>Results</h1>\n";
 
-if (($res = stExecSQL("SELECT * FROM compos ORDER BY name DESC")) !== FALSE)
-foreach ($res as $compo)
+$text = TRUE;
+$showResults = stGetSetting("showResults", FALSE);
+
+if (($res = stExecSQL("SELECT * FROM compos WHERE enabled<>0 ORDER BY name DESC")) !== FALSE)
 {
-  $sql =
-    "SELECT DISTINCT SUM(votes.value) AS votesum,entries.*,votes.* ".
-    "FROM entries LEFT JOIN votes ON entries.id=votes.entry_id ".
-    "WHERE entries.compo_id=".$compo["id"]." ORDER BY ".
-    ($showResults ? "entries.id" : "votesum")." ASC";
+  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 ".($showResults ? "votesum DESC" : "entries.id ASC");
 
-  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";
+    if (($fres = stExecSQL($sql)) !== FALSE)
+    {
+      if ($text)
+      {
+        echo "\n<b>".$compo["name"]."</b>\n";
+        $index = 1;
+        foreach ($fres as $entry)
+        {
+          printf("%3s.  %-35s  by  %-25s (%d pts)\n",
+            ($showResults ? $index : ""),
+            chentities($entry["name"]),
+            (stGetSetting("showAuthors", FALSE) ? chentities($entry["author"]) : "-"),
+            ($showResults ? $entry["votesum"] : "?")
+            );
+          $index++;
+        }
+      }
+      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;
-  if (($fres = stExecSQL($sql)) !== FALSE)
-  foreach ($fres as $entry)
-  {
-    echo
-      "<tr>".
-      "<td>".($showResults ? "#".$index : "")."</td>".
-      "<td>".($showResults ? $entry["votesum"] : "?")."</td>".
-      "<td>".chentities($entry["name"])."</td>".
-      "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>".
-      "</tr>\n";
+        $index = 1;
+        foreach ($fres as $entry)
+        {
+          echo
+            "<tr>".
+            "<td>".($showResults ? "#".$index : "")."</td>".
+            "<td>".($showResults ? $entry["votesum"] : "?")."</td>".
+            "<td>".chentities($entry["name"])."</td>".
+            "<td>".(stGetSetting("showAuthors", FALSE) ? chentities($entry["author"]) : "-")."</td>".
+            "</tr>\n";
+          $index++;
+        }
+
+        echo "</table>\n";
+      }
+    }
   }
-
-  echo "</table>\n";
+  if ($text) echo "</pre>\n";
 }
 ?>
\ No newline at end of file