An easy point of sale system with automatic inventory tracking. https://netsyms.biz/apps/nickelbox/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. require __DIR__ . '/../required.php';
  8. require __DIR__ . '/functions.php';
  9. require __DIR__ . '/apisettings.php';
  10. $VARS = $_GET;
  11. if ($_SERVER['REQUEST_METHOD'] != "GET") {
  12. $VARS = array_merge($VARS, $_POST);
  13. }
  14. $requestbody = file_get_contents('php://input');
  15. $requestjson = json_decode($requestbody, TRUE);
  16. if (json_last_error() == JSON_ERROR_NONE) {
  17. $VARS = array_merge($VARS, $requestjson);
  18. }
  19. // If we're not using the old api.php file, allow more flexible requests
  20. if (strpos($_SERVER['REQUEST_URI'], "/api.php") === FALSE) {
  21. $route = explode("/", substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "api/") + 4));
  22. if (count($route) >= 1) {
  23. $VARS["action"] = $route[0];
  24. }
  25. if (count($route) >= 2 && strpos($route[1], "?") !== 0) {
  26. for ($i = 1; $i < count($route); $i++) {
  27. if (empty($route[$i]) || strpos($route[$i], "=") === false) {
  28. continue;
  29. }
  30. $key = explode("=", $route[$i], 2)[0];
  31. $val = explode("=", $route[$i], 2)[1];
  32. $VARS[$key] = $val;
  33. }
  34. }
  35. if (strpos($route[count($route) - 1], "?") === 0) {
  36. $morevars = explode("&", substr($route[count($route) - 1], 1));
  37. foreach ($morevars as $var) {
  38. $key = explode("=", $var, 2)[0];
  39. $val = explode("=", $var, 2)[1];
  40. $VARS[$key] = $val;
  41. }
  42. }
  43. }
  44. if (!authenticate()) {
  45. header('WWW-Authenticate: Basic realm="' . $SETTINGS['site_title'] . '"');
  46. header('HTTP/1.1 401 Unauthorized');
  47. die("401 Unauthorized: you need to supply valid credentials.");
  48. }
  49. if (empty($VARS['action'])) {
  50. http_response_code(404);
  51. die("404 No action specified");
  52. }
  53. if (!isset($APIS[$VARS['action']])) {
  54. http_response_code(404);
  55. die("404 Action not defined");
  56. }
  57. $APIACTION = $APIS[$VARS["action"]];
  58. if (!file_exists(__DIR__ . "/actions/" . $APIACTION["load"])) {
  59. http_response_code(404);
  60. die("404 Action not found");
  61. }
  62. if (!empty($APIACTION["vars"])) {
  63. checkVars($APIACTION["vars"]);
  64. }
  65. require_once __DIR__ . "/actions/" . $APIACTION["load"];