"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"); $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 DECIMAL (5,2) 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 DECIMAL (5,2) NOT NULL"; $stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql)); $stmt->execute(); $sql = "ALTER TABLE %products% ADD tax DECIMAL (5,2) NULL AFTER priceC"; $stmt = $pdo->prepare($this->basedb->resolveTablenamesInSqlString($sql)); $stmt->execute(); $sql = "ALTER TABLE %histprod% ADD tax DECIMAL (5,2) 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 DECIMAL (9,2) NULL AFTER netto"; $stmt = $pdo->prepare(DbUtils::substTableAlias($sql)); $stmt->execute(); $sql = "ALTER TABLE %bill% ADD prevnetto DECIMAL (9,2) 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 idprepare(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 = "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;"; $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->updateUserTable1126_1127($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 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 createTables($decpoint,$billlanguage,$currency,$timezone) { $pdo = $this->pdo; $this->basedb->setTimeZone($timezone); $this->basedb->dropTables($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->createBillTable($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); $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;"; $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 , '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')"); $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.1.29')"); $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 , '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 , 'digigopaysetready', '1')"); $this->basedb->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'waitergopayprint', '0')"); // 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_manager,$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_manager`,`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_manager,$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_manager`,`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_manager,$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')); } 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 = ""; 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) { // only receipts - no views kitchen,bar,supply $this->insertUser($waiterTxt[$lang],$adminpass,0,1,0,0,0,1,0,1,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,$lang,1); } } else { $this->insertUser($waiterTxt[$lang],$adminpass,0,1,0,0,1,1,0,1,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,$lang,1); $this->insertUser($bossTxt[$lang],$adminpass ,0,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,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.1.29"; $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" ); if (!in_array($version, $supportedVersions)) { echo json_encode("Quellversion nicht unterstützt"); return; } $ret = $admin->updateUserTable1128_1129($_POST['prefix'], $version); if(session_id() == '') { session_start(); } session_destroy(); if ($ret) { $admin->writeConfigFile($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password'],$_POST['prefix']); echo json_encode("OK"); } else { echo json_encode("ERROR"); } } ?>