ordersprinter/webapp/php/utilities/basedb.php

1186 lines
41 KiB
PHP
Raw Normal View History

2020-11-19 22:47:44 +01:00
<?php
class Checks {
private function checkwriteaccessconfigfolder() {
return (is_writable("../php"));
}
private function checkwriteaccessconfigfile() {
if (file_exists("../php/config.php")) {
return (is_writable("../php/config.php"));
} else {
return (is_writable("../php"));
}
}
private function checkwriteaccessprivkey() {
if (file_exists("../php/privkey.pem")) {
return (is_writable("../php/privkey.pem"));
} else {
return (is_writable("../php"));
}
}
private function checkwriteaccesspubkey() {
if (file_exists("../php/cert.pem")) {
return (is_writable("../php/cert.pem"));
} else {
return (is_writable("../php"));
}
}
private function checkwritecustomerfolder() {
return (is_writable("../customer"));
}
private function checkwritespeisekarte() {
if (file_exists("../customer/speisekarte.txt")) {
return (is_writable("../customer/speisekarte.txt"));
} else {
return (is_writable("../customer"));
}
}
function checkWriteAccess() {
$retArray = array(
"configfolder" => $this->checkwriteaccessconfigfolder(),
"configfile" => $this->checkwriteaccessconfigfile(),
"customerfolder" => $this->checkwritecustomerfolder(),
"speisekarte" => $this->checkwritespeisekarte()
);
echo json_encode($retArray);
}
function checkWriteAccessNoJson() {
return(array(
"configfolder" => $this->checkwriteaccessconfigfolder(),
"configfile" => $this->checkwriteaccessconfigfile(),
"customerfolder" => $this->checkwritecustomerfolder(),
"speisekarte" => $this->checkwritespeisekarte(),
"privkey" => $this->checkwriteaccessprivkey(),
"pubkey" => $this->checkwriteaccesspubkey()
));
}
}
class Basedb {
var $prefix = "";
var $timezone = "Europe/Berlin";
function setPrefix($pre) {
$this->prefix = $pre;
}
function setTimeZone($zone) {
$this->timezone = $zone;
}
function doSQL($pdo,$sql) {
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function doSQLcatch($pdo,$sql) {
try {
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
} catch (Exception $e) {
// nothing - table not present or whatever...
}
}
function resolveTablenamesInSqlString($sqlString) {
2020-11-19 23:10:26 +01:00
return DbUtils::substTableAlias($sqlString);
2020-11-19 22:47:44 +01:00
}
function dropTables($pdo) {
2020-11-19 23:00:58 +01:00
$this->doSQLcatch($pdo, "DROP TABLE `%hsout%`");
$this->doSQLcatch($pdo, "DROP TABLE `%hsin%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "DROP TABLE `%comments%`");
$this->doSQLcatch($pdo, "DROP TABLE `%reservations%`");
$this->doSQLcatch($pdo, "DROP TABLE `%work%`");
$this->doSQLcatch($pdo, "DROP TABLE `%hist%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histprod%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histconfig%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histuser%`");
$this->doSQLcatch($pdo, "DROP TABLE `%histactions%`");
$this->doSQLcatch($pdo, "drop TABLE `%queueextras%`");
$this->doSQLcatch($pdo, "drop TABLE `%extrasprods%`");
$this->doSQLcatch($pdo, "drop TABLE `%extras%`");
$this->doSQLcatch($pdo, "drop TABLE `%billproducts%`");
2020-11-19 23:10:26 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%recordsqueue%`");
$this->doSQLcatch($pdo, "drop TABLE `%records%`");
2020-11-19 23:11:27 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%times%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%queue%`");
$this->doSQLcatch($pdo, "drop TABLE `%printjobs%`");
2020-11-19 23:02:12 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%customerlog%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%bill%`");
$this->doSQLcatch($pdo, "drop TABLE `%ratings%`");
2020-11-19 23:10:26 +01:00
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%user%`");
2020-11-19 23:03:48 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%roles%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%closing%`");
$this->doSQLcatch($pdo, "drop TABLE `%config%`");
$this->doSQLcatch($pdo, "drop TABLE `%products%`");
2020-11-19 23:03:35 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%prodimages%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%prodtype%`");
$this->doSQLcatch($pdo, "drop TABLE `%pricelevel%`");
$this->doSQLcatch($pdo, "drop TABLE `%tablepos%`");
$this->doSQLcatch($pdo, "drop TABLE `%tablemaps%`");
$this->doSQLcatch($pdo, "drop TABLE `%resttables%`");
$this->doSQLcatch($pdo, "drop TABLE `%room%`");
$this->doSQLcatch($pdo, "drop TABLE `%payment%`");
2020-11-19 23:02:08 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%groupcustomer%`");
$this->doSQLcatch($pdo, "drop TABLE `%vacations%`");
$this->doSQLcatch($pdo, "drop TABLE `%groups%`");
$this->doSQLcatch($pdo, "drop TABLE `%customers%`");
2020-11-19 22:47:44 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%logo%`");
2020-11-19 23:00:18 +01:00
$this->doSQLcatch($pdo, "drop TABLE `%log%`");
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:02:12 +01:00
2020-11-19 22:47:44 +01:00
2020-11-19 23:02:12 +01:00
function createCustomerLogTable($pdo) {
$sql = "
CREATE TABLE `%customerlog%` (
`id` INT (3) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`date` DATETIME NULL,
`customerid` INT(10) NULL,
`billid` INT(10) NULL,
`action` INT(2) NULL,
2020-11-19 23:10:26 +01:00
`userid` INT(10) NULL,
2020-11-19 23:02:12 +01:00
`remark` VARCHAR ( 500 ) NULL,
FOREIGN KEY (billid) REFERENCES %bill%(id),
FOREIGN KEY (customerid) REFERENCES %customers%(id),
FOREIGN KEY (userid) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:02:12 +01:00
$stmt->execute();
2020-11-19 23:00:18 +01:00
}
function createLogTable($pdo) {
$sql = "
CREATE TABLE `%log%` (
`id` INT (3) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`date` DATETIME NULL,
`component` VARCHAR ( 20 ) NULL,
`message` VARCHAR ( 500 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:00:18 +01:00
$stmt->execute();
2020-11-19 22:47:44 +01:00
}
function createPaymentTable($pdo) {
$sql = "
CREATE TABLE `%payment%` (
`id` INT (3) NOT NULL UNIQUE,
`name` VARCHAR ( 20 ) NOT NULL,
`name_en` VARCHAR ( 20 ) NOT NULL,
`name_esp` VARCHAR ( 20 ) NOT NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createUserTable($pdo)
{
$sql = "
CREATE TABLE `%user%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR ( 150 ) NOT NULL,
`userpassword` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:10:26 +01:00
`is_admin` INT (1) NOT NULL,
`right_waiter` INT (1) NOT NULL,
`right_kitchen` INT (1) NOT NULL,
`right_bar` INT (1) NOT NULL,
`right_supply` INT (1) NOT NULL,
`right_paydesk` INT (1) NOT NULL,
`right_statistics` INT (1) NOT NULL,
`right_bill` INT (1) NOT NULL,
`right_products` INT (1) NOT NULL,
`right_manager` INT (1) NOT NULL,
`right_closing` INT (1) NOT NULL,
`right_reservation` INT (1) NOT NULL,
`right_rating` INT (1) NOT NULL,
`right_changeprice` INT (1) NOT NULL,
`right_customers` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`lastmodule` VARCHAR ( 30 ) NULL,
`ordervolume` INT (2) NULL,
`language` INT (2) NULL,
`receiptprinter` INT (1) NULL,
`roombtnsize` INT(1) NULL,
`tablebtnsize` INT(1) NULL,
`prodbtnsize` INT(1) NULL,
`prefertablemap` INT(1) NULL,
2020-11-19 22:48:24 +01:00
`keeptypelevel` INT(1) NOT NULL,
2020-11-19 22:53:50 +01:00
`extrasapplybtnpos` INT(1) NOT NULL,
2020-11-19 23:10:26 +01:00
`active` INT (2) NOT NULL
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
2020-11-19 23:03:48 +01:00
function createRolesTable($pdo)
{
try {
$sql = "
CREATE TABLE %roles% (
id INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR ( 150 ) NOT NULL,
is_admin INT (1) NOT NULL,
right_waiter INT (1) NOT NULL,
right_kitchen INT (1) NOT NULL,
right_bar INT (1) NOT NULL,
right_supply INT (1) NOT NULL,
right_paydesk INT (1) NOT NULL,
right_statistics INT (1) NOT NULL,
right_bill INT (1) NOT NULL,
right_products INT (1) NOT NULL,
right_manager INT (1) NOT NULL,
right_closing INT (1) NOT NULL,
right_dash INT (1) NOT NULL,
right_reservation INT (1) NOT NULL,
right_rating INT (1) NOT NULL,
right_changeprice INT (1) NOT NULL,
right_customers INT (1) NOT NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
} catch (Exception $ex) {
// table may exists due to other installations
}
}
2020-11-19 22:47:44 +01:00
function createRoomTable($pdo)
{
$sql = "
CREATE TABLE `%room%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`roomname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 22:55:09 +01:00
`abbreviation` VARCHAR (10) NULL,
2020-11-19 22:47:44 +01:00
`printer` INT(2) NULL,
`removed` INT(2) NULL,
`sorting` INT(2) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createTableMapsTable($pdo)
{
$sql = "
CREATE TABLE `%tablemaps%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`roomid` INT (10) NOT NULL,
`img` MEDIUMBLOB,
`sizex` INT(4) NULL,
`sizey` INT(4) NULL,
FOREIGN KEY (roomid) REFERENCES %room%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createTablePosTable($pdo)
{
$sql = "
CREATE TABLE `%tablepos%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tableid` INT (10) NOT NULL,
`x` INT(4) NULL,
`y` INT(4) NULL,
FOREIGN KEY (tableid) REFERENCES %resttables%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createRestTables($pdo)
{
$sql = "
CREATE TABLE `%resttables%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tableno` VARCHAR ( 150 ) NOT NULL,
`roomid` INT ( 10 ) NOT NULL,
`removed` INT(2) NULL,
`sorting` INT(2) NULL,
FOREIGN KEY (roomid) REFERENCES %room%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createConfigTable($pdo) {
$sql = "
CREATE TABLE `%config%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 1000 ) ,
`setting` VARCHAR ( 10000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createLogoTable($pdo) {
$sql = "
CREATE TABLE `%logo%` (
`id` INT (2) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 100 ) ,
`setting` BLOB
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createProdTypeTable($pdo)
{
$sql = "
CREATE TABLE `%prodtype%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 150 ) NOT NULL,
`usekitchen` INT(1) NOT NULL,
`usesupplydesk` INT(1) NOT NULL,
`kind` INT(2) NOT NULL,
`printer` INT(2) NULL,
`sorting` INT(2) NULL,
`reference` INT (10) NULL,
`removed` INT(1) NULL,
FOREIGN KEY (reference) REFERENCES %prodtype%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createExtrasTable($pdo) {
$sql = "
CREATE TABLE `%extras%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:58 +01:00
`price` " . DECIMALSMALL . " NOT NULL,
2020-11-19 22:47:44 +01:00
`removed` INT(1) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createExtrasprodsTable($pdo) {
$sql = "
CREATE TABLE `%extrasprods%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`extraid` INT (10) NOT NULL,
`prodid` INT (10) NOT NULL,
FOREIGN KEY (extraid) REFERENCES %extras%(id),
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createQueueExtrasTable($pdo) {
$sql = "
CREATE TABLE `%queueextras%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`queueid` INT (10) NOT NULL,
`extraid` INT (10) NOT NULL,
`name` VARCHAR (200) NOT NULL,
FOREIGN KEY (extraid) REFERENCES %extras%(id),
FOREIGN KEY (queueid) REFERENCES %queue%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createProductTable($pdo)
{
$sql = "
CREATE TABLE `%products%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`shortname` VARCHAR ( 150 ) NOT NULL,
`longname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:05 +01:00
`priceA` " . DECIMALSMALL . " NULL,
`priceB` " . DECIMALSMALL . " NULL,
`priceC` " .DECIMALSMALL . " NULL,
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
`amount` INT(5) NULL,
2020-11-19 22:47:44 +01:00
`category` INT(3) NULL,
`favorite` INT(1) NULL,
`sorting` INT(2) NULL,
`available` INT(2) NOT NULL,
`audio` VARCHAR ( 150 ) NULL,
`removed` INT(1) NULL,
2020-11-19 23:10:26 +01:00
FOREIGN KEY (category) REFERENCES %prodtype%(id)
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createPriceLevelTable($pdo) {
$sql = "
CREATE TABLE `%pricelevel%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR ( 1000 ) ,
`info` VARCHAR ( 1000 ),
`info_en` VARCHAR ( 1000 ) ,
`info_esp` VARCHAR ( 1000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createClosingTable($pdo) {
$sql = "
CREATE TABLE `%closing%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`closingdate` DATETIME NOT NULL ,
`billcount` INT(5) NOT NULL ,
2020-11-19 23:00:05 +01:00
`billsum` " . DECIMALBIG . " NOT NULL ,
2020-11-19 22:58:23 +01:00
`signature` blob NULL,
2020-11-19 22:47:44 +01:00
`remark` VARCHAR ( 1000 )
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createRatingsTable($pdo) {
$sql = "
CREATE TABLE `%ratings%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`service` INT(2) NULL,
`kitchen` INT(2) NULL,
`remark` VARCHAR ( 200 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createBillTable($pdo)
{
$sql = "
CREATE TABLE `%bill%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`billdate` DATETIME NOT NULL ,
2020-11-19 23:00:05 +01:00
`brutto` " . DECIMALMIDDLE . " NULL,
2020-11-19 23:10:26 +01:00
`netto` " . DECIMALMIDDLE . " NULL,
2020-11-19 23:00:05 +01:00
`prevbrutto` " . DECIMALBIG . " NULL,
`prevnetto` " . DECIMALBIG . " NULL,
2020-11-19 22:47:44 +01:00
`tableid` VARCHAR ( 150 ) NOT NULL,
`closingid` INT(4) NULL,
`status` VARCHAR(2) NULL,
`paymentid` INT(2) NULL,
`userid` INT(3) NULL,
`ref` INT(10) NULL,
2020-11-19 23:00:05 +01:00
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 22:47:44 +01:00
`host` INT(2) NULL,
2020-11-19 22:52:25 +01:00
`reason` VARCHAR ( 150 ) NULL,
2020-11-19 23:00:58 +01:00
`reservationid` VARCHAR( 30 ) NULL,
`guestinfo` VARCHAR( 30 ) NULL,
2020-11-19 23:02:08 +01:00
`intguestid` INT(10) NULL,
`intguestpaid` INT(2) NULL,
2020-11-19 22:58:23 +01:00
`signature`blob NULL,
2020-11-19 23:00:58 +01:00
FOREIGN KEY (closingid) REFERENCES %closing%(id),
2020-11-19 22:47:44 +01:00
FOREIGN KEY (paymentid) REFERENCES %payment%(id),
FOREIGN KEY (userid) REFERENCES %user%(id),
2020-11-19 23:02:08 +01:00
FOREIGN KEY (ref) REFERENCES %bill%(id),
FOREIGN KEY (intguestid) REFERENCES %customers%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:02:08 +01:00
$stmt->execute();
}
function createCustomersTable($pdo)
{
$sql = "
CREATE TABLE `%customers%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR(50) NULL,
`address` VARCHAR(200) NULL,
`email` VARCHAR(50) NULL,
`phone` VARCHAR(30) NULL,
`mobil` VARCHAR(30) NULL,
`www` VARCHAR(50) NULL,
`remark` VARCHAR(500) NULL,
`created` DATETIME NULL,
`lastmodified` DATETIME NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:02:08 +01:00
$stmt->execute();
}
function createGroupsTable($pdo)
{
$sql = "
CREATE TABLE `%groups%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR(50) NULL,
`remark` VARCHAR(200) NULL,
`created` DATETIME NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:02:08 +01:00
$stmt->execute();
}
function createGroupCustomerTable($pdo)
{
$sql = "
CREATE TABLE `%groupcustomer%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`groupid` INT(10) NOT NULL,
`customerid` INT(10) NOT NULL,
FOREIGN KEY (groupid) REFERENCES %groups%(id),
FOREIGN KEY (customerid) REFERENCES %customers%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:02:08 +01:00
$stmt->execute();
}
function createVacationsTable($pdo)
{
$sql = "
CREATE TABLE `%vacations%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`customerid` INT(10) NOT NULL,
`checkin` DATE NULL,
`checkout` DATE NULL,
`room` VARCHAR(50) NULL,
`remark` VARCHAR(200) NULL,
FOREIGN KEY (customerid) REFERENCES %customers%(id)
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
/*
* Create the queue table:
* action: P=Pay, S=Storno
*/
function createQueueTable($pdo)
{
$sql = "
CREATE TABLE `%queue%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tablenr` INT( 3 ) NULL ,
`productid` INT( 10 ) NULL ,
`pricelevel` INT( 3 ) NOT NULL ,
2020-11-19 23:00:05 +01:00
`price` " . DECIMALSMALL . " NOT NULL,
`tax` " . DECIMALSMALL . " NOT NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
2020-11-19 22:47:44 +01:00
`productname` VARCHAR( 150 ) NULL,
`ordertime` DATETIME NULL ,
2020-11-19 23:10:26 +01:00
`orderuser` INT(10) NOT NULL ,
2020-11-19 22:47:44 +01:00
`anoption` VARCHAR( 150 ) NULL ,
2020-11-19 22:55:20 +01:00
`pricechanged` INT(1) NULL ,
`togo` INT(1) NULL ,
2020-11-19 23:00:46 +01:00
`readytime` DATETIME NULL,
2020-11-19 22:47:44 +01:00
`delivertime` DATETIME NULL,
`paidtime` DATETIME NULL,
`billid` INT(10),
`toremove` INT(3) NOT NULL,
`cooking` INT(10) NULL,
`workprinted` INT(2) NOT NULL,
2020-11-19 22:50:09 +01:00
`isclosed` INT(1) NULL,
2020-11-19 22:47:44 +01:00
FOREIGN KEY (tablenr) REFERENCES %resttables%(id),
FOREIGN KEY (pricelevel) REFERENCES %pricelevel%(id),
FOREIGN KEY (productid) REFERENCES %products%(id),
2020-11-19 23:00:58 +01:00
FOREIGN KEY (billid) REFERENCES %bill%(id),
2020-11-19 22:47:44 +01:00
FOREIGN KEY (cooking) REFERENCES %user%(id),
FOREIGN KEY (orderuser) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createBillProductsTable($pdo) {
$sql = "
CREATE TABLE `%billproducts%` (
`queueid` INT( 10 ) NOT NULL,
`billid` INT(10) NOT NULL,
FOREIGN KEY (queueid) REFERENCES %queue%(id),
2020-11-19 23:00:58 +01:00
FOREIGN KEY (billid) REFERENCES %bill%(id)
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
2020-11-19 23:03:35 +01:00
function createProdimagesTable($pdo) {
$sql = "
CREATE TABLE `%prodimages%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`imgh` MEDIUMBLOB,
`imgm` MEDIUMBLOB,
`imgl` MEDIUMBLOB
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
try {
$this->doSQL($pdo,$sql);
} catch (Exception $ex) {
// do nothing - the table may already exist (previous installation etc.
}
}
2020-11-19 22:47:44 +01:00
function createHistTables($pdo) {
$sql = "
CREATE TABLE `%hist%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`action` INT ( 2 ) NOT NULL,
`refid` INT (10) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histprod%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`prodid` INT (10) NOT NULL,
`shortname` VARCHAR ( 150 ) NOT NULL,
`longname` VARCHAR ( 150 ) NOT NULL,
2020-11-19 23:00:05 +01:00
`priceA` " . DECIMALSMALL . " NULL,
`priceB` " . DECIMALSMALL . " NULL,
`priceC` " . DECIMALSMALL . " NULL,
`tax` " . DECIMALSMALL . " NULL,
2020-11-19 23:00:31 +01:00
`taxaustria` INT(1) NULL,
2020-11-19 22:47:44 +01:00
`sorting` INT(2) NULL,
`available` INT(2) NOT NULL,
`favorite` INT(1) NULL,
`audio` VARCHAR ( 150 ) NULL,
2020-11-19 23:00:35 +01:00
`extras` VARCHAR ( 300 ) NULL,
2020-11-19 22:47:44 +01:00
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histconfig%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`configid` INT (10) ,
`setting` VARCHAR ( 10000 ),
FOREIGN KEY (configid) REFERENCES %config%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histuser%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userid` INT (10) ,
`username` VARCHAR ( 150 ) NOT NULL,
`is_admin` INT (1) NOT NULL,
`right_waiter` INT (1) NOT NULL,
`right_kitchen` INT (1) NOT NULL,
`right_bar` INT (1) NOT NULL,
`right_supply` INT (1) NOT NULL,
`right_paydesk` INT (1) NOT NULL,
`right_statistics` INT (1) NOT NULL,
`right_bill` INT (1) NOT NULL,
`right_products` INT (1) NOT NULL,
`right_manager` INT (1) NOT NULL,
2020-11-19 22:59:47 +01:00
`right_closing` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`right_reservation` INT (1) NOT NULL,
`right_rating` INT (1) NOT NULL,
`right_changeprice` INT (1) NOT NULL,
2020-11-19 23:02:08 +01:00
`right_customers` INT (1) NOT NULL,
2020-11-19 22:47:44 +01:00
`active` INT (2) NOT NULL,
FOREIGN KEY (userid) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
$sql = "
CREATE TABLE `%histactions%` (
`id` INT (3) NOT NULL,
`name` VARCHAR ( 20 ) NOT NULL,
`description` VARCHAR ( 150 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb
";
$this->doSQL($pdo,$sql);
}
function createPrintJobsTable($pdo) {
$sql = "
CREATE TABLE `%printjobs%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`content` TEXT NOT NULL ,
`type` INT (2) NOT NULL ,
2020-11-19 23:10:26 +01:00
`printer` INT(2) NULL
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
function createWorkTable($pdo) {
$sql = "
CREATE TABLE `%work%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`item` VARCHAR ( 20 ) NOT NULL ,
`value` VARCHAR ( 20 ) NOT NULL ,
2020-11-19 22:58:23 +01:00
`signature` blob NULL
2020-11-19 22:47:44 +01:00
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createRecordsQueueTable($pdo) {
$sql = "
CREATE TABLE `%recordsqueue%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`recordid` INT (10) NOT NULL,
`queueid` INT (10) NOT NULL,
FOREIGN KEY (recordid) REFERENCES %records%(id),
FOREIGN KEY (queueid) REFERENCES %queue%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
function createRecordsTable($pdo) {
$sql = "
CREATE TABLE `%records%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`userid` INT (10) NULL,
`tableid` INT (10) NULL,
`action` INT (3) NOT NULL,
FOREIGN KEY (userid) REFERENCES %user%(id),
FOREIGN KEY (tableid) REFERENCES %resttables%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
}
2020-11-19 23:11:27 +01:00
function createTimesTable($pdo) {
$sql = "
CREATE TABLE `%times%` (
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` DATETIME NOT NULL ,
`userid` INT (10) NULL,
`action` INT(1) NULL,
`comment` VARCHAR(200) NULL,
FOREIGN KEY (userid) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
2020-11-19 22:47:44 +01:00
function getPrivkey($pdo) {
$sql = "SELECT signature FROM %work% WHERE item=?";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute(array("privkey"));
$row = $stmt->fetchObject();
$privkey = $row->signature;
return(openssl_get_privatekey($privkey));
}
function signLastBillid($pdo) {
$sql = "SELECT MAX(id) as maxbillid FROM %bill%";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute();
$row =$stmt->fetchObject();
if ($row != null) {
$lastBillId = $row->maxbillid;
} else {
$lastBillId = 0;
}
$pkeyid = $this->getPrivkey($pdo);
$lastBillId = intval($lastBillId);
openssl_sign("B($lastBillId)", $signature, $pkeyid);
openssl_free_key($pkeyid);
$signature = base64_encode($signature);
$sql = "SELECT id FROM %work% WHERE item=?";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute(array("lastbillid"));
if ($stmt->rowCount() > 0) {
$sql = "UPDATE %work% SET value=?, signature=? WHERE item=?";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute(array($lastBillId,$signature,"lastbillid"));
} else {
$sql = "INSERT INTO `%work%` (`id` , `item`,`value`,`signature`) VALUES ( NULL,?,?,?)";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 22:47:44 +01:00
$stmt->execute(array("lastbillid",$lastBillId,$signature));
}
}
2020-11-19 23:10:06 +01:00
function initTableOrder($pdo) {
$maxNoOfRoom = array();
$sql = "SELECT id,roomid FROM %resttables% WHERE removed is null";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$sql = "UPDATE %resttables% SET sorting=? WHERE id=?";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
foreach ($result as $r) {
$tableid = $r["id"];
$roomid = $r["roomid"];
if (!key_exists($roomid, $maxNoOfRoom)) {
$maxNoOfRoom[$roomid] = 0;
}
$nextSort = $maxNoOfRoom[$roomid] + 1;
$maxNoOfRoom[$roomid] = $nextSort;
$stmt->execute(array($nextSort,$tableid));
}
$sql = "UPDATE %resttables% SET active='1' WHERE active is null";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
$stmt->execute();
$sql = "UPDATE %resttables% SET allowoutorder='1' WHERE allowoutorder is null";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
$stmt->execute();
$sql = "UPDATE %resttables% SET name=tableno WHERE name is null";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
$stmt->execute();
}
function initRoomOrder($pdo) {
$sql = "SELECT id FROM %room% WHERE removed IS NULL ORDER BY id";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$counter = 1;
$sql = "UPDATE %room% SET sorting=? WHERE id=?";
2020-11-19 23:10:26 +01:00
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
2020-11-19 23:10:06 +01:00
foreach($result as $aRoom) {
$stmt->execute(array($counter,$aRoom["id"]));
$counter++;
}
}
2020-11-19 23:00:58 +01:00
function createHsinTable($pdo) {
$sql = "
CREATE TABLE `%hsin%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`reservationid` VARCHAR( 30 ) NULL ,
`billid` INT(10) NULL,
`date` VARCHAR( 10 ) NULL,
`time` VARCHAR( 5 ) NULL,
`number` INT(10) NULL,
`prodid` INT(10) NULL,
`prodname` VARCHAR( 100 ) NULL,
`tax` VARCHAR( 50 ) NULL,
`brutto` " . DECIMALSMALL . " NOT NULL,
`total` " . DECIMALSMALL . " NOT NULL,
`currency` VARCHAR( 5 ) NULL,
`waiterid` VARCHAR( 20 ) NULL,
`waitername` VARCHAR( 20 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createHsoutTable($pdo) {
$sql = "
CREATE TABLE `%hsout%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`reservationid` VARCHAR( 50 ) NULL ,
`object` VARCHAR( 50 ) NULL ,
`guest` VARCHAR( 100 ) NULL
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
2020-11-19 22:47:44 +01:00
function createCommentsTable($pdo) {
$sql = "
CREATE TABLE `%comments%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`comment` VARCHAR( 150 ) NULL ,
`prodid` INT (10) NULL ,
`sorting` INT(2) NULL,
`active` INT (2) NOT NULL,
FOREIGN KEY (prodid) REFERENCES %products%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createReservationsTable($pdo) {
$sql = "
CREATE TABLE `%reservations%` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`creator` INT (10) NOT NULL,
`creationdate` DATETIME NOT NULL,
`scheduledate` DATETIME NOT NULL,
`name` VARCHAR( 100 ) NULL,
`email` VARCHAR( 100 ) NULL,
`starttime` INT (3) NOT NULL,
`duration` INT (3) NOT NULL,
`persons` INT (10) NULL,
`phone` VARCHAR( 40 ) NULL,
`remark` VARCHAR( 400 ) NULL,
FOREIGN KEY (creator) REFERENCES %user%(id)
) CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDb ;
";
$this->doSQL($pdo,$sql);
}
function createEmptyTables($pdo)
{
2020-11-19 23:00:18 +01:00
$this->createLogTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createPaymentTable($pdo);
$this->createUserTable($pdo);
$this->createRoomTable($pdo);
$this->createRestTables($pdo);
$this->createTableMapsTable($pdo);
$this->createTablePosTable($pdo);
$this->createConfigTable($pdo);
$this->createProdTypeTable($pdo);
$this->createProductTable($pdo);
$this->createPriceLevelTable($pdo);
$this->createClosingTable($pdo);
$this->createRatingsTable($pdo);
2020-11-19 23:02:08 +01:00
$this->createCustomersTable($pdo);
$this->createGroupsTable($pdo);
$this->createGroupCustomerTable($pdo);
$this->createVacationsTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createBillTable($pdo);
$this->createQueueTable($pdo);
$this->createBillProductsTable($pdo);
$this->createHistTables($pdo);
$this->createPrintJobsTable($pdo);
$this->createWorkTable($pdo);
$this->createCommentsTable($pdo);
2020-11-19 23:00:58 +01:00
$this->createHsinTable($pdo);
$this->createHsoutTable($pdo);
2020-11-19 22:47:44 +01:00
$this->createReservationsTable($pdo);
$this->createLogoTable($pdo);
$this->createExtrasTable($pdo);
$this->createExtrasprodsTable($pdo);
2020-11-19 23:10:26 +01:00
$this->createQueueExtrasTable($pdo);
}
private function createContentInPaymentTable($pdo) {
$sql = "INSERT INTO %payment% (id,name,name_en,name_esp) VALUES (?,?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('1', 'Barzahlung', 'Cash', 'Contado'));
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('2', 'EC-Kartenzahlung','Electr. purse (EC)','Pago con tarjeta EC'));
$stmt->execute(array('3', 'Kreditkartenzahlung','Credit card','Tarjeta de credito'));
$stmt->execute(array('4', 'Rechnung','bill','Factura'));
$stmt->execute(array('5', 'Ueberweisung','Bank transfer','Transferencia'));
$stmt->execute(array('6', 'Lastschrift','Debit','Cargo en cuenta'));
$stmt->execute(array('7', 'Hotelzimmer','Hotel room','Habitación'));
$stmt->execute(array('8', 'Gast','Guest','Cliente'));
}
public function defineHistActions ($pdo) {
$sql = "INSERT INTO %histactions% (id,name,description) VALUES (?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('1', 'ProdInit', 'Initiales Befuellen der Produkttabelle'));
$stmt->execute(array('2', 'ConfigInit', 'Initiales Befuellen der Konfigurationstabelle'));
$stmt->execute(array('3', 'UserInit', 'Initiales Befuellen der Benutzertabelle'));
$stmt->execute(array('4', 'ProdChange', 'Modifikation der Produktdaten'));
$stmt->execute(array('5', 'ProdCreation', 'Neues Produkt'));
$stmt->execute(array('6', 'ConfigChange', 'Modifikation der Konfiguration'));
$stmt->execute(array('7', 'UserCreation', 'Neuer Benutzer'));
$stmt->execute(array('8', 'UserChange', 'Modifikation eines Benutzers'));
}
function readConfigTableAndSendToHist($pdo) {
$sql_query = "SELECT * FROM %config%";
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (NULL,?,?)";
$stmt_query = $pdo->prepare(DbUtils::substTableAlias($sql_query));
$stmt_insert_histconfig = $pdo->prepare(DbUtils::substTableAlias($sql_insert_histconfig));
$stmt_query->execute();
$result = $stmt_query->fetchAll();
foreach($result as $row){
$stmt_insert_histconfig->execute(array($row['id'],$row['setting']));
$newRefIdForHist = $pdo->lastInsertId();
$this->insertIntoHist($pdo, '2', $newRefIdForHist);
}
}
private function insertIntoHist($pdo,$action,$refIdForHist) {
date_default_timezone_set($this->timezone);
$currentTime = date('Y-m-d H:i:s');
$sql_insert_hist = "INSERT INTO %hist% (id,date,action,refid) VALUES (NULL,?,?,?)";
$stmt_insert_hist = $pdo->prepare(DbUtils::substTableAlias($sql_insert_hist));
$stmt_insert_hist->execute(array($currentTime, $action, $refIdForHist));
}
function createAndIntializeTables($pdo,$decpoint, $billlanguage, $currency, $timezone) {
$this->setTimeZone($timezone);
$this->dropTables($pdo);
$this->createEmptyTables($pdo);
$this->createContentInPaymentTable($pdo);
$this->defineHistActions($pdo);
$rect = Version::getDefaultCustomRecTemplate();
$foodtemplate = Version::getDefaultWorkTemplateFood();
$drinktemplate = Version::getDefaultWorkTemplateDrinks();
$printpass = md5("123");
$this->doSQL($pdo, "INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('1', 'A', 'Normale Preisstufe', 'Normal', 'Normal')");
$this->doSQL($pdo, "INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('2', 'B', 'Wochenendtarif', 'Weekend prices','Tarifa del fin de semana')");
$this->doSQL($pdo, "INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('3', 'C', 'Happy Hour', 'Happy Hour','Happy Hour')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'pricelevel', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'tax', '19.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'togotax', '7.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustrianormal', '20.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaerm1', '10.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaerm2', '13.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaspecial', '19.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'stornocode', '123')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'printpass', '$printpass')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'companyinfo', 'Musterrestaurant\nBeispielstrasse 123\n12345 Musterort')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'rectemplate', '$rect')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'foodtemplate', '$foodtemplate')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'drinktemplate', '$drinktemplate')");
$resTxt = 'Vielen Dank für Ihre Reservierung am DATUM um ZEIT Uhr für ANZAHL Personen.\n\nWir freuen uns auf Ihren Besuch!\n\nBETRIEBSINFO';
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'reservationnote', '$resTxt')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'serverurl', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'email', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'receiveremail', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'payprinttype', 's')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'billlanguage', $billlanguage)");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'currency', '$currency')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'receiptfontsize', '12')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'version', '1.3.0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'paymentconfig', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'remoteaccesscode', null)");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'decpoint', '$decpoint')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'timezone', '$timezone')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'webimpressum', 'Musterrestaurant\nBeispielstrasse 123\n12345 Musterort')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'cancelunpaidcode', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'bigfontworkreceipt', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'prominentsearch', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'groupworkitems', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'addreceipttoprinter', null)");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtphost', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpauth', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpuser', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtppass', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpsecure', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpport', '587')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount1', '50')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount2', '20')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount3', '10')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'austria', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'paydeskid', 'OrderSprinter-1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'aeskey', '0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'certificatesn', '1234567')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'digigopaysetready', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'waitergopayprint', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'oneprodworkreceipts', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'digiprintwork', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'printandqueuejobs', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'cashenabled', '1')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'beepcooked', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hotelinterface', '0')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hsinfile', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hsoutfile', '')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hscurrency', 'EUR')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hs3refresh', '60')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'memorylimit', '256')");
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'restaurantmode', '1')");
// prepare for later inconsistency check if version is obsolete
date_default_timezone_set($timezone);
$installDate = date('Y-m-d H:i:s');
$this->doSQL($pdo, "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'installdate', '$installDate')");
$this->readConfigTableAndSendToHist($pdo);
return;
2020-11-19 23:03:38 +01:00
}
public static function loadSampleProdImages($pdo) {
$sql = "UPDATE %products% SET prodimageid=?";
CommonUtils::execSql($pdo, $sql, array(null));
$sql = "DELETE FROM %prodimages%";
CommonUtils::execSql($pdo, $sql, null);
$sql = "ALTER TABLE %prodimages% AUTO_INCREMENT = 1";
CommonUtils::execSql($pdo, $sql, null);
$file = "../customer/prodimages.txt";
$handle = fopen ($file, "r");
2020-11-19 23:11:27 +01:00
$sql = "INSERT INTO %prodimages% (keyname,imgh,imgm,imgl) VALUES(?,?,?,?)";
2020-11-19 23:03:38 +01:00
while (!feof($handle)) {
$textline = trim(fgets($handle));
if ($textline != "") {
$parts = explode(';', $textline);
2020-11-19 23:11:27 +01:00
CommonUtils::execSql($pdo, $sql, array($parts[1],$parts[2],$parts[3],$parts[4]));
2020-11-19 23:03:38 +01:00
}
}
2020-11-19 23:02:08 +01:00
2020-11-19 23:03:38 +01:00
fclose ($handle);
2020-11-19 22:47:44 +01:00
}
2020-11-19 23:10:23 +01:00
public function sortProdTypes($pdo) {
$orderedTypeIds = array();
$sql = "SELECT id,IFNULL(reference,0) as reference,removed FROM %prodtype% WHERE removed is null ORDER by id";
$alltypes = CommonUtils::fetchSqlAll($pdo, $sql, null);
foreach($alltypes as $aType) {
$id = $aType["id"];
$sql = "UPDATE %prodtype% SET sorting=? WHERE id=?";
if (!array_key_exists($id, $orderedTypeIds)) {
$brothersAndMe = self::getAllTypesOfSameParent($alltypes, $aType);
$sort = 1;
foreach($brothersAndMe as $brotherid) {
CommonUtils::execSql($pdo, $sql, array($sort,$brotherid));
$orderedTypeIds[] = $brotherid;
$sort++;
}
}
}
}
private static function getAllTypesOfSameParent($alltypes,$keyType) {
$brothers = array();
foreach($alltypes as $t) {
if ($t['reference'] == $keyType['reference']) {
$brothers[] = $t['id'];
}
}
return $brothers;
}
2020-11-19 22:47:44 +01:00
}