1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?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/. */
-
- /**
- * Make things happen when buttons are pressed and forms submitted.
- */
- require_once __DIR__ . "/required.php";
-
- if ($VARS['action'] !== "signout") {
- dieifnotloggedin();
- }
-
- /**
- * Redirects back to the page ID in $_POST/$_GET['source'] with the given message ID.
- * The message will be displayed by the app.
- * @param string $msg message ID (see lang/messages.php)
- * @param string $arg If set, replaces "{arg}" in the message string when displayed to the user.
- */
- function returnToSender($msg, $arg = "") {
- global $VARS;
- if ($arg == "") {
- header("Location: app.php?page=" . urlencode($VARS['source']) . "&msg=" . $msg);
- } else {
- header("Location: app.php?page=" . urlencode($VARS['source']) . "&msg=$msg&arg=$arg");
- }
- die();
- }
-
- switch ($VARS['action']) {
- case "itemsearch":
- header("Content-Type: application/json");
- if (!is_empty($VARS['q'])) {
- $where["AND"]["OR"] = [
- "name[~]" => $VARS['q'],
- "code1[~]" => $VARS['q'],
- "code2[~]" => $VARS['q']
- ];
- } else {
- exit(json_encode(["status" => "ERROR", "items" => false]));
- }
-
- $items = $binstack->select('items', [
- 'itemid (id)',
- 'name',
- 'code1',
- 'code2',
- 'cost',
- 'price'
- ], $where);
- $items = (count($items) > 0 ? $items : false);
- exit(json_encode(["status" => "OK", "items" => $items]));
- case "signout":
- session_destroy();
- header('Location: index.php');
- die("Logged out.");
- }
|