changeset 94:6edd7d623eab

Start adding votekey modes code.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Oct 2013 20:28:58 +0300
parents f36ebd03afd6
children d9de08fb5b28
files createdb.php mconfig.inc.php.example msite.inc.php results.inc.php
diffstat 4 files changed, 98 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/createdb.php	Fri Oct 18 20:26:03 2013 +0300
+++ b/createdb.php	Fri Oct 18 20:28:58 2013 +0300
@@ -320,6 +320,13 @@
 }
 
 
+if (!isset($siteSettings["voteKeyMode"]) || $siteSettings["voteKeyMode"] < 0)
+{
+  echo "FATAL ERROR! VoteKeyMode not set in site settings! This setting "
+  "MUST be defined and should not be changed after database creation.\n";
+  exit;
+}
+
 // Check if database spec provided, if not use default
 if (($spec = stCArg(2)) === FALSE)
   $spec = $siteSettings["sqlDB"];
--- a/mconfig.inc.php.example	Fri Oct 18 20:26:03 2013 +0300
+++ b/mconfig.inc.php.example	Fri Oct 18 20:28:58 2013 +0300
@@ -10,6 +10,8 @@
   "voteMin"         => -1,
   "voteMax"         => 2,
 
+  "voteKeyMode"     => -1, // See msite.inc.php for VOTE_*
+
   "voteTimeout"     => 120,
   "admTimeout"      => 15,
 );
--- a/msite.inc.php	Fri Oct 18 20:26:03 2013 +0300
+++ b/msite.inc.php	Fri Oct 18 20:28:58 2013 +0300
@@ -18,6 +18,19 @@
 define("SESS_ADMIN", "admin");
 
 
+//
+// Different voting modes
+//
+// VOTE_FREELY - Vote keys are not tied to attendees, and do not need to be activated
+define("VOTE_FREELY", 0);
+
+// VOTE_ACTIVATE - Vote keys are not tied to attendees, but require manual activation.
+define("VOTE_ACTIVATE", 1);
+
+// VOTE_ASSIGN - Keys are tied to attendees, activated by assigning the key to attendee.
+define("VOTE_ASSIGN", 2);
+
+
 if (function_exists("ini_set"))
 {
   // Use cookies to store the session ID on the client side
--- a/results.inc.php	Fri Oct 18 20:26:03 2013 +0300
+++ b/results.inc.php	Fri Oct 18 20:28:58 2013 +0300
@@ -32,80 +32,95 @@
   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 (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE)
+  if ($useASCII) echo "<pre>\n";
+  foreach ($res as $compo)
   {
-    if ($useASCII) echo "<pre>\n";
-    foreach ($res as $compo)
+    $sqlConds = $sqlJoins = "";
+    switch (stGetSetting("voteKeyMode"))
     {
-      $sql =
-        "SELECT entries.*,SUM(votes.value) AS votesum ".
-        "FROM entries ".
-        "LEFT JOIN votes ON entries.id=votes.entry_id ".
-        "LEFT JOIN attendees ON attendees.id=votes.voter_id ".
-        "WHERE entries.compo_id=".$compo["id"]." AND attendees.active<>0 ".
-        "GROUP BY votes.entry_id ".
-        "ORDER BY votesum DESC";
+      case VOTE_FREELY:
+        break;
+      
+      case VOTE_ACTIVATE:
+        $sqlConds = "AND votekeys.active<>0 ";
+        break;
+      
+      case VOTE_ASSIGN:
+        $sqlJoins = "LEFT JOIN attendees ON votekeys.voter_id=attendees.id ";
+        break;
+    }
 
-      if (($fres = stExecSQL($sql)) !== FALSE)
+    $sql =
+      "SELECT entries.*,SUM(votes.value) AS votesum ".
+      "FROM entries ".
+      "LEFT JOIN votes ON entries.id=votes.entry_id ".
+      "LEFT JOIN votekeys ON votekeys.id=votes.voter_id ".
+      $sqlJoins.
+      "WHERE entries.compo_id=".$compo["id"]." ".
+      $sqlConds.
+      "GROUP BY votes.entry_id ".
+      "ORDER BY votesum DESC";
+
+    if (($fres = stExecSQL($sql)) !== FALSE)
+    {
+      if ($useASCII)
       {
-        if ($useASCII)
-        {
-          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"];
+        echo "<b> ".$compo["name"]." </b>\n";
+        echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
 
-            printf("  %s  by  %s (%d pts)\n",
-              chentities(stChop($entry["name"], 30)),
-              chentities(stChop($showAuthors ? $entry["author"] : "-", 30)),
-              $entry["votesum"]);
-
-          }
-          echo "\n\n";
-        }
-        else
+        $index = 0;
+        $prev = FALSE;
+        foreach ($fres as $entry)
         {
-          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 == 0)
           {
-            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";
+            $index++;
+            printf("%3d.", $index);
           }
+          else
+            echo "    ";
+          $prev = $entry["votesum"];
 
-          echo "</table>\n";
+          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 ($useASCII) echo "</pre>\n";
   }
+  if ($useASCII) echo "</pre>\n";
 }
 ?>
\ No newline at end of file