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:12:37 +01:00
|
|
|
require_once 'ossystem.php';
|
2020-11-19 23:10:06 +01:00
|
|
|
|
|
|
|
class Queue {
|
|
|
|
public static function putintoqueue($pdo,$prodid,$tableid,$tablecode,$dailycode) {
|
2020-11-19 23:12:39 +01:00
|
|
|
$timezone = DbUtils::getConfigItem($pdo, "timezone", "Europe/Berlin");
|
2020-11-19 23:10:06 +01:00
|
|
|
date_default_timezone_set($timezone);
|
|
|
|
$ordertime = date('Y-m-d H:i:s');
|
2020-11-19 23:12:39 +01:00
|
|
|
if (DB == "mysql") {
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
$sql = "INSERT INTO %queue% (date,prodid,tableid,tablecode,dailycode) VALUES(?,?,?,?,?)";
|
|
|
|
DbUtils::execSql($pdo, $sql, array($ordertime,$prodid,$tableid,$tablecode,$dailycode));
|
|
|
|
$pdo->commit();
|
|
|
|
DbUtils::log("Added product with id $prodid to mysql queue table");
|
|
|
|
return array("status" => "OK");
|
|
|
|
} else {
|
|
|
|
$filename = dirname(__FILE__) . '/../db/' . QUEUE_FILE;
|
|
|
|
try {
|
|
|
|
$queueItems = array();
|
|
|
|
if (file_exists($filename)) {
|
|
|
|
$queueItemsFileContent = file_get_contents($filename);
|
|
|
|
$queueItems = json_decode($queueItemsFileContent,true);
|
|
|
|
}
|
|
|
|
$queueItems[] = array("date" => $ordertime,"prodid" => $prodid,"tableid" => $tableid, "tablecode" => $tablecode, "dailycode" => $dailycode);
|
|
|
|
file_put_contents($filename, json_encode($queueItems));
|
|
|
|
DbUtils::log("Add product with id $prodid to file queue");
|
|
|
|
return array("status" => "OK");
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
return array("status" => "ERROR","msg" => $ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
2020-11-19 23:10:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_GET["command"])) {
|
|
|
|
$command = $_GET["command"];
|
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
$pdo = null;
|
|
|
|
if (DB == "mysql") {
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
}
|
2020-11-19 23:10:06 +01:00
|
|
|
|
|
|
|
switch ($command) {
|
|
|
|
case "putintoqueue":
|
|
|
|
$ret = Queue::putintoqueue($pdo,$_POST["prodid"],$_POST["tableid"],$_POST["tablecode"],$_POST["dailycode"]);
|
|
|
|
echo json_encode($ret);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|