2020-11-19 23:10:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'php/dbutils.php';
|
|
|
|
require_once 'php/config.php';
|
|
|
|
|
|
|
|
|
|
|
|
class Sync {
|
|
|
|
public static function insertSystemData($pdo,$systemdata) {
|
|
|
|
try {
|
|
|
|
if (!isset($systemdata["guestcode"])) {
|
|
|
|
return array("status" => "ERROR","msg" => "No Access code transmitted!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$transmittedGuestcode = $systemdata["guestcode"];
|
|
|
|
if ($transmittedGuestcode != CODE) {
|
|
|
|
return array("status" => "ERROR","msg" => "Wrong Access code!");
|
|
|
|
}
|
|
|
|
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'timezone');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'dailycode');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'resttables');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'types');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'products');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'currency');
|
|
|
|
self::insertIntoSystemTable($pdo, $systemdata, 'decpoint');
|
|
|
|
|
2020-11-19 23:10:21 +01:00
|
|
|
self::insertIntoSystemTableWithCheck($pdo, $systemdata, 'askdaycode');
|
|
|
|
self::insertIntoSystemTableWithCheck($pdo, $systemdata, 'asktablecode');
|
|
|
|
self::insertIntoSystemTableWithCheck($pdo, $systemdata, 'guesttimeout');
|
|
|
|
|
2020-11-19 23:10:06 +01:00
|
|
|
if (isset($systemdata["timezone"])) {
|
|
|
|
self::updateOsAccessStatus($pdo, $systemdata["timezone"]);
|
|
|
|
}
|
2020-11-19 23:12:37 +01:00
|
|
|
if (isset($systemdata["logo"])) {
|
|
|
|
$logo = $systemdata["logo"];
|
|
|
|
} else {
|
|
|
|
$logo = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
DbUtils::execSql($pdo, "DELETE FROM %images% WHERE name='logo'",null);
|
|
|
|
$sql = "INSERT INTO %images% (name,content,contenttype,productid) VALUES('logo',?,?,?)";
|
|
|
|
DbUtils::execSql($pdo, $sql, array($logo, DbUtils::$TYPE_LOGO,null));
|
2020-11-19 23:10:06 +01:00
|
|
|
|
2020-11-19 23:12:37 +01:00
|
|
|
$sql = "DELETE FROM %images% WHERE contenttype=?";
|
|
|
|
DbUtils::execSql($pdo, $sql, array(DbUtils::$TYPE_PRODIMG));
|
|
|
|
DbUtils::execSql($pdo, "OPTIMIZE TABLE %images%",null);
|
|
|
|
if (isset($systemdata["prodimages"])) {
|
|
|
|
self::insertProdImages($pdo, $systemdata["prodimages"]);
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:10:06 +01:00
|
|
|
return array("status" => "OK");
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
return array("status" => "ERROR","msg" => $ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function insertIntoSystemTable($pdo,$data,$item) {
|
|
|
|
if (isset($data[$item])) {
|
|
|
|
$value = $data[$item];
|
|
|
|
$sql = "UPDATE %ossystem% SET value=? WHERE item=?";
|
|
|
|
DbUtils::execSql($pdo, $sql, array($value,$item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:10:21 +01:00
|
|
|
private static function insertIntoSystemTableWithCheck($pdo,$data,$item) {
|
|
|
|
if (isset($data[$item])) {
|
|
|
|
$sql = "SELECT id FROM %ossystem% WHERE item=?";
|
|
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, array($item));
|
|
|
|
if (count($result) == 0) {
|
|
|
|
$sql = "INSERT INTO %ossystem% (item,value) VALUES(?,?)";
|
|
|
|
DbUtils::execSql($pdo, $sql, array($item,$data[$item]));
|
|
|
|
} else {
|
|
|
|
self::insertIntoSystemTable($pdo, $data, $item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:12:37 +01:00
|
|
|
private static function insertProdImages($pdo,$imagedata) {
|
|
|
|
$sql = "INSERT INTO %images% (name,content,contenttype,productid) VALUES(?,?,?,?)";
|
|
|
|
foreach ($imagedata as $img) {
|
|
|
|
$prodid = $img['prodid'];
|
|
|
|
$imgl = $img['imagedata'];
|
|
|
|
DbUtils::execSql($pdo, $sql, array('',$imgl, DbUtils::$TYPE_PRODIMG,$prodid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 23:10:06 +01:00
|
|
|
private static function updateOsAccessStatus($pdo,$timezone) {
|
|
|
|
date_default_timezone_set($timezone);
|
|
|
|
$date = new DateTime();
|
|
|
|
$currentTimeStamp = $date->getTimestamp();
|
|
|
|
|
|
|
|
$sql = "SELECT id FROM %gueststatus% WHERE item=?";
|
|
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, array('lastosaccess'));
|
|
|
|
if (count($result) == 0) {
|
|
|
|
$sql = "INSERT INTO %gueststatus% (date,item) VALUES(?,?)";
|
|
|
|
} else {
|
|
|
|
$sql = "UPDATE %gueststatus% SET date=? WHERE item=?";
|
|
|
|
}
|
|
|
|
DbUtils::execSql($pdo, $sql, array($currentTimeStamp,'lastosaccess'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fetchQueueData($pdo) {
|
|
|
|
// id | date | tableid | prodid | tablecode | dailycode
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
$sql = "SELECT id,date,tableid,prodid,tablecode,dailycode FROM %queue%";
|
|
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, null);
|
|
|
|
$sql = "DELETE FROM %queue%";
|
|
|
|
DbUtils::execSql($pdo, $sql, null);
|
|
|
|
$pdo->commit();
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_POST["data"])) {
|
|
|
|
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
|
|
|
|
$data = $_POST["data"];
|
|
|
|
|
|
|
|
$utfdata = base64_decode($data);
|
|
|
|
$objFormat = json_decode($utfdata, true);
|
|
|
|
|
|
|
|
$ret = Sync::insertSystemData($pdo,$objFormat);
|
|
|
|
|
|
|
|
if ($ret["status"] != "OK") {
|
|
|
|
echo json_encode($ret);
|
|
|
|
} else {
|
|
|
|
$queuedData = Sync::fetchQueueData($pdo);
|
|
|
|
$ret = array("status" => "OK","msg" => $queuedData);
|
|
|
|
echo json_encode($ret);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "No data transmitted!";
|
|
|
|
}
|