- Handle type/stock for custom reports properly

- Convert reports.php to use SESSION based status messages.  Just to try it
  out.
This commit is contained in:
dave 2007-12-20 18:44:28 +00:00
parent 348647208f
commit 8c42e853af
2 changed files with 44 additions and 22 deletions

View File

@ -41,6 +41,7 @@
$id = intval($_GET['id']); $id = intval($_GET['id']);
mysql_query("DELETE FROM reports_committee WHERE mysql_query("DELETE FROM reports_committee WHERE
users_id='{$_SESSION['users_id']}' AND id='$id'"); users_id='{$_SESSION['users_id']}' AND id='$id'");
$_SESSION['messages'][] = 'unlinked';
header("Location: reports.php?edit=1"); header("Location: reports.php?edit=1");
exit; exit;
} }
@ -54,24 +55,33 @@
if($action == 'add') { if($action == 'add') {
$reports_id = intval($_POST['reports_id']); $reports_id = intval($_POST['reports_id']);
/* reports_id might be < 0, that's ok */ /* reports_id might be < 0, that's ok */
$category = mysql_escape_string(stripslashes($_POST['category'])); $category = $_POST['category'];
$category_exist = mysql_escape_string(stripslashes($_POST['category_exist'])); $category_exist = $_POST['category_exist'];
$comment = mysql_escape_string(stripslashes($_POST['comment'])); $comment = mysql_escape_string(stripslashes($_POST['comment']));
if($category_exist != '') $category = $category_exist; if($category_exist != '') $category = $category_exist;
$category = mysql_escape_string(stripslashes(trim($category)));
if($category) { if($category == '') {
$_SESSION['messages'][] = 'nocategory';
$type = $_POST['type']; header("Location: reports.php?edit=1");
$stock = $_POST['stock'];
if(!array_key_exists($type, $report_options['type']['values'])) {
echo "Invalid format: type=$type";
exit; exit;
} }
if(!array_key_exists($stock, $report_stock)) {
echo "Invalid stock: stock=$stock"; if($reports_id > 0) {
exit; $type = $_POST['type'];
$stock = $_POST['stock'];
if(!array_key_exists($type, $report_options['type']['values'])) {
echo "Invalid format: type=$type";
exit;
}
if(!array_key_exists($stock, $report_stock)) {
echo "Invalid stock: stock=$stock";
exit;
}
} else {
$type = '';
$stock = '';
} }
mysql_query("INSERT INTO `reports_committee` mysql_query("INSERT INTO `reports_committee`
@ -80,14 +90,9 @@
NULL , '{$_SESSION['users_id']}', NULL , '{$_SESSION['users_id']}',
'$reports_id', '$category', '$comment', '$reports_id', '$category', '$comment',
'$type', '$stock' );"); '$type', '$stock' );");
$_SESSION['messages'][] = 'added';
header("Location: reports.php?edit=1"); header("Location: reports.php?edit=1");
exit; exit;
}
else
{
header("Location: reports.php?edit=1&errormsg=nocategory");
exit;
}
} }
@ -111,8 +116,22 @@
} }
require_once("../ajax.inc.php"); require_once("../ajax.inc.php");
if($_GET['errormsg']=="nocategory")
echo error(i18n("You must select a category or type a new category name to add a report to your list"));
foreach($_SESSION['messages'] as $m) {
switch($m) {
case 'nocategory':
echo error(i18n("You must select a category or type a new category name to add a report to your list"));
break;
case 'added':
echo happy(i18n("Report successfully added"));
break;
case 'unlinked':
echo happy(i18n("Report successfully removed"));
break;
}
}
$_SESSION['messages'] = array();
/* Load all the users reports */ /* Load all the users reports */
$q = mysql_query("SELECT reports_committee.*,reports.name $q = mysql_query("SELECT reports_committee.*,reports.name
@ -289,8 +308,8 @@
} }
else else
{ {
// document.addreport.type.disabled=true; document.addreport.type.disabled=true;
// document.addreport.stock.disabled=true; document.addreport.stock.disabled=true;
document.addreport.type.style.display='none'; document.addreport.type.style.display='none';
document.addreport.stock.style.display='none'; document.addreport.stock.style.display='none';
document.getElementById('reporttypecustom').style.display=''; document.getElementById('reporttypecustom').style.display='';

View File

@ -233,6 +233,9 @@ if($_GET['switchlanguage'])
} }
} }
if(!is_array($_SESSION['messages'])) {
$_SESSION['messages'] = array();
}
function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") function i18n($str,$args=array(),$argsdesc=array(),$forcelang="")
{ {