ordersprinter/webapp/install/installer.php

2579 lines
76 KiB
PHP

<?php
error_reporting(E_ALL);
define ('IS_INSTALLMODE', '1');
if (is_readable("../php/config1.php")) {
require_once( "../php/config1.php" );
} else {
require_once( "../php/config.php" );
}
require_once ('../php/utilities/basedb.php');
require_once ('../php/utilities/decimaldefs.php');
require_once ('../php/admin.php');
class ConfigWriter {
function getConfigVals() {
if (!is_readable("../php/config.php") && (!is_readable("../php/config1.php"))) {
echo json_encode(array("status" => "Failed"));
}
$retArray = array(
"host" => MYSQL_HOST,
"db" => MYSQL_DB,
"user" => MYSQL_USER,
"password" => MYSQL_PASSWORD,
"tabprefix" => TAB_PREFIX);
echo json_encode(array("status" => "OK","result" => $retArray));
}
}
class InstallAdmin {
var $pdo;
var $basedb;
var $timezone;
function __construct() {
$this->basedb = new Basedb();
}
function setPrefix($pre) {
$this->basedb->setPrefix($pre);
}
function setPdo($pdo) {
$this->pdo = $pdo;
}
function setTimeZone($zone) {
$this->timezone = $zone;
}
function openDbAndReturnPdo ($host,$db,$user,$password) {
$dsn = 'mysql:host=' . $host . ';dbname=' . $db;
$pdo = null;
try {
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
echo 'Verbindungsproblem: ' . $e->getMessage();
$pdo = null;
}
return $pdo;
}
function checkPhpStatus() {
$extensions = array("gd","mysqli","openssl","pdo_mysql","PDO","session","zlib","curl");
$missing = array();
$extensions_status = 1;
foreach($extensions as $anExtension) {
if (!extension_loaded($anExtension)) {
$missing[] = $anExtension;
$extensions_status = 0;
}
}
set_time_limit(60*5+1);
ini_set('session.gc_maxlifetime',65535);
session_set_cookie_params(65535);
$max_execution_status = 1;
// 5 minutes = 5*60
if (ini_get('max_execution_time') < (5*60)) {
$max_execution_status = 0;
}
$session_lifetime_status = 1;
if (ini_get('session.gc_maxlifetime') < (10*60*60)) {
$session_lifetime_status = 0;
}
$ret = array("extensions_status" => $extensions_status, "missing_extensions" => join(",",$missing),
"max_execution_status" => $max_execution_status, "max_execution_time" => ini_get('max_execution_time'),
"session_lifetime_status" => $session_lifetime_status, "session_gc_maxlifetime" => ini_get('session.gc_maxlifetime')
);
echo json_encode($ret);
}
function updateVersion($pdo,$version) {
$setVersion = "update %config% set setting=? where name='version'";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($setVersion));
$stmt->execute(array($version));
$sql = "SELECT id FROM %config% WHERE name=?";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('version'));
$row = $stmt->fetchObject();
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql_insert_histconfig));
$stmt->execute(array($row->id,$version));
$newRefIdForHist = $pdo->lastInsertId();
$sql = "SELECT setting FROM %config% WHERE name=?";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('timezone'));
$row = $stmt->fetchObject();
date_default_timezone_set($row->setting);
$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($this->basedb->resolveTablenamesInSqlString($sql_insert_hist));
$stmt_insert_hist->execute(array($currentTime, '6', $newRefIdForHist));
}
function updateUserTable1022_1023($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.22") {
return false;
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$adminCl->changeOneConfigDbItem($pdo,"timezone","Europe/Berlin","%config%",true);
$this->updateVersion($pdo, '1.0.23');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1023_1024($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.23") {
$ret = $this->updateUserTable1022_1023($prefix,$version);
if (!$ret) { return false; }
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %user% ADD right_changeprice INT (1) NULL AFTER right_rating";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %user% SET right_changeprice=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$sql = "ALTER TABLE %user% MODIFY right_changeprice INT (1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %histuser% ADD right_changeprice INT (1) NULL AFTER right_rating";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %histuser% SET right_changeprice=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$sql = "ALTER TABLE %histuser% MODIFY right_changeprice INT (1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %user% ADD prefertablemap INT(1) NULL AFTER prodbtnsize";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %user% SET prefertablemap=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$this->basedb->createTableMapsTable($pdo);
$this->basedb->createTablePosTable($pdo);
$this->updateVersion($pdo, '1.0.24');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1024_1025($prefix,$version) {
$ret = true;
if ($version != "1.0.24") {
$ret = $this->updateUserTable1023_1024($prefix,$version);
if (!$ret) { return false; }
}
$ret &= $this->setVersion($prefix, '1.0.25');
return $ret;
}
function updateUserTable1025_1026($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.25") {
$ret = $this->updateUserTable1024_1025($prefix,$version);
if (!$ret) { return false; }
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% DROP payinprogress";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.0.26');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1026_1027($prefix,$version) {
$ret = true;
if ($version != "1.0.26") {
$ret = $this->updateUserTable1025_1026($prefix,$version);
if (!$ret) { return false; }
}
$ret &= $this->setVersion($prefix, '1.0.27');
return $ret;
}
function updateUserTable1027_1028($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.27") {
$ret = $this->updateUserTable1026_1027($prefix,$version);
if (!$ret) { return false; }
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% MODIFY tablenr INT( 3 ) NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.0.28');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1028_1029($prefix,$version) {
$ret = true;
if ($version != "1.0.28") {
$ret = $this->updateUserTable1027_1028($prefix,$version);
if (!$ret) { return false; }
}
$ret &= $this->setVersion($prefix, '1.0.29');
return $ret;
}
function updateUserTable1029_1030($prefix,$version) {
$ret = true;
if ($version != "1.0.29") {
$ret = $this->updateUserTable1028_1029($prefix,$version);
if (!$ret) { return false; }
}
$ret &= $this->setVersion($prefix, '1.0.30');
return $ret;
}
function updateUserTable1030_1031($prefix,$version) {
$ret = true;
if ($version != "1.0.30") {
$ret = $this->updateUserTable1029_1030($prefix,$version);
if (!$ret) { return false; }
}
$ret &= $this->setVersion($prefix, '1.0.31');
return $ret;
}
function updateUserTable1031_1032($prefix,$version) {
$ret = true;
if ($version != "1.0.31") {
$ret = $this->updateUserTable1030_1031($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.32');
return $ret;
}
function updateUserTable1032_1033($prefix,$version) {
$ret = true;
if ($version != "1.0.32") {
$ret = $this->updateUserTable1031_1032($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.33');
return $ret;
}
function updateUserTable1033_1034($prefix,$version) {
$ret = true;
if ($version != "1.0.33") {
$ret = $this->updateUserTable1032_1033($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.34');
return $ret;
}
function updateUserTable1034_1035($prefix,$version) {
$ret = true;
if ($version != "1.0.34") {
$ret = $this->updateUserTable1033_1034($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.35');
return $ret;
}
function updateUserTable1035_1036($prefix,$version) {
$ret = true;
if ($version != "1.0.35") {
$ret = $this->updateUserTable1034_1035($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.36');
return $ret;
}
function updateUserTable1036_1037($prefix,$version) {
$ret = true;
if ($version != "1.0.36") {
$ret = $this->updateUserTable1035_1036($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.37');
return $ret;
}
function updateUserTable1037_1038($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.37") {
$ret = $this->updateUserTable1036_1037($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% DROP action";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "ALTER TABLE %queue% ADD tax " . DECIMALSMALL . " NULL AFTER price";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "UPDATE %queue%,%bill% SET %queue%.tax = %bill%.tax WHERE %queue%.billid=%bill%.id";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
// at this point all queue items have the tax from the bill, if their billid was set - otherwise they keep being NULL
$sql = "UPDATE %queue%,%config% SET %queue%.tax = %config%.setting WHERE %queue%.billid is NULL AND %config%.name='tax' AND %queue%.tablenr is not null;";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "UPDATE %queue%,%config% SET %queue%.tax = %config%.setting WHERE %queue%.billid is NULL AND %config%.name='togotax' AND %queue%.tablenr is null;";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
// at this point all unpaid products have the normal tax
// allow bill table to have no taxes (tax column is needed for signature of old bills (verifyBill)
$sql = "ALTER TABLE %bill% MODIFY tax decimal(5,2) NULL";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "ALTER TABLE %queue% MODIFY tax " . DECIMALSMALL . " NOT NULL";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "ALTER TABLE %products% ADD tax " . DECIMALSMALL . " NULL AFTER priceC";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$sql = "ALTER TABLE %histprod% ADD tax " . DECIMALSMALL . " NULL AFTER priceC";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$this->updateVersion($pdo, "1.0.38");
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1038_1039($prefix,$version) {
$ret = true;
if ($version != "1.0.38") {
$ret = $this->updateUserTable1037_1038($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.0.39');
return $ret;
}
function updateUserTable1039_1040($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.39") {
$ret = $this->updateUserTable1038_1039($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('cancelunpaidcode',''));
$sql = "ALTER TABLE %hist% MODIFY refid INT (10) NULL";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.0.40');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1040_1041($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.40") {
$ret = $this->updateUserTable1039_1040($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %prodtype% ADD printer INT(2) NULL AFTER kind";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %prodtype% SET printer=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$sql = "UPDATE %printjobs% SET printer=? WHERE (type=1 OR type=2) AND printer is null";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$this->updateVersion($pdo, '1.0.41');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1041_1042($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.41") {
$ret = $this->updateUserTable1040_1041($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.0.42');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1042_1043($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.0.42") {
$ret = $this->updateUserTable1041_1042($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% ADD orderuser INT(10) NULL AFTER ordertime";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
// get the first user - at least the admin should be aways there
$sql = "SELECT id FROM %user% WHERE active=? ORDER BY id LIMIT 1";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$row = $stmt->fetchObject();
$userid = $row->id;
$sql = "UPDATE %queue% SET orderuser=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($userid));
$sql = "ALTER TABLE %queue% MODIFY orderuser INT(10) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %room% ADD printer INT(2) NULL AFTER roomname";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.0.43');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1043_1100($prefix,$version) {
$ret = true;
if ($version != "1.0.43") {
$ret = $this->updateUserTable1042_1043($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.0');
return $ret;
}
function updateUserTable1100_1101($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.0") {
$ret = $this->updateUserTable1043_1100($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %user% ADD keeptypelevel INT(1) NULL AFTER prefertablemap";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %user% SET keeptypelevel=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(0));
$sql = "ALTER TABLE %user% MODIFY keeptypelevel INT(1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('bigfontworkreceipt','0'));
$this->updateVersion($pdo, '1.1.1');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1101_1102($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.1") {
$ret = $this->updateUserTable1100_1101($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% ADD isclosed INT(1) NULL AFTER workprinted";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "select max(closingdate) as lastdate from %closing%";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$row = $stmt->fetchObject();
$lastclosingdate = $row->lastdate;
if (!is_null($lastclosingdate)) {
$sql = "UPDATE %queue% SET isclosed=? WHERE ordertime <= ?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1,$lastclosingdate));
}
$this->updateVersion($pdo, '1.1.2');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1102_1103($prefix,$version) {
$ret = true;
if ($version != "1.1.2") {
$ret = $this->updateUserTable1101_1102($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.3');
return $ret;
}
function updateUserTable1103_1104($prefix,$version) {
$ret = true;
if ($version != "1.1.3") {
$ret = $this->updateUserTable1102_1103($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.4');
return $ret;
}
function updateUserTable1104_1105($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.4") {
$ret = $this->updateUserTable1103_1104($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %bill% ADD reason VARCHAR ( 150 ) NULL AFTER host";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('prominentsearch','0'));
$this->updateVersion($pdo, '1.1.5');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1105_1106($prefix,$version) {
$ret = true;
if ($version != "1.1.5") {
$ret = $this->updateUserTable1104_1105($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.6');
return $ret;
}
function updateUserTable1106_1107($prefix,$version) {
$ret = true;
if ($version != "1.1.6") {
$ret = $this->updateUserTable1105_1106($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.7');
return $ret;
}
function updateUserTable1107_1108($prefix,$version) {
$ret = true;
if ($version != "1.1.7") {
$ret = $this->updateUserTable1106_1107($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.8');
return $ret;
}
function updateUserTable1108_1109($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.8") {
$ret = $this->updateUserTable1107_1108($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array('groupworkitems','1'));
$sql = "ALTER TABLE %user% ADD extrasapplybtnpos INT(1) NULL AFTER keeptypelevel";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %user% SET extrasapplybtnpos=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1));
$sql = "ALTER TABLE %user% MODIFY extrasapplybtnpos INT(1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.1.9');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1109_1110($prefix,$version) {
$ret = true;
if ($version != "1.1.9") {
$ret = $this->updateUserTable1108_1109($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.10');
return $ret;
}
function updateUserTable1110_1111($prefix,$version) {
$ret = true;
if ($version != "1.1.10") {
$ret = $this->updateUserTable1109_1110($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.11');
return $ret;
}
function updateUserTable1111_1112($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.11") {
$ret = $this->updateUserTable1110_1111($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %room% ADD `abbreviation` VARCHAR (10) NULL AFTER roomname";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.1.12');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1112_1113($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.12") {
$ret = $this->updateUserTable1111_1112($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %queue% ADD pricechanged INT(1) NULL AFTER anoption";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %queue% ADD togo INT(1) NULL AFTER pricechanged";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %queue% SET pricechanged=?,togo=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(0,0));
$this->updateVersion($pdo, '1.1.13');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1113_1114($prefix,$version) {
$ret = true;
if ($version != "1.1.13") {
$ret = $this->updateUserTable1112_1113($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.14');
return $ret;
}
function updateUserTable1114_1115($prefix,$version) {
$ret = true;
if ($version != "1.1.14") {
$ret = $this->updateUserTable1113_1114($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.15');
return $ret;
}
function updateUserTable1115_1116($prefix,$version) {
$ret = true;
if ($version != "1.1.15") {
$ret = $this->updateUserTable1114_1115($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.16');
return $ret;
}
function updateUserTable1116_1117($prefix,$version) {
$ret = true;
if ($version != "1.1.16") {
$ret = $this->updateUserTable1115_1116($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.17');
return $ret;
}
function updateUserTable1117_1118($prefix,$version) {
$ret = true;
if ($version != "1.1.17") {
$ret = $this->updateUserTable1116_1117($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.18');
return $ret;
}
function updateUserTable1118_1119($prefix,$version) {
$ret = true;
if ($version != "1.1.18") {
$ret = $this->updateUserTable1117_1118($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.19');
return $ret;
}
function updateUserTable1119_1120($prefix,$version) {
$ret = true;
if ($version != "1.1.19") {
$ret = $this->updateUserTable1118_1119($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.20');
return $ret;
}
function updateUserTable1120_1121($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.20") {
$ret = $this->updateUserTable1119_1120($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('discount1','50'));
$stmt->execute(array('discount2','20'));
$stmt->execute(array('discount3','10'));
$stmt->execute(array('austria','0'));
$this->updateVersion($pdo, '1.1.21');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1121_1122($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.21") {
$ret = $this->updateUserTable1120_1121($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('paydeskid','OrderSprinter-1'));
$stmt->execute(array('aeskey','0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20'));
$stmt->execute(array('certificatesn','1234567'));
$sql = "ALTER TABLE %bill% ADD prevbrutto " . DECIMALBIG . " NULL AFTER netto";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %bill% ADD prevnetto " . DECIMALBIG . " NULL AFTER prevbrutto";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "SELECT IFNULL(MAX(id), 0) as maxid FROM %bill%";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$row = $stmt->fetchObject();
$maxid = $row->maxid;
$sql = "UPDATE %bill% SET prevbrutto=?, prevnetto=? WHERE id=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(0,0,1));
for ($i=2;$i<=$maxid;$i++) {
$sql = "SELECT SUM(brutto) as sumbrutto, SUM(netto) as sumnetto FROM %bill% WHERE id<?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($i));
$row = $stmt->fetchObject();
$sql = "UPDATE %bill% SET prevbrutto=?, prevnetto=? WHERE id=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array($row->sumbrutto,$row->sumnetto,$i));
}
$this->updateVersion($pdo, '1.1.22');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1122_1123($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.22") {
$ret = $this->updateUserTable1121_1122($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "ALTER TABLE %work% MODIFY signature blob NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %bill% MODIFY signature blob NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %closing% MODIFY signature blob NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->updateVersion($pdo, '1.1.23');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1123_1124($prefix,$version) {
$ret = true;
if ($version != "1.1.23") {
$ret = $this->updateUserTable1122_1123($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.24');
return $ret;
}
function updateUserTable1124_1125($prefix,$version) {
$ret = true;
if ($version != "1.1.24") {
$ret = $this->updateUserTable1123_1124($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.25');
return $ret;
}
function updateUserTable1125_1126($prefix,$version) {
$ret = true;
if ($version != "1.1.25") {
$ret = $this->updateUserTable1124_1125($prefix,$version);
if (!$ret) {
return false;
}
}
$ret &= $this->setVersion($prefix, '1.1.26');
return $ret;
}
function updateUserTable1126_1127($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.26") {
$ret = $this->updateUserTable1125_1126($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('digigopaysetready','1'));
$this->updateVersion($pdo, '1.1.27');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1127_1128($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.27") {
$ret = $this->updateUserTable1126_1127($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$rect = $this->getDefaultCustomRecTemplate();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('rectemplate',$rect));
$this->updateVersion($pdo, '1.1.28');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1128_1129($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.28") {
$ret = $this->updateUserTable1127_1128($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('waitergopayprint',0));
$this->updateVersion($pdo, '1.1.29');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1129_1130($prefix,$version) {
$pdo = $this->pdo;
try {
if ($version != "1.1.29") {
$ret = $this->updateUserTable1128_1129($prefix,$version);
if (!$ret) {
return false;
}
}
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
// Bugfix - the update chain was ignoring the step to 1.1.27
$sql = "select count(id) as reccount from %config% where name='rectemplate'";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$row = $stmt->fetchObject();
if (intval($row->reccount) == 0) {
$rect = $this->getDefaultCustomRecTemplate();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('rectemplate',$rect));
}
$this->updateVersion($pdo, '1.1.30');
return true;
} catch (PDOException $e) {
return false;
}
}
private function execSql($pdo,$sql) {
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
}
private function execSqlWithParam($pdo,$sql,$param) {
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute($param);
}
function updateUserTable1130_1200($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.1.30") {
$ret = $this->updateUserTable1129_1130($prefix, $version);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->execSql($pdo, "ALTER TABLE %user% ADD right_closing INT (1) NULL AFTER right_products");
$this->execSql($pdo, "ALTER TABLE %histuser% ADD right_closing INT (1) NULL AFTER right_products");
$this->execSql($pdo, "UPDATE %user% SET right_closing=right_manager");
$this->execSql($pdo, "UPDATE %histuser% SET right_closing=right_manager");
$this->execSql($pdo, "ALTER TABLE %user% MODIFY right_closing INT(1) NOT NULL");
$this->execSql($pdo, "ALTER TABLE %histuser% MODIFY right_closing INT(1) NOT NULL");
$this->updateVersion($pdo, '1.2.0');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1200_1201($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.0") {
$ret = $this->updateUserTable1130_1200($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('addreceipttoprinter',null));
$this->updateVersion($pdo, '1.2.1');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1201_1202($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.1") {
$ret = $this->updateUserTable1200_1201($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$foodTemplate = $this->getDefaultWorkTemplateFood();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('foodtemplate',$foodTemplate));
$drinkTemplate = $this->getDefaultWorkTemplateDrinks();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('drinktemplate',$drinkTemplate));
$this->updateVersion($pdo, '1.2.2');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1202_1203($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.2") {
$ret = $this->updateUserTable1201_1202($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.3');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1203_1204($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.3") {
$ret = $this->updateUserTable1202_1203($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.4');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1204_1205($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.4") {
$ret = $this->updateUserTable1203_1204($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('oneprodworkreceipts',0));
$stmt->execute(array('digiprintwork',1));
$this->updateVersion($pdo, '1.2.5');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1205_1206($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.5") {
$ret = $this->updateUserTable1204_1205($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.6');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1206_1207($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.6") {
$ret = $this->updateUserTable1205_1206($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.7');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1207_1208($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.7") {
$ret = $this->updateUserTable1206_1207($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->basedb->createLogTable($pdo);
$this->updateVersion($pdo, '1.2.8');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1208_1209($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.8") {
$ret = $this->updateUserTable1207_1208($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.9');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1209_1210($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.9") {
$ret = $this->updateUserTable1208_1209($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.10');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1210_1211($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.10") {
$ret = $this->updateUserTable1209_1210($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('taxaustrianormal','20.0'));
$stmt->execute(array('taxaustriaerm1','10.0'));
$stmt->execute(array('taxaustriaerm2','13.0'));
$stmt->execute(array('taxaustriaspecial','19.0'));
$this->execSql($pdo, "ALTER TABLE %products% ADD taxaustria INT (1) NULL AFTER tax");
$this->execSql($pdo, "ALTER TABLE %products% ADD amount INT (5) NULL AFTER taxaustria");
$this->execSql($pdo, "ALTER TABLE %histprod% ADD taxaustria INT (1) NULL AFTER tax");
$this->execSql($pdo, "ALTER TABLE %queue% ADD taxaustria INT (1) NULL AFTER tax");
$this->updateVersion($pdo, '1.2.11');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1211_1212($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.11") {
$ret = $this->updateUserTable1210_1211($prefix, $version, $dbname);
if (!$ret) {
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->execSql($pdo, "ALTER TABLE %histprod% MODIFY extras VARCHAR(300) NULL");
$this->updateVersion($pdo, '1.2.12');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1212_1213($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.12") {
$ret = $this->updateUserTable1211_1212($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.11 to 1.2.12 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.13');
return true;
} catch (PDOException $e) {
return false;
}
}
function updateUserTable1213_1214($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.13") {
$ret = $this->updateUserTable1212_1213($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.12 to 1.2.13 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.14');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.13 to 1.2.14: $e";
return false;
}
}
function updateUserTable1214_1215($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.14") {
$ret = $this->updateUserTable1213_1214($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.13 to 1.2.14 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->execSql($pdo, "ALTER TABLE %queue% MODIFY readytime DATETIME NULL");
$this->execSqlWithParam($pdo, "UPDATE %queue% SET readytime=? WHERE readytime=?",array(null,'0000-00-00 00:00:00'));
$this->execSqlWithParam($pdo, "UPDATE %queue% SET paidtime=? WHERE paidtime=?",array(null,'0000-00-00 00:00:00'));
$this->execSqlWithParam($pdo, "UPDATE %queue% SET delivertime=? WHERE delivertime=?",array(null,'0000-00-00 00:00:00'));
$this->execSql($pdo, "OPTIMIZE TABLE %queue%");
$this->updateVersion($pdo, '1.2.15');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.14 to 1.2.15: $e";
return false;
}
}
function updateUserTable1215_1216($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.15") {
$ret = $this->updateUserTable1214_1215($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.14 to 1.2.15 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.16');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.15 to 1.2.16: $e";
return false;
}
}
function updateUserTable1216_1217($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.16") {
$ret = $this->updateUserTable1215_1216($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.15 to 1.2.16 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.17');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.16 to 1.2.17: $e";
return false;
}
}
function updateUserTable1217_1218($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.17") {
$ret = $this->updateUserTable1216_1217($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.16 to 1.2.17 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('printandqueuejobs','0'));
$stmt->execute(array('cashenabled','1'));
$stmt->execute(array('beepcooked','0'));
$this->updateVersion($pdo, '1.2.18');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.17 to 1.2.18: $e";
return false;
}
}
function updateUserTable1218_1219($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.18") {
$ret = $this->updateUserTable1217_1218($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.17 to 1.2.18 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO %payment% (id,name,name_en,name_esp) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('7', 'Hotelzimmer','Hotel room','Habitación'));
$this->basedb->createHsinTable($pdo);
$this->basedb->createHsoutTable($pdo);
$sql = "ALTER TABLE %bill% ADD reservationid VARCHAR(30) NULL AFTER reason";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %bill% ADD guestinfo VARCHAR(30) NULL AFTER reservationid";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('memorylimit','256'));
$this->updateVersion($pdo, '1.2.19');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.18 to 1.2.19: $e";
return false;
}
}
function updateUserTable1219_1220($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.19") {
$ret = $this->updateUserTable1218_1219($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.18 to 1.2.19 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.20');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.19 to 1.2.20: $e";
return false;
}
}
function updateUserTable1220_1221($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.20") {
$ret = $this->updateUserTable1219_1220($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.19 to 1.2.20 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('hs3refresh','60'));
$this->updateVersion($pdo, '1.2.21');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.20 to 1.2.21: $e";
return false;
}
}
function updateUserTable1221_1222($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.21") {
$ret = $this->updateUserTable1220_1221($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.20 to 1.2.21 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.2.22');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.21 to 1.2.22: $e";
return false;
}
}
function updateUserTable1222_1300($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.2.22") {
$ret = $this->updateUserTable1221_1222($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.21 to 1.2.22 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO %payment% (id,name,name_en,name_esp) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('8', 'Gast','Guest','Cliente'));
$sql = "ALTER TABLE %user% ADD right_customers INT (1) NULL AFTER right_changeprice";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %user% SET right_customers=right_manager";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %user% MODIFY right_customers INT (1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->execSql($pdo, "OPTIMIZE TABLE %user%");
$sql = "ALTER TABLE %histuser% ADD right_customers INT (1) NULL AFTER right_changeprice";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "UPDATE %histuser% SET right_customers=?";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(0));
$sql = "ALTER TABLE %histuser% MODIFY right_customers INT (1) NOT NULL";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->execSql($pdo, "OPTIMIZE TABLE %histuser%");
$this->basedb->createCustomersTable($pdo);
$this->basedb->createGroupsTable($pdo);
$this->basedb->createGroupCustomerTable($pdo);
$this->basedb->createVacationsTable($pdo);
$sql = "ALTER TABLE %bill% ADD intguestid INT(10) NULL AFTER guestinfo";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %bill% ADD intguestpaid INT(2) NULL AFTER intguestid";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %bill% ADD FOREIGN KEY (intguestid) REFERENCES %customers%(id)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->execSql($pdo, "OPTIMIZE TABLE %bill%");
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('restaurantmode','1'));
$this->updateVersion($pdo, '1.3.0');
return true;
} catch (PDOException $e) {
echo "Error in v1.2.22 to 1.3.0: $e";
return false;
}
}
function updateUserTable1300_1301($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.0") {
$ret = $this->updateUserTable1222_1300($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.2.22 to 1.3.0 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->basedb->createCustomerLogTable($pdo);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('cancelguestcode',''));
$this->updateVersion($pdo, '1.3.1');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.0 to 1.3.1: $e";
return false;
}
}
function updateUserTable1301_1302($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.1") {
$ret = $this->updateUserTable1300_1301($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.0 to 1.3.1 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('returntoorder','1'));
$this->updateVersion($pdo, '1.3.2');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.1 to 1.3.2: $e";
return false;
}
}
function updateUserTable1302_1303($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.2") {
$ret = $this->updateUserTable1301_1302($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.1 to 1.3.2 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "SHOW COLUMNS FROM %customers% LIKE 'hello'";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$result = $stmt->fetchAll();
if (count($result) == 0) {
$sql = "ALTER TABLE %customers% ADD hello VARCHAR(100) NULL AFTER www";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$sql = "ALTER TABLE %customers% ADD regards VARCHAR(100) NULL AFTER hello";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$this->execSql($pdo, "OPTIMIZE TABLE %customers%");
}
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('rksvserver',''));
$this->updateVersion($pdo, '1.3.3');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.2 to 1.3.3: $e";
return false;
}
}
function updateUserTable1303_1304($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.3") {
$ret = $this->updateUserTable1302_1303($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.2 to 1.3.3 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.3.4');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.3 to 1.3.4: $e";
return false;
}
}
function updateUserTable1304_1305($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.4") {
$ret = $this->updateUserTable1303_1304($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.3 to 1.3.4 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.3.5');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.4 to 1.3.5: $e";
return false;
}
}
function updateUserTable1305_1306($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.5") {
$ret = $this->updateUserTable1304_1305($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.4 to 1.3.5 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, '1.3.6');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.5 to 1.3.6: $e";
return false;
}
}
function updateUserTable1306_1307($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.6") {
$ret = $this->updateUserTable1305_1306($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.5 to 1.3.6 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('updateurl','http://www.ordersprinter.de/update'));
$this->updateVersion($pdo, '1.3.7');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.6 to 1.3.7: $e";
return false;
}
}
function updateUserTable1307_1308($prefix, $version, $dbname) {
$pdo = $this->pdo;
try {
if ($version != "1.3.7") {
$ret = $this->updateUserTable1306_1307($prefix, $version, $dbname);
if (!$ret) {
echo "Version update v1.3.6 to 1.3.7 not successful.";
return false;
}
}
DbUtils::overrulePrefix($prefix);
$sql = "SHOW COLUMNS FROM %user% LIKE 'mobiletheme'";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
$result = $stmt->fetchAll();
if (count($result) == 0) {
$sql = "ALTER TABLE %user% ADD mobiletheme INT(2) NULL AFTER language";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute();
}
$sql = "INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('discountname1',''));
$stmt->execute(array('discountname2',''));
$stmt->execute(array('discountname3',''));
$this->updateVersion($pdo, '1.3.8');
return true;
} catch (PDOException $e) {
echo "Error in v1.3.7 to 1.3.8: $e";
return false;
}
}
function setVersion($prefix,$theVersion) {
$pdo = $this->pdo;
try {
$adminCl = new Admin();
DbUtils::overrulePrefix($prefix);
$this->updateVersion($pdo, $theVersion);
return true;
} catch (PDOException $e) {
return false;
}
}
function signLastBillId() {
$pdo = $this->pdo;
$this->basedb->signLastBillid($pdo);
}
function getDefaultCustomRecTemplate() {
$rect = "l;\nt:llllllllllllllllllll; f: ; a_ID:rrrrrrrr\n;f: ;d:w\n\ng:v; c:v\n\nk:rrr; s: ; m:v; s: ; n:rrrrrr; o:rrrrrrr\nf:-\n";
$rect .= "START_PRODUCTS\na:rrr; s: ; c:v; s: ; b:rrrrrr; d:rrrrrrr\nEND_PRODUCTS\n\n";
$rect .= "p:rrrrr; q:rrrrrr; r:rrrrrrrr; n:rrrrrrrr\nSTART_TAXES\nt:rrrrr; m:rrrrrr; n:rrrrrrrr; b:rrrrrrrr\nEND_TAXES\n\n";
$rect .= "f: ; E_Summe:llllllllllllllllllll;\n\nj:l;";
return $rect;
}
function getDefaultWorkTemplateFood() {
$rect = "SS:Speisen\nt:v\nz:v\n";
$rect .= "\n";
$rect .= "START_WORK\n";
$rect .= "f:-;\n";
$rect .= "N:v;\ns: ;b:v;\n";
$rect .= "e:v\n";
$rect .= "END_WORK\n";
$rect .= "f:-";
return $rect;
}
function getDefaultWorkTemplateDrinks() {
$rect = "SS:Getränke\nt:v\nz:v\n";
$rect .= "\n";
$rect .= "START_WORK\n";
$rect .= "f:-;\n";
$rect .= "N:v;\ns: ;b:v;\n";
$rect .= "e:v\n";
$rect .= "END_WORK\n";
$rect .= "f:-";
return $rect;
}
function createTables($decpoint,$billlanguage,$currency,$timezone)
{
$pdo = $this->pdo;
$this->basedb->setTimeZone($timezone);
$this->basedb->dropTables($pdo);
$this->basedb->createLogTable($pdo);
$this->basedb->createRatingsTable($pdo);
$this->createPaymentTable($pdo);
$this->basedb->createUserTable($pdo);
$this->basedb->createRoomTable($pdo);
$this->basedb->createRestTables($pdo);
$this->basedb->createTableMapsTable($pdo);
$this->basedb->createTablePosTable($pdo);
$this->basedb->createConfigTable($pdo);
$this->basedb->createProdTypeTable($pdo);
$this->basedb->createProductTable($pdo);
$this->basedb->createPriceLevelTable($pdo);
$this->basedb->createClosingTable($pdo);
$this->basedb->createCustomersTable($pdo);
$this->basedb->createGroupsTable($pdo);
$this->basedb->createGroupCustomerTable($pdo);
$this->basedb->createVacationsTable($pdo);
$this->basedb->createBillTable($pdo);
$this->basedb->createCustomerLogTable($pdo);
$this->basedb->createQueueTable($pdo);
$this->basedb->createBillProductsTable($pdo);
$this->basedb->createHistTables($pdo);
$this->defineHistActions($pdo);
$this->basedb->createPrintJobsTable($pdo);
$this->basedb->createWorkTable($pdo);
$this->basedb->createCommentsTable($pdo);
$this->basedb->createReservationsTable($pdo);
$this->basedb->createLogoTable($pdo);
$this->basedb->createExtrasTable($pdo);
$this->basedb->createExtrasprodsTable($pdo);
$this->basedb->createQueueExtrasTable($pdo);
$this->basedb->createHsinTable($pdo);
$this->basedb->createHsoutTable($pdo);
$rect = $this->getDefaultCustomRecTemplate();
$foodtemplate = $this->getDefaultWorkTemplateFood();
$drinktemplate = $this->getDefaultWorkTemplateDrinks();
$printpass = md5("123");
$this->basedb->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('1', 'A', 'Normale Preisstufe', 'Normal', 'Normal')");
$this->basedb->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('2', 'B', 'Wochenendtarif', 'Weekend prices','Tarifa del fin de semana')");
$this->basedb->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`,`info_en`,`info_esp`) VALUES ('3', 'C', 'Happy Hour', 'Happy Hour','Happy Hour')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'pricelevel', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'tax', '19.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'togotax', '7.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustrianormal', '20.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaerm1', '10.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaerm2', '13.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'taxaustriaspecial', '19.0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'stornocode', '123')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'printpass', '$printpass')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'companyinfo', 'Musterrestaurant\nBeispielstrasse 123\n12345 Musterort')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'rectemplate', '$rect')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'foodtemplate', '$foodtemplate')");
$this->basedb->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->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'reservationnote', '$resTxt')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'serverurl', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'email', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'receiveremail', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'payprinttype', 's')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'billlanguage', $billlanguage)");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'currency', '$currency')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'receiptfontsize', '12')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'version', '1.3.8')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'paymentconfig', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'remoteaccesscode', null)");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'decpoint', '$decpoint')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'timezone', '$timezone')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'webimpressum', 'Musterrestaurant\nBeispielstrasse 123\n12345 Musterort')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'cancelunpaidcode', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'bigfontworkreceipt', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'prominentsearch', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'groupworkitems', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'addreceipttoprinter', null)");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtphost', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpauth', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpuser', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtppass', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpsecure', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'smtpport', '587')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount1', '50')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount2', '20')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discount3', '10')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'austria', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'paydeskid', 'OrderSprinter-1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'aeskey', '0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'certificatesn', '1234567')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'rksvserver', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'digigopaysetready', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'waitergopayprint', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'oneprodworkreceipts', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'digiprintwork', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'printandqueuejobs', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'cashenabled', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'beepcooked', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hotelinterface', '0')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hsinfile', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hsoutfile', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hscurrency', 'EUR')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'hs3refresh', '60')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'memorylimit', '512')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'updateurl', 'http://www.ordersprinter.de/update')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'restaurantmode', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'returntoorder', '1')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discountname1', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discountname2', '')");
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'discountname3', '')");
// prepare for later inconsistency check if version is obsolete
date_default_timezone_set($timezone);
$installDate = date('Y-m-d H:i:s');
$this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'installdate', '$installDate')");
$this->readConfigTableAndSendToHist($pdo);
return;
}
public function getCurrentVersion() {
try {
$pdo = $this->pdo;
$sql = "SELECT setting FROM %config% WHERE name=?";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array("version"));
$row = $stmt->fetchObject();
return($row->setting);
} catch (Exception $e) {
return null;
}
}
public function isTherePreviousVersion($db,$prefix) {
try {
$pdo = $this->pdo;
$sql = "SELECT count(*) as thecount FROM information_schema.tables WHERE table_schema = '$db' AND table_name = '" . $prefix . "config' LIMIT 1";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute();
$row = $stmt->fetchObject();
if ($row->thecount == 1) {
return true;
} else {
return false;
}
} catch (Exception $e) {
return false;
}
}
function readConfigTableAndSendToHist($pdo) {
$sql_query = "SELECT * FROM %config%";
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (NULL,?,?)";
$stmt_query = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql_query));
$stmt_insert_histconfig = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($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($this->basedb->resolveTablenamesInSqlString($sql_insert_hist));
$stmt_insert_hist->execute(array($currentTime, $action, $refIdForHist));
}
function insertUser($username,$adminpass,$is_admin,$right_waiter,$right_kitchen,$right_bar,
$right_supply,$right_paydesk,$right_statistics,$right_bill,$right_products,$right_changeprice,$right_customers,
$right_manager,$right_closing,$right_reservation,$right_rating,$lang,$prefertablemap) {
$md5adminpass = md5($adminpass);
$pdo = $this->pdo;
$userInsertSql = "INSERT INTO `%user%` (`id` , `username` , `userpassword`, `is_admin`, `right_waiter`,`right_kitchen`,`right_bar`,`right_supply`,`right_paydesk`,`right_statistics`,`right_bill`,`right_products`,`right_changeprice`,`right_customers`,`right_manager`,`right_closing`,`right_reservation`,`right_rating`,`language`,`prefertablemap`,`keeptypelevel`,`extrasapplybtnpos`,`active`) VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,'1','1')";
$stmt = $pdo->prepare(DbUtils::substTableAlias($userInsertSql));
$stmt->execute(array($username,$md5adminpass,$is_admin,$right_waiter,$right_kitchen,$right_bar,$right_supply,$right_paydesk,$right_statistics,$right_bill,$right_products,$right_changeprice,$right_customers,$right_manager,$right_closing,$right_reservation,$right_rating,$lang,$prefertablemap,0));
$newUserIdForHist = $pdo->lastInsertId();
// now insert into hist
$sql_insert_histuser = "INSERT INTO %histuser% (`id` , `userid`, `username` ,
`is_admin`, `right_waiter`,`right_kitchen`,`right_bar`,`right_supply`,`right_paydesk`,
`right_statistics`,`right_bill`,`right_products`,`right_changeprice`,`right_customers`,`right_manager`,`right_closing`,`right_reservation`,`right_rating`,`active`) VALUES (
NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt_insert_histuser = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql_insert_histuser));
$stmt_insert_histuser->execute(array($newUserIdForHist,$username,$is_admin,$right_waiter,$right_kitchen,$right_bar,$right_supply,$right_paydesk,$right_statistics,$right_bill,$right_products,$right_changeprice,$right_customers,$right_manager,$right_closing,$right_reservation,$right_rating,1));
$newRefIdForHist = $pdo->lastInsertId();
$this->insertIntoHist($pdo, '3', $newRefIdForHist);
}
function createPaymentTable($pdo) {
$this->basedb->createPaymentTable($pdo);
$sql = "INSERT INTO %payment% (id,name,name_en,name_esp) VALUES (?,?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('1', 'Barzahlung', 'Cash', 'Contado'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('2', 'EC-Kartenzahlung','Electr. purse (EC)','Pago con tarjeta EC'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('3', 'Kreditkartenzahlung','Credit card','Tarjeta de credito'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('4', 'Rechnung','bill','Factura'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('5', 'Ueberweisung','Bank transfer','Transferencia'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('6', 'Lastschrift','Debit','Cargo en cuenta'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('7', 'Hotelzimmer','Hotel room','Habitación'));
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array('8', 'Gast','Guest','Cliente'));
}
public function defineHistActions ($pdo) {
$sql = "INSERT INTO %histactions% (id,name,description) VALUES (?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($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 testDbConnection($host,$dbname,$user,$pass) {
$pdo = $this->openDbAndReturnPdo($host,$dbname,$user,$pass);
if (!is_null($pdo)) {
echo json_encode("OK");
} else {
echo json_encode("ERROR");
}
}
function writeConfigFile($host,$db,$user,$password,$prefix) {
$errorlevel = "<?php\nerror_reporting(E_ERROR);\n\n"; // development: E_ALL
$hostlines = "// Zum Aufbau der Verbindung zur Datenbank\n";
$hostlines .= "// die Daten erhalten Sie von Ihrem Provider\n";
$hostlines .= "defined('MYSQL_HOST') || define ( 'MYSQL_HOST','$host' );";
$userlines = "defined('MYSQL_USER') || define ( 'MYSQL_USER', '$user' );";
$dbpasslines = "defined('MYSQL_PASSWORD') || define ( 'MYSQL_PASSWORD', '$password' );";
$dblines = "defined('MYSQL_DB') || define ( 'MYSQL_DB', '$db' );";
$dbloglines = "defined('LOG') || define ( 'LOG', false );";
$prefixlines = "defined('TAB_PREFIX') || define ('TAB_PREFIX', '$prefix');";
$installstatusline = "defined('INSTALLSTATUS') || define ('INSTALLSTATUS', 'installed');";
$configText = "$errorlevel\n$hostlines\n$userlines\n$dbpasslines\n$dblines\n$dbloglines\n$prefixlines\n$installstatusline\n?>";
file_put_contents("../php/config.php", $configText);
try {
file_put_contents("../php/config1.php", $configText);
} catch (Exception $e) {
// nothing
}
}
function createSslKeys($pdo) {
$sslconfig = array(
"digest_alg" => "sha512",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
// thus the signature is exactly 512 bytes
// Create the private and public key
$res = openssl_pkey_new($sslconfig);
if (is_null($res) || ($res=="")) {
// openssl may be incorrectly installed
return false;
}
// Extract the private key from $res to $privKey
openssl_pkey_export($res, $privKey);
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
$sql = "INSERT INTO `%work%` (`id` , `item`,`value`,`signature`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array("privkey","privkey",$privKey));
$sql = "INSERT INTO `%work%` (`id` , `item`,`value`,`signature`) VALUES ( NULL,?,?,?)";
$stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql));
$stmt->execute(array("cert","cert",$pubKey));
return true;
}
static function insertSampleMenu($pdo,$adminCl) {
$menu = file_get_contents("../customer/speisekarte.txt");
$adminCl->fillSpeisekarteCore($pdo, $menu);
}
function insertSample($level,$lang,$adminpass,$workflow,$timezone) {
$pdo = $this->pdo;
$adminCl = new Admin();
$adminCl::overruleTimeZone($timezone);
$adminCl->changeOneConfigDbItem($pdo,"workflowconfig",$workflow,"%config%",true);
if ($level == 1) {
// nothing to do - empty db
} else {
$roomTxt1 = array("Raum 1 (Tischkarte)","Room 1 (table map)","Espacio 1 (mapa de mesas)");
$roomTxt2 = array("Raum 2 (Tischbuttons)","Room 2 (table buttons)","Espacio (botones des mesas)");
$tableTxt = array("Tisch","Table","Mesa");
$waiterTxt = array("Karl Kellner","Walter Waiter","Carlo Camarero");
$cookTxt = array("Koch 1","Charlie Cook","Cocinero 1");
$bossTxt = array("Charlie Chef","Maggy Manager","Jefe");
$sql = "INSERT INTO `%room%` (`id`, `roomname`) VALUES (?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1,$roomTxt1[$lang]));
if ($level == 3) {
$stmt->execute(array(2,$roomTxt2[$lang]));
}
$sql = "INSERT INTO `%resttables%` (`id` , `tableno`, `roomid`) VALUES (? ,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
for ($i=1;$i<7;$i++) {
$stmt->execute(array($i,$tableTxt[$lang] . " $i",1));
if ($level == 3) {
$stmt->execute(array($i + 6,$tableTxt[$lang] . " " . ($i + 6),2));
}
}
if ($level == 3) {
$sql = "INSERT INTO `%tablemaps%` (`id` , `roomid`, `img`,`sizex`,`sizey`) VALUES (NULL ,?,?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$room = file_get_contents("../customer/innenraum.png");
$stmt->execute(array(1,$room,739,490));
$sql = "INSERT INTO `%tablepos%` (`id` , `tableid`, `x`,`y`) VALUES (NULL ,?,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array(1,70,74));
$stmt->execute(array(2,9,57));
$stmt->execute(array(3,19,37));
$stmt->execute(array(4,30,21));
$stmt->execute(array(5,49,21));
$stmt->execute(array(6,76,22));
}
if ($workflow == 2) {
$this->insertUser( $waiterTxt[$lang], $adminpass,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,$lang,1);
if ($level == 3) {
$this->insertUser( $bossTxt[$lang], $adminpass,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,$lang,1);
}
} else {
$this->insertUser( $waiterTxt[$lang], $adminpass,0,1,0,0,1,1,0,1,0,0,0,0,0,1,0,$lang,1);
if ($level == 3) {
$this->insertUser( $cookTxt[$lang], $adminpass,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,$lang,1);
$this->insertUser( $bossTxt[$lang], $adminpass,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,$lang,1);
}
}
$logoimg = file_get_contents("../customer/logo.png");
$sql = "INSERT INTO %logo% (id,name,setting) VALUES(1,?,?)";
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
$stmt->execute(array("logoimg",$logoimg));
self::insertSampleMenu($pdo,$adminCl);
}
}
}
$command = $_GET["command"];
if ($command == 'checkWriteAccess') {
$checker = new Checks();
$checker->checkWriteAccess();
} else if ($command == 'checkPhpStatus') {
$checker = new InstallAdmin();
$checker->checkPhpStatus();
} else if ($command == 'testDbConnection') {
$admin = new InstallAdmin();
try {
if (isset($_POST['host']) && isset($_POST['dbname']) && isset($_POST['user']) && isset($_POST['pass'])) {
$admin->testDbConnection($_POST['host'],$_POST['dbname'],$_POST['user'],$_POST['pass']);
} else {
echo json_encode("ERROR");
}
} catch (Exception $e) {
echo json_encode("ERROR");
}
} else if ($command == 'getConfig') {
$configWriter = new ConfigWriter();
$configWriter->getConfigVals();
} else if ($command == 'install') {
$admin = new InstallAdmin();
$pdo = $admin->openDbAndReturnPdo($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password']);
$admin->setPdo($pdo);
$admin->setPrefix($_POST['prefix']);
$admin->setTimeZone($_POST['timezone']);
DbUtils::overruleTimeZone($_POST['timezone']);
DbUtils::overrulePrefix($_POST['prefix']);
set_time_limit(60*5);
$admin->createTables($_POST['point'],$_POST['lang'],$_POST['currency'],$_POST['timezone']);
$ok = $admin->createSslKeys($pdo);
$admin->signLastBillId();
if (!$ok) {
echo json_encode("Fehler: Ist OpenSSL richtig installiert?");
return;
}
$admin->insertUser("admin",$_POST['adminpass'],1,0,0,0,0,0,0,0,0,1,0,1,1,0,0,$_POST['lang'],1);
$admin->writeConfigFile($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password'],$_POST['prefix']);
if(session_id() == '') {
session_start();
}
session_destroy();
echo json_encode("OK");
} else if ($command == 'insertsamplecontent') {
try {
$admin = new InstallAdmin();
$pdo = $admin->openDbAndReturnPdo($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password']);
$admin->setPdo($pdo);
$admin->setPrefix($_POST['prefix']);
$admin->setTimeZone($_POST["timezone"]);
$admin->insertSample(intval($_POST["level"]),intval($_POST["lang"]),$_POST['adminpass'],$_POST["workflow"],$_POST["timezone"]);
echo json_encode("OK");
}
catch (PDOException $e) {
echo json_encode("ERROR: $e");
}
} else if ($command == 'gettimezones') {
$timezone_identifiers = DateTimeZone::listIdentifiers();
$zones = array();
for ($i=0; $i < count($timezone_identifiers); $i++) {
$zones[] = $timezone_identifiers[$i];
}
echo json_encode($zones);
} else if ($command == 'update') {
$installerVersion = "1.3.8";
$admin = new InstallAdmin();
$pdo = $admin->openDbAndReturnPdo($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password']);
$admin->setPdo($pdo);
$admin->setPrefix($_POST['prefix']);
$isPreviousInstallation = $admin->isTherePreviousVersion($_POST['db'],$_POST['prefix']);
if (!$isPreviousInstallation) {
echo json_encode("Stimmt der Tabellenpräfix?");
return;
}
$version = $admin->getCurrentVersion();
if ($version == $installerVersion) {
echo json_encode("Version bereits installiert");
return;
}
if (is_null($version)) {
echo json_encode("Version nicht bestimmbar");
return;
}
$supportedVersions = array("1.0.22","1.0.23","1.0.24","1.0.25","1.0.26","1.0.27","1.0.28","1.0.29",
"1.0.30","1.0.31","1.0.32","1.0.33","1.0.34","1.0.35","1.0.36","1.0.37","1.0.38","1.0.39",
"1.0.40","1.0.41","1.0.42","1.0.43",
"1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","1.1.5","1.1.6","1.1.7","1.1.8", "1.1.9","1.1.10","1.1.11","1.1.12","1.1.13","1.1.14","1.1.15","1.1.16","1.1.17",
"1.1.18","1.1.19","1.1.20","1.1.21","1.1.22","1.1.23","1.1.24","1.1.25","1.1.26","1.1.27","1.1.28","1.1.29","1.1.30",
"1.2.0","1.2.1","1.2.2", "1.2.3", "1.2.4","1.2.5","1.2.6","1.2.7","1.2.8","1.2.9","1.2.10","1.2.11","1.2.12","1.2.13","1.2.14","1.2.15","1.2.16","1.2.17",
"1.2.18","1.2.19","1.2.20","1.2.21","1.2.22","1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3.5","1.3.6","1.3.7"
);
if (!in_array($version, $supportedVersions)) {
echo json_encode("Quellversion nicht unterstützt");
return;
}
$ret = $admin->updateUserTable1307_1308($_POST['prefix'], $version, $_POST['db']);
if(session_id() == '') {
session_start();
}
session_destroy();
$autoupdate = $_POST["autoupdate"];
try {
if ($autoupdate == 1) {
unlink("../install/installer.php");
if (file_exists("../install/phpinfo.php")) {
unlink("../install/phpinfo.php");
}
rmdir("../install");
}
} catch (Exception $e) {
echo json_encode("Install-Verzeichnis lässt sich nicht löschen: ". $e->getMessage());
return;
}
if ($ret) {
$admin->writeConfigFile($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password'],$_POST['prefix']);
echo json_encode("OK");
} else {
echo json_encode("ERROR");
}
}
?>