From ac3e50f94ea4a8a8209470810b833160f11f8d64 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 21 Nov 2007 21:55:31 +0000 Subject: [PATCH] - Fix a bug in the student report generation - Simplify the report generation logic for report types. --- admin/reports.inc.php | 44 +++++++--------------------------- admin/reports_students.inc.php | 2 +- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 2a56e9d..ed15e82 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -179,14 +179,8 @@ foreach($stock as $n=>$v) { global $report_volunteers_fields; - switch($report['type']) { - case 'student': $allow_fields = array_keys($report_students_fields); break; - case 'judge': $allow_fields = array_keys($report_judges_fields); break; - case 'award': $allow_fields = array_keys($report_awards_fields); break; - case 'committee':$allow_fields = array_keys($report_committees_fields); break; - case 'school': $allow_fields = array_keys($report_schools_fields); break; - case 'volunteer': $allow_fields=array_keys($report_volunteers_fields); break; - } + $fieldvar = "report_{$report['type']}s_fields"; + $allow_fields = array_keys($$fieldvar); /* First delete all existing fields */ mysql_query("DELETE FROM reports_items @@ -233,6 +227,7 @@ foreach($stock as $n=>$v) { $r = mysql_fetch_assoc($q); $report['name'] = $r['name']; $report['id'] = $r['id']; + $report['system_report_id'] = $r['system_report_id']; $report['desc'] = $r['desc']; $report['creator'] = $r['creator']; $report['type'] = $r['type']; @@ -245,15 +240,8 @@ foreach($stock as $n=>$v) { $report['filter'] = array(); $report['loc'] = array(); - $allow_fields = array(); - switch($report['type']) { - case 'student': $allow_fields = array_keys($report_students_fields); break; - case 'judge': $allow_fields = array_keys($report_judges_fields); break; - case 'award': $allow_fields = array_keys($report_awards_fields); break; - case 'committee':$allow_fields = array_keys($report_committees_fields); break; - case 'school': $allow_fields = array_keys($report_schools_fields); break; - case 'volunteer':$allow_fields = array_keys($report_volunteer_fields); break; - } + $fieldvar = "report_{$report['type']}s_fields"; + $allow_fields = array_keys($$fieldvar); $q = mysql_query("SELECT * FROM reports_items WHERE reports_id='{$report['id']}' @@ -384,14 +372,8 @@ foreach($stock as $n=>$v) { global $filter_ops; //print_r($report); - 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"; + $fields = $$fieldvar; $gen_mode = ''; $fieldname = array(); @@ -521,16 +503,8 @@ foreach($stock as $n=>$v) { $filter_query = " AND ".implode(" AND ", $filter); } - - $q = ''; - switch($report['type']) { - case 'student': $q = report_students_fromwhere($report, $components); break; - case 'judge': $q = report_judges_fromwhere($report, $components); break; - case 'award': $q = report_awards_fromwhere($report, $components); break; - case 'committee': $q = report_committees_fromwhere($report, $components); break; - case 'school': $q = report_schools_fromwhere($report, $components); break; - case 'volunteer': $q = report_volunteers_fromwhere($report, $components); break; - } + $func = "report_{$report['type']}s_fromwhere"; + $q = call_user_func_array($func, array($report, $components)); $q = "SELECT $sel $q $filter_query $group_query ORDER BY $order"; diff --git a/admin/reports_students.inc.php b/admin/reports_students.inc.php index 32c8da3..8246fc8 100644 --- a/admin/reports_students.inc.php +++ b/admin/reports_students.inc.php @@ -474,7 +474,7 @@ $report_students_fields = array( $q = " FROM schools, projects $awards_join, projectdivisions, projectcategories, registrations - JOIN students ON students.registrations_id=registrations_id + JOIN students ON students.registrations_id=registrations.id $partner_join $emergencycontact_join $tour_join