ordersprinter/gastsystem/php/tables.php

110 lines
3.0 KiB
PHP

<?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 = 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;
return array("status" => "OK",
"msg" => $tablesArr,
"currency" => $currency,
"decpoint" => $decpoint,
"askdaycode" => $askdaycode,
"asktablecode" => $asktablecode,
"timeout" => $guesttimeout);
}
public static function checkcodes($pdo,$tableid,$tablecode,$dailycode) {
$tablecode = trim($tablecode);
$dailycode = trim($dailycode);
$askdaycode = DbUtils::getConfigItem($pdo, 'askdaycode', 1);
$asktablecode = DbUtils::getConfigItem($pdo, 'asktablecode', 1);
$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.");
}
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!");
}
}
}
}
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!");
}
}
return array("status" => "OK");
}
}
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;
}
}