Browse Source

Add readonly item view (close #13)

master
Skylar Ittner 3 years ago
parent
commit
cd100535ac
  1. 3
      action.php
  2. 4
      langs/en/actions.json
  3. 3
      langs/en/items.json
  4. 9
      lib/getitemtable.php
  5. 4
      pages.php
  6. 8
      pages/editimages.php
  7. 11
      pages/edititem.php
  8. 173
      pages/item.php
  9. 2
      pages/items.php
  10. 2
      static/js/items.js

3
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;

4
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"
}

3
langs/en/items.json

@ -8,5 +8,6 @@
"editing item": "Editing {item}",
"cloning item": "Copying {oitem} <i class=\"fa fa-angle-right\"></i> {nitem}",
"itemid": "Item ID",
"id": "ID"
"id": "ID",
"Edit Item": "Edit Item"
}

9
lib/getitemtable.php

@ -115,8 +115,13 @@ $out['recordsFiltered'] = $recordsFiltered;
$usercache = [];
for ($i = 0; $i < count($items); $i++) {
$items[$i]["editbtn"] = '<a class="btn btn-primary" href="app.php?page=edititem&id=' . $items[$i]['itemid'] . '"><i class="fas fa-edit"></i> ' . $Strings->get("edit", false) . '</a>';
$items[$i]["clonebtn"] = '<a class="btn btn-success" href="app.php?page=edititem&id=' . $items[$i]['itemid'] . '&clone=1"><i class="fas fa-clone"></i> ' . $Strings->get("clone", false) . '</a>';
$user = new User($_SESSION['uid']);
if ($user->hasPermission("INV_EDIT")) {
$items[$i]["editbtn"] = '<a class="btn btn-primary" href="app.php?page=edititem&id=' . $items[$i]['itemid'] . '"><i class="fas fa-edit"></i> ' . $Strings->get("edit", false) . '</a>';
} else {
$items[$i]["editbtn"] = '';
}
$items[$i]["viewbtn"] = '<a class="btn btn-info" href="app.php?page=item&id=' . $items[$i]['itemid'] . '"><i class="fas fa-eye"></i> ' . $Strings->get("view", false) . '</a>';
if (is_null($items[$i]['userid'])) {
$items[$i]["username"] = "";
} else {

4
pages.php

@ -50,6 +50,10 @@ define("PAGES", [
"static/js/categories.js"
],
],
"item" => [
"title" => "Item",
"navbar" => false
],
"edititem" => [
"title" => "Edit item",
"navbar" => false,

8
pages/editimages.php

@ -82,6 +82,12 @@ if (!empty($VARS['id']) && $database->has('items', ['itemid' => $VARS['id']])) {
</div>
<div class="card-footer d-flex">
<a href="./app.php?page=edititem&id=<?php echo $_GET['id']; ?>" class="btn btn-success mr-auto"><i class="fas fa-arrow-left"></i> <?php $Strings->get("Back"); ?></a>
<?php
$source = "edititem";
if ($_GET['source'] === "item") {
$source = "item";
}
?>
<a href="./app.php?page=<?php echo $source; ?>&id=<?php echo $_GET['id']; ?>" class="btn btn-success mr-auto"><i class="fas fa-arrow-left"></i> <?php $Strings->get("Back"); ?></a>
</div>
</div>

11
pages/edititem.php

@ -231,7 +231,13 @@ if (!empty($VARS['id'])) {
}
?>" />
<input type="hidden" name="action" value="edititem" />
<input type="hidden" name="source" value="items" />
<?php
if (isset($_GET['source']) && $_GET['source'] === "item" && $editing && !$cloning) {
echo '<input type="hidden" name="source" value="item" />';
} else {
echo '<input type="hidden" name="source" value="items" />';
}
?>
<?php
if ($cloning) {
?>
@ -245,7 +251,8 @@ if (!empty($VARS['id'])) {
if ($editing && !$cloning) {
?>
<button type="submit" class="btn btn-success mr-1"><i class="fas fa-save"></i> <?php $Strings->get("save"); ?></button>
<a href="./app.php?page=editimages&id=<?php echo $_GET['id']; ?>" class="btn btn-primary mr-auto"><i class="fas fa-images"></i> <?php $Strings->get("Edit Images"); ?></a>
<a href="./app.php?page=editimages&id=<?php echo $_GET['id']; ?>" class="btn btn-primary mr-1"><i class="fas fa-images"></i> <?php $Strings->get("Edit Images"); ?></a>
<a class="btn btn-success mr-auto" href="app.php?page=edititem&id=<?php echo $VARS['id']; ?>&clone=1"><i class="fas fa-clone"></i> <?php $Strings->get("clone"); ?></a>
<a href="action.php?action=deleteitem&source=items&itemid=<?php echo htmlspecialchars($VARS['id']); ?>" class="btn btn-danger ml-auto"><i class="fas fa-times"></i> <?php $Strings->get('delete'); ?></a>
<?php
} else {

173
pages/item.php

@ -0,0 +1,173 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
require_once __DIR__ . '/../required.php';
redirectifnotloggedin();
if ($database->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']
]);
?>
<div class="card">
<div class="card-body">
<div class="card-title d-flex flex-wrap justify-content-between">
<h3><a href="app.php?page=items" class="text-body"><i class="fas fa-arrow-left"></i></a> <?php echo $item['name']; ?></h3>
<div>
<a href="app.php?page=edititem&id=<?php echo $item['itemid']; ?>&source=item" class="btn btn-primary"><i class="fas fa-edit"></i> <?php $Strings->get('Edit Item'); ?></a>
<a href="app.php?page=editimages&id=<?php echo $item['itemid']; ?>&source=item" class="btn btn-info"><i class="fas fa-images"></i> <?php $Strings->get('Edit Images'); ?></a>
</div>
</div>
<div class="d-flex justify-content-around flex-wrap">
<div class="list-group-item h5 mb-2">
<i class="fas fa-archive"></i> <?php
$Strings->get("category");
echo ": " . $item['catname'];
?>
</div>
<div class="list-group-item h5 mb-2">
<i class="fas fa-map-marker"></i> <?php
$Strings->get("location");
echo ": " . $item['locname'];
?>
</div>
<div class="list-group-item h5 mb-2">
<i class="fas fa-hashtag"></i> <?php
$Strings->get("quantity");
echo ": " . $item['qty'];
?>
</div>
<div class="list-group-item h5 mb-2">
<i class="fas fa-money-bill"></i> <?php
$Strings->get("Item cost");
echo ": " . $item['cost'];
?>
</div>
<div class="list-group-item h5 mb-2">
<i class="fas fa-shopping-cart"></i> <?php
$Strings->get("Sale price");
echo ": " . $item['price'];
?>
</div>
<?php
if (!is_null($item['userid']) && is_numeric($item['userid'])) {
?>
<div class="list-group-item h5 mb-2">
<i class="fas fa-user"></i> <?php
$Strings->get("assigned to");
echo ": " . (new User($item['userid']))->getName();
?>
</div>
<?php
}
?>
</div>
<div class="row mt-4 mx-2 mb-4">
<div class="col-12 col-sm-6 col-md-4">
<h5><i class="fas fa-info"></i> <?php $Strings->get('Description'); ?></h5>
<div>
<?php echo strip_tags($item['text1']); ?>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4">
<h5><i class="fas fa-sticky-note"></i> <?php $Strings->get('Notes'); ?></h5>
<div>
<?php echo strip_tags($item['text2']); ?>
</div>
</div>
<div class="col-12 col-sm-6 col-md-4">
<h5><i class="fas fa-comments"></i> <?php $Strings->get('Comments'); ?></h5>
<div>
<?php echo strip_tags($item['text3']); ?>
</div>
</div>
</div>
<hr />
<div class="row mt-4">
<?php
$images = $database->select('images', ['imageid', 'imagename', 'primary'], ['itemid' => $VARS['id']]);
foreach ($images as $i) {
?>
<div class="col-12 col-sm-6 col-md-4 col-lg-4 col-xl-3">
<div class="card m-2">
<img class="card-img" src="image.php?i=<?php echo $i['imagename']; ?>" alt="<?php echo $i['imagename']; ?>">
<div class="card-img-overlay text-right">
<?php
if ($i['primary']) {
?>
<span class="badge badge-success p-2"><i class="fas fa-star"></i></span>
<?php
}
?>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

2
pages/items.php

@ -14,7 +14,7 @@ redirectifnotloggedin();
</div>
<?php if (isset($_GET['filter']) && $_GET['filter'] == 'stock') { ?>
<script nonce="<?php echo $SECURE_NONCE; ?>">var filter = "stock";</script>
<div class="alert alert-blue-grey"><i class="fa fa-filter fa-fw"></i> <?php $Strings->get("only showing understocked"); ?> &nbsp; <a href="app.php?page=items" class="btn btn-sm btn-blue-grey"><?php $Strings->get("show all items"); ?></a></div>
<div class="alert alert-blue-grey mt-1"><i class="fa fa-filter fa-fw"></i> <?php $Strings->get("only showing understocked"); ?> &nbsp; <a href="app.php?page=items" class="btn btn-sm btn-blue-grey text-light"><?php $Strings->get("show all items"); ?></a></div>
<?php
} else {
echo "<script nonce=\"$SECURE_NONCE\">var filter = null;</script>\n";

2
static/js/items.js

@ -49,7 +49,7 @@ var itemtable = $('#itemtable').DataTable({
json.items.forEach(function (row) {
json.data.push([
"",
"<span class='btn-group-vertical btn-group-sm'>" + row.editbtn + " " + row.clonebtn + "</span>",
"<span class='btn-group-vertical btn-group-sm'>" + row.viewbtn + " " + row.editbtn + "</span>",
row.name,
row.catname,
row.locname + " (" + row.loccode + ")",

Loading…
Cancel
Save