ordersprinter/gastsystem/php/tables.php

101 lines
2.7 KiB
PHP
Raw Normal View History

2020-11-19 23:10:06 +01:00
<?php
require_once 'dbutils.php';
require_once 'config.php';
class Tables {
public static function gettables($pdo) {
$sql = "SELECT value FROM %ossystem% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('resttables'));
if (is_null($result) || (count($result) == 0)) {
return array("status" => "ERROR","msg" => "Keine Tischdefinition hinterlegt.");
}
if (is_null($result[0]["value"])) {
return array("status" => "ERROR","msg" => "Keine Tischdefinition hinterlegt oder Tische für die Gastbestellung nicht eingerichtet.");
}
$tables = json_decode($result[0]["value"], true);
$tablesArr = array();
foreach ($tables as $t) {
$tablesArr[] = array("id" => $t["id"],"name" => $t["name"]);
}
$currency = "";
$decpoint = ".";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('currency'));
if (count($result) > 0) {
$currency = $result[0]["value"];
}
$result = DbUtils::fetchSqlAll($pdo, $sql, array('decpoint'));
if (count($result) > 0) {
$decpoint = $result[0]["value"];
}
return array("status" => "OK","msg" => $tablesArr,"currency" => $currency,"decpoint" => $decpoint, "timeout" => TIMEOUT);
}
public static function checkcodes($pdo,$tableid,$tablecode,$dailycode) {
$tablecode = trim($tablecode);
$dailycode = trim($dailycode);
$sql = "SELECT value FROM %ossystem% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('resttables'));
if (count($result) == 0) {
return array("status" => "ERROR","msg" => "Keine Tischdefinition hinterlegt.");
}
$resttables = $result[0];
$tables = json_decode($resttables["value"], true);
foreach ($tables as $t) {
if ($t["id"] == $tableid) {
if (trim($t["code"]) == $tablecode) {
break;
} else {
return array("status" => "ERROR","msg" => "Falscher Tischcode!");
}
}
}
$sql = "SELECT value FROM %ossystem% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('dailycode'));
if (count($result) == 0) {
return array("status" => "ERROR","msg" => "Keine Tageslosung wurde hinterlegt.");
}
$dailycodeInDb = trim($result[0]["value"]);
if ($dailycode == $dailycodeInDb) {
return array("status" => "OK");
} else {
return array("status" => "ERROR","msg" => "Falsche Tageslosung angegeben!");
}
}
}
if (isset($_GET["command"])) {
$command = $_GET["command"];
$pdo = DbUtils::openDbAndReturnPdoStatic();
switch ($command) {
case "gettables":
$ret = Tables::gettables($pdo);
echo json_encode($ret);
break;
case "checkcodes":
$ret = Tables::checkcodes($pdo,$_POST["tableid"],$_POST["tablecode"],$_POST["dailycode"]);
echo json_encode($ret);
break;
default:
break;
}
}