From 998fe35d677bca7677010ef3fecdb556e889fdae Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 20 Dec 2007 01:05:04 +0000 Subject: [PATCH] - Add a tour number to the database, and modify the tour editor to include the number, and an option to create numbers automatically - Completely remove all references (hopefully) to the Tour ID - Add a Tour type report - Rework the student report query so it actually makes sense. It really should be a whole bunch of left joins based on the students. Using comma (cross) joins creates situations where if the right side of the join doesn't have information, it wipes out the left side. (Happened before with emergency contact info). - Remove the (two) old custom tour reports - Add 4 new tour reports to the database: - ALL tours for the committee, tour list for students, student emergency contact info for tour coordinators, and a list of tour assignments for students --- admin/reports.inc.php | 15 +--- admin/reports_editor.php | 15 ++-- admin/reports_gen.php | 1 - admin/reports_students.inc.php | 36 +++++--- admin/reports_tour_selection.php | 140 ------------------------------- admin/reports_tours.inc.php | 97 +++++++++++++++++++++ admin/reports_tours.php | 100 ---------------------- admin/tours_assignments.php | 10 +-- admin/tours_manager.php | 29 +++++++ admin/tours_sa.php | 6 +- db/db.code.version.txt | 2 +- db/db.update.85.sql | 70 ++++++++++++++++ tours.class.php | 4 +- 13 files changed, 242 insertions(+), 283 deletions(-) delete mode 100644 admin/reports_tour_selection.php create mode 100644 admin/reports_tours.inc.php delete mode 100644 admin/reports_tours.php create mode 100644 db/db.update.85.sql diff --git a/admin/reports.inc.php b/admin/reports.inc.php index a74c035..6b9f6f0 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -27,6 +27,7 @@ require_once("reports_committees.inc.php"); /* $report_students_fields */ require_once("reports_volunteers.inc.php"); /* $report_volunteers_fields */ require_once("reports_schools.inc.php"); + require_once("reports_tours.inc.php"); require_once('../lpdf.php'); require_once('../lcsv.php'); @@ -252,16 +253,6 @@ foreach($report_stock as $n=>$v) { 'desc' => 'Award Winners', 'custom_url' => 'admin/reports_acpresentation.php?type=csv', 'creator' => 'The Grant Brothers'); - $x++; - $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Available Tours (CSV)', - 'desc' => 'Available Tours', - 'custom_url' => 'admin/reports_tours.php?type=csv', - 'creator' => 'The Grant Brothers'); - $x++; - $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Participant Tour Choices (CSV)', - 'desc' => 'Participant Tour Choices', - 'custom_url' => 'admin/reports_tour_selection.php?type=csv', - 'creator' => 'The Grant Brothers'); function report_save_field($report, $type, $loc) { @@ -269,6 +260,7 @@ foreach($report_stock as $n=>$v) { global $report_students_fields, $report_judges_fields, $report_awards_fields; global $report_committees_fields, $report_schools_fields; global $report_volunteers_fields; + global $report_tours_fields; $fieldvar = "report_{$report['type']}s_fields"; @@ -312,6 +304,7 @@ foreach($report_stock as $n=>$v) { global $allow_options, $report_students_fields, $report_judges_fields; global $report_committees_fields, $report_awards_fields; global $report_schools_fields, $report_volunteers_fields; + global $report_tours_fields; $report = array(); @@ -474,6 +467,7 @@ foreach($report_stock as $n=>$v) { { global $config, $report_students_fields, $report_judges_fields, $report_awards_fields, $report_schools_fields; global $report_stock, $report_committees_fields, $report_volunteers_fields; + global $report_tours_fields; global $filter_ops; //print_r($report); @@ -718,7 +712,6 @@ foreach($report_stock as $n=>$v) { } if(count($data)) $table['data'][] = $data; } - if(count($table['data'])) { $rep->addTable($table); } diff --git a/admin/reports_editor.php b/admin/reports_editor.php index e39db5d..9d20cca 100644 --- a/admin/reports_editor.php +++ b/admin/reports_editor.php @@ -32,6 +32,7 @@ require_once('reports_committees.inc.php'); require_once('reports_schools.inc.php'); require_once('reports_volunteers.inc.php'); + require_once('reports_tours.inc.php'); require_once('reports.inc.php'); $fields = array(); @@ -291,14 +292,9 @@ function reportChange() if($n > $n_columns) $n_columns = $n; if($colaction == 'add') $n_columns+=3; - switch($report['type']) { - case 'student': $fields = $report_students_fields; break; - case 'judge': $fields = $report_judges_fields; break; - case 'award': $fields = $report_awards_fields; break; - case 'committee': $fields = $report_committees_fields; break; - case 'school': $fields = $report_schools_fields; break; - case 'volunteer': $fields = $report_volunteers_fields; break; - } + $fieldvar = "report_{$report['type']}s_fields"; + if(isset($$fieldvar)) $fields = $$fieldvar; + echo "
"; @@ -337,7 +333,8 @@ function reportChange() echo ""; selector('type', array('student' => 'Student Report', 'judge' => 'Judge Report', 'award' => 'Award Report', 'committee' => 'Committee Member Report', - 'school' => 'School Report', 'volunteer' => 'Volunteer Report' ), + 'school' => 'School Report', 'volunteer' => 'Volunteer Report', + 'tour' => 'Tour Report'), $report['type']); diff --git a/admin/reports_gen.php b/admin/reports_gen.php index 2080d42..39f9723 100644 --- a/admin/reports_gen.php +++ b/admin/reports_gen.php @@ -25,7 +25,6 @@ require_once("../common.inc.php"); require_once("../user.inc.php"); user_auth_required('committee', 'admin'); - require_once('reports.inc.php'); $id = intval($_GET['id']); diff --git a/admin/reports_students.inc.php b/admin/reports_students.inc.php index f030c05..d4be5d1 100644 --- a/admin/reports_students.inc.php +++ b/admin/reports_students.inc.php @@ -387,6 +387,20 @@ $report_students_fields = array( 'width' => 4, 'table' => "tours.name", 'components' => array('tours')), + + 'tour_assign_num' => array( + 'name' => 'Tours -- Assigned Tour Number', + 'header' => 'Tour', + 'width' => 0.5, + 'table' => "tours.num", + 'components' => array('tours')), + + 'tour_assign_numname' => array( + 'name' => 'Tours -- Assigned Tour Number and Name', + 'header' => 'Tour', + 'width' => 4, + 'table' => "CONCAT(tours.num,': ', tours.name)", + 'components' => array('tours')), 'fair_year' => array ( 'name' => 'Fair -- Year', @@ -471,24 +485,22 @@ $report_students_fields = array( students.id=emergencycontact.students_id )"; } - $q = " FROM - schools, projects $awards_join, projectdivisions, - projectcategories, registrations - JOIN students ON students.registrations_id=registrations.id - $partner_join - $emergencycontact_join + $q = " FROM students + LEFT JOIN registrations ON registrations.id=students.registrations_id + LEFT JOIN schools ON schools.id=students.schools_id + LEFT JOIN projects ON projects.registrations_id=students.registrations_id + LEFT JOIN projectdivisions ON projectdivisions.id=projects.projectdivisions_id + LEFT JOIN projectcategories ON projectcategories.id=projects.projectcategories_id + LEFT JOIN emergencycontact ON emergencycontact.students_id=students.id $tour_join + $partner_join WHERE - schools.id=students.schools_id - AND projects.registrations_id=students.registrations_id - AND projectdivisions.id=projects.projectdivisions_id - AND projectcategories.id=projects.projectcategories_id - AND (registrations.status='complete' OR registrations.status='paymentpending') - AND students.year='$year' + students.year='$year' AND projects.year='$year' AND registrations.year='$year' AND projectcategories.year='$year' AND projectdivisions.year='$year' + AND (registrations.status='complete' OR registrations.status='paymentpending') $awards_where $tour_where "; diff --git a/admin/reports_tour_selection.php b/admin/reports_tour_selection.php deleted file mode 100644 index 8ba1988..0000000 --- a/admin/reports_tour_selection.php +++ /dev/null @@ -1,140 +0,0 @@ - - Copyright (C) 2005 James Grant - - 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. -*/ -?> -newPage(); - $rep->setFontSize(11); -} -else if($type=="csv") -{ - $rep=new lcsv(i18n("Participant Tour Selections")); -} - -$table=array(); -$table['header']=array( i18n("Student ID")); - -$choicesh=array(); -$max = $config['tours_choices_max']; -for($x=0; $x<$max; $x++) { - $choicesh[] = i18n("Choice ".($x+1).($x==0?"(most preferred)":"")); -} -$table['header']=array_merge($table['header'],$choicesh); -$table['header'][] = "Name"; -$table['header'][] = "Grade"; -$table['header'][] = "Email"; - -/* Load tours */ -$tour = array(); -$q = mysql_query("SELECT * FROM tours"); -while($r = mysql_fetch_object($q)) { - $tour[$r->id] =$r->name; -} - -$q=mysql_query("SELECT students_id - FROM - tours_choice - WHERE - year='{$config['FAIRYEAR']}' - ORDER BY tours_choice.rank,tours_choice.tour_id"); - -$students_done = array(); - -while($r=mysql_fetch_object($q)) -{ - -// print_r($judge_divs); -// print_r($judge_subdivs); - - if($students_done[$r->students_id] == true) continue; - $students_done[$r->students_id] = true; - - /* Make sure the student is complete */ - $qq = mysql_query("SELECT registrations.status - FROM - students,registrations - WHERE - students.id='{$r->students_id}' - AND students.registrations_id=registrations.id - AND students.year='{$config['FAIRYEAR']}' - AND registrations.year='{$config['FAIRYEAR']}' - "); - $rr = mysql_fetch_object($qq); - if($rr->status != 'complete') continue; - - $qq = mysql_query("SELECT * FROM tours_choice WHERE ". - " year='".$config['FAIRYEAR']."' AND ". - " students_id='".$r->students_id."' ". - " ORDER BY rank "); - $c = array(); - /* Define an array for tour choices */ - for($x=0;$x<$max;$x++) { - $c[$x] = ''; - } - /* Load up to $max tour choices */ - $x = 0; - while($rr = mysql_fetch_object($qq)) { - $c[$x] = $tour[$rr->tour_id]; - $x++; - if($x == $max) break; - } - - $qq = mysql_query("SELECT * FROM students WHERE ". - " year='".$config['FAIRYEAR']."' AND ". - " id='".$r->students_id."' " - ); - $rr = mysql_fetch_object($qq); - $name = $rr->firstname." ".$rr->lastname; - $grade = $rr->grade; - $em = $rr->email; - - $tmp=array( - $r->students_id, - ); - $tmp = array_merge($tmp,$c); - $tmp[] = $name; - $tmp[] = $grade; - $tmp[] = $em; -// print_r($tmp); - $table['data'][]=$tmp; -} - -$rep->addTable($table); -$rep->output(); - -?> diff --git a/admin/reports_tours.inc.php b/admin/reports_tours.inc.php new file mode 100644 index 0000000..dd0466e --- /dev/null +++ b/admin/reports_tours.inc.php @@ -0,0 +1,97 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ + +$report_tours_fields = array( + 'tour_name' => array( + 'name' => 'Tour -- Name', + 'header' => 'Tour Name', + 'width' => 3, + 'table' => 'tours.name' ), + + 'tour_num' => array( + 'name' => 'Tour -- Number', + 'header' => 'Num', + 'width' => 0.75, + 'table' => 'tours.num' ), + + 'tour_desc' => array( + 'name' => 'Tour -- Description', + 'header' => 'Tour Description', + 'width' => 3.0, + 'table' => 'tours.description'), + + 'tour_capacity' => array( + 'name' => 'Tour -- Capacity', + 'header' => 'Cap', + 'width' => 0.4, + 'table' => 'tours.capacity' ), + + 'tour_mingrade' => array( + 'name' => 'Tour -- Minimum Grade', + 'header' => 'Min Gr.', + 'width' => 0.4, + 'table' => 'tours.grade_min' ), + + 'tour_maxgrade' => array( + 'name' => 'Tour -- Maximum Grade', + 'header' => 'Max Gr.', + 'width' => 0.4, + 'table' => 'tours.grade_max' ), + + 'tour_location' => array( + 'name' => 'Tour -- Location', + 'header' => 'Tour Location', + 'width' => 2.0, + 'table' => 'tours.location'), + + 'tour_contact' => array( + 'name' => 'Tour -- Contact', + 'header' => 'Contact', + 'width' => 1.5, + 'table' => 'tours.contact' ), + + 'tour_id' => array( + 'name' => 'Tour -- Database ID', + 'header' => '#', + 'width' => 0.4, + 'table' => 'tours.id' ), + +); + + function report_tours_fromwhere($report, $components) + { + global $config, $report_tours_fields; + + $fields = $report_tours_fields; + $year = $report['year']; + + $q = " FROM + tours + WHERE + tours.year='$year' + "; + + return $q; +} + +?> diff --git a/admin/reports_tours.php b/admin/reports_tours.php deleted file mode 100644 index 015b390..0000000 --- a/admin/reports_tours.php +++ /dev/null @@ -1,100 +0,0 @@ - - Copyright (C) 2005 James Grant - - 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. -*/ -?> -newPage(); - $rep->setFontSize(11); -} -else if($type=="csv") -{ - $rep=new lcsv(i18n("Available Tours")); -} - -$table=array(); -$table['header']=array( i18n("ID"), - i18n("Name"), - i18n("Description"), - i18n("Capacity"), - i18n("Minimum Grade"), - i18n("Maximum Grade"), - i18n("Contact"), - i18n("Location")); - - -$q=mysql_query("SELECT * - FROM - tours - WHERE - year='".$config['FAIRYEAR']."' - ORDER BY - id"); -while($r=mysql_fetch_object($q)) -{ - -// print_r($judge_divs); -// print_r($judge_subdivs); - - $n = str_replace("\r","", $r->name); - $n = str_replace("\n"," ", $n); - $d = str_replace("\r","", $r->description); - $d = str_replace("\n"," ", $d); - $c = str_replace("\r","", $r->contact); - $c = str_replace("\n"," ", $c); - $l = str_replace("\r","", $r->location); - $l = str_replace("\n"," ", $l); - - $tmp=array( - $r->id, - mysql_escape_string($n), - mysql_escape_string($d), - $r->capacity, - $r->grade_min, - $r->grade_max, - mysql_escape_string($c), - mysql_escape_string($l) - - ); -// print_r($tmp); - $table['data'][]=$tmp; -} - -$rep->addTable($table); -$rep->output(); - -?> diff --git a/admin/tours_assignments.php b/admin/tours_assignments.php index 194343e..9701f0b 100644 --- a/admin/tours_assignments.php +++ b/admin/tours_assignments.php @@ -32,11 +32,9 @@ year='{$config['FAIRYEAR']}'"; $r = mysql_query($query); $tours = array(); - $x = 1; while($i = mysql_fetch_object($r)) { $tours[$i->id]['name'] = $i->name; - $tours[$i->id]['num'] = $x; - $x++; + $tours[$i->id]['num'] = $i->num; } if($_GET['action']=='info') { @@ -172,7 +170,7 @@ function switchinfo() else $j=i18n("students"); echo happy(i18n("%1 %2 added to tour #%3 (%4)",array( - $added,$j,$tours_id,$tours[$tours_id]['name']))); + $added,$j,$tours[$tours_id]['num'],$tours[$tours_id]['name']))); } $tours_id = intval($_GET['tours_id']); @@ -184,7 +182,7 @@ function switchinfo() AND year='{$config['FAIRYEAR']}' AND rank='0'"); - echo happy(i18n("Removed student from tour #%1 (%2)",array($tours_id,$tours[$tours_id]['name']))); + echo happy(i18n("Removed student from tour #%1 (%2)",array($tours[$tours_id]['num'],$tours[$tours_id]['name']))); } @@ -194,7 +192,7 @@ function switchinfo() tour_id='$tours_id' AND year='{$config['FAIRYEAR']}' AND rank='0'"); - echo happy(i18n("Emptied all students from tour #%1 (%2)",array($tours_id,$tours[$tours_id]['name']))); + echo happy(i18n("Emptied all students from tour #%1 (%2)",array($tours[$tours_id]['num'],$tours[$tours_id]['name']))); } diff --git a/admin/tours_manager.php b/admin/tours_manager.php index 086bdf8..93a0cf4 100644 --- a/admin/tours_manager.php +++ b/admin/tours_manager.php @@ -28,11 +28,26 @@ require("../tours.class.php"); require("../tableeditor.class.php"); + + send_header("Tour Management", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Tours' => 'admin/tours.php') ); + + + if($_GET['action'] == 'renumber') { + $q = mysql_query("SELECT id FROM tours WHERE year='{$config['FAIRYEAR']}'"); + $x = 1; + while($i = mysql_fetch_object($q)) { + mysql_query("UPDATE tours SET num='$x' WHERE id='{$i->id}'"); + $x++; + } + echo happy(i18n('Tours successfully renumbered')); + } + + ?>