From cf4bcfc315830dfee54dba50d9832d93f247ac6a Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 17 May 2017 23:09:51 -0600 Subject: [PATCH] App now works. TODO: add edit permissions --- .gitignore | 1 + action.php | 160 +- app.php | 9 +- database.mwb | Bin 0 -> 10234 bytes index.php | 3 +- lang/en_us.php | 43 + lang/messages.php | 54 +- pages.php | 65 +- pages/categories.php | 40 + pages/editcat.php | 68 + pages/edititem.php | 171 ++ pages/editloc.php | 88 + pages/home.php | 41 +- pages/items.php | 85 + pages/locations.php | 51 + static/css/app.css | 7 +- static/css/bootstrap.min.css | 2 +- static/css/datatables.min.css | 21 + static/css/easy-autocomplete.min.css | 11 + static/css/easy-autocomplete.themes.min.css | 11 + static/css/material-color.css | 1951 +++++++++++++++++ static/css/material-color.min.css | 2 + static/css/tables.css | 112 + static/fonts/glyphicons-halflings-regular.eot | Bin 0 -> 20127 bytes static/fonts/glyphicons-halflings-regular.svg | 288 +++ static/fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 45404 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 23424 bytes .../fonts/glyphicons-halflings-regular.woff2 | Bin 0 -> 18028 bytes static/img/up-arrow-black.png | Bin 0 -> 516 bytes static/img/up-arrow-black.svg | 94 + static/img/up-arrow-white.png | Bin 0 -> 538 bytes static/img/up-arrow-white.svg | 94 + static/js/app.js | 18 +- static/js/categories.js | 11 + static/js/datatables.min.js | 256 +++ static/js/editcat.js | 3 + static/js/edititem.js | 80 + static/js/editloc.js | 3 + static/js/items.js | 30 + static/js/jquery.easy-autocomplete.min.js | 10 + static/js/locations.js | 30 + 41 files changed, 3901 insertions(+), 12 deletions(-) create mode 100644 database.mwb create mode 100644 pages/categories.php create mode 100644 pages/editcat.php create mode 100644 pages/edititem.php create mode 100644 pages/editloc.php create mode 100644 pages/items.php create mode 100644 pages/locations.php create mode 100644 static/css/datatables.min.css create mode 100644 static/css/easy-autocomplete.min.css create mode 100644 static/css/easy-autocomplete.themes.min.css create mode 100644 static/css/material-color.css create mode 100644 static/css/material-color.min.css create mode 100644 static/css/tables.css create mode 100644 static/fonts/glyphicons-halflings-regular.eot create mode 100644 static/fonts/glyphicons-halflings-regular.svg create mode 100644 static/fonts/glyphicons-halflings-regular.ttf create mode 100644 static/fonts/glyphicons-halflings-regular.woff create mode 100644 static/fonts/glyphicons-halflings-regular.woff2 create mode 100644 static/img/up-arrow-black.png create mode 100644 static/img/up-arrow-black.svg create mode 100644 static/img/up-arrow-white.png create mode 100644 static/img/up-arrow-white.svg create mode 100644 static/js/categories.js create mode 100644 static/js/datatables.min.js create mode 100644 static/js/editcat.js create mode 100644 static/js/edititem.js create mode 100644 static/js/editloc.js create mode 100644 static/js/items.js create mode 100644 static/js/jquery.easy-autocomplete.min.js create mode 100644 static/js/locations.js diff --git a/.gitignore b/.gitignore index 07fe371..df78ea5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor settings.php nbproject/private +database.mwb.bak *.sync-conflict* \ No newline at end of file diff --git a/action.php b/action.php index f4f4851..08542a1 100644 --- a/action.php +++ b/action.php @@ -3,9 +3,11 @@ /** * Make things happen when buttons are pressed and forms submitted. */ - require_once __DIR__ . "/required.php"; +require_once __DIR__ . "/lib/login.php"; +require_once __DIR__ . "/lib/userinfo.php"; + dieifnotloggedin(); /** @@ -25,6 +27,162 @@ function returnToSender($msg, $arg = "") { } switch ($VARS['action']) { + case "edititem": + $insert = true; + if (is_empty($VARS['itemid'])) { + $insert = true; + } else { + if ($database->has('items', ['itemid' => $VARS['itemid']])) { + $insert = false; + } else { + returnToSender("invalid_itemid"); + } + } + if (is_empty($VARS['name']) || is_empty($VARS['cat']) || is_empty($VARS['loc'])) { + returnToSender('invalid_parameters'); + } + if (is_empty($VARS['qty'])) { + $VARS['qty'] = 1; + } + if (!$database->has('categories', ['catid' => $VARS['cat']])) { + returnToSender('invalid_category'); + } + if (!$database->has('locations', ['locid' => $VARS['loc']])) { + returnToSender('invalid_location'); + } + + if (!is_empty($VARS['assignedto']) && user_exists($VARS['assignedto'])) { + $userid = getUserByUsername($VARS['assignedto'])['uid']; + } else { + $userid = null; + } + + $data = [ + 'name' => $VARS['name'], + 'code1' => $VARS['code1'], + 'code2' => $VARS['code2'], + 'text1' => $VARS['text1'], + 'text2' => $VARS['text2'], + 'text3' => $VARS['text3'], + 'catid' => $VARS['cat'], + 'locid' => $VARS['loc'], + 'qty' => $VARS['qty'], + 'userid' => $userid + ]; + + if ($insert) { + $database->insert('items', $data); + } else { + $database->update('items', $data, ['itemid' => $VARS['itemid']]); + } + + returnToSender("item_saved"); + case "editcat": + $insert = true; + if (is_empty($VARS['catid'])) { + $insert = true; + } else { + if ($database->has('categories', ['catid' => $VARS['catid']])) { + $insert = false; + } else { + returnToSender("invalid_catid"); + } + } + if (is_empty($VARS['name'])) { + returnToSender('invalid_parameters'); + } + + $data = [ + 'catname' => $VARS['name'] + ]; + + if ($insert) { + $database->insert('categories', $data); + } else { + $database->update('categories', $data, ['catid' => $VARS['catid']]); + } + + returnToSender("category_saved"); + case "editloc": + $insert = true; + if (is_empty($VARS['locid'])) { + $insert = true; + } else { + if ($database->has('locations', ['locid' => $VARS['locid']])) { + $insert = false; + } else { + returnToSender("invalid_locid"); + } + } + if (is_empty($VARS['name'])) { + returnToSender('invalid_parameters'); + } + + $data = [ + 'locname' => $VARS['name'], + 'loccode' => $VARS['code'], + 'locinfo' => $VARS['info'] + ]; + + if ($insert) { + $database->insert('locations', $data); + } else { + $database->update('locations', $data, ['locid' => $VARS['locid']]); + } + + returnToSender("location_saved"); + case "deleteitem": + if ($database->has('items', ['itemid' => $VARS['itemid']])) { + $database->delete('items', ['itemid' => $VARS['itemid']]); + returnToSender("item_deleted"); + } + returnToSender("invalid_parameters"); + case "deletecat": + if ($database->has('categories', ['catid' => $VARS['catid']])) { + if ($database->has('items', ['catid' => $VARS['catid']])) { + returnToSender("category_in_use"); + } + $database->delete('categories', ['catid' => $VARS['catid']]); + returnToSender("category_deleted"); + } + returnToSender("invalid_parameters"); + case "deleteloc": + if ($database->has('locations', ['locid' => $VARS['locid']])) { + if ($database->has('items', ['locid' => $VARS['locid']])) { + returnToSender("location_in_use"); + } + $database->delete('locations', ['locid' => $VARS['locid']]); + returnToSender("location_deleted"); + } + returnToSender("invalid_parameters"); + case "autocomplete_category": + exit(json_encode($database->select('categories', ['catid (id)', 'catname (name)'], ['catname[~]' => $VARS['q'], 'LIMIT' => 10]))); + case "autocomplete_location": + exit(json_encode($database->select('locations', ['locid (id)', 'locname (name)'], ["OR" => ['locname[~]' => $VARS['q'], 'loccode' => $VARS['q']], 'LIMIT' => 10]))); + case "autocomplete_user": + header("Content-Type: application/json"); + $client = new GuzzleHttp\Client(); + + $response = $client + ->request('POST', PORTAL_API, [ + 'form_params' => [ + 'key' => PORTAL_KEY, + 'action' => "usersearch", + 'search' => $VARS['q'] + ] + ]); + + if ($response->getStatusCode() != 200) { + exit("[]"); + } + + $resp = json_decode($response->getBody(), TRUE); + if ($resp['status'] == "OK") { + exit(json_encode($resp['result'])); + } else { + exit("[]"); + } + break; case "signout": session_destroy(); header('Location: index.php'); diff --git a/app.php b/app.php index c855a1c..aaecc1b 100644 --- a/app.php +++ b/app.php @@ -30,6 +30,7 @@ if (!is_empty($_GET['page'])) { + -