2007-03-18 07:10:54 +00:00
|
|
|
<?
|
|
|
|
/*
|
|
|
|
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>
|
|
|
|
|
|
|
|
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("../common.inc.php");
|
|
|
|
auth_required('admin');
|
|
|
|
|
|
|
|
require_once('reports_students.inc.php');
|
2007-03-18 19:59:02 +00:00
|
|
|
require_once('reports_judges.inc.php');
|
|
|
|
require_once('reports_awards.inc.php');
|
2007-03-18 07:10:54 +00:00
|
|
|
require_once('reports.inc.php');
|
|
|
|
|
|
|
|
$fields = array();
|
2007-03-19 06:51:44 +00:00
|
|
|
$locs = array('X' => 'xp', 'Y' => 'yp', 'W' => 'wp', 'H' => 'hp', 'LineHeight' => 'lhp');
|
2007-03-18 07:10:54 +00:00
|
|
|
|
|
|
|
function field_selector($name, $id, $selected)
|
|
|
|
{
|
|
|
|
global $fields;
|
|
|
|
echo "<select name=\"$name\" id=\"$id\">";
|
|
|
|
echo "<option value=\"\" />-- None --</option>";
|
|
|
|
foreach($fields as $k=>$f) {
|
|
|
|
$sel = ($selected == $k) ? 'selected=\"selected\"': '' ;
|
|
|
|
echo "<option value=\"$k\" $sel >{$f['name']}</option>";
|
|
|
|
}
|
|
|
|
echo "</select>";
|
|
|
|
}
|
|
|
|
|
2007-03-19 06:51:44 +00:00
|
|
|
function selector($name, $a, $selected)
|
|
|
|
{
|
|
|
|
echo "<select name=\"$name\">";
|
|
|
|
foreach($a as $v=>$val) {
|
|
|
|
$sel = ($selected == $v) ? 'selected=\"selected\"' : '';
|
|
|
|
echo "<option value=\"$v\" $sel>$val</option>";
|
|
|
|
}
|
|
|
|
echo '</select>';
|
|
|
|
}
|
2007-03-18 07:10:54 +00:00
|
|
|
/*
|
|
|
|
<script type="text/javascript">
|
|
|
|
function reportChange()
|
|
|
|
{
|
|
|
|
var index = document.forms.report.report.selectedIndex;
|
|
|
|
|
|
|
|
document.getElementById('report').submit();
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
/* Clean out existing settings
|
|
|
|
<?foreach($fields as $k=>$f) {
|
|
|
|
echo "document.getElementById('$k').checked=false;\n";
|
|
|
|
}?>
|
|
|
|
document.getElementById('group0').value = '';
|
|
|
|
document.getElementById('group1').value = '';
|
|
|
|
// document.getElementById('group2').value = '';
|
|
|
|
document.getElementById('sort0').value = '';
|
|
|
|
document.getElementById('sort1').value = '';
|
|
|
|
document.getElementById('sort2').value = '';
|
|
|
|
document.getElementById('distinct0').value = '';
|
|
|
|
document.getElementById('type').value = 'pdf';
|
|
|
|
document.getElementById('group_new_page').value = 'no';
|
|
|
|
|
|
|
|
/* Load appropriate settings
|
|
|
|
if(index == 0) {
|
|
|
|
/* Do nothing
|
|
|
|
}
|
|
|
|
<?$x=1;
|
|
|
|
foreach($reports as $r) {
|
|
|
|
echo "else if(index == $x) {\n";
|
|
|
|
foreach($r['cols'] as $c) {
|
|
|
|
echo "document.getElementById('$c').checked=true;\n";
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
foreach($r['sort'] as $c) {
|
|
|
|
echo "document.getElementById('sort$i').value='$c';\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
foreach($r['group'] as $c) {
|
|
|
|
echo "document.getElementById('group$i').value='$c';\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if(is_array($r['distinct'])) {
|
|
|
|
$i = 0;
|
|
|
|
foreach($r['distinct'] as $c) {
|
|
|
|
echo "document.getElementById('distinct$i').value='$c';\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_array($r['option'])) {
|
|
|
|
foreach($r['option'] as $k=>$v) {
|
|
|
|
echo "document.getElementById('$k').value='$v';\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$x++;
|
|
|
|
echo "}\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
*/
|
|
|
|
|
|
|
|
function parse_fields($f)
|
|
|
|
{
|
|
|
|
$ret = array();
|
|
|
|
if(!is_array($_POST[$f])) return array();
|
|
|
|
foreach($_POST[$f] as $c) {
|
|
|
|
if(trim($c) == '') continue;
|
|
|
|
$ret[] = stripslashes($c);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2007-03-19 06:51:44 +00:00
|
|
|
function parse_loc($f)
|
|
|
|
{
|
|
|
|
global $locs;
|
|
|
|
$ret = array();
|
|
|
|
if(!is_array($_POST[$f])) return array();
|
|
|
|
|
|
|
|
foreach($_POST[$f] as $c=>$l) {
|
|
|
|
if(trim($c) == '') continue;
|
|
|
|
foreach($l as $ll=>$val) {
|
|
|
|
$floatloc = array_values($locs);
|
|
|
|
if(in_array($ll, $floatloc)) {
|
|
|
|
$val = floatval($val);
|
|
|
|
} else if($ll == 'face') {
|
|
|
|
$val = ($val == 'bold') ? 'bold' : '';
|
|
|
|
} else if($ll = 'align') {
|
|
|
|
$aligns = array('left', 'right', 'center');
|
|
|
|
if(!in_array($val, $aligns)) {
|
|
|
|
echo "Invalid alignment $val";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ret[$c][$ll] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2007-03-18 07:10:54 +00:00
|
|
|
|
|
|
|
/* 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');
|
2007-03-19 06:51:44 +00:00
|
|
|
$report['loc'] = parse_loc('loc');
|
2007-03-18 07:10:54 +00:00
|
|
|
|
2007-03-18 19:59:02 +00:00
|
|
|
// print_r($report);
|
|
|
|
|
2007-03-18 07:10:54 +00:00
|
|
|
$loadaction = $_POST['loadaction'];
|
|
|
|
$colaction = $_POST['colaction'];
|
|
|
|
$repaction = $_POST['repaction'];
|
|
|
|
|
|
|
|
$repaction_save = $repaction;
|
|
|
|
/* Sort out priorities */
|
|
|
|
if($loadaction != '') {
|
|
|
|
$report = report_load(intval($_POST['id']));
|
|
|
|
$colaction = '';
|
|
|
|
$repaction = '';
|
|
|
|
}
|
|
|
|
if($colaction != '') {
|
|
|
|
$repaction = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($repaction == 'try') {
|
|
|
|
/* Try this report save it to the database under a new report, and mark it as
|
|
|
|
* temporary, so when the generator finishes with it, it deletes it */
|
|
|
|
report_gen($report);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_header("Administration - Reports > Editor");
|
|
|
|
|
|
|
|
if($repaction == 'save') {
|
|
|
|
/* Save the report */
|
|
|
|
$report['id'] = report_save($report);
|
|
|
|
echo happy(i18n("Report Saved"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if($repaction == 'del') {
|
|
|
|
report_delete($report['id']);
|
|
|
|
echo happy(i18n("Report Deleted"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Setup ------ */
|
|
|
|
|
|
|
|
$n_columns = intval($_POST['ncolumns']);
|
|
|
|
$n = count($report['col']) + 1;
|
|
|
|
if($n > $n_columns) $n_columns = $n;
|
|
|
|
if($colaction == 'add') $n_columns+=3;
|
|
|
|
|
|
|
|
switch($report['type']) {
|
2007-03-18 19:59:02 +00:00
|
|
|
case 'student': $fields = $report_students_fields; break;
|
|
|
|
case 'judge': $fields = $report_judges_fields; break;
|
2007-03-18 21:48:36 +00:00
|
|
|
case 'award': $fields = $report_awards_fields; break;
|
2007-03-18 07:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "<a href=\"reports.php\"><< ".i18n("Back to Reports")."</a><br />";
|
|
|
|
echo "<br />";
|
|
|
|
|
|
|
|
echo "<form method=\"post\" name=\"reportload\" action=\"reports_editor.php\" onChange=\"document.reportload.submit()\">";
|
|
|
|
echo "<input type=\"hidden\" name=\"loadaction\" value=\"load\" />";
|
|
|
|
echo "<select name=\"id\" id=\"report\">";
|
|
|
|
echo "<option value=\"0\">".i18n("Create New Report")."</option>\n";
|
|
|
|
|
|
|
|
$reports = report_load_all();
|
|
|
|
$x=0;
|
|
|
|
foreach($reports as $r) {
|
|
|
|
$sel = ($report['id'] == $r['id']) ? 'selected=\"selected\"' : '';
|
|
|
|
echo "<option value=\"{$r['id']}\" $sel>{$r['name']}</option>\n";
|
|
|
|
}
|
|
|
|
echo "</select>";
|
|
|
|
echo "<input type=\"submit\" value=\"Load\"></form>";
|
|
|
|
echo "<hr />";
|
|
|
|
|
|
|
|
|
|
|
|
echo "<form method=\"post\" name=\"report\" action=\"reports_editor.php\">";
|
|
|
|
echo "<input type=\"hidden\" name=\"id\" value=\"{$report['id']}\" />";
|
|
|
|
echo "<input type=\"hidden\" name=\"ncolumns\" value=\"$n_columns\" />";
|
|
|
|
|
|
|
|
echo "<h4>Report Information</h4>";
|
|
|
|
echo "<table>";
|
|
|
|
echo "<tr><td>Name: </td>";
|
|
|
|
echo "<td><input type=\"text\" name=\"name\" size=\"80\" value=\"{$report['name']}\" /></td>";
|
|
|
|
echo "</tr>";
|
|
|
|
echo "<tr><td>Created By: </td>";
|
|
|
|
echo "<td><input type=\"text\" name=\"creator\" size=\"80\" value=\"{$report['creator']}\" /></td>";
|
|
|
|
echo "</tr>";
|
|
|
|
echo "<tr><td>Description: </td>";
|
|
|
|
echo "<td><textarea name=\"desc\" rows=\"3\" cols=\"60\">{$report['desc']}</textarea></td>";
|
|
|
|
echo "</tr>";
|
|
|
|
echo "<tr><td>Type: </td>";
|
2007-03-18 19:59:02 +00:00
|
|
|
echo "<td><select name=\"type\">";
|
|
|
|
$sel = ($report['type'] == 'student') ? 'selected=\"selected\"' : '';
|
|
|
|
echo "<option value=\"student\" $sel>Student Report</option>";
|
|
|
|
$sel = ($report['type'] == 'judge') ? 'selected=\"selected\"' : '';
|
|
|
|
echo "<option value=\"judge\" $sel>Judge Report</option>";
|
|
|
|
$sel = ($report['type'] == 'award') ? 'selected=\"selected\"' : '';
|
|
|
|
echo "<option value=\"award\" $sel>Award Report</option>";
|
|
|
|
echo "</select></td>";
|
2007-03-18 07:10:54 +00:00
|
|
|
echo "</tr></table>";
|
|
|
|
|
|
|
|
echo "<h4>Report Data</h4>";
|
|
|
|
echo "<table>";
|
|
|
|
$x=0;
|
|
|
|
foreach($report['col'] as $f) {
|
|
|
|
echo "<tr><td>Column ".($x + 1).": </td>";
|
|
|
|
echo "<td>";
|
|
|
|
field_selector("col[]", "col$x", $f);
|
|
|
|
echo "</td></tr>";
|
2007-03-19 06:51:44 +00:00
|
|
|
|
2007-03-18 07:10:54 +00:00
|
|
|
$x++;
|
|
|
|
}
|
|
|
|
for(;$x<$n_columns;$x++) {
|
|
|
|
echo "<tr><td>Column ".($x + 1).": </td>";
|
|
|
|
echo "<td>";
|
|
|
|
field_selector("col[]", "col$x", '');
|
|
|
|
echo "</td></tr>";
|
2007-03-19 06:51:44 +00:00
|
|
|
|
2007-03-18 07:10:54 +00:00
|
|
|
}
|
|
|
|
echo "<tr><td></td>";
|
|
|
|
echo "<td align=\"right\">";
|
|
|
|
echo "<select name=\"colaction\"><option value=\"\"></option><option value=\"add\">Add more columns</option></select>";
|
|
|
|
echo "<input type=\"submit\" value=\"Go\">";
|
|
|
|
echo "</td></tr>";
|
|
|
|
echo "</table>\n";
|
|
|
|
|
2007-03-19 06:51:44 +00:00
|
|
|
echo "<h4>Label Data Locations</h4>";
|
|
|
|
echo "<table>";
|
|
|
|
$x=0;
|
|
|
|
|
|
|
|
if($report['option']['type'] == 'label') {
|
|
|
|
|
|
|
|
foreach($report['col'] as $f) {
|
|
|
|
echo "<tr><td align=\"right\">Loc ".($x+1).": </td>";
|
|
|
|
echo "<td>";
|
|
|
|
foreach($locs as $k=>$v) {
|
|
|
|
echo "$k=<input type=\"text\" size=\"3\" name=\"loc[$f][$v]\" value=\"{$report['loc'][$f][$v]}\">";
|
|
|
|
}
|
|
|
|
echo 'Face=';
|
|
|
|
selector("loc[$f][face]",
|
|
|
|
array('' => '', 'bold' => 'Bold'),
|
|
|
|
$report['loc'][$f]['face']);
|
|
|
|
echo 'Align';
|
|
|
|
selector("loc[$f][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
|
|
|
|
$report['loc'][$f]['align']);
|
|
|
|
$x++;
|
|
|
|
}
|
|
|
|
for(;$x<$n_columns;$x++) {
|
|
|
|
echo "<tr><td align=\"right\">Loc ".($x+1).": </td>";
|
|
|
|
echo "<td>";
|
|
|
|
foreach($locs as $k=>$v) {
|
|
|
|
echo "$k=<input type=\"text\" size=\"3\" name=\"loc[$x][$v]\" value=\"\">";
|
|
|
|
}
|
|
|
|
echo 'Face=';
|
|
|
|
selector("loc[$f][face]",
|
|
|
|
array('' => '', 'bold' => 'Bold'),
|
|
|
|
'');
|
|
|
|
echo 'Align';
|
|
|
|
selector("loc[$f][align]",
|
|
|
|
array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
|
|
|
|
'center');
|
|
|
|
echo "</td></tr>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-18 07:10:54 +00:00
|
|
|
echo "<h4>Grouping</h4>";
|
|
|
|
for($x=0;$x<2;$x++) {
|
|
|
|
echo "Group By".($x + 1).": ";
|
|
|
|
field_selector("group[]", "group$x", $report['group'][$x]);
|
|
|
|
echo "<br />";
|
|
|
|
}
|
|
|
|
echo "<h4>Sorting</h4>";
|
|
|
|
for($x=0;$x<3;$x++) {
|
|
|
|
echo "Sort By".($x + 1).": ";
|
|
|
|
field_selector("sort[]", "sort$x", $report['sort'][$x]);
|
|
|
|
echo "<br />";
|
|
|
|
}
|
|
|
|
echo "<h4>Distinct</h4>";
|
|
|
|
echo "Distinct Column: ";
|
|
|
|
field_selector("distinct[]", "distinct0", $report['distinct'][0]);
|
|
|
|
|
|
|
|
echo "<h4>Options</h4>";
|
|
|
|
foreach($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\"' : '';
|
|
|
|
echo "<option value=\"$k\" $sel>$v</option>";
|
|
|
|
}
|
|
|
|
echo "</select><br />\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<br />";
|
|
|
|
echo "<select name=\"repaction\">";
|
|
|
|
$sel = ($repaction_save == 'save') ? "selected=\"selected\"" : '';
|
|
|
|
echo " <option value=\"save\" $sel>Save this report</option>";
|
|
|
|
$sel = ($repaction_save == 'try') ? "selected=\"selected\"" : '';
|
|
|
|
echo " <option value=\"try\" $sel>Try this report</option>";
|
|
|
|
echo " <option value=\"\" ></option>";
|
|
|
|
echo " <option value=\"del\" >Delete this report</option>";
|
|
|
|
echo "</select>";
|
|
|
|
echo "<input type=\"submit\" value=\"Go\">";
|
|
|
|
|
|
|
|
echo "</form>";
|
|
|
|
|
|
|
|
send_footer();
|
|
|
|
?>
|