From 8c42e853af7f2b03bb32158eeae41c38524cb242 Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 20 Dec 2007 18:44:28 +0000 Subject: [PATCH] - Handle type/stock for custom reports properly - Convert reports.php to use SESSION based status messages. Just to try it out. --- admin/reports.php | 63 ++++++++++++++++++++++++++++++----------------- common.inc.php | 3 +++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/admin/reports.php b/admin/reports.php index 8998135..c00001e 100644 --- a/admin/reports.php +++ b/admin/reports.php @@ -41,6 +41,7 @@ $id = intval($_GET['id']); mysql_query("DELETE FROM reports_committee WHERE users_id='{$_SESSION['users_id']}' AND id='$id'"); + $_SESSION['messages'][] = 'unlinked'; header("Location: reports.php?edit=1"); exit; } @@ -54,24 +55,33 @@ 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'])); + $category = $_POST['category']; + $category_exist = $_POST['category_exist']; $comment = mysql_escape_string(stripslashes($_POST['comment'])); if($category_exist != '') $category = $category_exist; + $category = mysql_escape_string(stripslashes(trim($category))); - if($category) { - - $type = $_POST['type']; - $stock = $_POST['stock']; - - if(!array_key_exists($type, $report_options['type']['values'])) { - echo "Invalid format: type=$type"; + if($category == '') { + $_SESSION['messages'][] = 'nocategory'; + header("Location: reports.php?edit=1"); exit; } - if(!array_key_exists($stock, $report_stock)) { - echo "Invalid stock: stock=$stock"; - exit; + + if($reports_id > 0) { + $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` @@ -80,14 +90,9 @@ NULL , '{$_SESSION['users_id']}', '$reports_id', '$category', '$comment', '$type', '$stock' );"); + $_SESSION['messages'][] = 'added'; header("Location: reports.php?edit=1"); exit; - } - else - { - header("Location: reports.php?edit=1&errormsg=nocategory"); - exit; - } } @@ -111,8 +116,22 @@ } 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 */ $q = mysql_query("SELECT reports_committee.*,reports.name @@ -289,8 +308,8 @@ } else { -// document.addreport.type.disabled=true; -// document.addreport.stock.disabled=true; + 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=''; diff --git a/common.inc.php b/common.inc.php index a660c03..323a4c3 100644 --- a/common.inc.php +++ b/common.inc.php @@ -233,6 +233,9 @@ if($_GET['switchlanguage']) } } +if(!is_array($_SESSION['messages'])) { + $_SESSION['messages'] = array(); +} function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") {