ordersprinter/webapp/php/printqueue.php

1279 lines
46 KiB
PHP
Raw Permalink Normal View History

2020-11-19 22:47:44 +01:00
<?php
// Datenbank-Verbindungsparameter
require_once ('config.php');
require_once ('globals.php');
require_once ('dbutils.php');
require_once ('bill.php');
require_once ('closing.php');
2020-11-19 23:03:48 +01:00
require_once ('admin.php');
2020-11-19 22:47:44 +01:00
2020-11-19 23:15:07 +01:00
defined('LAST_REC_TEMPLATE') || define ( 'LAST_REC_TEMPLATE','0' );
defined('NEED_PASS') || define ( 'NEED_PASS',true );
2020-11-19 22:47:44 +01:00
class PrintQueue {
2020-11-19 22:59:47 +01:00
var $dbutils;
2020-11-19 22:47:44 +01:00
var $userrights;
var $admin;
2020-11-19 23:03:20 +01:00
var $instance = null;
2020-11-19 22:47:44 +01:00
2020-11-19 23:03:48 +01:00
private static $FOOD = 1;
private static $DRINK = 2;
private static $RECEIPT = 3;
private static $CLOSING = 4;
public static $CANCELFOOD = 5;
public static $CANCELDRINK = 6;
2020-11-19 23:11:52 +01:00
public static $PICKUP = 7;
2020-11-19 23:10:37 +01:00
public static $FOOD_PRINTSERVER = 0;
public static $DRINK_PRINTSERVER = 1;
2020-11-19 23:03:48 +01:00
2020-11-19 22:59:47 +01:00
function __construct() {
$this->dbutils = new DbUtils();
2020-11-19 22:47:44 +01:00
$this->userrights = new Userrights();
2020-11-19 22:59:47 +01:00
$this->admin = new Admin();
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
function handleCommand($command) {
2020-11-19 22:59:54 +01:00
$fl = null;
if (isset($_GET['fl'])) {
2020-11-19 23:11:47 +01:00
$fl = intval($_GET['fl']);
2020-11-19 22:59:54 +01:00
}
2020-11-19 23:03:20 +01:00
if (isset($_GET['instance'])) {
$this->instance = $_GET['instance'];
}
2020-11-19 23:14:48 +01:00
$printersize = new Printersizes($_GET);
2020-11-19 23:03:20 +01:00
2020-11-19 23:11:44 +01:00
$pass = '';
if (isset($_POST['pass'])) {
$pass = $_POST['pass'];
}
2020-11-19 22:59:47 +01:00
// these command are only allowed for user with waiter rights
2020-11-19 23:14:48 +01:00
if ($command == 'getNextTicketJobs') {
try {
$this->getNextTicketJobs($pass,$printersize,$fl);
} catch (Exception $ex) {
echo $ex->getMessage();
}
} else if ($command == 'getNextReceiptPrintJobs') {
2020-11-19 22:47:44 +01:00
if(isset($_GET['printers'])) {
2020-11-19 23:11:44 +01:00
$this->getNextReceiptPrintJobs($pass,$_GET['language'],$_GET['printers'],$fl);
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:11:44 +01:00
$this->getNextReceiptPrintJobs($pass,$_GET['language'],"1,2,3,4,5,6",$fl);
2020-11-19 22:47:44 +01:00
}
} else if ($command == 'getNextClosingPrintJobs') {
2020-11-19 23:11:44 +01:00
$this->getNextClosingPrintJobs($pass,$_GET['language'],$fl);
2020-11-19 22:47:44 +01:00
} else if ($command == 'getNextFoodWorkPrintJobs') {
if (isset($_GET['printer'])) {
2020-11-19 23:11:44 +01:00
$this->getNextFoodWorkPrintJobs($_GET['printer'],$pass,$fl);
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:11:44 +01:00
$this->getNextFoodWorkPrintJobs(null,$pass,$fl);
2020-11-19 22:47:44 +01:00
}
} else if ($command == 'getNextDrinkWorkPrintJobs') {
if (isset($_GET['printer'])) {
2020-11-19 23:11:44 +01:00
$this->getNextDrinkWorkPrintJobs($_GET['printer'],$pass,$fl);
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:11:44 +01:00
$this->getNextDrinkWorkPrintJobs(null,$pass,$fl);
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:11:52 +01:00
} else if ($command == 'getNextPickupPrintJobs') {
if (isset($_GET['printer'])) {
$this->getNextPickupPrintPrintJobs($_GET['printer'],$pass,$fl);
} else {
$this->getNextPickupPrintPrintJobs(null,$pass,$fl);
}
2020-11-19 23:03:48 +01:00
} else if ($command == 'getNextCancelFoodWorkPrintJobs') {
if (isset($_GET['printer'])) {
2020-11-19 23:11:44 +01:00
$this->getNextCancelFoodWorkPrintJobs($_GET['printer'],$pass,$fl);
2020-11-19 23:03:48 +01:00
} else {
2020-11-19 23:11:44 +01:00
$this->getNextCancelFoodWorkPrintJobs(null,$pass,$fl);
2020-11-19 23:03:48 +01:00
}
} else if ($command == 'getNextCancelDrinkWorkPrintJobs') {
if (isset($_GET['printer'])) {
2020-11-19 23:11:44 +01:00
$this->getNextCancelDrinkWorkPrintJobs($_GET['printer'],$pass,$fl);
2020-11-19 23:03:48 +01:00
} else {
2020-11-19 23:11:44 +01:00
$this->getNextCancelDrinkWorkPrintJobs(null,$pass,$fl);
2020-11-19 23:03:48 +01:00
}
2020-11-19 22:47:44 +01:00
} else if ($command == 'deletePrintJob') {
2020-11-19 23:11:44 +01:00
$this->deletePrintJob($pass,$_POST['id']);
2020-11-19 22:47:44 +01:00
} else if ($command == 'queueReceiptPrintJob') {
2020-11-19 22:59:50 +01:00
if (isset($_POST['useaddrecprinter'])) {
$this->queueReceiptPrintJob($_POST['billid'],$_POST['useaddrecprinter']);
} else {
$this->queueReceiptPrintJob($_POST['billid'],0);
}
2020-11-19 22:47:44 +01:00
} else if ($command == 'queueClosingSummary') {
$this->queueClosingSummary($_GET['closingid']);
} else if ($command == 'testConnection') {
2020-11-19 23:11:44 +01:00
$this->testConnection($pass);
2020-11-19 22:47:44 +01:00
} else if ($command == 'getReceiptConfig') {
2020-11-19 23:11:47 +01:00
$this->getReceiptConfig($fl);
2020-11-19 23:14:48 +01:00
} else if ($command == 'getTicketPng') {
$this->getTicketPng($_GET["imgtype"],$_GET["addinfo"]);
2020-11-19 22:47:44 +01:00
} else if ($command == 'getLogoAsPng') {
$this->getLogoAsPng();
2020-11-19 23:12:39 +01:00
} else if ($command == 'getLogoAsPngWithAlphaChannel') {
$this->getLogoAsPngWithAlphaChannel();
2020-11-19 22:47:44 +01:00
} else if ($command == 'getLogoAsWbmp') {
$this->getLogoAsWbmp();
} else if ($command == 'getPrintJobOverview') {
2020-11-19 22:59:47 +01:00
$pdo = DbUtils::openDbAndReturnPdoStatic();
$this->getPrintJobOverview($pdo);
} else if ($command == 'clearprintjobs') {
$pdo = DbUtils::openDbAndReturnPdoStatic();
$this->clearprintjobs($pdo);
} else if ($command == 'batchReceiptPrintJob') {
$this->batchReceiptPrintJob($_POST['start'],$_POST['end']);
2020-11-19 23:00:18 +01:00
} else if ($command == 'getLastLog') {
2020-11-19 23:11:44 +01:00
$this->getLastLog($pass);
2020-11-19 23:02:16 +01:00
} else if ($command == 'deleteSpooledPrintJob') {
$this->deleteSpooledPrintJob($_POST['id']);
2020-11-19 23:03:48 +01:00
} else if ($command == 'reprintworkreceipt') {
2020-11-19 23:15:07 +01:00
$this->reprintworkreceipt($_GET["id"]);
2020-11-19 22:47:44 +01:00
} else {
echo "Kommando nicht erkannt!";
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:03:20 +01:00
private function checkForPrinterInstance($pdo,$rectype) {
if (!is_null($this->instance)) {
$assignedInstance = CommonUtils::getConfigValue($pdo, $rectype . "prinstance", 1);
if ($this->instance == $assignedInstance) {
return true;
} else {
return false;
}
} else {
return true;
}
}
2020-11-19 22:59:57 +01:00
private function saveLastPrintServerAccess($pdo) {
2020-11-19 23:12:59 +01:00
date_default_timezone_set(DbUtils::getTimeZoneDb($pdo));
2020-11-19 22:59:57 +01:00
$date = new DateTime();
$unixTimeStamp = $date->getTimestamp();
$sql = "SELECT count(id) as countid FROM %work% WHERE item=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('lastprtserveraccess'));
$row = $stmt->fetchObject();
if ($row->countid == 0) {
$sql = "INSERT INTO %work% (item,value,signature) VALUES(?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('lastprtserveraccess',$unixTimeStamp,null));
} else {
$sql = "UPDATE %work% SET value=? WHERE item=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($unixTimeStamp,'lastprtserveraccess'));
}
}
2020-11-19 22:47:44 +01:00
function testConnection($md5pass) {
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Type: text/html; charset=utf8" );
2020-11-19 23:00:18 +01:00
$isCorrect = $this->isPasswordCorrect(null,$md5pass,true);
2020-11-19 22:47:44 +01:00
if ($isCorrect) {
echo "ok";
} else {
// Output from isPasswordCorrect method already
// echo " - false -";
}
}
/*
* Insert a "work" (food or drink) job into the printjob queue. The POS Print Server will
* pick these jobs and delete them after successful printing
*/
2020-11-19 23:14:48 +01:00
public static function queueWorkPrintJob($pdo,$table,$timestamp,$prods,$kind,$printer,$username,$userid,$isTogo) {
2020-11-19 23:03:48 +01:00
$workId = Workreceipts::getNextWorkReceiptId($pdo);
2020-11-19 22:47:44 +01:00
$table .= " ($username)";
2020-11-19 23:14:48 +01:00
$content = json_encode(array("workid" => $workId,"table" => $table, "userid" => $userid, "time" => $timestamp, "products" => $prods));
2020-11-19 22:47:44 +01:00
2020-11-19 23:11:52 +01:00
$printInsertSql = "INSERT INTO `%printjobs%` (`content`,`type`,`printer`) VALUES (?,?,?)";
CommonUtils::execSql($pdo, $printInsertSql, array($content,intval($kind) + 1,$printer));
2020-11-19 23:00:18 +01:00
$idOfWorkJob = $pdo->lastInsertId();
2020-11-19 23:03:48 +01:00
$sql = "UPDATE %queue% SET printjobid=? WHERE id=?";
foreach($prods as $aProd) {
$queueid = $aProd["id"];
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($idOfWorkJob,$queueid));
2020-11-19 23:10:37 +01:00
if (isset($aProd["allqueueids"])) {
foreach($aProd["allqueueids"] as $aQueueId) {
$stmt->execute(array($idOfWorkJob,$aQueueId));
}
}
2020-11-19 23:03:48 +01:00
}
2020-11-19 23:10:37 +01:00
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"QUEUE","Create work job with id=$idOfWorkJob for tableid $table from user $username of kind $kind for printer=$printer");
2020-11-19 23:11:52 +01:00
2020-11-19 23:11:54 +01:00
$printAPickupReceipt = false;
2020-11-19 23:11:52 +01:00
$printpickups = CommonUtils::getConfigValue($pdo, "printpickups", 0);
if ($printpickups == 1) {
2020-11-19 23:11:54 +01:00
$printAPickupReceipt = true;
} else if ($printpickups == 2) {
if ($isTogo) {
$printAPickupReceipt = true;
}
}
if ($printAPickupReceipt) {
2020-11-19 23:11:52 +01:00
$sql = "INSERT INTO `%printjobs%` (`content`,`type`,`printer`) VALUES (?,?,?)";
CommonUtils::execSql($pdo, $sql, array($content,self::$PICKUP,1));
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
function getPrintJobOverview($pdo) {
2020-11-19 22:47:44 +01:00
if (!($this->userrights->hasCurrentUserRight('right_manager')) &&
!($this->userrights->hasCurrentUserRight('is_admin'))
) {
echo json_encode(array("status" => "ERROR", "code" => ERROR_DB_PRIVS_MISSING, "msg" => ERROR_DB_PRIVS_MISSING_MSG));
return;
}
$jobs = array();
for ($printer=1;$printer<7;$printer++) {
2020-11-19 23:12:24 +01:00
$sql = "SELECT J.id as id,B.id as billid,billdate,brutto,";
$sql .= "CASE ";
$sql .= " WHEN tableid='-1' THEN '---' ";
$sql .= " WHEN tableid='0' THEN 'To-Go' ";
$sql .= " ELSE (SELECT tableno FROM %resttables% WHERE id=B.tableid) ";
$sql .= "END as tablename,";
$sql .= "type FROM %printjobs% J,%bill% B WHERE printer=? AND type=? AND content=B.id ";
$resultBills = CommonUtils::fetchSqlAll($pdo, $sql, array($printer,self::$RECEIPT));
2020-11-19 23:11:52 +01:00
$sql = "SELECT %printjobs%.id as id,%closing%.id as closingid,type,closingdate FROM %printjobs%,%closing% WHERE printer=? AND type = '" . self::$CLOSING . "' AND content=%closing%.id";
2020-11-19 23:02:57 +01:00
$resultClosings = CommonUtils::fetchSqlAll($pdo, $sql, array($printer));
$result = array_merge($resultBills,$resultClosings);
2020-11-19 23:02:16 +01:00
$jobs[] = array("printer" => $printer, "count" => count($result),"jobs" => $result);
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:03:48 +01:00
$sql = "SELECT %printjobs%.id as id,content FROM %printjobs% WHERE type=? AND removed is null";
2020-11-19 22:47:44 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:03:48 +01:00
$stmt->execute(array(self::$FOOD));
2020-11-19 23:02:16 +01:00
$result = $stmt->fetchAll();
$works = array();
foreach($result as $r) {
$works[] = array("id" => $r['id'],"content" => json_decode($r['content']));
}
$jobs[] = array("printer" => 7, "count" => count($result),"jobs" => $works);
2020-11-19 23:03:48 +01:00
$stmt->execute(array(self::$DRINK));
2020-11-19 23:02:16 +01:00
$result = $stmt->fetchAll();
$works = array();
foreach($result as $r) {
$works[] = array("id" => $r['id'],"content" => json_decode($r['content']));
}
$jobs[] = array("printer" => 8, "count" => count($result),"jobs" => $works);
2020-11-19 23:11:52 +01:00
$stmt->execute(array(self::$PICKUP));
$result = $stmt->fetchAll();
$works = array();
foreach($result as $r) {
$works[] = array("id" => $r['id'],"content" => json_decode($r['content']));
}
$jobs[] = array("printer" => 9, "count" => count($result),"jobs" => $works);
2020-11-19 22:47:44 +01:00
2020-11-19 23:03:48 +01:00
2020-11-19 23:14:04 +01:00
$sql = "SELECT %printjobs%.id as id,content FROM %printjobs% WHERE removed is not null";
$printedWorkReceips = CommonUtils::fetchSqlAll($pdo, $sql);
$printedWorkReceiptsInJson = array();
foreach ($printedWorkReceips as $printedWorkReceipt) {
2020-11-19 23:15:07 +01:00
$printjobentry = array("id" => $printedWorkReceipt['id'],"content" => json_decode($printedWorkReceipt['content']));
$printedWorkReceiptsInJson[] = $printjobentry;
2020-11-19 23:14:04 +01:00
}
echo json_encode(array("status" => "OK", "msg" => $jobs, "printedworkreceips" => $printedWorkReceiptsInJson));
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:47 +01:00
function clearprintjobs($pdo) {
if (!($this->userrights->hasCurrentUserRight('right_manager')) &&
!($this->userrights->hasCurrentUserRight('is_admin'))
) {
echo json_encode(array("status" => "ERROR", "code" => ERROR_DB_PRIVS_MISSING, "msg" => ERROR_DB_PRIVS_MISSING_MSG));
return;
}
2020-11-19 23:03:48 +01:00
$sql = "DELETE FROM %printjobs% WHERE (type <> ?) AND (type <> ?)";
CommonUtils::execSql($pdo, $sql, array(self::$FOOD,self::$DRINK));
$sql = "UPDATE %printjobs% SET removed=? WHERE (type = ?) OR (type = ?)";
CommonUtils::execSql($pdo, $sql, array(1,self::$FOOD,self::$DRINK));
2020-11-19 22:59:47 +01:00
$this->getPrintJobOverview($pdo);
}
function batchReceiptPrintJob($start,$end) {
try {
$start = intval($start);
$end = intval($end);
} catch (Exception $ex) {
echo json_encode(array("status" => "ERROR", "code" => NUMBERFORMAT_ERROR, "msg" => NUMBERFORMAT_ERROR_MSG));
return;
}
if(!($this->userrights->hasCurrentUserRight('right_bill'))) {
echo json_encode(array("status" => "ERROR", "code" => ERROR_BILL_NOT_AUTHOTRIZED, "msg" => ERROR_BILL_NOT_AUTHOTRIZED_MSG));
} else {
if ($start > $end) {
$tmp = $end;
$end = $start;
$start = $tmp;
}
if(session_id() == '') {
session_start();
}
$printer = $_SESSION['receiptprinter'];
$pdo = DbUtils::openDbAndReturnPdoStatic();
for($jobId=$start;$jobId <= $end;$jobId++) {
$sql = "SELECT count(id) as countid FROM %bill% WHERE id=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($jobId));
$row =$stmt->fetchObject();
if ($row->countid == 1) {
$printInsertSql = "INSERT INTO `%printjobs%` (`id` , `content`,`type`,`printer`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($printInsertSql));
2020-11-19 23:14:10 +01:00
$stmt->execute(array($jobId,self::$RECEIPT,$printer));
2020-11-19 22:59:47 +01:00
}
}
echo json_encode(array("status" => "OK"));
}
}
2020-11-19 23:03:48 +01:00
function checkForUserRightManagerAdmin() {
2020-11-19 23:02:16 +01:00
if (!($this->userrights->hasCurrentUserRight('right_manager')) &&
!($this->userrights->hasCurrentUserRight('is_admin'))
) {
echo "Benutzerrechte nicht ausreichend!";
return false;
2020-11-19 23:03:48 +01:00
} else {
return true;
}
}
2020-11-19 23:15:07 +01:00
function reprintworkreceipt($printjobid) {
2020-11-19 23:03:48 +01:00
if ($this->checkForUserRightManagerAdmin()) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
2020-11-19 23:15:07 +01:00
$sql = "UPDATE %printjobs% SET removed=? WHERE id=?";
CommonUtils::execSql($pdo, $sql, array(null,$printjobid));
echo json_encode(array("status" => "OK"));
2020-11-19 23:03:48 +01:00
}
}
function deleteSpooledPrintJob($printjobid) {
if ($this->checkForUserRightManagerAdmin()) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
$sql = "DELETE FROM %printjobs% WHERE id=?";
CommonUtils::execSql($pdo, $sql, array($printjobid));
echo json_encode(array("status" => "OK"));
2020-11-19 23:02:16 +01:00
}
}
2020-11-19 23:12:18 +01:00
public static function internalQueueReceiptPrintjob($pdo,$billid,$recprinter) {
try {
2020-11-19 23:14:02 +01:00
CommonUtils::log($pdo, "PRINTQUEUE", "Insert bill with id=$billid for printer=$recprinter into queue.");
2020-11-19 23:12:18 +01:00
$printInsertSql = "INSERT INTO `%printjobs%` (`content`,`type`,`printer`) VALUES (?,?,?)";
CommonUtils::execSql($pdo, $printInsertSql, array((string)($billid),self::$RECEIPT,$recprinter));
2020-11-19 23:14:02 +01:00
$addPrinter = CommonUtils::getConfigValue($pdo, 'addreceipttoprinter', null);
if (!is_null($addPrinter)) {
CommonUtils::execSql($pdo, $printInsertSql, array((string)($billid),self::$RECEIPT,$addPrinter));
}
2020-11-19 23:12:18 +01:00
} catch (Exception $ex) {
return array("status" => "ERROR","msg" => $ex->getMessage());
}
return array("status" => "OK");
}
2020-11-19 22:59:50 +01:00
function queueReceiptPrintJob($billid,$useaddrecprinter) {
2020-11-19 22:47:44 +01:00
// waiter, or manager, bill, admin rights required
if (!($this->userrights->hasCurrentUserRight('right_paydesk')) &&
!($this->userrights->hasCurrentUserRight('right_manager')) &&
!($this->userrights->hasCurrentUserRight('right_bill')) &&
!($this->userrights->hasCurrentUserRight('right_waiter')) &&
!($this->userrights->hasCurrentUserRight('is_admin'))
) {
echo "Benutzerrechte nicht ausreichend!";
return false;
} else {
// PAY_PRINT_TYPE = 3 means printing as paydesk print -> choose the printer
// (print type is misused also for selection of printer)
if(session_id() == '') {
session_start();
}
$printer = $_SESSION['receiptprinter'];
// now get receipt info from bill table
2020-11-19 23:12:43 +01:00
$pdo = DbUtils::openDbAndReturnPdoStatic();
$doubleReceipt = CommonUtils::getConfigValue($pdo, 'doublereceipt', 0);
$isBillPaidByCard = Bill::isBillPaidByCard($pdo,$billid);
$noOfInsert = 1;
if ($isBillPaidByCard && ($doubleReceipt == 1)) {
$noOfInsert = 2;
}
CommonUtils::log($pdo, "PRINTQUEUE", "Insert bill $noOfInsert x with id=$billid for printer=$printer into queue.");
2020-11-19 23:00:18 +01:00
2020-11-19 22:59:50 +01:00
$sql = "SELECT setting FROM %config% WHERE name=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array("addreceipttoprinter"));
$row = $stmt->fetchObject();
$addprinter = $row->setting;
2020-11-19 22:47:44 +01:00
$printInsertSql = "INSERT INTO `%printjobs%` (`id` , `content`,`type`,`printer`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($printInsertSql));
2020-11-19 23:12:43 +01:00
for ($times=0;$times < $noOfInsert; $times++) {
$stmt->execute(array((string)($billid),self::$RECEIPT,$printer));
}
2020-11-19 22:59:50 +01:00
2020-11-19 23:00:09 +01:00
if (!is_null($addprinter) && ($addprinter != "") && ($useaddrecprinter == 1)) {
2020-11-19 23:03:48 +01:00
$stmt->execute(array((string)($billid),self::$RECEIPT,$addprinter));
2020-11-19 22:59:50 +01:00
}
2020-11-19 22:47:44 +01:00
echo json_encode("OK");
}
}
public function queueClosingSummary($closingid) {
if (!($this->userrights->hasCurrentUserRight('right_paydesk')) &&
!($this->userrights->hasCurrentUserRight('right_manager')) &&
!($this->userrights->hasCurrentUserRight('right_bill')) &&
2020-11-19 22:59:47 +01:00
!($this->userrights->hasCurrentUserRight('right_closing')) &&
2020-11-19 22:47:44 +01:00
!($this->userrights->hasCurrentUserRight('right_waiter')) &&
!($this->userrights->hasCurrentUserRight('is_admin'))
) {
echo "Benutzerrechte nicht ausreichend!";
return false;
} else {
if(session_id() == '') {
session_start();
}
$printer = $_SESSION['receiptprinter'];
$pdo = $this->dbutils->openDbAndReturnPdo();
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo, "PRINTQUEUE", "Insert closing with id=$closingid for printer=$printer into queue.");
2020-11-19 22:47:44 +01:00
$printInsertSql = "INSERT INTO `%printjobs%` (`id` , `content`,`type`,`printer`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($printInsertSql));
2020-11-19 23:03:48 +01:00
$stmt->execute(array((string)($closingid),self::$CLOSING,$printer));
2020-11-19 22:47:44 +01:00
echo json_encode("OK");
}
}
2020-11-19 22:48:24 +01:00
function getBigFontWorkReceiptSetting($pdo) {
$sql = "SELECT setting FROM %config% WHERE name=?";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array("bigfontworkreceipt"));
$row =$stmt->fetchObject();
return $row->setting;
}
2020-11-19 23:00:18 +01:00
function isPasswordCorrect($pdo,$pass,$verbose) {
if (is_null($pdo)) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
}
2020-11-19 22:59:47 +01:00
$sql = "SELECT setting FROM %config% WHERE name=?";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array("printpass"));
$row =$stmt->fetchObject();
if ($row != null) {
$passInDb = $row->setting;
2020-11-19 22:47:44 +01:00
if ($passInDb != null) {
// plain comparison
if ($pass == $passInDb) {
return true;
} else {
if ($verbose) {
echo "Error: Falscher Printpass!";
}
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
} else {
if ($verbose) {
echo "Error: kein Printpass in DB gesetzt!";
}
2020-11-19 22:59:47 +01:00
}
2020-11-19 22:47:44 +01:00
}
if ($verbose) {
echo "Error: DB konnte nicht abgefragt werden!";
}
return false;
}
2020-11-19 23:14:48 +01:00
private function getTicketPng($imgtype,$addinfo) {
if ($imgtype == 1) {
$this->getLogoAsPng();
} else if ($imgtype == 2) {
Bill::outputBillQrCode($addinfo);
} else if ($imgtype == 3) {
Admin::getwaiterphotoforprint($addinfo);
}
2020-11-19 23:12:37 +01:00
}
2020-11-19 22:47:44 +01:00
function getLogoAsPng() {
2020-11-19 23:12:39 +01:00
$this->getLogoAsPngCore(false);
}
function getLogoAsPngWithAlphaChannel() {
$this->getLogoAsPngCore(true);
}
function getLogoAsPngCore($saveAlphaChannel) {
2020-11-19 23:12:37 +01:00
$sendEmptyImageInsteadOfNone = false;
if (isset($_GET["style"])) {
if ($_GET["style"] == "always") {
$sendEmptyImageInsteadOfNone = true;
}
}
$pdo = DbUtils::openDbAndReturnPdoStatic();
2020-11-19 22:47:44 +01:00
2020-11-19 23:12:37 +01:00
//header("Content-Disposition: attachment; filename=logo.png");
2020-11-19 22:47:44 +01:00
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_PNG));
$sql = "SELECT setting from %logo% WHERE name=?";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array('logoimg'));
$row = $stmt->fetchObject();
if ($stmt->rowCount() > 0) {
$img = $row->setting;
2020-11-19 23:12:37 +01:00
if (is_null($img)) {
if ($sendEmptyImageInsteadOfNone) {
2020-11-19 23:14:48 +01:00
CommonUtils::outputEmptyImage();
2020-11-19 23:12:37 +01:00
}
} else {
2020-11-19 23:12:39 +01:00
$php_img = imagecreatefromstring($img);
$colorAlpha = null;
2020-11-19 23:12:37 +01:00
imagesavealpha($php_img, true);
2020-11-19 23:12:39 +01:00
if ($saveAlphaChannel) {
$colorAlpha = imagecolorallocatealpha($php_img, 0, 0, 0, 127);
imagepng($php_img, NULL);
imagecolordeallocate($php_img,$colorAlpha);
} else {
$width = imagesx($php_img);
$height = imagesy($php_img);
$bgImg = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($bgImg, 255, 255, 255);
imagefill($bgImg, 0, 0, $white);
imagecopyresampled(
$bgImg, $php_img,
0, 0, 0, 0,
$width, $height,
$width, $height);
imagepng($bgImg, NULL);
imagecolordeallocate($bgImg,$white);
imagedestroy($bgImg);
}
2020-11-19 23:12:37 +01:00
imagedestroy($php_img);
2020-11-19 23:12:39 +01:00
}
2020-11-19 23:12:37 +01:00
} else {
if ($sendEmptyImageInsteadOfNone) {
2020-11-19 23:14:48 +01:00
CommonUtils::outputEmptyImage();
2020-11-19 23:12:37 +01:00
}
2020-11-19 22:47:44 +01:00
}
}
function getLogoAsWbmp() {
$pdo = $this->dbutils->openDbAndReturnPdo();
$genInfo = $this->admin->getGeneralConfigItems(false,$pdo);
header("Content-Disposition: attachment; filename=logo.wbmp");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
$logourl = $genInfo["logourl"];
$img = file_get_contents("../" . $logourl);
$php_img = imagecreatefromstring($img);
$foreground_color = imagecolorallocate($im, 255, 0, 0);
imagewbmp($php_img, NULL, $foreground_color);
imagedestroy($php_img);
}
2020-11-19 23:11:47 +01:00
function getReceiptConfig($fl = null) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
2020-11-19 22:47:44 +01:00
2020-11-19 23:11:47 +01:00
$decpoint = CommonUtils::getConfigValue($pdo, "decpoint", ",");
$billlanguage = CommonUtils::getConfigValue($pdo, "billlanguage", 0);
$version = CommonUtils::getConfigValue($pdo, "version", "0");
$currency = CommonUtils::getConfigValue($pdo, "currency", "Euro");
$companyinfo = CommonUtils::getConfigValue($pdo, "companyinfo", "");
$retArray = array("decpoint" => $decpoint,
"billlanguage" => $billlanguage,
"version" => $version,
"currency" => $currency,
"companyinfo" => $companyinfo
2020-11-19 22:47:44 +01:00
);
2020-11-19 23:11:47 +01:00
if (!is_null($fl) && ($fl >= 12)) {
$retArray["pollbills"] = CommonUtils::getConfigValue($pdo, "pollbills", 2);
$retArray["pollworksf"] = CommonUtils::getConfigValue($pdo, "pollworksf", 2);
$retArray["pollworksd"] = CommonUtils::getConfigValue($pdo, "pollworksd", 2);
$retArray["pollclosings"] = CommonUtils::getConfigValue($pdo, "pollclosings", 2);
}
2020-11-19 23:11:52 +01:00
if (!is_null($fl) && ($fl >= 13)) {
$retArray["pollpickups"] = CommonUtils::getConfigValue($pdo, "pollpickups", 2);
}
2020-11-19 22:47:44 +01:00
echo json_encode($retArray);
}
2020-11-19 23:00:05 +01:00
function getNextClosingPrintJobs($md5pass,$language,$fl=0) {
2020-11-19 23:00:18 +01:00
$pdo = $this->dbutils->openDbAndReturnPdo();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
2020-11-19 22:47:44 +01:00
if ($isCorrect) {
ob_start();
2020-11-19 23:00:18 +01:00
2020-11-19 22:59:57 +01:00
$this->saveLastPrintServerAccess($pdo);
2020-11-19 22:47:44 +01:00
$closing = new Closing();
$sql = "SELECT id,content,type,printer FROM %printjobs% WHERE type=? ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array(4));
$result = $stmt->fetchAll();
$closingarray = array();
foreach($result as $aClos) {
$jobid = $aClos['id'];
$closid = $aClos["content"];
$printer = $aClos["printer"];
2020-11-19 23:02:57 +01:00
2020-11-19 23:03:20 +01:00
if (!is_null($this->instance)) {
if (!$this->checkForPrinterInstance($pdo, "k" . $printer)) {
continue;
}
}
2020-11-19 23:14:48 +01:00
$theClosing = $closing->getClosingSummaryWoSign($closid, $pdo, false,false,$fl);
2020-11-19 22:47:44 +01:00
$aClosing = array("id" => $jobid,"closing" => $theClosing, "printer" => $printer);
$closingarray[] = $aClosing;
}
echo json_encode($closingarray);
ob_end_flush();
} else {
echo json_encode(array());
}
}
2020-11-19 23:14:10 +01:00
function getTemplate($pdo,$templatekey,$closingid) {
return CommonUtils::getConfigValueAtClosingTime($pdo, $templatekey, "", $closingid);
2020-11-19 22:59:54 +01:00
}
2020-11-19 23:00:18 +01:00
function getLastLog ($md5pass) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
2020-11-19 23:12:59 +01:00
if ($isCorrect) {
2020-11-19 23:00:18 +01:00
echo json_encode(CommonUtils::getLastLog($pdo));
} else {
echo json_encode("Log file from server unavaible due to wrong printcode");
}
}
2020-11-19 23:14:48 +01:00
private function getNextClosingTicketJobs($pdo,$printersizes) {
$closing = new Closing();
$sqlreceiptprinters = "select substring(name,2,1) as printer from %config% where name like 'k%prinstance' AND setting=?";
$billsql = "select J.id as jobid, content, printer from %printjobs% J left join %bill% B ON J.content=B.id where type=? and printer in ($sqlreceiptprinters)";
$result = CommonUtils::fetchSqlAll($pdo, $billsql, array(self::$CLOSING,$this->instance));
$tickets = array();
foreach ($result as $r) {
$jobid = $r['jobid'];
$closid = $r["content"];
$printer = $r["printer"];
$theClosing = $closing->getClosingSummaryWoSign($closid, $pdo, false,true,16);
$template = $theClosing["template"];
$osversion = $theClosing["version"];
$label = DbUtils::$OSLABEL . "-" . DbUtils::$OSVERSLABEL;
$line = "\n{TAB:}\n{-:links:$label $osversion}\n";
$template .= $line;
$printersize = $printersizes->getPrinterSize(Printersizes::$JOBTYPE_RECEIPT,$printer);
$aTicket = Layouter::layoutTicket($template, array($theClosing),$printersize);
$tickets[] = array(
"id" => $jobid,
"tickettype" => "C",
"printer" => $r["printer"],
"entries" => $aTicket["printer"]);
}
return $tickets;
}
private function getNextReceiptTicketJobs($pdo,$printersizes) {
$bill = new Bill();
$sqlreceiptprinters = "select substring(name,2,1) as printer from %config% where name like 'k%prinstance' AND setting=?";
$billsql = "select J.id as jobid, content, printer from %printjobs% J left join %bill% B ON J.content=B.id where type=? and printer in ($sqlreceiptprinters)";
$result = CommonUtils::fetchSqlAll($pdo, $billsql, array(self::$RECEIPT,$this->instance));
$tickets = array();
foreach ($result as $r) {
$aBill = $bill->getBillWithIdAsTicket($pdo, $r["content"]);
$template = $aBill["template"];
2020-11-19 23:15:07 +01:00
if (LAST_REC_TEMPLATE == 1) {
$template = CommonUtils::getConfigValue($pdo, "rectemplate", $template);
}
2020-11-19 23:14:48 +01:00
$osversion = $aBill["version"];
$printer = $r["printer"];
$label = DbUtils::$OSLABEL . "-" . DbUtils::$OSVERSLABEL;
$line = "\n{TAB:}\n{-:links:$label $osversion}\n";
$template .= $line;
$printersize = $printersizes->getPrinterSize(Printersizes::$JOBTYPE_RECEIPT,$printer);
$aTicket = Layouter::layoutTicket($template, array($aBill),$printersize);
$tickets[] = array(
"id" => $r["jobid"],
"tickettype" => "R",
"printer" => $r["printer"],
"entries" => $aTicket["printer"]);
}
return $tickets;
}
private function getNextWorkTicketJobs($pdo,$printersizes,$workJobType) {
$templatekey = "foodtemplate";
$theType = self::$FOOD;
if ($workJobType === 'd') {
$templatekey = "drinktemplate";
$theType = self::$DRINK;
}
$template = $this->getTemplate($pdo, $templatekey,null);
$sqlworkprinters = "select substring(name,2,1) as printer from %config% where name like '$workJobType%prinstance' AND setting=?";
$workjobssql = "select J.id as jobid, content, printer from %printjobs% J where type=? and printer in ($sqlworkprinters) AND removed is null ORDER BY id";
$workJobsResult = CommonUtils::fetchSqlAll($pdo, $workjobssql, array($theType,$this->instance));
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: retrieve " . count($workJobsResult) . " jobs");
$tickets = $this->getWorkTicketsCore($pdo,$template,$printersizes,$workJobsResult,strtoupper($workJobType),'getNextWorkPrintJobs');
return $tickets;
}
private function getNextCancelTicketJobs($pdo,$printersizes,$workJobType) {
$theType = self::$CANCELFOOD;
if ($workJobType === 'd') {
$theType = self::$CANCELDRINK;
}
$template = $this->getTemplate($pdo, 'canceltemplate',null);
$sqlworkprinters = "select substring(name,2,1) as printer from %config% where name like '$workJobType%prinstance' AND setting=?";
$workjobssql = "select J.id as jobid, content, printer from %printjobs% J where type=? and printer in ($sqlworkprinters) AND removed is null ORDER BY id";
$workJobsResult = CommonUtils::fetchSqlAll($pdo, $workjobssql, array($theType,$this->instance));
CommonUtils::log($pdo,"PRINTQUEUE", "getNextCancelPrintJobs: retrieve " . count($workJobsResult) . " jobs");
$tickets = $this->getWorkTicketsCore($pdo,$template,$printersizes,$workJobsResult,"C" . strtoupper($workJobType),'getNextCancelPrintJobs');
return $tickets;
}
private function getNextPickupTicketJobs($pdo,$printersizes) {
$template = $this->getTemplate($pdo, 'pickuptemplate',null);
$theType = self::$PICKUP;
$sqlworkprinters = "select substring(name,2,1) as printer from %config% where name like 'p%prinstance' AND setting=?";
$workjobssql = "select J.id as jobid, content, printer from %printjobs% J where type=? and printer in ($sqlworkprinters) AND removed is null ORDER BY id";
$workJobsResult = CommonUtils::fetchSqlAll($pdo, $workjobssql, array($theType,$this->instance));
CommonUtils::log($pdo,"PRINTQUEUE", "getNextpickupPrintJobs: retrieve " . count($workJobsResult) . " jobs");
$tickets = $this->getWorkTicketsCore($pdo,$template,$printersizes,$workJobsResult,'P','getNextPickupPrintJobs');
return $tickets;
}
private function getWorkTicketsCore($pdo,$template,$printersizes,$workJobs,$workJobType,$msgLabel) {
$jobPrinterType = Printersizes::$JOBTYPE_FOOD;
if (strtolower($workJobType) === 'd') {
$jobPrinterType = Printersizes::$JOBTYPE_DRINK;
} else if (strtolower($workJobType) === 'p') {
$jobPrinterType = Printersizes::$JOBTYPE_PICKUP;
}
$tickets = array();
foreach($workJobs as $aWorkJob) {
$aWorkInstance = (array) json_decode($aWorkJob["content"],true); // is in json format
$jobid = $aWorkJob["jobid"];
$printer = $aWorkJob["printer"];
$printersize = $printersizes->getPrinterSize($jobPrinterType,$printer);
CommonUtils::log($pdo,"PRINTQUEUE", "$msgLabel: collect work receipt with id=$jobid for printer=$printer");
$aTicket = Layouter::layoutTicket($template, array($aWorkInstance),$printersize);
$tickets[] = array(
"id" => $jobid,
"tickettype" => strtoupper($workJobType),
"printer" => $printer,
"entries" => $aTicket["printer"]);
}
return $tickets;
}
private function getNextTicketJobs($md5pass,$printersizes,$fl) {
$pdo = DbUtils::openDbAndReturnPdoStatic();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
2020-11-19 23:15:07 +01:00
if ($isCorrect || !(NEED_PASS)) {
2020-11-19 23:14:48 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getTickets: fl=$fl");
ob_start();
$rectickets = $this->getNextReceiptTicketJobs($pdo, $printersizes);
$foodTickets = $this->getNextWorkTicketJobs($pdo, $printersizes, 'f');
$drinkTickets = $this->getNextWorkTicketJobs($pdo, $printersizes, 'd');
$cancelFoodTickets = $this->getNextCancelTicketJobs($pdo, $printersizes, 'f');
$cancelDrinkTickets = $this->getNextCancelTicketJobs($pdo, $printersizes, 'd');
$pickupTickets = $this->getNextPickupTicketJobs($pdo,$printersizes);
$clsTickets = $this->getNextClosingTicketJobs($pdo, $printersizes);
$tickets = array_merge($rectickets,$foodTickets,$drinkTickets,$cancelFoodTickets,$cancelDrinkTickets,$pickupTickets,$clsTickets);
$this->saveLastPrintServerAccess($pdo);
$ticketsInJson = json_encode($tickets);
echo $ticketsInJson;
ob_end_flush();
CommonUtils::log($pdo,"PRINTQUEUE", "getNextTicketJobs: sent data to caller");
} else {
CommonUtils::log($pdo,"PRINTQUEUE", "getNextTicketJobs: Wrong printcode");
echo json_encode(array());
}
}
2020-11-19 22:58:39 +01:00
function getNextReceiptPrintJobs($md5pass,$language,$printers,$fl) {
2020-11-19 23:00:18 +01:00
$pdo = $this->dbutils->openDbAndReturnPdo();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
2020-11-19 22:47:44 +01:00
if ($isCorrect) {
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getReceipts: p=$printers, fl=$fl");
2020-11-19 23:03:20 +01:00
2020-11-19 22:47:44 +01:00
ob_start();
$printersArr = explode ( ',', $printers );
2020-11-19 22:59:57 +01:00
$this->saveLastPrintServerAccess($pdo);
2020-11-19 22:47:44 +01:00
if (intval($language) > 2) {
$genInfo = $this->admin->getGeneralConfigItems(false,$pdo);
$language = $genInfo["billlanguage"];
}
$bill = new Bill();
$sql = "SELECT id,content,type,printer FROM %printjobs% WHERE type=? ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array(3));
$result = $stmt->fetchAll();
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextReceiptPrintJobs: retrieve " . count($result) . " jobs");
2020-11-19 22:47:44 +01:00
$billarray = array();
foreach($result as $aBill) {
$printJobId = $aBill['id'];
$aBillId = $aBill["content"];
$printer = $aBill["printer"];
2020-11-19 23:14:10 +01:00
$sql = "SELECT closingid FROM %bill% WHERE id=?";
$r = CommonUtils::fetchSqlAll($pdo, $sql, array($aBillId));
if (count($r) > 0) {
$template = $this->getTemplate($pdo, "rectemplate",$r[0]["closingid"]);
} else {
$template = $this->getTemplate($pdo, "rectemplate",null);
}
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextReceiptPrintJobs: collect bill with id=$aBillId for printer=$printer");
2020-11-19 22:47:44 +01:00
if (in_array($printer, $printersArr)) {
2020-11-19 23:03:20 +01:00
if (!$this->checkForPrinterInstance($pdo, "k" . $printer)) {
continue;
}
2020-11-19 22:58:39 +01:00
if (is_null($fl)) {
$receiptJob = array("id" => $printJobId,"bill" => $bill->getBillWithId($pdo,$aBillId,$language,$printer));
2020-11-19 23:03:04 +01:00
} else if ($fl >= 9) {
$hosttext = CommonUtils::getConfigValue($pdo, 'hosttext', '');
$receiptJob = array("id" => $printJobId,"bill" => $bill->getBillWithId($pdo,$aBillId,$language,$printer,true,true), "template" => $template, "hosttext" => $hosttext);
2020-11-19 23:02:24 +01:00
} else if ($fl >= 6) {
$receiptJob = array("id" => $printJobId,"bill" => $bill->getBillWithId($pdo,$aBillId,$language,$printer,true,true), "template" => $template);
2020-11-19 23:00:58 +01:00
} else if ($fl >= 4) {
$receiptJob = array("id" => $printJobId,"bill" => $bill->getBillWithId($pdo,$aBillId,$language,$printer,true), "template" => $template);
2020-11-19 22:59:54 +01:00
} else if ($fl >= 1) {
2020-11-19 22:58:39 +01:00
$receiptJob = array("id" => $printJobId,"bill" => $bill->getBillWithId($pdo,$aBillId,$language,$printer), "template" => $template);
}
2020-11-19 23:14:48 +01:00
2020-11-19 23:14:10 +01:00
if ($fl < 15) {
unset($receiptJob["bill"]["billoverallinfo"]["sn"]);
unset($receiptJob["bill"]["billoverallinfo"]["uid"]);
unset($receiptJob["bill"]["billoverallinfo"]["version"]);
unset($receiptJob["bill"]["billoverallinfo"]["companyinfo"]);
unset($receiptJob["bill"]["billoverallinfo"]["systemid"]);
}
2020-11-19 22:47:44 +01:00
$billarray[] = $receiptJob;
}
}
echo json_encode($billarray);
ob_end_flush();
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextReceiptPrintJobs: sent data to caller");
2020-11-19 22:47:44 +01:00
} else {
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextReceiptPrintJobs: Wrong printcode");
2020-11-19 22:47:44 +01:00
echo json_encode(array());
}
}
2020-11-19 23:11:52 +01:00
function getNextPickupPrintPrintJobs($printer,$md5pass,$fl) {
$pdo = $this->dbutils->openDbAndReturnPdo();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
if ($isCorrect) {
CommonUtils::log($pdo,"PRINTQUEUE", "getNextPickupPrintPrintJobs: type = " . self::$PICKUP . " , printer = $printer, fl= $fl");
if (!$this->checkForPrinterInstance($pdo, "p" . $printer)) {
echo json_encode(array());
return;
}
$this->saveLastPrintServerAccess($pdo);
2020-11-19 23:14:10 +01:00
$template = $this->getTemplate($pdo, "pickuptemplate",null);
2020-11-19 23:11:52 +01:00
if (is_null($printer)) {
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND removed is null ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array(self::$PICKUP));
} else {
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND removed is null AND printer=? ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array(self::$PICKUP,$printer));
}
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
CommonUtils::log($pdo,"PRINTQUEUE", "getNextPickupPrintPrintJobs: retrieve " . count($result) . " jobs");
$workarray = array();
foreach($result as $aWorkJob) {
$aWork = (array) json_decode($aWorkJob["content"]); // is in json format
$ps = (array) ($aWork["products"]);
foreach($ps as $p) {
if (isset($p->singleprod)) {
unset($p->singleprod);
}
if (isset($p->allqueueids)) {
unset($p->allqueueids);
}
}
CommonUtils::log($pdo,"PRINTQUEUE", "getNextPickupPrintPrintJobs: collect pickupreceipt with id=" . $aWorkJob["id"] . " for printer=$printer");
$workid = $aWork["workid"];
unset($aWork["workid"]);
$workarray[] = array("workid" => $workid,"id" => $aWorkJob["id"],"content" => $aWork, "bigfontworkreceipt" => 0, "template" => $template);
}
CommonUtils::log($pdo,"PRINTQUEUE", "getNextPickupPrintPrintJobs: sent data to caller");
echo json_encode($workarray);
} else {
CommonUtils::log($pdo,"PRINTQUEUE", "getNextPickupPrintPrintJobs: wrong printcode");
echo json_encode(array());
}
}
2020-11-19 22:59:54 +01:00
function getNextFoodWorkPrintJobs($printer,$md5pass,$fl) {
2020-11-19 23:11:52 +01:00
$this->getNextWorkPrintJobs($md5pass,self::$FOOD,$printer,$fl,"getNextFoodWorkPrintJobs");
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:59:54 +01:00
function getNextDrinkWorkPrintJobs($printer,$md5pass,$fl) {
2020-11-19 23:11:52 +01:00
$this->getNextWorkPrintJobs($md5pass,self::$DRINK,$printer,$fl,"getNextDrinkWorkPrintJobs");
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:11:52 +01:00
function getNextWorkPrintJobs($md5pass,$theType,$printer,$fl,$logmsg) {
2020-11-19 23:00:18 +01:00
$pdo = $this->dbutils->openDbAndReturnPdo();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
2020-11-19 22:47:44 +01:00
2020-11-19 22:53:18 +01:00
if ($isCorrect) {
2020-11-19 23:11:52 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "$logmsg: type = $theType, printer = $printer, fl= $fl");
2020-11-19 23:03:20 +01:00
$checkType = "f";
if ($theType == 2) {
$checkType = "d";
}
if (!$this->checkForPrinterInstance($pdo, $checkType . $printer)) {
echo json_encode(array());
return;
}
2020-11-19 22:59:57 +01:00
$this->saveLastPrintServerAccess($pdo);
2020-11-19 22:48:24 +01:00
$bigFontWorkReceipt = $this->getBigFontWorkReceiptSetting($pdo);
2020-11-19 22:59:54 +01:00
$templatekey = "foodtemplate";
if ($theType === 2) {
$templatekey = "drinktemplate";
}
2020-11-19 23:14:10 +01:00
$template = $this->getTemplate($pdo, $templatekey,null);
2020-11-19 22:59:54 +01:00
2020-11-19 22:47:44 +01:00
if (is_null($printer)) {
2020-11-19 23:03:48 +01:00
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND removed is null ORDER BY id";
2020-11-19 22:47:44 +01:00
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array($theType));
} else {
2020-11-19 23:11:42 +01:00
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND removed is null AND printer=? ORDER BY id";
2020-11-19 22:47:44 +01:00
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array($theType,$printer));
}
2020-11-19 23:11:42 +01:00
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: retrieve " . count($result) . " jobs");
2020-11-19 22:47:44 +01:00
$workarray = array();
foreach($result as $aWorkJob) {
2020-11-19 23:02:21 +01:00
$aWork = (array) json_decode($aWorkJob["content"]); // is in json format
2020-11-19 23:10:37 +01:00
$ps = (array) ($aWork["products"]);
foreach($ps as $p) {
if (isset($p->singleprod)) {
unset($p->singleprod);
}
if (isset($p->allqueueids)) {
unset($p->allqueueids);
}
}
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: collect work receipt with id=" . $aWorkJob["id"] . " for printer=$printer");
2020-11-19 23:02:27 +01:00
2020-11-19 23:03:48 +01:00
$workid = $aWork["workid"];
unset($aWork["workid"]);
2020-11-19 23:02:27 +01:00
if (($fl >= 5) && ($fl <= 6)) {
$prods = (array) ($aWork["products"]);
$targetProds = array();
foreach ($prods as $aProd) {
$theArrProd = (array) $aProd;
$newTargetProd = array("id" => $theArrProd["id"],
"longname" => $theArrProd["longname"],
"option" => $theArrProd["option"],
"price" => $theArrProd["price"],
"extras" => $theArrProd["extras"],
"ordertime" => $theArrProd["ordertime"],
"kind" => $theArrProd["kind"],
"printer" => $theArrProd["printer"],
);
$targetProds[] = $newTargetProd;
}
$aWork["products"] = $targetProds;
2020-11-19 23:03:48 +01:00
} else if ($fl < 5) {
2020-11-19 23:02:21 +01:00
$prods = (array) ($aWork["products"]);
$targetProds = array();
foreach ($prods as $aProd) {
$theArrProd = (array) $aProd;
2020-11-19 23:03:48 +01:00
2020-11-19 23:02:21 +01:00
$newTargetProd = array("id" => $theArrProd["id"],
"longname" => $theArrProd["longname"],
"option" => $theArrProd["option"],
"extras" => $theArrProd["extras"],
"ordertime" => $theArrProd["ordertime"],
"kind" => $theArrProd["kind"],
"printer" => $theArrProd["printer"],
);
$targetProds[] = $newTargetProd;
}
$aWork["products"] = $targetProds;
}
2020-11-19 22:59:54 +01:00
if ($fl >= 2) {
2020-11-19 23:03:48 +01:00
if ($fl >= 10) {
$workarray[] = array("workid" => $workid,"id" => $aWorkJob["id"],"content" => $aWork, "bigfontworkreceipt" => intval($bigFontWorkReceipt), "template" => $template);
} else {
$workarray[] = array("id" => $aWorkJob["id"],"content" => $aWork, "bigfontworkreceipt" => intval($bigFontWorkReceipt), "template" => $template);
}
2020-11-19 22:59:54 +01:00
} else {
2020-11-19 23:03:48 +01:00
// default without template
$workarray[] = array("id" => $aWorkJob["id"],"content" => $aWork, "bigfontworkreceipt" => intval($bigFontWorkReceipt));
2020-11-19 22:59:54 +01:00
}
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: sent data to caller");
2020-11-19 22:47:44 +01:00
echo json_encode($workarray);
} else {
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: wrong printcode");
2020-11-19 22:47:44 +01:00
echo json_encode(array());
}
}
2020-11-19 23:03:48 +01:00
function getNextCancelFoodWorkPrintJobs($printer,$md5pass,$fl) {
$this->getNextCancelWorkPrintJobs($md5pass,self::$CANCELFOOD,$printer,$fl);
}
function getNextCancelDrinkWorkPrintJobs($printer,$md5pass,$fl) {
$this->getNextCancelWorkPrintJobs($md5pass,self::$CANCELDRINK,$printer,$fl);
}
function getNextCancelWorkPrintJobs($md5pass,$theType,$printer,$fl) {
$pdo = $this->dbutils->openDbAndReturnPdo();
$isCorrect = $this->isPasswordCorrect($pdo,$md5pass,false);
if ($isCorrect) {
CommonUtils::log($pdo,"PRINTQUEUE", "getNextCancelWorkPrintJobs: type = $theType, printer = $printer, fl= $fl");
$checkType = "f";
if ($theType == 6) {
$checkType = "d";
}
if (!$this->checkForPrinterInstance($pdo, $checkType . $printer)) {
echo json_encode(array());
return;
}
$this->saveLastPrintServerAccess($pdo);
$templatekey = "canceltemplate";
2020-11-19 23:14:10 +01:00
$template = $this->getTemplate($pdo, $templatekey,null);
2020-11-19 23:03:48 +01:00
if (is_null($printer)) {
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND removed is null ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array($theType));
} else {
$sql = "SELECT id,content,type FROM %printjobs% WHERE type=? AND printer=? AND removed is null ORDER BY id";
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
$stmt->execute(array($theType,$printer));
}
$result = $stmt->fetchAll();
CommonUtils::log($pdo,"PRINTQUEUE", "getNextCancelWorkPrintJobs: retrieve " . count($result) . " jobs");
$workarray = array();
foreach($result as $aWorkJob) {
$aWork = (array) json_decode($aWorkJob["content"],true); // is in json format
CommonUtils::log($pdo,"PRINTQUEUE", "getNextCancelWorkPrintJobs: collect work receipt with id=" . $aWorkJob["id"] . " for printer=$printer");
$workid = $aWork["workid"];
unset($aWork["workid"]);
2020-11-19 23:10:37 +01:00
$showType = self::$FOOD_PRINTSERVER;
if ($theType == self::$CANCELDRINK) {
$showType = self::$DRINK_PRINTSERVER;
}
2020-11-19 23:03:48 +01:00
$workarray[] = array("workid" => $workid,
"id" => $aWorkJob["id"],
"refworkid" => $aWork["refworkid"],
"longname" => $aWork["longname"],
2020-11-19 23:10:37 +01:00
"kind" => $showType,
2020-11-19 23:03:48 +01:00
"table" => $aWork["table"],
"time" => $aWork["time"],
"price" => $aWork["price"],
"extras" => $aWork["extras"],
"template" => $template);
}
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: sent data to caller");
echo json_encode($workarray);
} else {
CommonUtils::log($pdo,"PRINTQUEUE", "getNextWorkPrintJobs: wrong printcode");
echo json_encode(array());
}
}
2020-11-19 22:47:44 +01:00
function deletePrintJob($pass,$id) {
2020-11-19 23:14:48 +01:00
$pdo = DbUtils::openDbAndReturnPdoStatic();
2020-11-19 23:00:18 +01:00
$isCorrect = $this->isPasswordCorrect($pdo,$pass,false);
2020-11-19 22:47:44 +01:00
if ($isCorrect) {
2020-11-19 22:59:47 +01:00
$pdo = $this->dbutils->openDbAndReturnPdo();
2020-11-19 22:59:57 +01:00
$this->saveLastPrintServerAccess($pdo);
2020-11-19 23:03:48 +01:00
$sql = "SELECT type FROM %printjobs% WHERE id=?";
$result = CommonUtils::fetchSqlAll($pdo, $sql, array($id));
if (count($result) > 0) {
$type = $result[0]['type'];
2020-11-19 23:11:52 +01:00
if (($type == self::$FOOD) || ($type == self::$DRINK) || ($type == self::$CANCELFOOD) || ($type == self::$CANCELDRINK) || ($type == self::$PICKUP)) {
2020-11-19 23:03:48 +01:00
$sql = "UPDATE %printjobs% SET removed=? WHERE id=?";
CommonUtils::execSql($pdo, $sql, array(1,$id));
} else {
$sql = "DELETE FROM %printjobs% WHERE id=?";
CommonUtils::execSql($pdo, $sql, array($id));
}
}
2020-11-19 22:47:44 +01:00
echo json_encode(array("status" => "OK", "code" => OK, "msg" => "Druckauftrag erfolgreich gelöscht."));
} else {
2020-11-19 23:00:18 +01:00
CommonUtils::log($pdo,"PRINTQUEUE", "deletePrintJob: wrong printcode");
2020-11-19 22:47:44 +01:00
echo json_encode(array("status" => "ERROR", "code" => ERROR_NOT_AUTHOTRIZED, "msg" => ERROR_NOT_AUTHOTRIZED_MSG));
}
}
}
2020-11-19 23:14:48 +01:00
class Printersizes {
public static $JOBTYPE_RECEIPT = 1;
public static $JOBTYPE_FOOD = 2;
public static $JOBTYPE_DRINK = 3;
public static $JOBTYPE_PICKUP = 4;
private $receiptPrinterSizes = array();
private $foodPrinterSizes = array();
private $drinkPrinterSizes = array();
private $pickupPrinterSizes = array();
private $defaultSize = 32;
function __construct($urlgetParam) {
if (isset($urlgetParam['printersizes'])) {
$printersizesParameter = $_GET['printersizes'];
$printerParts = explode('-',$printersizesParameter);
foreach($printerParts as $aPrinterSequence) {
$printerSequence = explode('_',$aPrinterSequence);
$pureSizes = array_slice($printerSequence,1,count($printerSequence)-1);
switch(strtoupper($printerSequence[0])) {
case "R":
$this->receiptPrinterSizes = $pureSizes;
break;
case "F":
$this->foodPrinterSizes = $pureSizes;
break;
case "D":
$this->drinkPrinterSizes = $pureSizes;
break;
case "P":
$this->pickupPrinterSizes = $pureSizes;
break;
}
}
}
}
public function getPrinterSize($jobtype,$printer) {
$defaultSizes = array(32,32,32,32,32,32);
$sizeArrayToUse = $defaultSizes;
switch ($jobtype) {
case self::$JOBTYPE_RECEIPT:
$sizeArrayToUse = $this->receiptPrinterSizes;
break;
case self::$JOBTYPE_FOOD:
$sizeArrayToUse = $this->foodPrinterSizes;
break;
case self::$JOBTYPE_DRINK:
$sizeArrayToUse = $this->drinkPrinterSizes;
break;
case self::$JOBTYPE_PICKUP:
$sizeArrayToUse = $this->pickupPrinterSizes;
break;
default:
$sizeArrayToUse = $defaultSizes;
break;
}
$printer = intval($printer)-1;
if (count($sizeArrayToUse) >= $printer) {
return $sizeArrayToUse[$printer];
} else {
return $this->defaultSize;
}
}
2020-11-19 23:15:07 +01:00
}