From e6745e693b23451aa11e13d5c7ea07b59e86d2af Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 15 Sep 2017 14:09:59 -0600 Subject: [PATCH] Prevent adding item if there are no categories or locations (Close #4) --- lang/en_us.php | 3 ++- lang/messages.php | 4 ++++ pages/edititem.php | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lang/en_us.php b/lang/en_us.php index d4edea5..abeff46 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -86,5 +86,6 @@ define("STRINGS", [ "only showing understocked" => "Only showing understocked items.", "show all items" => "Show all items", "missing name" => "You need to enter a name.", - "use the dropdowns" => "Whoops, you need to use the category and location autocomplete boxes." + "use the dropdowns" => "Whoops, you need to use the category and location autocomplete boxes.", + "make categories and locations" => "Please create at least one category and location before adding an item." ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 840b41e..0572c76 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -80,5 +80,9 @@ define("MESSAGES", [ "use_the_drop_luke" => [ "string" => "use the dropdowns", "type" => "danger" + ], + "noloccat" => [ + "string" => "make categories and locations", + "type" => "info" ] ]); diff --git a/pages/edititem.php b/pages/edititem.php index ad012a2..27c0fd6 100644 --- a/pages/edititem.php +++ b/pages/edititem.php @@ -5,6 +5,11 @@ require_once __DIR__ . "/../lib/userinfo.php"; redirectifnotloggedin(); +if ($database->count("locations") == 0 || $database->count("categories") == 0) { + header('Location: app.php?page=items&msg=noloccat'); + die(); +} + $itemdata = [ 'name' => '', 'catid' => '', @@ -55,6 +60,7 @@ if (!is_empty($VARS['id'])) { } else { // item id is invalid, redirect to a page that won't cause an error when pressing Save header('Location: app.php?page=edititem'); + die(); } } ?>