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. */ ?> 'x', 'Y' => 'y', 'W' => 'w', 'H' => 'h', 'Lines' => 'lines'); function field_selector($name, $id, $selected) { global $fields; echo ""; } function selector($name, $a, $selected, $onchange='') { echo "'; } function parse_fields($f) { global $locs; $ret = array(); if(!is_array($_POST[$f])) return array(); $x = 0; foreach($_POST[$f] as $o=>$d) { if(is_array($d)) { $a = array(); foreach($d as $l=>$v) { /* Scrub the array data */ $floatloc = array_values($locs); if($l == 'field' || $l == 'value') { $v = stripslashes($v); } else if(in_array($l, $floatloc)) { $v = floatval($v); if($l == 'lines' && $v==0) $v=1; } else if($l == 'face') { $v = ($v == 'bold') ? 'bold' : ''; } else if($l == 'align') { $aligns = array('left', 'right', 'center'); if(!in_array($v, $aligns)) { echo "Invalid alignment $v"; exit; } } else if($l == 'valign') { $aligns = array('vtop', 'vbottom', 'vcenter'); if(!in_array($v, $aligns)) { echo "Invalid valignment $v"; exit; } } $a[$l] = $v; } if(trim($a['field']) == '') continue; $ret[$x] = $a; } else { if(trim($d) == '') continue; $ret[$x]['field'] = stripslashes($d); } $x++; } return $ret; } function parse_options($f) { $ret = array(); if(!is_array($_POST[$f])) return array(); foreach($_POST[$f] as $c=>$v) { if(trim($c) == '') continue; $ret[$c] = stripslashes($v); } return $ret; } /* Decode the report */ $report = array(); $report['id'] = intval($_POST['id']); $report['name'] = stripslashes($_POST['name']); $report['creator'] = stripslashes($_POST['creator']); $report['desc'] = stripslashes($_POST['desc']); $report['type'] = stripslashes($_POST['type']); $report['col'] = parse_fields('col'); $report['group'] = parse_fields('group'); $report['sort'] = parse_fields('sort'); $report['distinct'] = parse_fields('distinct'); $report['option'] = parse_options('option'); $report['filter'] = parse_fields('filter'); // print("
");print_r($_POST);print("
"); // print("
");print_r($report);print("
"); $reloadaction = $_POST['reloadaction']; $loadaction = $_POST['loadaction']; $colaction = $_POST['colaction']; $repaction = $_POST['repaction']; $repaction_save = $repaction; /* Sort out priorities */ if($reloadaction != '') { $loadaction = ''; $colaction = ''; $repaction = ''; } if($loadaction != '') { $id = intval($_POST['id']); $report = report_load($id); if($id == 0) $report['type'] = 'student'; $colaction = ''; $repaction = ''; } if($colaction != '') { $repaction = ''; } if($repaction == 'try') { /* Generate the report from what was passed through POST */ report_gen($report); exit; } send_header("Reports Editor", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php') ); ?> "; $q = mysql_query("SELECT system_report_id FROM reports WHERE 1 ORDER BY system_report_id DESC"); $r = mysql_fetch_assoc($q); $sid = $r['system_report_id'] + 1; $n = mysql_escape_string($report['name']); $c = mysql_escape_string($report['creator']); $d = mysql_escape_string($report['desc']); $t = mysql_escape_string($report['type']); echo "INSERT INTO `reports` (`id`, `system_report_id`, `name`, `desc`, `creator`, `type`) VALUES\n"; echo "\t('', '$sid', '$n', '$d', '$c', '$t');\n"; echo "INSERT INTO `reports_items` (`id`, `reports_id`, `type`, `ord`, `field`, `value`, `x`, `y`, `w`, `h`, `lines`, `face`, `align`) VALUES "; /* Do the options */ $x = 0; foreach($report['option'] as $k=>$v) { echo "\n\t('', LAST_INSERT_ID(), 'option', $x, '$k', '$v', 0, 0, 0, 0, 0, '', ''),"; $x++; } /* Do the fields */ $fields = array('col', 'group', 'sort', 'distinct', 'filter'); $first = true; foreach($fields as $f) { foreach($report[$f] as $x=>$v) { $k = $v['field']; $vx = intval($v['x']); $vy = intval($v['y']); $vw = intval($v['w']); $vh = intval($v['h']); $vlines = intval($v['lines']); if($vlines == 0) $vlines = 1; $face = $v['face']; $align = $v['align']. ' ' . $v['valign']; $value=mysql_escape_string(stripslashes($v['value'])); if(!$first) echo ','; $first = false; echo "\n\t('', LAST_INSERT_ID(), '$f', $x, '$k', '$value', $vx, $vy, $vw, $vh, $vlines, '$face', '$align')"; } } echo ";\n"; echo ""; } /* ---- Setup ------ */ $n_columns = intval($_POST['ncolumns']); $n = count($report['col']) + 1; if($n > $n_columns) $n_columns = $n; if($colaction == 'add') $n_columns+=3; $fieldvar = "report_{$report['type']}s_fields"; if(isset($$fieldvar)) $fields = $$fieldvar; echo "
"; echo "
"; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo ""; echo ""; echo "

Report Information

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Name:
Created By:
Description:
Type: "; selector('type', array('student' => 'Student Report', 'judge' => 'Judge Report', 'award' => 'Award Report', 'committee' => 'Committee Member Report', 'school' => 'School Report', 'volunteer' => 'Volunteer Report', 'tour' => 'Tour Report'), $report['type'], "onChange=\"reportReload();\""); echo ""; echo "
"; echo "

Report Data

"; echo ""; $x=0; //only go through the columns if there are columns to go through if(count($report['col'])) { foreach($report['col'] as $o=>$d) { echo ""; echo ""; $x++; } } for(;$x<$n_columns;$x++) { echo ""; echo ""; } echo ""; echo ""; echo "
Column ".($x + 1).": "; if(intval($x) != intval($o)) { echo ("WARNING, out of order!"); } field_selector("col[$o][field]", "col$o", $d['field']); echo "
Column ".($x + 1).": "; field_selector("col[$x][field]", "col$x", ''); echo "
"; echo ""; echo ""; echo "
\n"; echo "

Label Data Locations

"; echo ""; $x=0; if($report['option']['type'] == 'label') { foreach($report['col'] as $o=>$d) { $f = $d['field']; echo ""; echo ""; echo ""; } } echo "
Loc ".($o+1).": "; foreach($locs as $k=>$v) { echo "$k="; } echo 'Face='; selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), $d['face']); echo 'Align'; selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'), $d['align']); echo 'vAlign'; selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'), $d['valign']); if($f == 'static_text') { echo "
Text="; } else { echo ""; } $x++; } for(;$x<$n_columns;$x++) { echo "
Loc ".($x+1).": "; foreach($locs as $k=>$v) { echo "$k="; } echo 'Face='; selector("col[$x][face]", array('' => '', 'bold' => 'Bold'), ''); echo 'Align'; selector("col[$x][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'), 'center'); echo 'vAlign'; selector("col[$x][valign]", array('vcenter' => 'Center', 'vtop' => 'Top', 'vbottom' => 'Bottom'), 'top'); echo ""; echo "
\n"; echo "

Grouping

"; for($x=0;$x<2;$x++) { echo "Group By".($x + 1).": "; $f = $report['group'][$x]['field']; field_selector("group[$x]", "group$x", $f); echo "
"; } echo "

Sorting

"; for($x=0;$x<3;$x++) { echo "Sort By".($x + 1).": "; $f = $report['sort'][$x]['field']; field_selector("sort[$x]", "sort$x",$f); echo "
"; } echo "

Distinct

"; echo "Distinct Column: "; $x=0; $f = $report['distinct'][$x]['field']; field_selector("distinct[$x]", "distinct0", $f); echo "

Filtering

"; echo ""; for($x=0;$x<3;$x++) { echo ""; } echo "
Filter".($x + 1).":"; field_selector("filter[$x][field]", "filter$x",$report['filter'][$x]['field']); echo "
"; selector("filter[$x][x]", $filter_ops,$report['filter'][$x]['x']); $v = $report['filter'][$x]['value']; echo "Text="; echo "
"; echo "

Options

"; foreach($report_options as $ok=>$o) { echo "{$o['desc']}:
\n"; } echo "
"; if($report['system_report_id'] != 0) { echo notice(i18n('This is a system report, it cannot be changed or deleted. To save changes you have made to it, please select the \'Save as a new report\' option.')); } echo ""; echo ""; echo "
"; send_footer(); ?>