Updated the communication queries in communication.inc.php to use the conferences system rather than fair years.

This commit is contained in:
jacob 2010-11-01 21:23:17 +00:00
parent 5e0886c812
commit e4d94ffca2
2 changed files with 92 additions and 51 deletions

View File

@ -1,51 +1,79 @@
<? <?
$mailqueries=array( $mailqueries=array(
"committee_all"=>array("name"=>"Committee members (all)","query"=> "committee_all"=>array("name"=>"Committee members (all)","query"=>
"SELECT firstname, lastname, organization, email FROM users WHERE types LIKE '%committee%' AND deleted='no' GROUP BY uid"), "SELECT firstname, lastname, organization, email FROM users
JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.roles_id
WHERE roles.type = 'committee' AND users.deleted = 'no'
GROUP BY users.id"),
/* The WHERE clause evaluates which rows to add to the GROUP /* The WHERE clause evaluates which rows to add to the GROUP
BY, the HAVING clase evaluates which grouped rows show up. We BY, the HAVING clase evaluates which grouped rows show up. We
want to to evaluate 'deleted' AFTER the grouping, so we catch want to to evaluate 'deleted' AFTER the grouping, so we catch
the case where the MAX(year) has deleted='yes'. If we use WHERE the case where the MAX(conferences_id) has deleted='yes'. If we use WHERE
deleted='no', we'll only add non-deleted rows to the group, and 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 end up picking up a user active in, say 2007 and 2008, but
deleted in 2009. */ deleted in 2009. */
"judges_all"=>array("name"=>"Judges from all years (except deleted judges)","query"=> "judges_all"=>array("name"=>"Judges from all conferences (except deleted judges)","query"=>
"SELECT firstname, lastname, email, deleted, MAX(year) "SELECT firstname, lastname, email, deleted, MAX(conferences_id) FROM users
FROM users WHERE types LIKE '%judge%' GROUP BY uid HAVING deleted='no' ORDER BY email"), JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.roles_id
WHERE roles.type ='judge' GROUP BY users.accounts_id HAVING deleted='no' ORDER BY email"),
"judges_active_thisyear"=>array("name"=>"Judges active for this year", "query"=> "judges_active_thisconference"=>array("name"=>"Judges active for this conference", "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"), "SELECT firstname, lastname, email FROM users
LEFT JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.roles_id
WHERE roles.type='judge' AND conferences_id={$conference['id']} AND deleted='no' AND user_roles.active='yes' ORDER BY email"),
"judges_inactive"=>array("name"=>"Judges not active for this year", "query"=> "judges_inactive_thisconference"=>array("name"=>"Judges in the conference that are not active", "query"=>
"SELECT firstname, lastname, email, judge_active, deleted, MAX(year) "SELECT firstname, lastname, email FROM users
FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id LEFT JOIN user_roles ON user_roles.users_id = users.id
WHERE types LIKE '%judge%' JOIN roles ON roles.id = user_roles.roles_id
GROUP BY uid HAVING deleted='no' AND ((max(year)='{$config['FAIRYEAR']}' AND judge_active='no') OR max(year)<'{$config['FAIRYEAR']}') WHERE roles.type='judge' AND conferences_id={$conference['id']} AND deleted='no' AND user_roles.active='no' ORDER BY email"),
ORDER BY email"),
"judges_active_complete_thisyear"=>array("name"=>"Judges active for this year and complete", "query"=> "judges_inactive_allconferences"=>array("name"=>"Judges inactive for any conference", "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"), "SELECT firstname, lastname, email FROM users
LEFT JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.roles_id
WHERE roles.type='judge' AND deleted='no' AND user_roles.active='no' ORDER BY email"),
"judges_active_incomplete_thisyear"=>array("name"=>"Judges active for this year but not complete", "query"=> "judges_active_complete_thisconference"=>array("name"=>"Judges active for this conference 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='no' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"), "SELECT firstname, lastname, email FROM users
LEFT JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.id
WHERE roles.type = 'judge' AND conferences_id = {$conference['id']}
AND user_roles.complete='yes'
AND deleted='no'
AND user_roles.active='yes'
ORDER BY email"),
"participants_complete_thisyear"=>array("name"=>"Participants complete this year","query"=> "judges_active_incomplete_thisconference"=>array("name"=>"Judges active for this conference but not complete", "query"=>
"SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".$config['FAIRYEAR']."' AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"), "SELECT firstname, lastname, email FROM users
LEFT JOIN user_roles ON user_roles.users_id = users.id
JOIN roles ON roles.id = user_roles.id
WHERE roles.type = 'judge' AND conferences_id = {$conference['id']}
AND user_roles.complete='no'
AND deleted='no'
AND user_roles.active='yes'
ORDER BY email"),
"participants_complete_paymentpending_thisyear"=>array("name"=>"Participants complete this year but payment pending","query"=> "participants_complete_thisconference"=>array("name"=>"Participants complete for this conference","query"=>
"SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".$config['FAIRYEAR']."' AND registrations.status!='complete' AND registrations.status='paymentpending' ORDER BY students.email"), "SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.conferences_id='".$conference['id']."' AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"),
"participants_notcomplete_thisyear"=>array("name"=>"Participants not complete this year","query"=> "participants_complete_paymentpending_thisconference"=>array("name"=>"Participants complete for this conference but payment pending","query"=>
"SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".$config['FAIRYEAR']."' AND registrations.status!='complete' AND registrations.status!='new' ORDER BY students.email"), "SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.conferences_id='".$conference['id']."' AND registrations.status!='complete' AND registrations.status='paymentpending' ORDER BY students.email"),
"participants_notcomplete_thisconference"=>array("name"=>"Participants not complete for this conference","query"=>
"SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.conferences_id='".$conference['id']."' AND registrations.status!='complete' AND registrations.status!='new' ORDER BY students.email"),
/* // FIXME - not sure if this has a sensible equivalent when dealing with "conferences" rather than fair years
"participants_complete_lastyear"=>array("name"=>"Participants complete last year","query"=> "participants_complete_lastyear"=>array("name"=>"Participants complete last year","query"=>
"SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".($config['FAIRYEAR']-1)."' AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"), "SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".($config['FAIRYEAR']-1)."' AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"),
*/
"participants_complete_allyears"=>array("name"=>"Participants complete all years","query"=> "participants_complete_allconferences"=>array("name"=>"Participants complete for all conferences","query"=>
"SELECT DISTINCT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"), "SELECT DISTINCT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"),
"participants_cwsf_thisyear"=>array("name"=>"CWSF Winners for this year","query"=>" "participants_cwsf_thisconference"=>array("name"=>"CWSF Winners for this conference","query"=>"
SELECT DISTINCT students.firstname, students.lastname, students.email SELECT DISTINCT students.firstname, students.lastname, students.email
FROM award_awards FROM award_awards
JOIN award_prizes ON award_prizes.award_awards_id=award_awards.id JOIN award_prizes ON award_prizes.award_awards_id=award_awards.id
@ -53,14 +81,14 @@
JOIN projects ON winners.projects_id=projects.id JOIN projects ON winners.projects_id=projects.id
JOIN registrations ON projects.registrations_id=registrations.id JOIN registrations ON projects.registrations_id=registrations.id
JOIN students ON students.registrations_id=registrations.id JOIN students ON students.registrations_id=registrations.id
WHERE award_awards.cwsfaward='1' AND winners.year='".$config['FAIRYEAR']."' WHERE award_awards.cwsfaward='1' AND winners.conferences_id='".$conference['id']."'
ORDER BY students.email"), ORDER BY students.email"),
"sponsors"=>array("name"=>"Organization sponsors","query"=> "sponsors"=>array("name"=>"Organization sponsors","query"=>
"SELECT id, organization, email FROM sponsors WHERE email!='' ORDER BY email"), "SELECT id, organization, email FROM sponsors WHERE email!='' ORDER BY email"),
"sponsors_primarycontacts"=>array("name"=>"Organization sponsors (primary contacts)","query"=> "sponsors_primarycontacts"=>array("name"=>"Organization sponsors (primary contacts)","query"=>
"SELECT uid, MAX(users.year) AS year, sponsors.organization, users.firstname, users.lastname, users.email, deleted, users_sponsor.primary "SELECT uid, MAX(users.conferences_id) AS conferences_id, sponsors.organization, users.firstname, users.lastname, users.email, deleted, users_sponsor.primary
FROM sponsors, FROM sponsors,
users_sponsor, users_sponsor,
users users
@ -73,20 +101,18 @@
HAVING deleted='no' AND users_sponsor.primary='yes' HAVING deleted='no' AND users_sponsor.primary='yes'
ORDER BY users.email ORDER BY users.email
"), "),
"sponsors_allcontacts"=>array("name"=>"Organization sponsors (all contacts)","query"=> "sponsors_allcontacts"=>array("name"=>"Organization sponsors (all contacts)","query"=>
"SELECT DISTINCT(users.email), sponsors.organization, users.firstname, users.lastname, users.email "SELECT DISTINCT(users.email), sponsors.organization, users.firstname, users.lastname, users.email
FROM sponsors, FROM sponsors
users_sponsor, JOIN users_sponsor ON users_sponsor.sponsors_id = sponsors.id
users JOIN users ON users.id = users_sponsor.users_id
WHERE JOIN user_roles ON user_roles.users_id = users.id
users.id=users_sponsor.users_id JOIN roles ON roles.id = user_roles.roles_id
AND users_sponsor.sponsors_id=sponsors.id WHERE
AND users.types LIKE '%sponsor%' roles.type = 'sponsor'
AND users.deleted='no' AND users.deleted='no'
AND users.email!='' AND users.email!=''
ORDER BY users.email ORDER BY users.email"),
"),
/* /*
"special_award_sponsors_unconfirmed"=>array("name"=>"Special award sponsors (unconfirmed only)","query"=> "special_award_sponsors_unconfirmed"=>array("name"=>"Special award sponsors (unconfirmed only)","query"=>
@ -97,21 +123,37 @@
*/ */
"school_principals"=>array("name"=>"School principals","query"=> "school_principals"=>array("name"=>"School principals","query"=>
"SELECT school, principal AS firstname, schoolemail AS email FROM schools WHERE schools.year='".$config['FAIRYEAR']."' AND schoolemail!=''"), "SELECT school, principal AS firstname, schoolemail AS email FROM schools WHERE schools.conferences_id='".$conference['id']."' AND schoolemail!=''"),
"school_scienceheads"=>array("name"=>"School science heads","query"=> "school_scienceheads"=>array("name"=>"School science heads","query"=>
"SELECT school, sciencehead AS firstname, scienceheademail AS email FROM schools WHERE schools.year='".$config['FAIRYEAR']."' AND scienceheademail!=''"), "SELECT school, sciencehead AS firstname, scienceheademail AS email FROM schools WHERE schools.conferences_id='".$conference['id']."' AND scienceheademail!=''"),
"school_teachers_thisyear"=>array("name"=>"Teachers (as entered by students) this year","query"=> "school_teachers_thisconference"=>array("name"=>"Teachers (as entered by students) for this conference","query"=>
"SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE year='".$config['FAIRYEAR']."' AND teacheremail!=''"), "SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE conferences_id='".$conference['id']."' AND teacheremail!=''"),
/* // FIXME again, not sure that this has a sensible equivalent with conferences
"school_teachers_lastyear"=>array("name"=>"Teachers (as entered by students) last year","query"=> "school_teachers_lastyear"=>array("name"=>"Teachers (as entered by students) last year","query"=>
"SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE year='".($config['FAIRYEAR']-1)."' AND teacheremail!=''"), "SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE year='".($config['FAIRYEAR']-1)."' AND teacheremail!=''"),
"school_teachers_allyears"=>array("name"=>"Teachers (as entered by students) all years","query"=> */
"school_teachers_allconferences"=>array("name"=>"Teachers (as entered by students) all conferences","query"=>
"SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE teacheremail!=''"), "SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE teacheremail!=''"),
/* Volunteers */ /* Volunteers */
"volunteers_active_complete_thisyear"=>array("name"=>"Volunteers active for this year and complete", "query"=> "volunteers_active_complete_thisconference"=>array("name"=>"Volunteers active for this conference and complete", "query"=>
"SELECT id, firstname, lastname, email FROM users LEFT JOIN users_volunteer ON users_volunteer.users_id=users.id WHERE users.year='{$config['FAIRYEAR']}' AND users_volunteer.volunteer_complete='yes' AND users_volunteer.volunteer_active='yes' AND users.deleted='no' AND types LIKE '%volunteer%' ORDER BY email"), "SELECT users.id, firstname, lastname, email
FROM users LEFT JOIN user_roles ON user_roles.users_id = users.id JOIN roles ON roles.id = user_roles.roles_id
WHERE users.conferences_id = '".$conference['id']."'
AND roles.type='volunteer'
AND user_roles.complete='yes'
AND user_roles.active='yes'
AND users.deleted='no'
ORDER BY email"),
"volunteers_active_incomplete_thisyear"=>array("name"=>"Volunteers active for this year but not complete", "query"=> "volunteers_active_incomplete_thisconference"=>array("name"=>"Volunteers active for this conference but not complete", "query"=>
"SELECT id, firstname, lastname, email FROM users LEFT JOIN users_volunteer ON users_volunteer.users_id=users.id WHERE users.year='{$config['FAIRYEAR']}' AND users_volunteer.volunteer_complete='no' AND users_volunteer.volunteer_active='yes' AND users.deleted='no' AND users.types LIKE '%volunteer%' ORDER BY email"), "SELECT users.id, firstname, lastname, email
FROM users LEFT JOIN user_roles ON user_roles.users_id = users.id JOIN roles ON roles.id = user_roles.roles_id
WHERE users.conferences_id = '".$conference['id']."'
AND roles.type='volunteer'
AND user_roles.complete='no'
AND user_roles.active='yes'
AND users.deleted='no'
ORDER BY email"),
); );
?> ?>

View File

@ -25,7 +25,6 @@
require_once("common.inc.php"); require_once("common.inc.php");
require_once("user.inc.php"); require_once("user.inc.php");
user_auth_required(); user_auth_required();
echo $config['dates']['fairdate'] . "<hr>";
// find out if this user actually is in this conference // find out if this user actually is in this conference
$query = "SELECT COUNT(*) FROM users WHERE conferences_id = {$conference['id']}" $query = "SELECT COUNT(*) FROM users WHERE conferences_id = {$conference['id']}"
. " AND accounts_id = " . $_SESSION['accounts_id']; . " AND accounts_id = " . $_SESSION['accounts_id'];