An easy point of sale system with automatic inventory tracking. https://netsyms.biz/apps/nickelbox/
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * This file contains global settings and utility functions.
  4. */
  5. ob_start(); // allow sending headers after content
  6. // Unicode, solves almost all stupid encoding problems
  7. header('Content-Type: text/html; charset=utf-8');
  8. // l33t $ecurity h4x
  9. header('X-Content-Type-Options: nosniff');
  10. header('X-XSS-Protection: 1; mode=block');
  11. $session_length = 60 * 60; // 1 hour
  12. session_set_cookie_params($session_length, "/", null, false, false);
  13. session_start(); // stick some cookies in it
  14. // renew session cookie
  15. setcookie(session_name(), session_id(), time() + $session_length);
  16. //
  17. // Composer
  18. require __DIR__ . '/vendor/autoload.php';
  19. // Settings file
  20. require __DIR__ . '/settings.php';
  21. // List of alert messages
  22. require __DIR__ . '/lang/messages.php';
  23. // text strings (i18n)
  24. require __DIR__ . '/lang/' . LANGUAGE . ".php";
  25. /**
  26. * Kill off the running process and spit out an error message
  27. * @param string $error error message
  28. */
  29. function sendError($error) {
  30. die("<!DOCTYPE html><html><head><title>Error</title></head><body><h1 style='color: red; font-family: sans-serif; font-size:100%;'>" . htmlspecialchars($error) . "</h1></body></html>");
  31. }
  32. date_default_timezone_set(TIMEZONE);
  33. // Database settings
  34. // Also inits database and stuff
  35. use Medoo\Medoo;
  36. $database;
  37. try {
  38. $database = new Medoo([
  39. 'database_type' => DB_TYPE,
  40. 'database_name' => DB_NAME,
  41. 'server' => DB_SERVER,
  42. 'username' => DB_USER,
  43. 'password' => DB_PASS,
  44. 'charset' => DB_CHARSET
  45. ]);
  46. } catch (Exception $ex) {
  47. //header('HTTP/1.1 500 Internal Server Error');
  48. sendError("Database error. Try again later. $ex");
  49. }
  50. if (!DEBUG) {
  51. error_reporting(0);
  52. } else {
  53. error_reporting(E_ALL);
  54. ini_set('display_errors', 'On');
  55. }
  56. $VARS;
  57. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  58. $VARS = $_POST;
  59. define("GET", false);
  60. } else {
  61. $VARS = $_GET;
  62. define("GET", true);
  63. }
  64. /**
  65. * Checks if a string or whatever is empty.
  66. * @param $str The thingy to check
  67. * @return boolean True if it's empty or whatever.
  68. */
  69. function is_empty($str) {
  70. return (is_null($str) || !isset($str) || $str == '');
  71. }
  72. /**
  73. * I18N string getter. If the key doesn't exist, outputs the key itself.
  74. * @param string $key I18N string key
  75. * @param boolean $echo whether to echo the result or return it (default echo)
  76. */
  77. function lang($key, $echo = true) {
  78. if (array_key_exists($key, STRINGS)) {
  79. $str = STRINGS[$key];
  80. } else {
  81. $str = $key;
  82. }
  83. if ($echo) {
  84. echo $str;
  85. } else {
  86. return $str;
  87. }
  88. }
  89. /**
  90. * I18N string getter (with builder). If the key doesn't exist, outputs the key itself.
  91. * @param string $key I18N string key
  92. * @param array $replace key-value array of replacements.
  93. * If the string value is "hello {abc}" and you give ["abc" => "123"], the
  94. * result will be "hello 123".
  95. * @param boolean $echo whether to echo the result or return it (default echo)
  96. */
  97. function lang2($key, $replace, $echo = true) {
  98. if (array_key_exists($key, STRINGS)) {
  99. $str = STRINGS[$key];
  100. } else {
  101. $str = $key;
  102. }
  103. foreach ($replace as $find => $repl) {
  104. $str = str_replace("{" . $find . "}", $repl, $str);
  105. }
  106. if ($echo) {
  107. echo $str;
  108. } else {
  109. return $str;
  110. }
  111. }
  112. function dieifnotloggedin() {
  113. if ($_SESSION['loggedin'] != true) {
  114. sendError("Session expired. Please log out and log in again.");
  115. }
  116. }
  117. /**
  118. * Check if the previous database action had a problem.
  119. * @param array $specials int=>string array with special response messages for SQL errors
  120. */
  121. function checkDBError($specials = []) {
  122. global $database;
  123. $errors = $database->error();
  124. if (!is_null($errors[1])) {
  125. foreach ($specials as $code => $text) {
  126. if ($errors[1] == $code) {
  127. sendError($text);
  128. }
  129. }
  130. sendError("A database error occurred:<br /><code>" . $errors[2] . "</code>");
  131. }
  132. }
  133. /*
  134. * http://stackoverflow.com/a/20075147
  135. */
  136. if (!function_exists('base_url')) {
  137. function base_url($atRoot = FALSE, $atCore = FALSE, $parse = FALSE) {
  138. if (isset($_SERVER['HTTP_HOST'])) {
  139. $http = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
  140. $hostname = $_SERVER['HTTP_HOST'];
  141. $dir = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
  142. $core = preg_split('@/@', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))), NULL, PREG_SPLIT_NO_EMPTY);
  143. $core = $core[0];
  144. $tmplt = $atRoot ? ($atCore ? "%s://%s/%s/" : "%s://%s/") : ($atCore ? "%s://%s/%s/" : "%s://%s%s");
  145. $end = $atRoot ? ($atCore ? $core : $hostname) : ($atCore ? $core : $dir);
  146. $base_url = sprintf($tmplt, $http, $hostname, $end);
  147. } else
  148. $base_url = 'http://localhost/';
  149. if ($parse) {
  150. $base_url = parse_url($base_url);
  151. if (isset($base_url['path']))
  152. if ($base_url['path'] == '/')
  153. $base_url['path'] = '';
  154. }
  155. return $base_url;
  156. }
  157. }
  158. function redirectIfNotLoggedIn() {
  159. if ($_SESSION['loggedin'] !== TRUE) {
  160. header('Location: ' . URL . '/index.php');
  161. die();
  162. }
  163. }