forked from science-ation/science-ation
refactor the standard ajax stuff to a common file
implement an ajax report fetcher for the my reports editor page using JSON to select the right stock/type defaults
This commit is contained in:
parent
7bbea6351a
commit
5d8632b07e
@ -29,43 +29,10 @@ ogram; see the file COPYING. If not, write to
|
||||
'Administration' => 'admin/index.php',
|
||||
'Judges' => 'admin/judges.php')
|
||||
);
|
||||
require_once("../ajax.inc.php");
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
function getHTTPObject()
|
||||
{
|
||||
var xmlhttp;
|
||||
/*@cc_on
|
||||
@if (@_jscript_version >= 5)
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
@else
|
||||
xmlhttp = false;
|
||||
@end @*/
|
||||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
|
||||
{
|
||||
try {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} catch (e)
|
||||
{
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
var http=getHTTPObject();
|
||||
|
||||
|
||||
var starttime=0;
|
||||
var startpercent=0;
|
||||
var deltatime=0;
|
||||
|
39
admin/report.ajax.php
Normal file
39
admin/report.ajax.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?
|
||||
/*
|
||||
This file is part of the 'Science Fair In A Box' project
|
||||
SFIAB Website: http://www.sfiab.ca
|
||||
|
||||
Copyright (C) 2007 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_once("../common.inc.php");
|
||||
require_once("../user.inc.php");
|
||||
require_once("reports.inc.php");
|
||||
|
||||
user_auth_required('committee');
|
||||
|
||||
if($_GET['reports_id'])
|
||||
$reports_id=$_GET['reports_id'];
|
||||
|
||||
if($reports_id > 0) {
|
||||
$report = report_load($reports_id);
|
||||
echo json_encode($report);
|
||||
}
|
||||
else
|
||||
echo json_encode(array());
|
||||
?>
|
@ -4,7 +4,7 @@
|
||||
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 James Grant <james@lightbox.org>
|
||||
Copyright (C) 2007 David Grant <dave@lightbox.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
@ -104,6 +104,8 @@
|
||||
);
|
||||
}
|
||||
|
||||
require_once("../ajax.inc.php");
|
||||
|
||||
/* Load all the users reports */
|
||||
$q = mysql_query("SELECT reports_committee.*,reports.name
|
||||
FROM reports_committee
|
||||
@ -193,7 +195,7 @@
|
||||
echo "<option value=\"{$r['id']}\">{$r['name']}</option>\n";
|
||||
}
|
||||
echo "</select>";
|
||||
echo "<input type=\"submit\" value=\"Generate Report\"></form>";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Generate Report")."\"></form>";
|
||||
echo "<br />";
|
||||
|
||||
send_footer();
|
||||
@ -203,23 +205,78 @@
|
||||
echo '<hr />';
|
||||
|
||||
?>
|
||||
<SCRIPT language="JavaScript">
|
||||
<script type="text/javascript">
|
||||
function add_reload()
|
||||
{
|
||||
document.addreport.action.value='reload';
|
||||
document.addreport.submit();
|
||||
var url="report.ajax.php?reports_id="+document.addreport.reports_id.options[document.addreport.reports_id.selectedIndex].value;
|
||||
// alert(url);
|
||||
http.open("GET",url,true);
|
||||
http.onreadystatechange=handleResponse;
|
||||
http.send(null);
|
||||
return true;
|
||||
}
|
||||
</SCRIPT>
|
||||
|
||||
function handleResponse()
|
||||
{
|
||||
try {
|
||||
if(http.readyState==4)
|
||||
{
|
||||
//eval the JSON to get the object if the length is big enough (custom reports return json [])
|
||||
if(http.responseText.length>3) {
|
||||
document.addreport.type.disabled=false;
|
||||
document.addreport.stock.disabled=false;
|
||||
document.addreport.type.style.display='';
|
||||
document.addreport.stock.style.display='';
|
||||
document.getElementById('reporttypecustom').style.display='none';
|
||||
document.getElementById('reportstockcustom').style.display='none';
|
||||
var obj=eval(http.responseText);
|
||||
if(obj['option']['type']) {
|
||||
for(i=0;i<document.addreport.type.options.length;i++) {
|
||||
if(document.addreport.type.options[i].value==obj['option']['type'])
|
||||
document.addreport.type.selectedIndex=i;
|
||||
}
|
||||
}
|
||||
else
|
||||
document.addreport.type.selectedIndex=0;
|
||||
|
||||
if(obj['option']['stock']) {
|
||||
for(i=0;i<document.addreport.stock.options.length;i++) {
|
||||
if(document.addreport.stock.options[i].value==obj['option']['stock'])
|
||||
document.addreport.stock.selectedIndex=i;
|
||||
}
|
||||
}
|
||||
else
|
||||
document.addreport.stock.selectedIndex=0;
|
||||
|
||||
if(obj['desc'])
|
||||
document.addreport.comment.value=obj['desc'];
|
||||
}
|
||||
else
|
||||
{
|
||||
document.addreport.type.disabled=true;
|
||||
document.addreport.stock.disabled=true;
|
||||
document.addreport.type.style.display='none';
|
||||
document.addreport.stock.style.display='none';
|
||||
document.getElementById('reporttypecustom').style.display='';
|
||||
document.getElementById('reportstockcustom').style.display='';
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
alert('caught error'+e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?
|
||||
|
||||
/* Create an add report box */
|
||||
echo '<h3>'.i18n('Add a Report to your Report List').'</h3>';
|
||||
echo "<form method=\"post\" name=\"addreport\"action=\"reports.php\">";
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"add\">";
|
||||
echo "<table>\n";
|
||||
echo "<table class=\"tableedit\">\n";
|
||||
echo '<tr><td colspan="2">';
|
||||
echo "<select name=\"reports_id\" onChange=\"add_reload()\">";
|
||||
echo "<option value=\"\">".i18n("Choose a report")."</option>\n";
|
||||
$x=0;
|
||||
foreach($reports as $r) {
|
||||
$x++;
|
||||
@ -237,36 +294,33 @@
|
||||
|
||||
echo "</select></td></tr>";
|
||||
|
||||
echo "<tr><td>Category:</td><td>";
|
||||
echo "<tr><td>".i18n("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 i18n("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 i18n("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 "<option value=\"$k\">$v</option>";
|
||||
}
|
||||
echo "</select></td></tr>";
|
||||
echo "</select><span id=\"report{$ok}custom\" style=\"display: none;\">".i18n("Custom")."</span></td></tr>";
|
||||
}
|
||||
echo "<tr><td>Comments:</td><td>";
|
||||
echo "<tr><td>".i18n("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 "<tr><td colspan=\"2\"><input type=\"submit\" value=\"".i18n("Add Report to My Reports")."\" /></td></tr>";
|
||||
|
||||
|
||||
echo '</table></form>';
|
||||
|
34
ajax.inc.php
Normal file
34
ajax.inc.php
Normal file
@ -0,0 +1,34 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
function getHTTPObject()
|
||||
{
|
||||
var xmlhttp;
|
||||
/*@cc_on
|
||||
@if (@_jscript_version >= 5)
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
@else
|
||||
xmlhttp = false;
|
||||
@end @*/
|
||||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
|
||||
{
|
||||
try {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} catch (e)
|
||||
{
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
var http=getHTTPObject();
|
||||
|
||||
</script>
|
@ -21,40 +21,11 @@
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
?>
|
||||
|
||||
<?
|
||||
require_once("ajax.inc.php");
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
function getHTTPObject()
|
||||
{
|
||||
var xmlhttp;
|
||||
/*@cc_on
|
||||
@if (@_jscript_version >= 5)
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch (e) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch (E) {
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
@else
|
||||
xmlhttp = false;
|
||||
@end @*/
|
||||
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
|
||||
{
|
||||
try {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} catch (e)
|
||||
{
|
||||
xmlhttp = false;
|
||||
}
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
|
||||
var http=getHTTPObject();
|
||||
var queryInProgress=false;
|
||||
var translateOpen=false;
|
||||
var translationObject;
|
||||
|
Loading…
Reference in New Issue
Block a user