From cd100535acc251c0903b72045c8316934bf3042c Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 6 Oct 2018 00:43:58 -0600 Subject: [PATCH] Add readonly item view (close #13) --- action.php | 3 + langs/en/actions.json | 4 +- langs/en/items.json | 3 +- lib/getitemtable.php | 9 ++- pages.php | 4 + pages/editimages.php | 8 +- pages/edititem.php | 11 ++- pages/item.php | 173 ++++++++++++++++++++++++++++++++++++++++++ pages/items.php | 2 +- static/js/items.js | 2 +- 10 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 pages/item.php diff --git a/action.php b/action.php index 07e31d6..e282a7c 100644 --- a/action.php +++ b/action.php @@ -122,6 +122,9 @@ switch ($VARS['action']) { $database->update('items', $data, ['itemid' => $VARS['itemid']]); } + if ($VARS['source'] == "item") { + returnToSender("item_saved", "&id=" . $VARS['itemid']); + } returnToSender("item_saved"); case "editcat": $insert = true; diff --git a/langs/en/actions.json b/langs/en/actions.json index 73a24e1..3da53a6 100644 --- a/langs/en/actions.json +++ b/langs/en/actions.json @@ -2,5 +2,7 @@ "edit": "Edit", "clone": "Clone", "save": "Save", - "delete": "Delete" + "delete": "Delete", + "view": "View", + "show all items": "Show All Items" } diff --git a/langs/en/items.json b/langs/en/items.json index 2bfc451..15c6549 100644 --- a/langs/en/items.json +++ b/langs/en/items.json @@ -8,5 +8,6 @@ "editing item": "Editing {item}", "cloning item": "Copying {oitem} {nitem}", "itemid": "Item ID", - "id": "ID" + "id": "ID", + "Edit Item": "Edit Item" } diff --git a/lib/getitemtable.php b/lib/getitemtable.php index b0361bc..88b157c 100644 --- a/lib/getitemtable.php +++ b/lib/getitemtable.php @@ -115,8 +115,13 @@ $out['recordsFiltered'] = $recordsFiltered; $usercache = []; for ($i = 0; $i < count($items); $i++) { - $items[$i]["editbtn"] = ' ' . $Strings->get("edit", false) . ''; - $items[$i]["clonebtn"] = ' ' . $Strings->get("clone", false) . ''; + $user = new User($_SESSION['uid']); + if ($user->hasPermission("INV_EDIT")) { + $items[$i]["editbtn"] = ' ' . $Strings->get("edit", false) . ''; + } else { + $items[$i]["editbtn"] = ''; + } + $items[$i]["viewbtn"] = ' ' . $Strings->get("view", false) . ''; if (is_null($items[$i]['userid'])) { $items[$i]["username"] = ""; } else { diff --git a/pages.php b/pages.php index c5b92e5..e324a56 100644 --- a/pages.php +++ b/pages.php @@ -50,6 +50,10 @@ define("PAGES", [ "static/js/categories.js" ], ], + "item" => [ + "title" => "Item", + "navbar" => false + ], "edititem" => [ "title" => "Edit item", "navbar" => false, diff --git a/pages/editimages.php b/pages/editimages.php index 91ef7c3..0170470 100644 --- a/pages/editimages.php +++ b/pages/editimages.php @@ -82,6 +82,12 @@ if (!empty($VARS['id']) && $database->has('items', ['itemid' => $VARS['id']])) { \ No newline at end of file diff --git a/pages/edititem.php b/pages/edititem.php index b388aa8..f4da79e 100644 --- a/pages/edititem.php +++ b/pages/edititem.php @@ -231,7 +231,13 @@ if (!empty($VARS['id'])) { } ?>" /> - + '; + } else { + echo ''; + } + ?> @@ -245,7 +251,8 @@ if (!empty($VARS['id'])) { if ($editing && !$cloning) { ?> - get("Edit Images"); ?> + get("Edit Images"); ?> + get("clone"); ?> get('delete'); ?> count("locations") == 0 || $database->count("categories") == 0) { + header('Location: app.php?page=items&msg=noloccat'); + die(); +} + +$item = [ + 'itemid' => '', + 'name' => '', + 'catid' => '', + 'catname' => '', + 'locid' => '', + 'locname' => '', + 'loccode' => '', + 'code1' => '', + 'code2' => '', + 'text1' => '', + 'text2' => '', + 'text3' => '', + 'qty' => 1, + 'want' => 0, + 'cost' => 0.0, + 'price' => 0.0, + 'userid' => '']; + +if (empty($VARS['id']) || !$database->has('items', ['itemid' => $VARS['id']])) { + header('Location: app.php?page=items&msg=invalid_itemid'); + die(); +} +$item = $database->get( + 'items', [ + '[>]categories' => [ + 'catid' => 'catid' + ], + '[>]locations' => [ + 'locid' => 'locid' + ] + ], [ + 'itemid', + 'name', + 'code1', + 'code2', + 'text1', + 'text2', + 'text3', + 'items.catid', + 'catname', + 'items.locid', + 'locname', + 'loccode', + 'qty', + 'want', + 'cost', + 'price', + 'userid' + ], [ + 'itemid' => $VARS['id'] + ]); +?> + +
+
+ + +
+
+ get("category"); + echo ": " . $item['catname']; + ?> +
+
+ get("location"); + echo ": " . $item['locname']; + ?> +
+
+ get("quantity"); + echo ": " . $item['qty']; + ?> +
+
+ get("Item cost"); + echo ": " . $item['cost']; + ?> +
+
+ get("Sale price"); + echo ": " . $item['price']; + ?> +
+ +
+ get("assigned to"); + echo ": " . (new User($item['userid']))->getName(); + ?> +
+ +
+ +
+
+
get('Description'); ?>
+
+ +
+
+
+
get('Notes'); ?>
+
+ +
+
+
+
get('Comments'); ?>
+
+ +
+
+
+ +
+ +
+ select('images', ['imageid', 'imagename', 'primary'], ['itemid' => $VARS['id']]); + foreach ($images as $i) { + ?> +
+
+ <?php echo $i['imagename']; ?> +
+ + + +
+
+
+ +
+
+
\ No newline at end of file diff --git a/pages/items.php b/pages/items.php index a1405ae..2ea748e 100644 --- a/pages/items.php +++ b/pages/items.php @@ -14,7 +14,7 @@ redirectifnotloggedin(); -
get("only showing understocked"); ?>   get("show all items"); ?>
+
get("only showing understocked"); ?>   get("show all items"); ?>
var filter = null;\n"; diff --git a/static/js/items.js b/static/js/items.js index 5fe0cbd..298fa14 100644 --- a/static/js/items.js +++ b/static/js/items.js @@ -49,7 +49,7 @@ var itemtable = $('#itemtable').DataTable({ json.items.forEach(function (row) { json.data.push([ "", - "" + row.editbtn + " " + row.clonebtn + "", + "" + row.viewbtn + " " + row.editbtn + "", row.name, row.catname, row.locname + " (" + row.loccode + ")",