# HG changeset patch # User Matti Hamalainen # Date 1485388773 -7200 # Node ID c4b93729269d911bdca6f15f96246203d0002bfc # Parent 04495bb47dc91958b9be138e4b09f2aefef29426 Add visual hint about user/votekeys that have been used for voting. diff -r 04495bb47dc9 -r c4b93729269d admajax.php --- 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