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 {
|
2020-11-19 23:14:02 +01:00
|
|
|
public static function putintoqueue($pdo,$ordertime,$tableid,$tablecode,$dailycode,$orders) {
|
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(?,?,?,?,?)";
|
2020-11-19 23:14:02 +01:00
|
|
|
foreach($orders as $anOrder) {
|
|
|
|
$prodid = $anOrder["prodid"];
|
|
|
|
DbUtils::execSql($pdo, $sql, array($ordertime,$prodid,$tableid,$tablecode,$dailycode));
|
|
|
|
DbUtils::log("Added product with id $prodid to mysql queue table");
|
|
|
|
}
|
2020-11-19 23:14:48 +01:00
|
|
|
$pdo->commit();
|
2020-11-19 23:14:02 +01:00
|
|
|
|
2020-11-19 23:12:39 +01:00
|
|
|
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);
|
|
|
|
}
|
2020-11-19 23:14:02 +01:00
|
|
|
foreach($orders as $anOrder) {
|
|
|
|
$prodid = $anOrder["prodid"];
|
|
|
|
$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");
|
|
|
|
}
|
2020-11-19 23:12:39 +01:00
|
|
|
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":
|
2020-11-19 23:14:02 +01:00
|
|
|
$ret = Queue::putintoqueue($pdo,$_POST["ordertime"],$_POST["tableid"],$_POST["tablecode"],$_POST["dailycode"],$_POST["orders"]);
|
2020-11-19 23:10:06 +01:00
|
|
|
echo json_encode($ret);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|