# HG changeset patch # User Matti Hamalainen # Date 1382117338 -10800 # Node ID 6edd7d623eab932d5b50069b1df5e7a9052a2d60 # Parent f36ebd03afd64ff0ceb517a72e27c4b2fc1857d9 Start adding votekey modes code. diff -r f36ebd03afd6 -r 6edd7d623eab createdb.php --- 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"]; diff -r f36ebd03afd6 -r 6edd7d623eab mconfig.inc.php.example --- 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, ); diff -r f36ebd03afd6 -r 6edd7d623eab msite.inc.php --- 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 diff -r f36ebd03afd6 -r 6edd7d623eab results.inc.php --- 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 "

Sorry, no results available! Nothing to see here, move along.

"; } 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 "
\n";
+  foreach ($res as $compo)
   {
-    if ($useASCII) echo "
\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 " ".$compo["name"]." \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 " ".$compo["name"]." \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 "

".$compo["name"]."

\n". - "\n". - " \n". - " \n". - " \n". - " \n". - " \n". - " \n"; - - $index = 0; - foreach ($fres as $entry) + if ($entry["votesum"] != $prev || $index == 0) { - if ($entry["votesum"] != $prev) - $index++; - $prev = $entry["votesum"]; - echo - "". - "". - "". - "". - "". - "\n"; + $index++; + printf("%3d.", $index); } + else + echo " "; + $prev = $entry["votesum"]; - echo "
#PointsNameAuthor
#".$index."".$entry["votesum"]."".chentities($entry["name"])."".($showAuthors ? chentities($entry["author"]) : "-")."
\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 "

".$compo["name"]."

\n". + "\n". + " \n". + " \n". + " \n". + " \n". + " \n". + " \n"; + + $index = 0; + foreach ($fres as $entry) + { + if ($entry["votesum"] != $prev) + $index++; + $prev = $entry["votesum"]; + echo + "". + "". + "". + "". + "". + "\n"; + } + + echo "
#PointsNameAuthor
#".$index."".$entry["votesum"]."".chentities($entry["name"])."".($showAuthors ? chentities($entry["author"]) : "-")."
\n"; } } - if ($useASCII) echo "
\n"; } + if ($useASCII) echo "
\n"; } ?> \ No newline at end of file