science-ation/admin/reports_judges.inc.php

561 lines
17 KiB
PHP

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
require_once('../questions.inc.php');
/* Take the language array in users_judge, unserialize it, and join it
* with a space */
function report_judges_languages(&$report, $field, $text)
{
$l = unserialize($text);
return join(' ', $l);
}
$report_judges_divs = array();
function report_judges_5_div(&$report, $field, $text)
{
global $report_judges_divs;
/* Text is users_judge.div_prefs */
$year = $report['year'];
$divprefs = unserialize($text);
if(!is_array($divprefs)) return '';
/* Load divisions, only once */
if(count($report_judges_divs) == 0) {
$q = mysql_query("SELECT * FROM projectdivisions WHERE year='$year'");
while(($d = mysql_fetch_assoc($q))) {
$report_judges_divs[$d['id']] = $d;
}
}
/* Find all 5-expert selections, and add them to the return */
$ret = array();
$retl = array();
foreach($divprefs as $div_id=>$sel) {
if($sel != 5) continue;
$ret[] = $report_judges_divs[$div_id]['division_shortform'];
$retl[] = $report_judges_divs[$div_id]['division'];
}
/* Join it all together with spaces */
if($field == 'div_prefs_5')
return join(' ', $ret);
return join(', ', $retl);
}
$report_judges_cats = array();
function report_judges_highest_cat(&$report, $field, $text)
{
global $report_judges_cats;
/* Text is users_judge.cat_prefs */
$year = $report['year'];
$catprefs = unserialize($text);
if(!is_array($catprefs)) return '';
if(count($report_judges_cats) == 0) {
$q = mysql_query("SELECT * FROM projectcategories WHERE year='$year'");
while(($c = mysql_fetch_assoc($q))) {
$report_judges_cats[$c['id']] = $c;
}
}
/* Find all 2-highest selections, and add them to the return */
$ret = array();
$retl = array();
foreach($catprefs as $cat_id=>$sel) {
if($sel != 2) continue;
$ret[] = $report_judges_cats[$cat_id]['category_shortform'];
$retl[] = $report_judges_cats[$cat_id]['category'];
}
/* Join it all together with spaces */
if($field == 'cat_prefs_highest')
return join(' ', $ret);
return join(', ', $retl);
}
function report_judges_custom_question(&$report, $field, $text)
{
/* Field is 'question_x', users_id is passed in $text */
$q_ord = substr($field, 9);
$year = $report['year'];
$users_id = $text;
/* Find the actual question ID */
$q = mysql_query("SELECT * FROM questions WHERE year='$year' AND ord='$q_ord'");
if(mysql_num_rows($q) != 1)
return 'Question not specified';
$question = mysql_fetch_assoc($q);
$q = mysql_query("SELECT * FROM question_answers WHERE users_id='$users_id' AND questions_id='{$question['id']}'");
if(mysql_num_rows($q) != 1)
return '';
$answer = mysql_fetch_assoc($q);
return $answer['answer'];
}
/* Components: languages, teams */
$report_judges_fields = array(
'last_name' => array(
'name' => 'Judge -- Last Name',
'header' => 'Last Name',
'width' => 1.0,
'table' => 'users.lastname' ),
'first_name' => array(
'name' => 'Judge -- First Name',
'header' => 'First Name',
'width' => 1.0,
'table' => 'users.firstname' ),
'name' => array(
'name' => 'Judge -- Full Name (last, first)',
'header' => 'Name',
'width' => 1.75,
'table' => "CONCAT(users.lastname, ', ', users.firstname)",
'table_sort'=> 'users.lastname' ),
'namefl' => array(
'name' => 'Judge -- Full Name (first last)',
'header' => 'Name',
'width' => 1.75,
'table' => "CONCAT(users.firstname, ' ', users.lastname)",
'table_sort'=> 'users.lastname' ),
'email' => array(
'name' => 'Judge -- Email',
'header' => 'Email',
'width' => 2.0,
'table' => 'users.email'),
'address' => array(
'name' => 'Judge -- Address Street',
'header' => 'Address',
'width' => 2.0,
'table' => "CONCAT(users.address, ' ', users.address2)"),
'city' => array(
'name' => 'Judge -- Address City',
'header' => 'City',
'width' => 1.5,
'table' => 'users.city' ),
'province' => array(
'name' => 'Judge -- Address '.$config['provincestate'],
'header' => $config['provincestate'],
'width' => 0.75,
'table' => 'users.province' ),
'postal' => array(
'name' => 'Judge -- Address '.$config['postalzip'],
'header' => $config['postalzip'],
'width' => 0.75,
'table' => 'users.postalcode' ),
'phone_home' => array(
'name' => 'Judge -- Phone (Home)',
'header' => 'Phone(Home)',
'width' => 1,
'table' => 'users.phonehome'),
'phone_work' => array(
'name' => 'Judge -- Phone (Work)',
'header' => 'Phone(Work)',
'width' => 1.25,
'table' => "users.phonework"),
'organization' => array(
'name' => 'Judge -- Organization',
'header' => 'Organization',
'width' => 2,
'table' => 'users.organization'),
'languages' => array(
'name' => 'Judge -- Languages',
'header' => 'Lang',
'width' => 0.75,
'table' => 'users_judge.languages',
'exec_function' => 'report_judges_languages',
'components' => array('users_judge')),
'complete' => array(
'name' => 'Judge -- Registration Complete',
'header' => 'Cmpl',
'width' => 0.4,
'table' => 'users_judge.judge_complete',
'value_map' => array ('no' => 'No', 'yes' => 'Yes'),
'components' => array('users_judge')),
'willing_chair' => array(
'name' => 'Judge -- Willing Chair',
'header' => 'Will Chair?',
'width' => 1,
'table' => 'users_judge.willing_chair',
'value_map' => array ('no' => 'No', 'yes' => 'Yes'),
'components' => array('users_judge')),
'years_school' => array(
'name' => 'Judge -- Years of Experience at School level',
'header' => 'Sch',
'width' => 0.5,
'table' => 'users_judge.years_school',
'components' => array('users_judge')),
'years_regional' => array(
'name' => 'Judge -- Years of Experience at Regional level',
'header' => 'Rgn',
'width' => 0.5,
'table' => 'users_judge.years_regional',
'components' => array('users_judge')),
'years_national' => array(
'name' => 'Judge -- Years of Experience at National level',
'header' => 'Ntl',
'width' => 0.5,
'table' => 'users_judge.years_national',
'components' => array('users_judge')),
'highest_psd' => array(
'name' => 'Judge -- Highest Post-Secondary Degree',
'header' => 'Highest PSD',
'width' => 1.25,
'table' => 'users_judge.highest_psd',
'components' => array('users_judge')),
'div_prefs_5' => array(
'name' => 'Judge -- Divisions Selected as 5-Expert (Shortform)',
'header' => 'Expert Div',
'width' => 1,
'table' => 'users_judge.div_prefs',
'exec_function' => 'report_judges_5_div',
'components' => array('users_judge')),
'div_prefs_5_long' => array(
'name' => 'Judge -- Divisions Selected as 5-Expert (Full division names)',
'header' => 'Expert Div',
'width' => 1.5,
'table' => 'users_judge.div_prefs',
'exec_function' => 'report_judges_5_div', /* Yes, the same function as div_prefs_5 */
'components' => array('users_judge')),
'cat_prefs_highest' => array(
'name' => 'Judge -- Age Categories Selected as Highest Preference (Shortform)',
'header' => 'Pref Cat',
'width' => 0.8,
'table' => 'users_judge.cat_prefs',
'exec_function' => 'report_judges_highest_cat',
'components' => array('users_judge')),
'cat_prefs_highest_long' => array(
'name' => 'Judge -- Age Categories Selected as Highest Preference (Full category names)',
'header' => 'Pref Cat',
'width' => 1.2,
'table' => 'users_judge.cat_prefs',
'exec_function' => 'report_judges_highest_cat', /* Yes, the same function as cat_prefs_highest */
'components' => array('users_judge')),
'special_award_only' => array(
'name' => 'Judge -- Special Award Only Requested',
'header' => 'SA Only',
'width' => 0.8,
'table' => 'users_judge.special_award_only'),
'year' => array(
'name' => 'Judge -- Year',
'header' => 'Year',
'width' => 0.5,
'table' => 'users.year'),
'captain' => array(
'name' => 'Judge Team -- Captain?',
'header' => 'Cptn',
'width' => 0.5,
'table' => 'judges_teams_link.captain',
'value_map' => array ('no' => 'No', 'yes' => 'Yes'),
'components' => array('teams')),
'team' => array(
'name' => 'Judge Team -- Name',
'header' => 'Team Name',
'width' => 3.0,
'table' => 'judges_teams.name',
'components' => array('teams')),
'teamnum' => array(
'name' => 'Judge Team -- Team Number',
'header' => 'Team',
'width' => 0.5,
'table' => 'judges_teams.num',
'components' => array('teams')),
'project_pn' => array(
'name' => 'Project -- Number',
'header' => 'Number',
'width' => 0.5,
'table' => 'projects.projectnumber',
'components' => array('teams', 'projects')),
'project_title' => array(
'name' => 'Project -- Title',
'header' => 'Project',
'width' => 3,
'table' => 'projects.title',
'components' => array('teams', 'projects')),
'project_summary' => array(
'name' => 'Project -- Summary',
'header' => 'Summary',
'width' => 5,
'table' => 'projects.summary',
'components' => array('teams', 'projects')),
'project_language' => array(
'name' => 'Project -- Language',
'header' => 'Lang',
'width' => 0.4,
'table' => 'projects.language',
'components' => array('teams', 'projects')),
'project_students' => array(
'name' => 'Project -- Student Name(s) (REQUIRES MYSQL 5.0) ',
'header' => 'Student(s)',
'width' => 3.0,
'table' => "GROUP_CONCAT(students.firstname, ' ', students.lastname ORDER BY students.lastname SEPARATOR ', ')",
'group_by' => array('users.id','judges_teams_timeslots_projects_link.id'),
'components' => array('teams', 'projects', 'students')),
'project_timeslot_start' => array(
'name' => 'Project -- Timeslot Start Time (HH:MM)',
'header' => 'Start',
'width' => 0.75,
'table' => "TIME_FORMAT(judges_timeslots.starttime,'%H:%i')",
'components' => array('teams', 'projects')),
'project_timeslot_end ' => array(
'name' => 'Project -- Timeslot End Time (HH:MM)',
'header' => 'End',
'width' => 0.75,
'table' => "TIME_FORMAT(judges_timeslots.endtime,'%H:%i')",
'components' => array('teams', 'projects')),
'project_timeslot' => array(
'name' => 'Project -- Timeslot Start - End (HH:MM - HH:MM)',
'header' => 'Timeslot',
'width' => 1.5,
'table' => "CONCAT(TIME_FORMAT(judges_timeslots.starttime,'%H:%i'),'-',TIME_FORMAT(judges_timeslots.endtime,'%H:%i'))",
'components' => array('teams', 'projects')),
'project_timeslot_date' => array(
'name' => 'Project -- Timeslot Date - (YYYY-MM-DD)',
'header' => 'Timeslot Date',
'width' => 1,
'table' => "judges_timeslots.date",
'components' => array('teams', 'projects')),
'question_1' => array(
'name' => 'Judge -- Custom Judge Registration Question 1',
'header' => 'Q1',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true, /* Only disables in the report editor, a report can still use it */
'exec_function' => 'report_judges_custom_question'),
'question_2' => array(
'name' => 'Judge -- Custom Judge Registration Question 2',
'header' => 'Q2',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_3' => array(
'name' => 'Judge -- Custom Judge Registration Question 3',
'header' => 'Q3',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_4' => array(
'name' => 'Judge -- Custom Judge Registration Question 4',
'header' => 'Q4',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_5' => array(
'name' => 'Judge -- Custom Judge Registration Question 5',
'header' => 'Q5',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_6' => array(
'name' => 'Judge -- Custom Judge Registration Question 6',
'header' => 'Q6',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_7' => array(
'name' => 'Judge -- Custom Judge Registration Question 7',
'header' => 'Q7',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_8' => array(
'name' => 'Judge -- Custom Judge Registration Question 8',
'header' => 'Q8',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_9' => array(
'name' => 'Judge -- Custom Judge Registration Question 9',
'header' => 'Q9',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'question_10' => array(
'name' => 'Judge -- Custom Judge Registration Question 10',
'header' => 'Q10',
'width' => 1,
'table' => 'users.id',
'editor_disabled' => true,
'exec_function' => 'report_judges_custom_question'),
'static_text' => array(
'name' => 'Static Text (useful for labels)',
'header' => '',
'width' => 0.1,
'table' => "CONCAT(' ')"),
);
/* Overwrite the question_1 .. question_10 fields with the
* question name and header from the list of questions */
function report_judges_update_questions($year)
{
global $report_judges_fields;
$qs = questions_load_questions('judgereg', $year);
if(count($qs) > 10) {
echo "Not enough judge question fields, please file a bug report at sfiab.ca and report that you have ".count($qs)." custom judge questions, but the system can handle a maximum of 10.";
exit;
}
foreach($qs as $qid=>$q) {
$f = "question_{$q['ord']}";
$report_judges_fields[$f]['header'] = $q['db_heading'];
$report_judges_fields[$f]['name'] = 'Judge -- Custom Judge Question: '.$q['question'];
$report_judges_fields[$f]['editor_disabled'] = false;
}
}
$report_judges_questions_updated = false;
/* Do the overwrites for the current year, this is for the editor, because
* it doesn't call a _fromwhere */
report_judges_update_questions($config['FAIRYEAR']);
function report_judges_fromwhere($report, $components)
{
global $config, $report_judges_fields;
$year = $report['year'];
if($report_judges_questions_updated == false) {
/* Do overwrites for the report year, overwriting the previous
* overwrites for the current year, because the report year
* could be different, and the questions may have changed */
report_judges_update_questions($year);
$report_judges_questions_updated = true;
}
if(in_array('users_judge', $components)) {
$uj_from = 'LEFT JOIN users_judge ON users_judge.users_id=users.id';
}
$teams_from = '';
$teams_where = '';
if(in_array('teams', $components)) {
$teams_from = "LEFT JOIN judges_teams_link ON judges_teams_link.users_id=users.id
LEFT JOIN judges_teams ON judges_teams.id=judges_teams_link.judges_teams_id";
$teams_where = "AND judges_teams_link.year='$year'
AND judges_teams.year='$year'";
}
$projects_from='';
$projects_where='';
if(in_array('projects', $components)) {
$projects_from = "LEFT JOIN judges_teams_timeslots_projects_link ON
judges_teams_timeslots_projects_link.judges_teams_id=judges_teams.id
LEFT JOIN projects ON projects.id=judges_teams_timeslots_projects_link.projects_id
LEFT JOIN judges_timeslots ON judges_timeslots.id=judges_teams_timeslots_projects_link.judges_timeslots_id";
$projects_where = "AND judges_teams_timeslots_projects_link.year='$year'
AND projects.year='$year'";
}
$students_from='';
$students_where='';
if(in_array('students', $components)) {
$students_from = "LEFT JOIN students ON students.registrations_id=projects.registrations_id";
$students_where = "AND students.year='$year'";
}
/* Search the report for a filter based on judge year */
$year_where = "AND users.year='$year'";
foreach($report['filter'] as $d) {
if($d['field'] == 'year') {
/* Don't interally filter on year, we'll do it externally */
$year_where = '';
}
}
$q = " FROM users
$teams_from
$projects_from
$students_from
$uj_from
WHERE
users.types LIKE '%judge%'
$year_where
$teams_where
$projects_where
$students_where
AND deleted='no'
";
return $q;
}
?>