changeset 1091:c4b93729269d

Add visual hint about user/votekeys that have been used for voting.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Jan 2017 01:59:33 +0200
parents 04495bb47dc9
children 95b74632cfe2
files admajax.php
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Jan 26 01:59:07 2017 +0200
+++ b/admajax.php	Thu Jan 26 01:59:33 2017 +0200
@@ -399,7 +399,9 @@
       break;
   }
 
-  return "votekey ".($cond ? "vkeyActive" : "vkeyInactive");
+  return
+    "votekey ".($cond ? "vkeyActive" : "vkeyInactive").
+    " ".($item["nvotes"] > 0 ? "vkeyUsed" : "vkeyUnused");
 }
 
 
@@ -1414,14 +1416,14 @@
         {
           case VOTE_FREELY:
           case VOTE_ACTIVATE:
-            $sql = stPrepareSQL("SELECT * FROM votekeys WHERE id=%D", "id");
+            $sql = stPrepareSQL("SELECT (SELECT COUNT(id) FROM votes WHERE key_id=%D) AS nvotes,votekeys.* FROM votekeys WHERE id=%D", "id", "id");
             break;
 
           case VOTE_ASSIGN:
-            $sql = stPrepareSQL("SELECT votekeys.key,attendees.* FROM attendees ".
+            $sql = stPrepareSQL("SELECT (SELECT COUNT(id) FROM votes WHERE key_id=%D) AS nvotes,votekeys.key,attendees.* FROM attendees ".
               "LEFT JOIN votekeys ON votekeys.id=attendees.key_id ".
-              "WHERE attendees.id=%D", "id");
-              break;
+              "WHERE attendees.id=%D", "id", "id");
+            break;
         }
         if (($res = stFetchSQL($sql)) !== FALSE)
         {
@@ -1476,7 +1478,10 @@
         {
           case VOTE_FREELY:
           case VOTE_ACTIVATE:
-            $sql = "SELECT * FROM votekeys ORDER BY votekeys.id ASC";
+            $sql = "SELECT votekeys.*,COUNT(votes.id) AS nvotes FROM votekeys ".
+              "LEFT JOIN votes ON votes.key_id=votekeys.id ".
+              "GROUP BY votekeys.id ".
+              "ORDER BY votekeys.id ASC";
 
             foreach (stExecSQL($sql) as $item)
             {
@@ -1489,8 +1494,10 @@
             break;
 
           case VOTE_ASSIGN:
-            $sql = "SELECT votekeys.key,attendees.* FROM attendees ".
+            $sql = "SELECT votekeys.*,attendees.*,COUNT(votes.id) AS nvotes FROM attendees ".
               "LEFT JOIN votekeys ON votekeys.id=attendees.key_id ".
+              "LEFT JOIN votes ON votes.key_id=attendees.key_id ".
+              "GROUP BY votekeys.id ".
               "ORDER BY attendees.regtime DESC";
 
             echo