214 lines
10 KiB
PHP
214 lines
10 KiB
PHP
<?php
|
|
// Datenbank-Verbindungsparameter
|
|
require_once ('config.php');
|
|
|
|
define ('DB_QUEUE_TABLE', TAB_PREFIX . 'queue');
|
|
define ('DB_PRODUCTS_TABLE', TAB_PREFIX . 'products');
|
|
define ('DB_USER_TABLE', TAB_PREFIX . 'user');
|
|
define ('DB_ROOM_TABLE', TAB_PREFIX . 'room');
|
|
define ('DB_RESTTABLES_TABLE', TAB_PREFIX . 'resttables');
|
|
define ('DB_PRODTYPE_TABLE', TAB_PREFIX . 'prodtype');
|
|
define ('DB_TABLEMAPS_TABLE', TAB_PREFIX . 'tablemaps');
|
|
define ('DB_TABLEPOS_TABLE', TAB_PREFIX . 'tablepos');
|
|
define ('DB_BILL_TABLE', TAB_PREFIX . 'bill');
|
|
define ('DB_PRICELEVEL_TABLE', TAB_PREFIX . 'pricelevel');
|
|
define ('DB_CONFIG_TABLE', TAB_PREFIX . 'config');
|
|
define ('DB_CLOSING_TABLE', TAB_PREFIX . 'closing');
|
|
define ('DB_PRINTJOB_TABLE', TAB_PREFIX . 'printjob');
|
|
define ('DB_WORK_TABLE', TAB_PREFIX . 'work');
|
|
define ('DB_COMMENTS_TABLE', TAB_PREFIX . 'comments');
|
|
define ('DB_HSIN_TABLE', TAB_PREFIX . 'hsin');
|
|
define ('DB_HSOUT_TABLE', TAB_PREFIX . 'hsout');
|
|
define ('DB_LOGO_TABLE', TAB_PREFIX . 'logo');
|
|
define ('DB_EXTRAS_TABLE', TAB_PREFIX . 'extras');
|
|
define ('DB_EXTRASPRODS_TABLE', TAB_PREFIX . 'extrasprods');
|
|
|
|
define ('DB_HIST_TABLE', TAB_PREFIX . 'hist');
|
|
define ('DB_HIST_PROD_TABLE', TAB_PREFIX . 'histprod');
|
|
define ('DB_HIST_CONFIG_TABLE', TAB_PREFIX . 'histconfig');
|
|
define ('DB_HIST_USER_TABLE', TAB_PREFIX . 'histuser');
|
|
define ('DB_HIST_ACTIONS_TABLE', TAB_PREFIX . 'histactions');
|
|
|
|
define ('DB_HIST_PAYMENT_TABLE', TAB_PREFIX . 'payment');
|
|
define ('DB_BILLPRODUCTS_TABLE', TAB_PREFIX . 'billproducts');
|
|
define ('DB_RESERVATIONS_TABLE', TAB_PREFIX . 'reservations');
|
|
define ('DB_QUEUEEXTRAS_TABLE', TAB_PREFIX . 'queueextras');
|
|
define ('DB_RATINGS_TABLE', TAB_PREFIX . 'ratings');
|
|
|
|
class DbUtils {
|
|
private static $timezone = null;
|
|
private static $prefix = null;
|
|
|
|
public static function overruleTimeZone($timezone) {
|
|
self::$timezone = $timezone;
|
|
}
|
|
public static function overrulePrefix($prefix) {
|
|
self::$prefix = $prefix;
|
|
}
|
|
|
|
public static function openDbAndReturnPdoStatic () {
|
|
$dsn = 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB;
|
|
$user = MYSQL_USER;
|
|
$password = MYSQL_PASSWORD;
|
|
$pdo = null;
|
|
try {
|
|
$pdo = new PDO($dsn, $user, $password);
|
|
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
}
|
|
catch (PDOException $e) {
|
|
echo 'Connection failed: ' . $e->getMessage();
|
|
}
|
|
return $pdo;
|
|
}
|
|
function openDbAndReturnPdo () {
|
|
$dsn = 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB;
|
|
$user = MYSQL_USER;
|
|
$password = MYSQL_PASSWORD;
|
|
$pdo = null;
|
|
try {
|
|
$pdo = new PDO($dsn, $user, $password);
|
|
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
}
|
|
catch (PDOException $e) {
|
|
echo 'Connection failed: ' . $e->getMessage();
|
|
}
|
|
return $pdo;
|
|
}
|
|
|
|
function testDbAccess($host,$dbname,$user,$pass) {
|
|
$dsn = 'mysql:host=' . $host . ';dbname=' . $dbname;
|
|
$user = $user;
|
|
$password = $pass;
|
|
$pdo = null;
|
|
try {
|
|
$pdo = new PDO($dsn, $user, $password);
|
|
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
}
|
|
catch (PDOException $e) {
|
|
//
|
|
}
|
|
if ($pdo != null) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* To use sql strings that are easy to read the table names are used
|
|
* without variables. But since the user can specify a prefix for all
|
|
* tables the substitution must be done somewhere. This is the function
|
|
* that replaces the %TABLE% by $prefix_table
|
|
*/
|
|
public static function substTableAlias($sqlString) {
|
|
$prefix = TAB_PREFIX;
|
|
if (!is_null(self::$prefix)) {
|
|
$prefix = self::$prefix;
|
|
}
|
|
|
|
$out = str_replace("%queue%",$prefix . 'queue',$sqlString);
|
|
$out = str_replace("%products%",$prefix . 'products',$out);
|
|
$out = str_replace("%user%",$prefix . 'user',$out);
|
|
$out = str_replace("%room%",$prefix . 'room',$out);
|
|
$out = str_replace("%resttables%",$prefix . 'resttables',$out);
|
|
$out = str_replace("%bill%",$prefix . 'bill',$out);
|
|
$out = str_replace("%tablemaps%",$prefix . "tablemaps",$out);
|
|
$out = str_replace("%tablepos%",$prefix . "tablepos",$out);
|
|
|
|
$out = str_replace("%pricelevel%",$prefix . 'pricelevel',$out);
|
|
$out = str_replace("%config%",$prefix . 'config',$out);
|
|
$out = str_replace("%closing%",$prefix . 'closing',$out);
|
|
$out = str_replace("%printjobs%",$prefix . 'printjob',$out);
|
|
|
|
$out = str_replace("%hist%",$prefix . 'hist',$out);
|
|
$out = str_replace("%histprod%",$prefix . 'histprod',$out);
|
|
$out = str_replace("%histconfig%",$prefix . 'histconfig',$out);
|
|
$out = str_replace("%histuser%",$prefix . 'histuser',$out);
|
|
$out = str_replace("%histactions%",$prefix . 'histactions',$out);
|
|
$out = str_replace("%payment%",$prefix . 'payment',$out);
|
|
$out = str_replace("%billproducts%", $prefix . 'billproducts',$out);
|
|
$out = str_replace("%work%",$prefix . 'work',$out);
|
|
$out = str_replace("%comments%",$prefix . 'comments',$out);
|
|
$out = str_replace("%hsin%",$prefix . 'hsin',$out);
|
|
$out = str_replace("%hsout%",$prefix . 'hsout',$out);
|
|
|
|
$out = str_replace("%reservations%",$prefix . 'reservations',$out);
|
|
$out = str_replace("%logo%",$prefix . 'logo',$out);
|
|
$out = str_replace("%log%",$prefix . 'log',$out);
|
|
$out = str_replace("%extras%", $prefix . 'extras',$out);
|
|
$out = str_replace("%extrasprods%",$prefix . 'extrasprods', $out);
|
|
$out = str_replace("%queueextras%",$prefix . 'queueextras', $out);
|
|
$out = str_replace("%ratings%",$prefix . 'ratings', $out);
|
|
return (str_replace("%prodtype%",$prefix . 'prodtype',$out));
|
|
}
|
|
|
|
public function resolveTablenamesInSqlString($sqlString) {
|
|
return DbUtils::substTableAlias($sqlString);
|
|
}
|
|
|
|
public static function getTimeZone() {
|
|
if (is_null(self::$timezone)) {
|
|
if(session_id() == '') {
|
|
session_start();
|
|
}
|
|
if (isset($_SESSION['timezone'])) {
|
|
return $_SESSION['timezone'];
|
|
} else {
|
|
return "Europe/Berlin";
|
|
}
|
|
} else {
|
|
return self::$timezone;
|
|
}
|
|
}
|
|
|
|
public static $userCols = array(
|
|
array("col" => 'id', "hist" => 1, "new" => null, "update" => null),
|
|
array("col" => 'username', "hist" => 1, "new" => 'username', "update" => null),
|
|
array("col" => 'userpassword', "hist" => 0, "new" => null, "update" => null),
|
|
array("col" => 'is_admin', "hist" => 1, "new" => 'isAdmin', "update" => 'isAdmin'),
|
|
array("col" => 'right_waiter', "hist" => 1, "new" => 'rWaiter', "update" => 'rWaiter'),
|
|
array("col" => 'right_kitchen', "hist" => 1, "new" => 'rKitchen', "update" => 'rKitchen'),
|
|
array("col" => 'right_bar', "hist" => 1, "new" => 'rBar', "update" => 'rBar'),
|
|
array("col" => 'right_supply', "hist" => 1, "new" => 'rSupply', "update" => 'rSupply'),
|
|
array("col" => 'right_paydesk', "hist" => 1, "new" => 'rPayDesk', "update" => 'rPayDesk'),
|
|
array("col" => 'right_statistics', "hist" => 1, "new" => 'rStat', "update" => 'rStat'),
|
|
array("col" => 'right_bill', "hist" => 1, "new" => 'rBill', "update" => 'rBill'),
|
|
array("col" => 'right_products', "hist" => 1, "new" => 'rProducts', "update" => 'rProducts'),
|
|
array("col" => 'right_reservation', "hist" => 1, "new" => 'rReservation', "update" => 'rReservation'),
|
|
array("col" => 'right_rating', "hist" => 1, "new" => 'rRating', "update" => 'rRating'),
|
|
array("col" => 'right_changeprice', "hist" => 1, "new" => 'rChangeprice', "update" => 'rChangeprice'),
|
|
array("col" => 'right_manager', "hist" => 1, "new" => 'rManager', "update" => 'rManager'),
|
|
array("col" => 'right_closing', "hist" => 1, "new" => 'rClosing', "update" => 'rClosing'),
|
|
array("col" => 'active', "hist" => 1, "new" => null ,"default" => 1, "update" => null),
|
|
array("col" => 'lastmodule', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'ordervolume', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'language', "hist" => 0, "new" => null, "update" => null),
|
|
array("col" => 'receiptprinter', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'roombtnsize', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'tablebtnsize', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'prodbtnsize', "hist" => 0, "new" => null ,"default" => null, "update" => null),
|
|
array("col" => 'prefertablemap', "hist" => 0, "new" => null ,"default" => 1, "update" => null),
|
|
array("col" => 'keeptypelevel', "hist" => 0, "new" => null ,"default" => 0, "update" => null),
|
|
array("col" => 'extrasapplybtnpos', "hist" => 0, "new" => null ,"default" => 1, "update" => null)
|
|
);
|
|
|
|
|
|
public static $prodCols = array(
|
|
array("col" => 'id', "hist" => 1, "property" => "prodid"),
|
|
array("col" => 'shortname', "hist" => 1, "property" => "shortName"),
|
|
array("col" => 'longname', "hist" => 1, "property" => "longName"),
|
|
array("col" => 'priceA', "hist" => 1, "property" => "priceA"),
|
|
array("col" => 'priceB', "hist" => 1, "property" => "priceB"),
|
|
array("col" => 'priceC', "hist" => 1, "property" => "priceC"),
|
|
array("col" => 'tax', "hist" => 1, "property" => "tax"),
|
|
array("col" => 'taxaustria', "hist" => 1, "property" => "taxaustria"),
|
|
array("col" => 'amount', "hist" => 0, "property" => "amount"),
|
|
array("col" => 'category', "hist" => 0, "property" => "category"),
|
|
array("col" => 'favorite', "hist" => 1, "property" => "favorite"),
|
|
array("col" => 'sorting', "hist" => 1),
|
|
array("col" => 'available', "hist" => 1, "property" => "available"),
|
|
array("col" => 'audio', "hist" => 1, "property" => "audio"),
|
|
array("col" => 'removed', "hist" => 0)
|
|
);
|
|
}
|
|
?>
|