- 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.
This commit is contained in:
dave 2007-12-10 02:50:53 +00:00
parent d024d30793
commit 3e3c28268c
7 changed files with 448 additions and 58 deletions

256
admin/committee_reports.php Normal file
View File

@ -0,0 +1,256 @@
<?
/*
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>
Copyright (C) 2007 David Grant <dave@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("../common.inc.php");
require_once("../user.inc.php");
require_once("reports.inc.php");
user_auth_required('committee');
/* Load the user's volunteer position selections */
$edit_mode = array_key_exists('edit', $_GET);
$action = $_GET['action'];
if($action=='') $action = $_POST['action'];
if($action == 'unlink') {
$id = intval($_GET['id']);
mysql_query("DELETE FROM reports_committee WHERE
users_id='{$_SESSION['users_id']}' AND id='$id'");
header("Location: committee_reports.php?edit=1");
exit;
}
if($action == 'add') {
$reports_id = intval($_POST['reports_id']);
/* reports_id might be < 0, that's ok */
$category = mysql_escape_string(stripslashes($_POST['category']));
$category_exist = mysql_escape_string(stripslashes($_POST['category_exist']));
$comment = mysql_escape_string(stripslashes($_POST['comment']));
if($category_exist != '') $category = $category_exist;
$type = $_POST['type'];
if(!array_key_exists($type, $report_options['type']['values'])) {
/* Invalid format, not possible unless someone manually
* changes the POST variable */
echo "Invalid format";
exit;
}
$stock = $_POST['stock'];
if(!array_key_exists($stock, $report_stock)) {
/* Invalid format, not possible unless someone manually
* changes the POST variable */
echo "Invalid stock";
exit;
}
mysql_query("INSERT INTO `reports_committee`
(`id`, `users_id` , `reports_id` , `category` , `comment` , `format` , `stock`)
VALUES (
NULL , '{$_SESSION['users_id']}',
'$reports_id', '$category', '$comment',
'$type', '$stock' );");
header("Location: committee_reports.php?edit=1");
}
//send the header
if($edit_mode == false) {
send_header("My Reports",
array("Committee Main" => "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 '<br />';
echo '<br />';
echo '<a href="committee_reports.php">'.i18n('Click here when you are finished editing your report list').'</a>';
echo '<br />';
echo '<br />';
}
echo '<table>';
$last_category = '';
while($i = mysql_fetch_object($q)) {
if($last_category != $i->category) {
/* New category */
echo '<h4>';
if($edit_mode == true) echo i18n('Category').': ';
echo "{$i->category}</h4>";
$last_category = $i->category;
}
if($i->reports_id > 0) $name = $i->name;
else $name = $report_custom[-$i->reports_id]['name'];
echo "<table><tr><td colspan=\"3\">$name</td>";
echo "<tr><td width=\"20px\">";
if($edit_mode == true) {
echo "<a title=\"Remove Report\" href=\"committee_reports.php?action=unlink&id={$i->id}\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\" border=\"0\" alt=\"Remove Report\" /></a>";
}
echo "</td>";
echo "<td><span style=\"font-size: 0.75em;\">";
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 "</span></td>";
echo "<td rowspan=\"2\">";
if($edit_mode == false) {
if($i->reports_id > 0) {
echo "<form method=\"get\" action=\"reports_gen.php\">";
echo "<input type=\"hidden\" name=\"id\" value=\"{$i->reports_id}\" />";
echo "<input type=\"hidden\" name=\"show_options\" value=\"1\" />";
} else {
$url = $report_custom[-$i->reports_id]['custom_url'];
echo "<form method=\"post\" action=\"{$config['SFIABDIRECTORY']}/$url\">";
}
echo "<input type=\"submit\" value=\"".i18n('Generate')."\" /><br />";
echo "</form>";
}
echo "</td></tr>";
echo "<tr><td></td><td>{$i->comment}</td></tr>";
echo "</table>";
}
}
if($edit_mode == false) {
echo "<hr />";
echo '<a href="committee_reports.php?edit=1">'.i18n('Click here to edit your Report List').'</a>';
send_footer();
exit;
}
echo '<hr />';
/* Load available reports */
$reports = report_load_all();
/* Create an add report box */
echo '<h4>'.i18n('Add a Report to your Report List').'</h4>';
echo "<form method=\"post\" action=\"committee_reports.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"add\">";
echo "<table>\n";
echo '<tr><td colspan="2">';
echo "<select name=\"reports_id\">";
$x=0;
foreach($reports as $r) {
$x++;
echo "<option value=\"{$r['id']}\">$x. {$r['name']}</option>";
}
$rid = -1;
foreach($report_custom as $r) {
$x++;
echo "<option value=\"$rid\">$x. {$r['name']}</option>";
$rid--;
}
echo "</select></td></tr>";
echo "<tr><td>Category:</td><td>";
$q = mysql_query("SELECT DISTINCT category FROM reports_committee
WHERE users_id='{$_SESSION['users_id']}'
ORDER BY category");
echo "Existing Category: <select name=\"category_exist\">";
echo "<option value=\"\">-- ".i18n('Use New Category')." --</option>";
while($i = mysql_fetch_object($q)) {
echo "<option value=\"{$i->category}\">{$i->category}</option>";
}
echo "</select><br />";
echo "OR New Category: <input type=\"text\" name=\"category\">";
echo "</td></tr>";
$option_keys = array('type','stock');
foreach($report_options as $ok=>$o) {
if(!in_array($ok, $option_keys)) continue;
echo "<tr><td>{$o['desc']}:</td>";
echo "<td><select name=\"$ok\" id=\"$ok\">";
foreach($o['values'] as $k=>$v) {
$sel = ($r['option'][$ok] == $k) ? 'selected=\"selected\"' : '';
echo "<option value=\"$k\" $sel>$v</option>";
}
echo "</select></td></tr>";
}
echo "<tr><td>Comments:</td><td>";
echo "<textarea rows=\"3\" cols=\"60\" name=\"comment\"></textarea></td></tr>";
echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Add Report to My Reports\" /></td></tr>";
echo '</table></form>';
echo '<hr />';
echo '<h4>Descriptions for All Reports</h4>';
echo "<table>\n";
$x=0;
foreach(array_merge($reports, $report_custom) as $r) {
$trclass = ($x % 2 == 0) ? "even" : "odd";
$x++;
echo "<tr class=\"$trclass\">";
echo "<td>$x.</td>";
// echo "</td>";
echo "<td><table width=\"100%\"><tr>";
echo "<td><b>{$r['name']}</b></td>";
echo "<td align=\"right\">Created By: {$r['creator']}</td></tr>";
echo "<tr><td colspan=\"2\">{$r['desc']}</td></tr>";
echo "</table></tr>";
}
echo "</table>";
echo "<br />";
send_footer();
?>

View File

@ -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();

View File

@ -459,7 +459,7 @@ function reportChange()
echo "</table>";
echo "<h4>Options</h4>";
foreach($options as $ok=>$o) {
foreach($report_options as $ok=>$o) {
echo "{$o['desc']}: <select name=\"option[$ok]\" id=\"$ok\">";
foreach($o['values'] as $k=>$v) {
$sel = ($report['option'][$ok] == $k) ? 'selected=\"selected\"' : '';

View File

@ -22,17 +22,18 @@
*/
?>
<?
require("../common.inc.php");
require_once("../common.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'admin');
require_once('reports_students.inc.php');
require_once('reports.inc.php');
$id = intval($_GET['id']);
$sid = intval($_GET['sid']);
$format = stripslashes($_GET['type']);
$type = stripslashes($_GET['type']);
$stock = stripslashes($_GET['stock']);
$year = intval($_GET['year']);
$show_options = array_key_exists('show_options', $_GET);
if($year < 1000) $year = $config['FAIRYEAR'];
/* If it's a system report, turn that into the actual report id */
@ -42,12 +43,94 @@
$id = $r['id'];
}
if($format == '') $format = NULL;
if($id && $year)
report_gen_by_id($id, $year, $format);
else {
header("Location: reports.php");
exit;
if($show_options == false) {
if($id && $year) {
$report = report_load($id);
$report['year'] = $year;
if($type != '') $report['option']['type'] = $type;
if($stock != '') $report['option']['stock'] = $stock;
report_gen($report);
} else {
exit;
header("Location: reports.php");
}
exit;
}
$report = report_load($id);
send_header('Report Options', array(
'Committee Main' => 'committee_main.php',
'My Reports' => 'admin/committee_reports.php'));
echo '<table>';
echo "<tr><td><b>".i18n('Report&nbsp;Name')."</b>:</td>";
echo "<td>{$report['name']}</td></tr>";
echo "<tr><td><b>".i18n('Description')."</b>:</td>";
echo "<td>{$report['desc']}</td></tr>";
echo "<tr><td><b>".i18n('Created By')."</b>:</td>";
echo "<td>{$report['creator']}</td></tr>";
echo '<tr><td colspan="2"><hr /></td></tr>';
/* See if the report is in this committee member's list */
$q = mysql_query("SELECT * FROM reports_committee
WHERE users_id='{$_SESSION['users_id']}'
AND reports_id='{$report['id']}'");
echo "<tr><td colspan=\"2\"><h4>".i18n('My Reports Info')."</h4></td></tr>";
if(mysql_num_rows($q) > 0) {
/* Yes, it is */
$i = mysql_fetch_object($q);
echo "<tr><td><b>".i18n('Category')."</b>:</td>";
echo "<td>{$i->category}</td></tr>";
echo "<tr><td><b>".i18n('Comment')."</b>:</td>";
echo "<td>{$i->comment}</td></tr>";
} else {
echo "<tr><td colspan=\"2\">".i18n('This report is NOT in your \'My Reports\' list.')."</td></tr>";
}
echo "</table>";
echo '<hr />';
echo "<h4>".i18n('Report Options')."</h4>";
echo '<form method=\"get\" action="reports_gen.php">';
echo "<input type=\"hidden\" name=\"id\" value=\"$id\">";
echo "<table>";
$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 "<tr><td><b>{$o['desc']}</b>:</td>";
echo "<td><select name=\"$ok\" id=\"$ok\">";
foreach($o['values'] as $k=>$v) {
$sel = ($report['option'][$ok] == $k) ? 'selected=\"selected\"' : '';
echo "<option value=\"$k\" $sel>$v</option>";
}
echo "</select></td></tr>";
}
/* Find all the years */
$q = mysql_query("SELECT DISTINCT year FROM config WHERE year>1000");
echo "<tr><td><b>".i18n('Year')."</b>:</td>";
echo "<td><select name=\"year\" id=\"year\">";
while($i = mysql_fetch_assoc($q)) {
$y = $i['year'];
$sel = ($config['FAIRYEAR'] == $y) ? 'selected=\"selected\"' : '';
echo "<option value=\"$y\" $sel>$y</option>";
}
echo "</select></td></tr>";
echo "</table>";
echo '<br />';
echo "<input type=\"submit\" value=\"".i18n('Generate Report')."\" />";
echo '</form>';
send_footer();
?>

View File

@ -52,6 +52,8 @@
echo '<ul>';
echo '<li><a href="user_personal.php">'.i18n('Edit My Profile').'</a></li>';
if(committee_auth_has_access('admin')) {
echo '<li><a href="admin/committee_reports.php">'.i18n('My Reports (View/Print/Edit)'
).'</a></li>';
echo '<li><a href="admin/">'.i18n('Administer the Fair').'</a></li>';
}
if(committee_auth_has_access('config')) {

View File

@ -1 +1 @@
74
75

10
db/db.update.75.sql Normal file
View File

@ -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