ordersprinter/gastsystem/php/tables.php

110 lines
3.0 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"]);
}
2020-11-19 23:10:21 +01:00
$currency = DbUtils::getConfigItem($pdo, 'currency', "");
$decpoint = DbUtils::getConfigItem($pdo, 'decpoint', ".");
$askdaycode = DbUtils::getConfigItem($pdo, 'askdaycode', 1);
$asktablecode = DbUtils::getConfigItem($pdo, 'asktablecode', 1);
$guesttimeout = DbUtils::getConfigItem($pdo, 'guesttimeout', 5) * 60;
2020-11-19 23:10:06 +01:00
2020-11-19 23:10:21 +01:00
return array("status" => "OK",
"msg" => $tablesArr,
"currency" => $currency,
"decpoint" => $decpoint,
"askdaycode" => $askdaycode,
"asktablecode" => $asktablecode,
"timeout" => $guesttimeout);
2020-11-19 23:10:06 +01:00
}
public static function checkcodes($pdo,$tableid,$tablecode,$dailycode) {
$tablecode = trim($tablecode);
$dailycode = trim($dailycode);
2020-11-19 23:10:21 +01:00
$askdaycode = DbUtils::getConfigItem($pdo, 'askdaycode', 1);
$asktablecode = DbUtils::getConfigItem($pdo, 'asktablecode', 1);
2020-11-19 23:10:06 +01:00
$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.");
}
2020-11-19 23:10:21 +01:00
if ($asktablecode == 1) {
$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!");
}
2020-11-19 23:10:06 +01:00
}
}
}
2020-11-19 23:10:21 +01:00
if ($askdaycode == 1) {
$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!");
}
2020-11-19 23:10:06 +01:00
}
2020-11-19 23:10:21 +01:00
return array("status" => "OK");
2020-11-19 23:10:06 +01:00
}
}
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;
}
}