<?
/* 
   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.
*/


function reports_schools_principal(&$report, $field, $text)
{
	$year = $report['year'];
	if($text > 0) { /* text is the uid */
		$u = user_load_by_uid_year($text, $year);
		return $u['name'];
	}
	return '';
}
function reports_schools_sciencehead(&$report, $field, $text)
{
	$year = $report['year'];
	if($text > 0) { /* text is the uid */
		$u = user_load_by_uid_year($text, $year);
		return $u['name'];
	}
	return '';
}

function reports_schools_shphone(&$report, $field, $text)
{
	$year = $report['year'];
	if($text > 0) { /* text is the uid */
		$u = user_load_by_uid_year($text, $year);
		return $u['phonework'];
	}
	return '';
}

function reports_schools_shemail(&$report, $field, $text)
{
	$year = $report['year'];
	if($text > 0) { /* text is the uid */
		$u = user_load_by_uid_year($text, $year);
		return $u['email'];
	}
	return '';
}

$report_schools_fields = array(
	'school' =>  array(
		'start_option_group' => 'School Information',
		'name' => 'School -- Name',
		'header' => 'School Name',
		'width' => 57.15 /*mm*/,
		'table' => 'schools.school' ),

	'schooladdr' => array(
		'name' => 'School -- Full Address',
		'header' => 'School Address',
		'width' => 76.2 /*mm*/,
		'table' => "CONCAT(schools.address, ', ', schools.city, ', ', schools.province_code, ', ', schools.postalcode)" ),

	'school_phone' => array(
		'name' => 'School -- Phone',
		'header' => 'School Phone',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.phone' ),

	'school_fax' => array(
		'name' => 'School -- Fax',
		'header' => 'School Fax',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.fax' ),

	'school_email' => array(
		'name' => 'School -- Email',
		'header' => 'School Email',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.schoolemail' ),

	'school_address' =>  array(
		'name' => 'School Address -- Street Address',
		'header' => 'Address',
		'width' => 50.8 /*mm*/,
		'table' => 'schools.address'),

	'school_city' =>  array(
		'name' => 'School Address -- City',
		'header' => 'City',
		'width' => 38.1 /*mm*/,
		'table' => 'schools.city' ),

	'school_province' =>  array(
		'name' => 'School Address -- '.$config['provincestate'],
		'header' => $config['provincestate'],
		'width' => 19.05 /*mm*/,
		'table' => 'schools.province_code' ),

	'school_city_prov' =>  array(
		'name' => 'School Address -- City, '.$config['provincestate'].' (for mailing)',
		'header' => 'City',
		'width' => 38.1 /*mm*/,
		'table' => "CONCAT(schools.city, ', ', schools.province_code)" ),

	'school_postal' =>  array(
		'name' => 'School Address -- '.$config['postalzip'],
		'header' => $config['postalzip'],
		'width' => 19.05 /*mm*/,
		'table' => 'schools.postalcode' ),

	'school_lang' =>  array(
		'name' => 'School -- Language Code',
		'header' => 'Lang',
		'width' => 12.7 /*mm*/,
		'table' => 'schools.schoollang' ),

	'school_level' =>  array(
		'name' => 'School -- Grade Levels',
		'header' => 'Level',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.schoollevel' ),

	'school_board' =>  array(
		'name' => 'School -- Board',
		'header' => 'Board',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.board' ),

	'school_district' =>  array(
		'name' => 'School -- District',
		'header' => 'District',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.district' ),

	'school_principal' => array(
		'name' => 'School -- Principal',
		'header' => 'Principal',
		'width' => 31.75 /*mm*/,
		'table' => 'schools.principal_uid',
		'exec_function' => 'reports_schools_principal'),

	'school_sh' => array(
		'name' => 'School -- Science Head',
		'header' => 'Science Head',
		'width' => 31.75 /*mm*/,
		'table' => 'schools.sciencehead_uid',
		'exec_function' => 'reports_schools_sciencehead'),

	'school_shphone' => array(
		'name' => 'School -- Science Head Phone',
		'header' => 'Science Hd Phone',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.sciencehead_uid',
		'exec_function' => 'reports_schools_shphone'),

	'school_shemail' => array(
		'name' => 'School -- Science Head Email',
		'header' => 'Science Head Email',
		'width' => 38.1 /*mm*/,
		'table' => 'schools.sciencehead_uid',
		'exec_function' => 'reports_schools_shemail'),

	'school_accesscode' => array(
		'start_option_group' => 'Access Codes',
		'name' => 'School -- Access Code',
		'header' => 'Access Code',
		'width' => 27.94 /*mm*/,
		'table' => 'schools.accesscode' ),

	'school_registration_password' => array(
		'name' => 'School -- Registration Password',
		'header' => 'Reg Pass',
		'width' => 19.05 /*mm*/,
		'table' => 'schools.registration_password' ),

	'school_project_limit' => array(
		'start_option_group' => 'Project Limits',
		'name' => 'School -- Project Limit',
		'header' => 'Limit',
		'width' => 19.05 /*mm*/,
		'table' => 'schools.projectlimit' ),

	'school_project_limit_per' => array(
		'name' => 'School -- Project Limit Per',
		'header' => 'Limit Per',
		'width' => 25.4 /*mm*/,
		'table' => 'schools.projectlimitper' ),

	/* The label system depends on each report type having fair_name and fair_logo */
	'fair_name' =>  array(
		'start_option_group' => 'Fair Information',
                'name' => 'Fair -- Name',
                'header' => 'Fair Name',
                'width' => 76.2 /*mm*/,
                'table' => "'".mysql_escape_string($config['fairname'])."'"),

        'fair_year' => array (
                'name' => 'Fair -- Year',
                'header' => 'Year',
                'width' => 12.7 /*mm*/,
                'table' => "{$config['FAIRYEAR']}"),

	'fair_logo' =>  array(
		'name' => 'Fair -- Logo (for Labels only)',
		'header' => '',
		'width' => 1 /*mm*/,
		'table' => "CONCAT(' ')"),


);

 function report_schools_fromwhere($report, $components)
 {
 	global $config, $report_schools_fields;
	
	$fields = $report_schools_fields;
	$year = $report['year'];

	$q = "	FROM
			schools
		WHERE
			schools.year='$year'
		";

	return $q;
}

?>
