forked from science-ation/science-ation
9bd50a5e5a
a way to make this page not jump back to the top after the reload.
301 lines
8.9 KiB
PHP
301 lines
8.9 KiB
PHP
<?
|
|
/*
|
|
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;
|
|
}
|
|
|
|
$reports_id = 0;
|
|
if($action == 'reload') {
|
|
$edit_mode = true;
|
|
$reports_id = intval($_POST['reports_id']);
|
|
}
|
|
|
|
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 = '';
|
|
$x=0;
|
|
while($i = mysql_fetch_object($q)) {
|
|
$trclass = ($x % 2 == 0) ? "even" : "odd";
|
|
$x++;
|
|
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;
|
|
$url = "admin/reports_gen.php?id={$i->reports_id}&show_options=1";
|
|
} else {
|
|
$name = $report_custom[-$i->reports_id]['name'];
|
|
$url = $report_custom[-$i->reports_id]['custom_url'];
|
|
}
|
|
|
|
if($edit_mode == false)
|
|
$name = "<a href=\"{$config['SFIABDIRECTORY']}/$url\">$name</a>";
|
|
|
|
echo "<table width=\"100%\"><tr class=\"$trclass\"><td>";
|
|
|
|
echo "<table><tr><td colspan=\"2\">";
|
|
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 $name.'</td></tr>';
|
|
|
|
/*
|
|
if($i->reports_id > 0) {
|
|
echo '<tr><td width=\"20px\"></td><td>';
|
|
echo '<span style=\"font-size: 0.75em;\">';
|
|
echo i18n('Format').": {$i->format}, ";
|
|
echo i18n('Paper').": {$report_stock[$i->stock]['name']}, ";
|
|
echo i18n('Year').": {$config['FAIRYEAR']}";
|
|
echo '</span>';
|
|
echo '</td></tr>';
|
|
}
|
|
*/
|
|
|
|
echo "<tr><td width=\"20px\"></td><td><span style=\"font-size: 0.85em;\">{$i->comment}</span></td></tr>";
|
|
echo "</table></tr></td></table>";
|
|
}
|
|
|
|
}
|
|
|
|
/* Load available reports */
|
|
$reports = report_load_all();
|
|
|
|
if($edit_mode == false) {
|
|
echo '<hr />';
|
|
echo '<a href="committee_reports.php?edit=1">'.i18n('Click here to edit your Report List').'</a>';
|
|
|
|
echo '<hr />';
|
|
echo "<h4>".i18n("All Reports")."</h4>";
|
|
|
|
/* Print all the reports in a pulldown menu for generation */
|
|
echo "<form method=\"get\" name=\"reportgen\" action=\"reports_gen.php\">";
|
|
echo "<input type=\"hidden\" name=\"show_options\" value=\"1\" />";
|
|
echo "<select name=\"id\" id=\"report\">";
|
|
echo "<option value=\"0\">".i18n("Select a Report")."</option>\n";
|
|
$x=0;
|
|
foreach($reports as $r) {
|
|
echo "<option value=\"{$r['id']}\">{$r['name']}</option>\n";
|
|
}
|
|
echo "</select>";
|
|
echo "<input type=\"submit\" value=\"Generate Report\"></form>";
|
|
echo "<br />";
|
|
|
|
send_footer();
|
|
exit;
|
|
}
|
|
|
|
echo '<hr />';
|
|
|
|
?>
|
|
<SCRIPT language="JavaScript">
|
|
function add_reload()
|
|
{
|
|
document.addreport.action.value='reload';
|
|
document.addreport.submit();
|
|
return true;
|
|
}
|
|
</SCRIPT>
|
|
<?
|
|
|
|
/* Create an add report box */
|
|
echo '<h4>'.i18n('Add a Report to your Report List').'</h4>';
|
|
echo "<form method=\"post\" name=\"addreport\"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\" onChange=\"add_reload()\">";
|
|
$x=0;
|
|
foreach($reports as $r) {
|
|
$x++;
|
|
$sel = ($reports_id == $r['id']) ? 'selected="selected"' : '';
|
|
echo "<option value=\"{$r['id']}\" $sel>$x. {$r['name']}</option>";
|
|
|
|
}
|
|
$rid = -1;
|
|
foreach($report_custom as $r) {
|
|
$x++;
|
|
$sel = ($reports_id == $rid) ? 'selected="selected"' : '';
|
|
echo "<option value=\"$rid\" $sel>$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>";
|
|
|
|
/* Load the full specific report */
|
|
if($reports_id > 0) $report = report_load($reports_id);
|
|
$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 = ($report['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 i18n('Click on the report number to try the report with the default report options before you add it to your Report List');
|
|
echo '<br /><br />';
|
|
echo "<table>\n";
|
|
$x=0;
|
|
foreach(array_merge($reports, $report_custom) as $r) {
|
|
$trclass = ($x % 2 == 0) ? "even" : "odd";
|
|
$x++;
|
|
echo "<tr class=\"$trclass\">";
|
|
if($r['custom_url'] == '') {
|
|
$url = "admin/reports_gen.php?id={$r['id']}";
|
|
} else {
|
|
$url = $r['custom_url'];
|
|
}
|
|
echo "<td><a href=\"{$config['SFIABDIRECTORY']}/$url\">$x.</a></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();
|
|
?>
|