2020-11-19 23:10:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'dbutils.php';
|
|
|
|
require_once 'config.php';
|
2020-11-19 23:12:39 +01:00
|
|
|
defined('DB') || define ( 'DB','mysql' );
|
2020-11-19 23:10:06 +01:00
|
|
|
|
|
|
|
class Tables {
|
|
|
|
public static function gettables($pdo) {
|
2020-11-19 23:12:39 +01:00
|
|
|
$tables = DbUtils::getConfigItem($pdo, 'resttables', null);
|
2020-11-19 23:10:06 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
if (is_null($tables)) {
|
2020-11-19 23:10:06 +01:00
|
|
|
return array("status" => "ERROR","msg" => "Keine Tischdefinition hinterlegt oder Tische für die Gastbestellung nicht eingerichtet.");
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
$tables = json_decode($tables,true);
|
2020-11-19 23:10:06 +01:00
|
|
|
$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:12:39 +01:00
|
|
|
$dailycodeInDbUntrimmed = DbUtils::getConfigItem($pdo, 'dailycode', null);
|
|
|
|
$dailycodeInDb = null;
|
|
|
|
if (!is_null($dailycodeInDbUntrimmed)) {
|
|
|
|
$dailycodeInDb = trim($dailycodeInDbUntrimmed);
|
|
|
|
}
|
2020-11-19 23:10:21 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
$resttables = DbUtils::getConfigItem($pdo, 'resttables', null);
|
2020-11-19 23:10:06 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
if (is_null($resttables)) {
|
2020-11-19 23:10:06 +01:00
|
|
|
return array("status" => "ERROR","msg" => "Keine Tischdefinition hinterlegt.");
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:10:21 +01:00
|
|
|
if ($asktablecode == 1) {
|
2020-11-19 23:12:39 +01:00
|
|
|
$tables = json_decode($resttables, true);
|
2020-11-19 23:10:21 +01:00
|
|
|
foreach ($tables as $t) {
|
2020-11-19 23:12:39 +01:00
|
|
|
DbUtils::log("CHECKE tid = " . $t["id"] . " mit tableid=" . $tableid);
|
2020-11-19 23:10:21 +01:00
|
|
|
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) {
|
2020-11-19 23:12:39 +01:00
|
|
|
|
|
|
|
if (is_null($dailycodeInDb)) {
|
2020-11-19 23:10:21 +01:00
|
|
|
return array("status" => "ERROR","msg" => "Keine Tageslosung wurde hinterlegt.");
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|