From 3e3c28268ca1fc93d1471d7219659384a698f77f Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 10 Dec 2007 02:50:53 +0000 Subject: [PATCH] - Implement "My Reports". Committee members (with admin access, because reports require admin access) can define a list of reports out of all the reports, and tag each one with a category and comments. - Add all except the ceremony scripts as "Custom" reports. The My Reports system can handle links to custom reports now, but not the ceremony scripts. They're too special. I think they should be moved out of the Reports Area. - Clean up some report variables to avoid collisions with local names ($options, and $stock) - Implment a new screen for report generation that lets the user set the format, stock, and year of the report. --- admin/committee_reports.php | 256 ++++++++++++++++++++++++++++++++++++ admin/reports.inc.php | 131 +++++++++++------- admin/reports_editor.php | 2 +- admin/reports_gen.php | 103 +++++++++++++-- committee_main.php | 2 + db/db.code.version.txt | 2 +- db/db.update.75.sql | 10 ++ 7 files changed, 448 insertions(+), 58 deletions(-) create mode 100644 admin/committee_reports.php create mode 100644 db/db.update.75.sql diff --git a/admin/committee_reports.php b/admin/committee_reports.php new file mode 100644 index 0000000..9299d4d --- /dev/null +++ b/admin/committee_reports.php @@ -0,0 +1,256 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2007 David 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. +*/ +?> + "committee_main.php") + ); + } else { + send_header("Edit My Reports", + array("Committee Main" => "committee_main.php", + "My Reports" => "admin/committee_reports.php") + ); + } + + /* Load all the users reports */ + $q = mysql_query("SELECT reports_committee.*,reports.name + FROM reports_committee + LEFT JOIN reports ON reports.id=reports_committee.reports_id + WHERE users_id='{$_SESSION['users_id']}' + ORDER BY category,id"); + echo mysql_error(); + if(mysql_num_rows($q) == 0) { + echo i18n('You have no reports saved'); + } else { + /* List each report with info */ + + if($edit_mode == true) { + echo i18n('Deleting all the reports from a category will also delete the category.'); + echo '
'; + echo '
'; + echo ''.i18n('Click here when you are finished editing your report list').''; + echo '
'; + echo '
'; + } + + echo ''; + $last_category = ''; + + while($i = mysql_fetch_object($q)) { + if($last_category != $i->category) { + /* New category */ + echo '

'; + if($edit_mode == true) echo i18n('Category').': '; + echo "{$i->category}

"; + $last_category = $i->category; + } + if($i->reports_id > 0) $name = $i->name; + else $name = $report_custom[-$i->reports_id]['name']; + echo "
"; + echo ""; + echo ""; + echo ""; + + echo ""; + echo "
$name
"; + if($edit_mode == true) { + echo "id}\">\"Remove"; + } + + + echo ""; + if($i->reports_id > 0) { + echo i18n('Format').": {$i->format}, "; + echo i18n('Paper').": {$report_stock[$i->stock]['name']}, "; + echo i18n('Year').": {$config['FAIRYEAR']}"; + } else { + echo i18n('Custom report, no options available'); + } + echo ""; + if($edit_mode == false) { + if($i->reports_id > 0) { + echo "
"; + echo "reports_id}\" />"; + echo ""; + } else { + $url = $report_custom[-$i->reports_id]['custom_url']; + echo ""; + } + echo "
"; + echo "
"; + } + echo "
{$i->comment}
"; + } + + } + + if($edit_mode == false) { + echo "
"; + echo ''.i18n('Click here to edit your Report List').''; + send_footer(); + exit; + } + + echo '
'; + + /* Load available reports */ + $reports = report_load_all(); + + /* Create an add report box */ + echo '

'.i18n('Add a Report to your Report List').'

'; + echo "
"; + echo ""; + echo "\n"; + echo '"; + + echo ""; + + $option_keys = array('type','stock'); + foreach($report_options as $ok=>$o) { + if(!in_array($ok, $option_keys)) continue; + echo ""; + echo ""; + } + echo ""; + echo ""; + + + echo '
'; + echo "
Category:"; + $q = mysql_query("SELECT DISTINCT category FROM reports_committee + WHERE users_id='{$_SESSION['users_id']}' + ORDER BY category"); + + echo "Existing Category:
"; + echo "OR New Category: "; + echo "
{$o['desc']}:
Comments:"; + echo "
'; + + + + echo '
'; + echo '

Descriptions for All Reports

'; + echo "\n"; + $x=0; + foreach(array_merge($reports, $report_custom) as $r) { + $trclass = ($x % 2 == 0) ? "even" : "odd"; + $x++; + echo ""; + echo ""; +// echo ""; + echo ""; + } + +echo "
$x."; + + echo ""; + echo ""; + echo ""; + echo "
{$r['name']}Created By: {$r['creator']}
{$r['desc']}
"; + + echo "
"; + +send_footer(); +?> diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 79171d1..4930543 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -43,24 +43,24 @@ 9 => 'NOT LIKE ', ); - $options = array(); - $options['type'] = array( 'desc' => 'Report Format', + $report_options = array(); + $report_options['type'] = array('desc' => 'Report Format', 'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label') ); - $options['group_new_page'] = array( 'desc' => 'Start each new grouping on a new page', + $report_options['group_new_page'] = array('desc' => 'Start each new grouping on a new page', 'values' => array('no'=>'No', 'yes'=>'Yes') ); - $options['allow_multiline'] = array( 'desc' => 'Allow table rows to span multiple lines', + $report_options['allow_multiline'] = array('desc' => 'Allow table rows to span multiple lines', 'values' => array('no'=>'No', 'yes'=>'Yes') ); - $options['label_box'] = array( 'desc' => 'Draw a box around each label', + $report_options['label_box'] = array('desc' => 'Draw a box around each label', 'values' => array('no'=>'No', 'yes'=>'Yes') ); - $options['label_fairname'] = array( 'desc' => 'Print the fair name at the top of each label', + $report_options['label_fairname'] = array('desc' => 'Print the fair name at the top of each label', 'values' => array('no'=>'No', 'yes'=>'Yes') ); - $options['label_logo'] = array( 'desc' => 'Print the fair logo at the top of each label', + $report_options['label_logo'] = array('desc' => 'Print the fair logo at the top of each label', 'values' => array('no'=>'No', 'yes'=>'Yes') ); @@ -81,8 +81,8 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ /* FIXME: put these in a databse */ - $stock = array(); - $stock['fullpage'] = array('name' => 'Letter 8.5 x 11 (3/4" margin)', + $report_stock = array(); + $report_stock['fullpage'] = array('name' => 'Letter 8.5 x 11 (3/4" margin)', 'page_width' => 8.5, 'page_height' => 11, 'label_width' => 7, @@ -93,7 +93,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 1, ); - $stock['fullpage_landscape'] = array('name' => 'Letter 8.5 x 11 Landscape (3/4" margin)', + $report_stock['fullpage_landscape'] = array('name' => 'Letter 8.5 x 11 Landscape (3/4" margin)', 'page_width' => 11, 'page_height' => 8.5, 'label_width' => 9.5, @@ -104,7 +104,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 1, ); - $stock['fullpage_full'] = array('name' => 'Letter 8.5 x 11 (no margin)', + $report_stock['fullpage_full'] = array('name' => 'Letter 8.5 x 11 (no margin)', 'page_width' => 8.5, 'page_height' => 11, 'label_width' => 8.5, @@ -115,7 +115,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 1, ); - $stock['fullpage_landscape_full'] = array('name' => 'Letter 8.5 x 11 Landscape (no margin)', + $report_stock['fullpage_landscape_full'] = array('name' => 'Letter 8.5 x 11 Landscape (no margin)', 'page_width' => 11, 'page_height' => 8.5, 'label_width' => 11, @@ -126,7 +126,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 1, ); - $stock['5961'] = array('name' => 'Avery 5961, G&T 99189', + $report_stock['5961'] = array('name' => 'Avery 5961, G&T 99189', 'page_width' => 8.5, 'page_height' => 11, 'label_width' => 4, @@ -137,7 +137,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 10, ); - $stock['5964'] = array('name' => 'Avery 5964, G&T 99763', + $report_stock['5964'] = array('name' => 'Avery 5964, G&T 99763', 'page_width' => 8.5, 'page_height' => 11, 'label_width' => 4, @@ -147,7 +147,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'y_spacing' => 0, 'rows' => 3, ); - $stock['nametag'] = array('name' => 'Cards 4"x3"', + $report_stock['nametag'] = array('name' => 'Cards 4"x3"', 'page_width' => 8.5, 'page_height' => 11, 'label_width' => 4, @@ -158,19 +158,62 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */ 'rows' => 3, ); -$options['stock'] = array('desc' => "Paper Type", +$report_options['stock'] = array('desc' => "Paper Type", 'values' => array() ); /* Add more types to the report format */ -foreach($stock as $n=>$v) { - $options['stock']['values'][$n] = $v['name']; +foreach($report_stock as $n=>$v) { + $report_options['stock']['values'][$n] = $v['name']; } - $allow_options = array_keys($options); + $allow_options = array_keys($report_options); + + /* A list of custom reports, as close as possible to a real report + * format, but with the 'custom_url' attached. */ + $report_custom = array(); + $x = 1; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Mailing Labels', + 'desc' => 'Mailing Label Generator', + 'custom_url' => 'admin/reports_mailinglabels.php', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Project Details (PDF)', + 'desc' => 'Project Details', + 'custom_url' => 'admin/reports_projects_details.php?type=pdf', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Judges List (CSV)', + 'desc' => 'Judges List', + 'custom_url' => 'admin/reports_judges.php?type=csv', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Judging Teams Project Assignments (PDF)', + 'desc' => 'Judging Teams Project Assignments', + 'custom_url' => 'admin/reports_judges_teams_projects.php?type=pdf', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Judging Teams Project Assignments (CSV)', + 'desc' => 'Judging Teams Project Assignments', + 'custom_url' => 'admin/reports_judges_teams_projects.php?type=csv', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Projects Judging Team Assignments (PDF)', + 'desc' => 'Projects Judging Team Assignments', + 'custom_url' => 'admin/reports_projects_judges_teams.php?type=pdf', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Projects Judging Team Assignments (CSV)', + 'desc' => 'Projects Judging Team Assignments', + 'custom_url' => 'admin/reports_projects_judges_teams.php?type=csv', + 'creator' => 'The Grant Brothers'); + $x++; + $report_custom[$x] = array('id' => $x, 'name' => 'Custom -- Award List for Award Ceremony Program (CSV)', + 'desc' => 'Award List for Award Ceremony Program creation', + 'custom_url' => 'admin/reports_program_awards.php?type=csv', + 'creator' => 'The Grant Brothers'); - function report_save_field($report, $type, $loc) { global $allow_options; @@ -355,25 +398,6 @@ foreach($stock as $n=>$v) { return $ret; } - - - function report_gen_by_id($report_id, $year, $format=NULL) - { - global $options; - $report = report_load($report_id); - $report['year'] = $year; - if($format != NULL) { - $keys = array_keys($options['type']['values']); - if(in_array($format, $keys)) { - $report['option']['type'] = $format; - } else { - print("type [$format] not permitted\n"); - exit; - } - } - return report_gen($report); - } - function report_delete($report_id) { $r = intval($report_id); @@ -397,7 +421,7 @@ foreach($stock as $n=>$v) { function report_gen($report) { global $config, $report_students_fields, $report_judges_fields, $report_awards_fields, $report_schools_fields; - global $stock, $report_committees_fields, $report_volunteers_fields; + global $report_stock, $report_committees_fields, $report_volunteers_fields; global $filter_ops; //print_r($report); @@ -412,14 +436,23 @@ foreach($stock as $n=>$v) { $table['widths']=array(); $table['dataalign']=array(); $table['option']=array(); - - if($report['option']['type']=='csv') { + + /* Validate the stock */ + if($report['option']['stock'] != '') { + if(!array_key_exists($report['option']['stock'], $report_stock)) { + echo "Invalid stock [{$report['option']['stock']}]"; + exit; + } + } + + switch($report['option']['type']) { + case 'csv': $rep=new lcsv(i18n($report['name'])); $gen_mode = 'table'; - - } else if($report['option']['type']=='label') { + break; + case 'label': /* Label */ - $label_stock = $stock[$report['option']['stock']]; + $label_stock = $report_stock[$report['option']['stock']]; $rep=new lpdf( i18n($config['fairname']), i18n($report['name']), $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"); @@ -429,7 +462,9 @@ foreach($stock as $n=>$v) { $rep->setLabelDimensions($label_stock['label_width'], $label_stock['label_height'], $label_stock['x_spacing'], $label_stock['y_spacing']); $gen_mode = 'label'; - } else { + break; + case 'pdf': case '': + /* FIXME: handle landscape pages in here */ $rep=new lpdf( i18n($config['fairname']), i18n($report['name']), $_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"); @@ -438,6 +473,10 @@ foreach($stock as $n=>$v) { $gen_mode = 'table'; if($report['option']['allow_multiline'] == 'yes') $table['option']['allow_multiline'] = true; + break; + default: + echo "Invalid type [{$report['option']['type']}]"; + exit; } $sel = array(); diff --git a/admin/reports_editor.php b/admin/reports_editor.php index 8710c01..e39db5d 100644 --- a/admin/reports_editor.php +++ b/admin/reports_editor.php @@ -459,7 +459,7 @@ function reportChange() echo ""; echo "

Options

"; - foreach($options as $ok=>$o) { + foreach($report_options as $ok=>$o) { echo "{$o['desc']}: "; + echo ""; + $format = $report['options']['type']; + $stock = $report['options']['stock']; + $year = $config['FAIRYEAR']; + + /* Out of all the report optoins, we really only want these ones */ + $option_keys = array('type','stock'); + foreach($report_options as $ok=>$o) { + if(!in_array($ok, $option_keys)) continue; + echo ""; + echo ""; + } + /* Find all the years */ + $q = mysql_query("SELECT DISTINCT year FROM config WHERE year>1000"); + echo ""; + echo ""; + + echo "
{$o['desc']}:
".i18n('Year').":
"; + + echo '
'; + echo ""; + echo ''; + + send_footer(); + + + ?> diff --git a/committee_main.php b/committee_main.php index b9220bb..2248420 100644 --- a/committee_main.php +++ b/committee_main.php @@ -52,6 +52,8 @@ echo '
    '; echo '
  • '.i18n('Edit My Profile').'
  • '; if(committee_auth_has_access('admin')) { + echo '
  • '.i18n('My Reports (View/Print/Edit)' + ).'
  • '; echo '
  • '.i18n('Administer the Fair').'
  • '; } if(committee_auth_has_access('config')) { diff --git a/db/db.code.version.txt b/db/db.code.version.txt index fff0a24..78eb67c 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -74 +75 diff --git a/db/db.update.75.sql b/db/db.update.75.sql new file mode 100644 index 0000000..5264399 --- /dev/null +++ b/db/db.update.75.sql @@ -0,0 +1,10 @@ +CREATE TABLE `reports_committee` ( + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `users_id` INT NOT NULL , + `reports_id` INT NOT NULL , + `category` VARCHAR( 128 ) NOT NULL , + `comment` TEXT NOT NULL , + `format` VARCHAR( 64 ) NOT NULL , + `stock` VARCHAR( 64 ) NOT NULL +) ENGINE = MYISAM +