diff --git a/admin/communication.inc.php b/admin/communication.inc.php index b6377bb..ac5ddc1 100644 --- a/admin/communication.inc.php +++ b/admin/communication.inc.php @@ -3,14 +3,26 @@ "committee_all"=>array("name"=>"Committee members (all)","query"=> "SELECT firstname, lastname, organization, email FROM users WHERE types LIKE '%committee%' AND deleted='no' AND year='{$config['FAIRYEAR']}' "), - "judges_all"=>array("name"=>"(BROKEN, DO NOT USE) Judges from all years","query"=> - "SELECT firstname, lastname, email FROM users WHERE 0 ORDER BY email"), + /* The WHERE clause evaluates which rows to add to the GROUP + BY, the HAVING clase evaluates which grouped rows show up. We + want to to evaluate 'deleted' AFTER the grouping, so we catch + the case where the MAX(year) has deleted='yes'. If we use WHERE + deleted='no', we'll only add non-deleted rows to the group, and + end up picking up a user active in, say 2007 and 2008, but + deleted in 2009. */ + "judges_all"=>array("name"=>"Judges from all years (except deleted judges)","query"=> + "SELECT firstname, lastname, email, deleted, MAX(year) + FROM users WHERE types LIKE '%judge%' GROUP BY uid HAVING deleted='no' ORDER BY email"), "judges_active_thisyear"=>array("name"=>"Judges active for this year", "query"=> "SELECT firstname, lastname, email FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id WHERE types LIKE '%judge%' AND year='{$config['FAIRYEAR']}' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"), - "judges_inactive"=>array("name"=>"(BROKEN, DO NOT USE) Judges not active for this year", "query"=> - "SELECT judges.id, firstname, lastname, email FROM judges WHERE id NOT IN (SELECT judges_id FROM judges_years WHERE year='".$config['FAIRYEAR']."') AND judges.deleted='no' ORDER BY email"), + "judges_inactive"=>array("name"=>"Judges not active for this year", "query"=> + "SELECT firstname, lastname, email, judge_active, deleted, MAX(year) + FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id + WHERE types LIKE '%judge%' + GROUP BY uid HAVING deleted='no' AND ((max(year)='{$config['FAIRYEAR']}' AND judge_active='no') OR max(year)<'{$config['FAIRYEAR']}') + ORDER BY email"), "judges_active_complete_thisyear"=>array("name"=>"Judges active for this year and complete", "query"=> "SELECT firstname, lastname, email FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id WHERE types LIKE '%judge%' AND year='{$config['FAIRYEAR']}' AND users_judge.judge_complete='yes' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"),