2020-11-19 22:44:19 +01:00
< ? php
// Datenbank-Verbindungsparameter
require_once ( 'dbutils.php' );
require_once ( 'commonutils.php' );
2020-11-19 22:47:44 +01:00
require_once ( 'queuecontent.php' );
2020-11-19 22:44:19 +01:00
// require_once ('content.php');
class Roomtables {
var $dbutils ;
function __construct () {
$this -> dbutils = new DbUtils ();
}
function handleCommand ( $command ) {
2020-11-19 23:00:46 +01:00
if ( session_id () == '' ) {
2020-11-19 22:44:19 +01:00
session_start ();
2020-11-19 23:00:46 +01:00
if ( ! isset ( $_SESSION [ 'angemeldet' ]) || ! $_SESSION [ 'angemeldet' ]) {
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:12:46 +01:00
return ;
2020-11-19 23:00:46 +01:00
}
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:00:46 +01:00
header ( " Cache-Control: no-store, no-cache, must-revalidate, max-age=0 " );
header ( " Cache-Control: post-check=0, pre-check=0 " , false );
header ( " Pragma: no-cache " );
2020-11-19 22:44:19 +01:00
2020-11-19 23:00:46 +01:00
if ( $command == 'showAllRooms' ) {
2020-11-19 22:44:19 +01:00
$this -> showAllRooms ();
} else if ( $command == 'getRooms' ) {
$this -> getRooms (); // only rooms!
} else if ( $command == 'showAllRoomsAndTablesWithUnpaidItems' ) {
$this -> showAllRoomsAndTablesWithUnpaidItems ();
} else if ( $command == 'getUnpaidTables' ) {
2020-11-19 22:54:51 +01:00
$this -> getUnpaidTables ( $_GET [ 'roomid' ]);
2020-11-19 22:44:19 +01:00
} else if ( $command == 'getRoomfield' ) {
$this -> getRoomfield ();
2020-11-19 23:10:06 +01:00
} else if ( $command == 'getRoomfieldAlsoInactive' ) {
$this -> getRoomfieldAlsoInactive ();
2020-11-19 22:44:19 +01:00
} else if ( $command == 'setRoomInfo' ) {
2020-11-19 23:13:57 +01:00
if ( self :: hasCurrentUserAdminRights ()) {
2020-11-19 23:11:57 +01:00
$this -> setRoomInfo ( $_POST [ 'rooms' ], $_POST [ 'togoworkprinter' ]);
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:13:57 +01:00
} else if ( $command == 'createTableCodes' ) {
self :: createTableCodes ();
} else if ( $command == 'tableqrcodes' ) {
self :: tableqrcodes ();
2020-11-19 22:44:19 +01:00
}
}
2020-11-19 23:13:57 +01:00
private static function hasCurrentUserAdminRights () {
2020-11-19 23:00:46 +01:00
if ( session_id () == '' ) {
session_start ();
}
if ( ! isset ( $_SESSION [ 'angemeldet' ]) || ! $_SESSION [ 'angemeldet' ]) {
return false ;
} else {
return ( $_SESSION [ 'is_admin' ]);
}
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:13:57 +01:00
private static function createTableCodes () {
if ( ! self :: hasCurrentUserAdminRights ()) {
echo json_encode ( array ( " status " => " ERROR " , " msg " => " Benutzerrechte nicht ausreichend " ));
return ;
}
try {
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
$sql = " SELECT id FROM %resttables% WHERE removed is null AND (code is NULL OR code='') " ;
$activeTables = CommonUtils :: fetchSqlAll ( $pdo , $sql );
$updateSql = " UPDATE %resttables% SET code=? WHERE id=? " ;
foreach ( $activeTables as $table ) {
$tableid = $table [ " id " ];
$uniqid = md5 ( uniqid ());
CommonUtils :: execSql ( $pdo , $updateSql , array ( $uniqid , $tableid ));
}
echo json_encode ( array ( " status " => " OK " ));
} catch ( Exception $ex ) {
echo json_encode ( array ( " status " => " ERROR " , " msg " => " Datenbank nicht erreichbar " ));
}
}
2020-11-19 22:44:19 +01:00
function showAllRooms () {
2020-11-19 23:11:44 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 23:00:46 +01:00
$roomtables = $this -> getAllTablesAndRooms ( $pdo );
2020-11-19 22:44:19 +01:00
echo json_encode ( $roomtables );
}
2020-11-19 22:47:44 +01:00
public static function getUnpaidTablesCore ( $pdo , $roomid ) {
2020-11-19 23:11:33 +01:00
$userarea = self :: getUserArea ( $pdo );
$areaWhere = " " ;
if ( ! is_null ( $userarea )) {
$area = intval ( $userarea );
$areaWhere = " AND R.area=' $area ' " ;
}
$tablesSql = " SELECT id,tableno FROM %resttables% R WHERE R.roomid=? AND removed is null $areaWhere ORDER BY sorting " ;
2020-11-19 23:00:46 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $tablesSql ));
$stmt -> execute ( array ( $roomid ));
$result = $stmt -> fetchAll ();
$tablesArr = array ();
foreach ( $result as $row ) {
$entry = array ( " id " => $row [ 'id' ], " name " => $row [ 'tableno' ]);
$tablesArr [] = $entry ;
2020-11-19 22:44:19 +01:00
}
$tableresult = array ();
foreach ( $tablesArr as $aTable ) {
$tableid = $aTable [ 'id' ];
2020-11-19 23:00:46 +01:00
$sql = " SELECT sum(%queue%.price) as sumprice,count(%queue%.price) as prodcount
FROM % queue %
INNER JOIN % products % ON % queue %. productid = % products %. id
INNER JOIN % pricelevel % ON % queue %. pricelevel = % pricelevel %. id
2020-11-19 23:12:27 +01:00
WHERE tablenr = ? AND paidtime is null AND toremove = '0'
AND isclosed is null " ;
2020-11-19 22:44:19 +01:00
2020-11-19 23:00:46 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
2020-11-19 22:44:19 +01:00
$stmt -> execute ( array ( $tableid ));
2020-11-19 23:00:46 +01:00
$row = $stmt -> fetchObject ();
2020-11-19 22:44:19 +01:00
if ( $row != null ) {
2020-11-19 23:00:46 +01:00
$prodcount = $row -> prodcount ;
2020-11-19 22:44:19 +01:00
$sumprice = $row -> sumprice ;
if ( $prodcount > 0 ) {
2020-11-19 22:47:44 +01:00
$aTableEntry = array ( " id " => $tableid , " name " => $aTable [ " name " ], " pricesum " => $sumprice );
2020-11-19 22:44:19 +01:00
$tableresult [] = $aTableEntry ;
}
}
}
2020-11-19 22:47:44 +01:00
return ( $tableresult );
}
function getUnpaidTables ( $roomid ) {
2020-11-19 23:12:46 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:47:44 +01:00
$priceTakeAway = $this -> getUnpaidSumOfTakeAway ( $pdo );
2020-11-19 23:12:46 +01:00
echo json_encode ( array ( " status " => " OK " , " tables " => self :: getUnpaidTablesCore ( $pdo , $roomid ), " takeawayprice " => $priceTakeAway ));
2020-11-19 22:44:19 +01:00
}
function showAllRoomsAndTablesWithUnpaidItems () {
2020-11-19 22:47:44 +01:00
$pdo = $this -> dbutils -> openDbAndReturnPdo ( $pdo );
$roomtables = $this -> getAllTablesAndRooms ( $pdo );
2020-11-19 22:44:19 +01:00
for ( $i = 0 ; $i < count ( $roomtables ); $i ++ ) {
$tablesArr = $roomtables [ $i ][ " tables " ];
$newtablesArr = array ();
for ( $j = 0 ; $j < count ( $tablesArr ); $j ++ ) {
$tableentry = $tablesArr [ $j ];
$tableid = $tableentry [ " id " ];
if ( $this -> hasTableUnpaidItems ( $tableid )) {
$newtablesArr [] = $tableentry ;
}
}
$roomtables [ $i ][ " tables " ] = $newtablesArr ;
}
echo json_encode ( $roomtables );
}
function hasTableUnpaidItems ( $tableid ) {
2020-11-19 23:00:46 +01:00
$sql = " SELECT %queue%.id as id,longname,%queue%.price as price,%pricelevel%.name as pricelevelname,%products%.id as prodid
FROM % queue %
INNER JOIN % products % ON % queue %. productid = % products %. id
INNER JOIN % pricelevel % ON % queue %. pricelevel = % pricelevel %. id
2020-11-19 23:12:27 +01:00
WHERE tablenr = $tableid AND paidtime is null AND toremove = '0'
2020-11-19 22:44:19 +01:00
ORDER BY ordertime ; " ;
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
2020-11-19 23:00:46 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 22:44:19 +01:00
$stmt -> execute ();
$count = $stmt -> rowCount ();
if ( $count > 0 ) {
return true ;
} else {
return false ;
}
}
/*
* get only the rooms ( for paydesk , because tables are dynamic due to their pay status )
*/
function getRooms () {
2020-11-19 23:11:33 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
$userarea = self :: getUserArea ( $pdo );
2020-11-19 23:10:06 +01:00
$sql = " SELECT id,roomname FROM %room% WHERE removed is null ORDER BY sorting " ;
2020-11-19 23:11:33 +01:00
$result = CommonUtils :: fetchSqlAll ( $pdo , $sql , null );
2020-11-19 23:00:46 +01:00
$roomArr = array ();
2020-11-19 22:44:19 +01:00
foreach ( $result as $row ) {
2020-11-19 23:11:33 +01:00
$tablesToLookAt = $this -> hasUserResponsibleTablesInRoom ( $pdo , $row [ 'id' ], $userarea );
if ( ! $tablesToLookAt ) {
continue ;
}
2020-11-19 23:00:46 +01:00
$roomEntry = array ( " id " => $row [ 'id' ], " name " => $row [ 'roomname' ]);
$roomArr [] = $roomEntry ;
2020-11-19 22:44:19 +01:00
}
2020-11-19 22:47:44 +01:00
$priceTakeAway = $this -> getUnpaidSumOfTakeAway ( $pdo );
echo json_encode ( array ( " roomstables " => $roomArr , " takeawayprice " => $priceTakeAway ));
}
private function getUnpaidSumOfTakeAway ( $pdo ) {
2020-11-19 23:12:27 +01:00
$sql = " SELECT IFNULL(SUM(IF(%queue%.toremove='0' AND %queue%.paidtime is null,%queue%.price,0.00)),0.00) as pricesum FROM %queue% " ;
2020-11-19 23:11:44 +01:00
$sql .= " WHERE %queue%.tablenr is null AND isclosed is null " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ();
$row = $stmt -> fetchObject ();
return $row -> pricesum ;
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:11:33 +01:00
private function hasUserResponsibleTablesInRoom ( $pdo , $roomid , $userarea ) {
if ( is_null ( $userarea )) {
return true ;
}
$sql = " SELECT count(id) as countid FROM %resttables% R WHERE R.roomid=? AND R.area=? " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $roomid , $userarea ));
$countid = $row -> countid ;
if ( $countid > 0 ) {
return true ;
} else {
return false ;
}
}
private static function getUserArea ( $pdo ) {
if ( session_id () == '' ) {
session_start ();
}
$userid = $_SESSION [ 'userid' ];
$sql = " SELECT area FROM %user% WHERE id=? " ;
$row = CommonUtils :: getRowSqlObject ( $pdo , $sql , array ( $userid ));
return $row -> area ;
}
2020-11-19 23:12:37 +01:00
private static function getTimesFromArray ( $tableid , $reservations ) {
foreach ( $reservations as $res ) {
if ( $res [ " tableid " ] == $tableid ) {
return $res [ " times " ];
}
}
return '' ;
}
2020-11-19 23:13:57 +01:00
private static function sqlForEndTime () {
$sqlEndTimeStamp = 'ADDTIME(CONCAT(starttime,":",starttimemin,":00"),CONCAT(duration,":",durationmins,":00"))' ;
$sqlEndHour = 'HOUR(' . $sqlEndTimeStamp . ') as endhour' ;
$sqlEndMin = 'MINUTE(' . $sqlEndTimeStamp . ') as endmin' ;
$sqlEndTime = " $sqlEndHour , $sqlEndMin " ;
return $sqlEndTime ;
}
2020-11-19 23:00:46 +01:00
private function getAllTablesAndRooms ( $pdo )
2020-11-19 22:47:44 +01:00
{
2020-11-19 23:13:57 +01:00
$sqlEndTimeStamp = 'ADDTIME(CONCAT(starttime,":",starttimemin,":00"),CONCAT(duration,":",durationmins,":00"))' ;
$sqlEndHour = 'HOUR(' . $sqlEndTimeStamp . ') ' ;
$sqlEndMin = 'LPAD(MINUTE(' . $sqlEndTimeStamp . '),2,0)' ;
$sql = " SELECT tableid,GROUP_CONCAT(DISTINCT CONCAT(starttime,':',LPAD(starttimemin,2,0),'-',( $sqlEndHour ),':',( $sqlEndMin )) ORDER BY starttime) as times from %reservations% R " ;
//$sql = "SELECT tableid,GROUP_CONCAT(DISTINCT CONCAT(starttime,':00-',(starttime+duration),':00') ORDER BY starttime) as times from %reservations% R ";
2020-11-19 23:12:37 +01:00
$sql .= " WHERE DATE(scheduledate)=CURDATE() AND (HOUR(NOW())-1) <= starttime GROUP BY tableid " ;
$reservations = CommonUtils :: fetchSqlAll ( $pdo , $sql );
2020-11-19 23:11:33 +01:00
$userarea = self :: getUserArea ( $pdo );
2020-11-19 23:00:46 +01:00
$queue = new QueueContent ();
2020-11-19 23:10:06 +01:00
$sql = " SELECT id,roomname FROM %room% WHERE removed is null ORDER BY sorting " ;
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
2020-11-19 23:00:46 +01:00
$stmt -> execute ();
2020-11-19 22:47:44 +01:00
$dbresult = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
2020-11-19 23:00:46 +01:00
2020-11-19 22:47:44 +01:00
$arrayOfRooms = array ();
2020-11-19 23:11:42 +01:00
$showprepinwaiter = CommonUtils :: getConfigValue ( $pdo , 'showprepinwaiter' , 1 );
2020-11-19 23:11:49 +01:00
$workflowconfig = CommonUtils :: getConfigValue ( $pdo , 'workflowconfig' , 0 );
$queryprodForTableView = false ;
if (( $showprepinwaiter == 1 ) && (( $workflowconfig == 0 ) || ( $workflowconfig == 1 ))) {
$queryprodForTableView = true ;
}
2020-11-19 23:12:37 +01:00
2020-11-19 22:47:44 +01:00
foreach ( $dbresult as $zeile ) {
2020-11-19 23:00:46 +01:00
$roomid = $zeile [ 'id' ];
2020-11-19 22:44:19 +01:00
2020-11-19 23:11:33 +01:00
$tablesToLookAt = $this -> hasUserResponsibleTablesInRoom ( $pdo , $roomid , $userarea );
if ( ! $tablesToLookAt ) {
continue ;
}
2020-11-19 22:44:19 +01:00
$tablesArray = array ();
2020-11-19 22:47:44 +01:00
2020-11-19 23:11:33 +01:00
$areaWhere = " " ;
if ( ! is_null ( $userarea )) {
$area = intval ( $userarea );
$areaWhere = " AND R.area=' $area ' " ;
}
$sql = " SELECT R.id as id,R.tableno as name,R.sorting as sorting, " ;
2020-11-19 23:12:27 +01:00
$sql .= " IFNULL(SUM(IF(Q.toremove='0' AND Q.paidtime is null AND Q.isclosed is null,Q.price,0.00)),0.00) as pricesum FROM %resttables% R " ;
2020-11-19 23:11:33 +01:00
$sql .= " LEFT OUTER JOIN %queue% Q ON Q.tablenr=R.id WHERE R.removed is null AND active='1' AND " ;
$sql .= " R.roomid=? $areaWhere GROUP BY R.id,name " ;
$sql .= " ORDER BY R.sorting " ;
2020-11-19 22:47:44 +01:00
2020-11-19 23:11:33 +01:00
2020-11-19 22:47:44 +01:00
$stmt = $pdo -> prepare ( DbUtils :: substTableAlias ( $sql ));
$stmt -> execute ( array ( $roomid ));
$tablesArray = $stmt -> fetchAll ( PDO :: FETCH_OBJ );
foreach ( $tablesArray as $tableEntry ) {
2020-11-19 23:12:37 +01:00
$resTxt = self :: getTimesFromArray ( $tableEntry -> id , $reservations );
2020-11-19 23:11:42 +01:00
$arrayOfProdsAndIdsOfATable = array ( " prods " => array (), " ids " => '' );
2020-11-19 23:11:49 +01:00
if ( $queryprodForTableView ) {
2020-11-19 23:11:42 +01:00
$arrayOfProdsAndIdsOfATable = $queue -> getAllPreparedProductsForTableidAsArray ( $pdo , $tableEntry -> id );
}
2020-11-19 22:47:44 +01:00
$arrayOfProdsOfATable = $arrayOfProdsAndIdsOfATable [ 'prods' ];
$numberOfProductsTotalToServe = $queue -> numberOfProductsForTableNotDelivered ( $pdo , $tableEntry -> id );
$numberOfReadyProducts = count ( $arrayOfProdsOfATable );
$queueids = $this -> getIdsFromProdList ( $arrayOfProdsOfATable );
$tableEntry -> prodcount = $numberOfProductsTotalToServe ;
$tableEntry -> prodready = $numberOfReadyProducts ;
$tableEntry -> readyQueueIds = $queueids ;
2020-11-19 23:12:37 +01:00
$tableEntry -> reservations = $resTxt ;
2020-11-19 22:47:44 +01:00
}
2020-11-19 22:44:19 +01:00
$aRoomEntry = array ( " id " => $roomid , " name " => $zeile [ 'roomname' ], " tables " => $tablesArray );
2020-11-19 23:00:46 +01:00
$arrayOfRooms [] = $aRoomEntry ;
2020-11-19 22:47:44 +01:00
}
$priceTakeAway = $this -> getUnpaidSumOfTakeAway ( $pdo );
2020-11-19 23:11:42 +01:00
$arrayOfProdsAndIdsOfATable = array ( " prods " => array (), " ids " => '' );
if ( $showprepinwaiter == 1 ) {
$arrayOfProdsAndIdsOfATable = $queue -> getAllPreparedProductsForTableidAsArray ( $pdo , null );
}
2020-11-19 22:47:44 +01:00
$arrayOfProdsOfATable = $arrayOfProdsAndIdsOfATable [ 'prods' ];
$numberOfProductsTotalToServe = $queue -> numberOfProductsForTableNotDelivered ( $pdo , null );
$numberOfReadyProducts = count ( $arrayOfProdsOfATable );
$queueids = $this -> getIdsFromProdList ( $arrayOfProdsOfATable );
2020-11-19 23:00:46 +01:00
2020-11-19 22:47:44 +01:00
return array ( " roomstables " => $arrayOfRooms , " takeawayprice " => $priceTakeAway ,
" takeawayprodcount " => $numberOfProductsTotalToServe ,
" takeawayprodready " => $numberOfReadyProducts ,
" takeawayReadyQueueIds " => $queueids
2020-11-19 23:00:46 +01:00
);
2020-11-19 22:44:19 +01:00
}
2020-11-19 22:47:44 +01:00
function getIdsFromProdList ( $arrayOfProdsOfATable ) {
$idArr = array ();
if ( ! is_null ( $arrayOfProdsOfATable ) && ( count ( $arrayOfProdsOfATable ) > 0 )) {
foreach ( $arrayOfProdsOfATable as $queueEntry ) {
$idArr [] = $queueEntry [ " id " ];
}
return $idArr ;
} else {
return array ();
}
}
2020-11-19 22:54:51 +01:00
2020-11-19 22:44:19 +01:00
2020-11-19 23:11:57 +01:00
function setRoomInfo ( $roomsAsJson , $togoworkprinter ) {
2020-11-19 23:11:33 +01:00
$rooms = json_decode ( $roomsAsJson , true );
2020-11-19 23:10:06 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 22:44:19 +01:00
$pdo -> beginTransaction ();
2020-11-19 23:10:06 +01:00
try {
2020-11-19 22:44:19 +01:00
2020-11-19 23:10:06 +01:00
$sql = " UPDATE %resttables% SET removed=1 " ;
CommonUtils :: execSql ( $pdo , $sql , null );
$sql = " UPDATE %room% SET removed=1 " ;
CommonUtils :: execSql ( $pdo , $sql , null );
2020-11-19 22:44:19 +01:00
2020-11-19 23:10:06 +01:00
foreach ( $rooms as $aRoom ) {
$roomid = $aRoom [ " roomid " ];
$printer = $aRoom [ " printer " ];
if ( $printer == 0 ) {
$printer = null ;
}
$name = trim ( $aRoom [ " name " ]);
$sorting = trim ( $aRoom [ " sorting " ]);
$abbreviation = trim ( $aRoom [ " abbreviation " ]);
if ( ! is_numeric ( $roomid )) {
$sql = " INSERT INTO %room% (roomname,abbreviation,printer,sorting) VALUES(?,?,?,?) " ;
CommonUtils :: execSql ( $pdo , $sql , array ( $name , $abbreviation , $printer , $sorting ));
$roomid = $pdo -> lastInsertId ();
} else {
$sql = " UPDATE %room% SET removed=?,roomname=?,abbreviation=?,printer=?,sorting=? WHERE id=? " ;
CommonUtils :: execSql ( $pdo , $sql , array ( null , $name , $abbreviation , $printer , $sorting , $roomid ));
}
2020-11-19 23:11:33 +01:00
if ( isset ( $aRoom [ " tables " ])) {
$tables = $aRoom [ " tables " ];
foreach ( $tables as $t ) {
$tableid = $t [ " id " ];
$tablename = $t [ " tablename " ];
$name = $t [ " name " ];
$code = " " ;
if ( isset ( $t [ " code " ])) {
$code = $t [ " code " ];
}
$area = $t [ " area " ];
if ( $area == 0 ) {
$area = null ;
}
$sorting = $t [ " sorting " ];
$active = $t [ " active " ];
$allowoutorder = $t [ " allowoutorder " ];
if ( ! is_numeric ( $tableid )) {
$sql = " INSERT INTO %resttables% (tableno,roomid,code,name,area,active,allowoutorder,sorting) VALUES(?,?,?,?,?,?,?,?) " ;
CommonUtils :: execSql ( $pdo , $sql , array ( $tablename , $roomid , $code , $name , $area , $active , $allowoutorder , $sorting ));
} else {
$sql = " UPDATE %resttables% SET removed=?,tableno=?,roomid=?,code=?,name=?,area=?,active=?,allowoutorder=?,sorting=? WHERE id=? " ;
CommonUtils :: execSql ( $pdo , $sql , array ( null , $tablename , $roomid , $code , $name , $area , $active , $allowoutorder , $sorting , $tableid ));
}
2020-11-19 23:10:06 +01:00
}
}
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:10:06 +01:00
$sql = " select %tablepos%.id as posid,%resttables%.removed FROM %tablepos%,%resttables% WHERE %resttables%.removed is not null AND %resttables%.id=%tablepos%.tableid " ;
$result = CommonUtils :: fetchSqlAll ( $pdo , $sql , null );
foreach ( $result as $r ) {
$sql = " DELETE FROM %tablepos% WHERE id=? " ;
CommonUtils :: execSql ( $pdo , $sql , array ( $r [ " posid " ]));
};
$sql = " select %tablemaps%.id as posid,%room%.removed FROM %tablemaps%,%room% WHERE %room%.removed is not null AND %room%.id=%tablemaps%.roomid " ;
$result = CommonUtils :: fetchSqlAll ( $pdo , $sql , null );
foreach ( $result as $r ) {
$sql = " DELETE FROM %tablemaps% WHERE id=? " ;
CommonUtils :: execSql ( $pdo , $sql , array ( $r [ " posid " ]));
}
2020-11-19 23:11:57 +01:00
$hist = new HistFiller ();
$hist -> updateConfigInHist ( $pdo , " togoworkprinter " , $togoworkprinter );
2020-11-19 23:12:37 +01:00
$sql = " SELECT R.id as resid FROM %reservations% R,%resttables% T WHERE R.tableid=T.id AND T.removed is not null " ;
$allReservIds = CommonUtils :: fetchSqlAll ( $pdo , $sql , null );
$sql = " DELETE FROM %reservations% WHERE id=? " ;
foreach ( $allReservIds as $resid ) {
CommonUtils :: execSql ( $pdo , $sql , array ( $resid [ " resid " ]));
}
2020-11-19 23:10:06 +01:00
$pdo -> commit ();
} catch ( Exception $ex ) {
echo json_encode ( array ( " status " => " ERROR " , " msg " => $ex -> getMessage ()));
$pdo -> rollBack ();
return ;
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:10:06 +01:00
$this -> getRoomfieldAlsoInactive ( $pdo );
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:10:06 +01:00
function getRoomfieldAlsoInactive ( $pdo = null ) {
if ( is_null ( $pdo )) {
$pdo = $this -> dbutils -> openDbAndReturnPdo ();
}
$this -> getRoomfieldCore ( $pdo , true );
}
function getRoomfield ( $pdo = null ) {
if ( is_null ( $pdo )) {
2020-11-19 23:11:57 +01:00
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 23:10:06 +01:00
}
$this -> getRoomfieldCore ( $pdo , false );
}
function getRoomfieldCore ( $pdo , $includeInActiveTables ) {
2020-11-19 22:44:19 +01:00
2020-11-19 23:10:06 +01:00
$sql = " SELECT id,roomname,IFNULL(abbreviation,'') as abbreviation,IFNULL(printer,0) as printer,sorting FROM %room% WHERE removed is null ORDER BY 'sorting' " ;
2020-11-19 23:00:46 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 22:44:19 +01:00
$stmt -> execute ();
$result = $stmt -> fetchAll ();
2020-11-19 23:10:06 +01:00
$numberOfRooms = count ( $result );
2020-11-19 22:44:19 +01:00
$maxTables = 0 ;
2020-11-19 23:00:46 +01:00
$roomArr = array ();
2020-11-19 23:10:06 +01:00
$where = " removed is null AND active='1' " ;
if ( $includeInActiveTables ) {
$where = " removed is null " ;
}
2020-11-19 22:44:19 +01:00
foreach ( $result as $row ) {
$roomid = $row [ 'id' ];
$roomname = $row [ 'roomname' ];
2020-11-19 22:55:09 +01:00
$abbreviation = $row [ 'abbreviation' ];
2020-11-19 22:47:44 +01:00
$printer = $row [ 'printer' ];
2020-11-19 23:10:06 +01:00
$roomsorting = $row [ 'sorting' ];
2020-11-19 22:44:19 +01:00
2020-11-19 23:11:33 +01:00
$sql = " SELECT id,tableno,IFNULL(code,'') as code,IFNULL(name,'') as name,IFNULL(allowoutorder,0) as allowoutorder,IFNULL(sorting,1) as sorting,IFNULL(active,1) as active,IFNULL(area,0) as area FROM %resttables% WHERE roomid=? AND $where ORDER BY 'sorting' " ;
2020-11-19 23:00:46 +01:00
$stmt = $pdo -> prepare ( $this -> dbutils -> resolveTablenamesInSqlString ( $sql ));
2020-11-19 22:44:19 +01:00
$stmt -> execute ( array ( $row [ 'id' ]));
$numberOfTables = $stmt -> rowCount ();
2020-11-19 23:00:46 +01:00
$maxTables = ( $maxTables < $numberOfTables ? $numberOfTables : $maxTables );
2020-11-19 22:44:19 +01:00
$tableresult = $stmt -> fetchAll ();
$tableArr = array ();
foreach ( $tableresult as $aTable ) {
2020-11-19 23:11:33 +01:00
$tableArr [] = array ( " id " => $aTable [ 'id' ], " tablename " => $aTable [ 'tableno' ], " name " => $aTable [ 'name' ], " code " => $aTable [ 'code' ], " area " => $aTable [ 'area' ], " allowoutorder " => $aTable [ 'allowoutorder' ], " active " => $aTable [ 'active' ], " sorting " => $aTable [ 'sorting' ]);
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:10:06 +01:00
$roomArr [] = array ( " roomid " => $roomid , " roomname " => $roomname , " abbreviation " => $abbreviation , " printer " => $printer , " sorting " => $roomsorting , " tables " => $tableArr , " noOfTables " => $numberOfTables );
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:11:57 +01:00
$togoworkprinter = CommonUtils :: getConfigValue ( $pdo , " togoworkprinter " , 0 );
echo json_encode ( array ( " status " => " OK " , " noOfRooms " => $numberOfRooms , " maxTables " => $maxTables , " roomfield " => $roomArr , " togoworkprinter " => $togoworkprinter ));
2020-11-19 22:44:19 +01:00
}
2020-11-19 23:10:06 +01:00
public static function getTablesForGuestsystem ( $pdo ) {
2020-11-19 23:12:10 +01:00
$sql = " SELECT id,name,IFNULL(code,'') as code FROM %resttables% WHERE removed is null AND active=? AND allowoutorder=? " ;
2020-11-19 23:10:06 +01:00
$result = CommonUtils :: fetchSqlAll ( $pdo , $sql , array ( 1 , 1 ));
return $result ;
}
2020-11-19 23:13:57 +01:00
2020-11-19 23:14:02 +01:00
private static function createSingleQRCode ( $guesturl , $tablename , $tableid , $code , $addOnText , $guestqrsize , $guestqrfontsize , $version ) {
$arg = $guesturl . '/index.php?code=' . $code . " _ " . $tableid . " _ " . $version ;
2020-11-19 23:13:57 +01:00
$txt = '<div style="width:' . $guestqrsize . 'px;text-align:center;">' ;
$txt .= 'Tisch: ' . $tablename . '<br>' ;
if ( ! is_null ( $code ) && ( $code != '' )) {
$txt .= '<img src="utilities/osqrcode.php?cmd=link&arg=' . $arg . '" style="width:' . $guestqrsize . 'px;" /><br>' ;
} else {
$txt .= '<p><b>Tischcode wurde noch nicht zugewiesen</b><br>' ;
}
$txt .= '<p><span style="font-size:' . $guestqrfontsize . 'px;">' . $addOnText . '</span>' ;
$txt .= '</div>' ;
return $txt ;
}
2020-11-19 23:14:02 +01:00
private static function createQrCodeForTables ( $pdo , $guesturl , $addOnText , $guestqrsize , $guestqrfontsize , $version ) {
2020-11-19 23:13:57 +01:00
$maxCols = round ( 500.0 / ( $guestqrsize + 20 ));
$allTables = self :: getTablesForGuestsystem ( $pdo );
$txt = '<table class="qrcodes">' ;
$col = 0 ;
foreach ( $allTables as $aTable ) {
$code = $aTable [ 'code' ];
$tableid = $aTable [ 'id' ];
$tablename = $aTable [ 'name' ];
if ( $col == 0 ) {
$txt .= " <tr> " ;
}
2020-11-19 23:14:02 +01:00
$txt .= '<td>' . self :: createSingleQRCode ( $guesturl , $tablename , $tableid , $code , $addOnText , $guestqrsize , $guestqrfontsize , $version );
2020-11-19 23:13:57 +01:00
$col ++ ;
if ( $col == $maxCols ) {
$col = 0 ;
$txt .= " </tr> " ;
}
}
$txt .= " </table> " ;
return $txt ;
}
private static function tableqrcodes () {
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 ( " Content-Type: text/html; charset=utf8 " );
$pdo = DbUtils :: openDbAndReturnPdoStatic ();
2020-11-19 23:14:02 +01:00
$version = CommonUtils :: getConfigValue ( $pdo , 'version' , " 0.0.0 " );
$version = str_replace ( " . " , " " , $version );
2020-11-19 23:13:57 +01:00
$guestUrl = CommonUtils :: getConfigValue ( $pdo , 'guesturl' , '' );
if ( CommonUtils :: strEndsWith ( $guestUrl , " / " )) {
$guestUrl = substr ( $guestUrl , 0 , strlen ( $guestUrl ) - 1 );
}
if ( CommonUtils :: strEndsWith ( $guestUrl , " /index.php " )) {
$guestUrl = substr ( $guestUrl , 0 , strlen ( $guestUrl ) - strlen ( " /index.php " ));
}
$guestqrtext = CommonUtils :: getConfigValue ( $pdo , 'guestqrtext' , '' );
$guestqrsize = CommonUtils :: getConfigValue ( $pdo , 'guestqrsize' , '' );
if (( $guestqrsize < 20 ) || ( $guestqrsize > 500 )) {
$guestqrsize = 150 ;
}
$guestqrfontsize = CommonUtils :: getConfigValue ( $pdo , 'guestqrfontsize' , '' );
if (( $guestqrfontsize < 5 ) || ( $guestqrfontsize > 50 )) {
$guestqrfontsize = 15 ;
}
if ( is_null ( $guestUrl ) || ( $guestUrl == '' )) {
echo " Gastbestell-URL noch nicht konfiguriert " ;
return ;
}
$txt = " <html><head> " ;
$txt .= " <title>Tisch QR-Codes für die Gastbestellung</title> " ;
$txt .= '<meta http-equiv="content-type" content="text/html; charset=utf-8">' ;
2020-11-19 23:14:13 +01:00
$txt .= '<link rel="stylesheet" type="text/css" href="../css/bestformat.css?v=1.6.7">' ;
2020-11-19 23:13:57 +01:00
$txt .= " </head> " ;
$txt .= " <body> " ;
$txt .= " <h1>Tisch QR-Codes für die Gastbestellung</h1><p> " ;
2020-11-19 23:14:02 +01:00
$txt .= self :: createQrCodeForTables ( $pdo , $guestUrl , $guestqrtext , $guestqrsize , $guestqrfontsize , $version );
2020-11-19 23:13:57 +01:00
$txt .= " </body></html> " ;
echo $txt ;
}
2020-11-19 22:44:19 +01:00
}