624 lines
21 KiB
PHP
624 lines
21 KiB
PHP
<?php
|
|
error_reporting(E_ALL);
|
|
|
|
class Installer {
|
|
private function checkwriteaccessconfigfolder() {
|
|
return (is_writable("../php"));
|
|
}
|
|
|
|
private function checkwriteaccessconfigfile() {
|
|
if (file_exists("../php/config.php")) {
|
|
return (is_writable("../php/config.php"));
|
|
} else {
|
|
return (is_writable("../php"));
|
|
}
|
|
}
|
|
|
|
private function checkwritecustomerfolder() {
|
|
return (is_writable("../customer"));
|
|
}
|
|
|
|
private function checkwritespeisekarte() {
|
|
if (file_exists("../customer/speisekarte.txt")) {
|
|
return (is_writable("../customer/speisekarte.txt"));
|
|
} else {
|
|
return (is_writable("../customer"));
|
|
}
|
|
}
|
|
|
|
function checkWriteAccess() {
|
|
$retArray = array(
|
|
"configfolder" => $this->checkwriteaccessconfigfolder(),
|
|
"configfile" => $this->checkwriteaccessconfigfile(),
|
|
"customerfolder" => $this->checkwritecustomerfolder(),
|
|
"speisekarte" => $this->checkwritespeisekarte()
|
|
);
|
|
echo json_encode($retArray);
|
|
}
|
|
}
|
|
|
|
class ConfigWriter {
|
|
function getConfigVals() {
|
|
if (is_readable("../php/config.php")) {
|
|
include( "../php/config.php" );
|
|
$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));
|
|
} else {
|
|
echo json_encode(array("status" => "Failed"));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class Admin {
|
|
var $prefix = "";
|
|
var $pdo;
|
|
|
|
function setPrefix($pre) {
|
|
$this->prefix = $pre;
|
|
}
|
|
|
|
function setPdo($pdo) {
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
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 createTables()
|
|
{
|
|
$pdo = $this->pdo;
|
|
|
|
$this->doSQLcatch($pdo, "DROP TABLE `%hist%`");
|
|
$this->doSQLcatch($pdo, "DROP TABLE `%histprod%`");
|
|
$this->doSQLcatch($pdo, "DROP TABLE `%histconfig%`");
|
|
$this->doSQLcatch($pdo, "DROP TABLE `%histuser%`");
|
|
$this->doSQLcatch($pdo, "DROP TABLE `%histactions%`");
|
|
|
|
$this->doSQLcatch($pdo, "drop TABLE `%billproducts%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%queue%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%printjobs%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%bill%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%user%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%closing%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%config%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%products%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%prodtype%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%pricelevel%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%resttables%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%room%`");
|
|
$this->doSQLcatch($pdo, "drop TABLE `%payment%`");
|
|
|
|
$this->createPaymentTable($pdo);
|
|
$this->createUserTable($pdo);
|
|
$this->createRoomTable($pdo);
|
|
$this->createRestTables($pdo);
|
|
$this->createConfigTable($pdo);
|
|
$this->createProdTypeTable($pdo);
|
|
$this->createProductTable($pdo);
|
|
$this->createPriceLevelTable($pdo);
|
|
$this->createClosingTable($pdo);
|
|
$this->createBillTable($pdo);
|
|
$this->createQueueTable($pdo);
|
|
$this->createBillProductsTable($pdo);
|
|
$this->createHistTables($pdo);
|
|
$this->createPrintJobsTable($pdo);
|
|
|
|
$this->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`) VALUES ('1', 'A', 'Normale Preisstufe')");
|
|
$this->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`) VALUES ('2', 'B', 'Wochenendtarif')");
|
|
$this->doSQL($pdo,"INSERT INTO `%pricelevel%` (`id` , `name`,`info`) VALUES ('3', 'C', 'Happy Hour')");
|
|
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'pricelevel', '1')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'tax', '19,0')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'togotax', '7,0')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'stornocode', '123')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'printpass', 'printen')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'companyinfo', 'Musterrestaurant\nBeispielstrasse 123\n12345 Musterort')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'serverurl', '')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'email', '')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'logourl', 'customer/logo.png')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'payprinttype', 'l')");
|
|
$this->doSQL($pdo,"INSERT INTO `%config%` (`id` , `name`, `setting`) VALUES (NULL , 'version', '1.0')");
|
|
|
|
$this->readConfigTableAndSendToHist($pdo);
|
|
|
|
return;
|
|
}
|
|
|
|
function doSQL($pdo,$sql) {
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function doSQLcatch($pdo,$sql) {
|
|
try {
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
} catch (Exception $e) {
|
|
// nothing - table not present or whatever...
|
|
}
|
|
}
|
|
|
|
function readConfigTableAndSendToHist($pdo) {
|
|
$sql_query = "SELECT * FROM %config%";
|
|
|
|
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (
|
|
NULL,?,?)";
|
|
|
|
$stmt_query = $pdo->prepare($this->resolveTablenamesInSqlString($sql_query));
|
|
$stmt_insert_histconfig = $pdo->prepare($this->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('Europe/Berlin');
|
|
$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->resolveTablenamesInSqlString($sql_insert_hist));
|
|
$stmt_insert_hist->execute(array($currentTime, $action, $refIdForHist));
|
|
}
|
|
|
|
function insertAdminUser($adminpass) {
|
|
$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_manager`,`active`) VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,'1')";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($userInsertSql));
|
|
$stmt->execute(array('admin',$md5adminpass,1,0,0,0,0,0,0,0,0,1));
|
|
$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_manager`,`active`) VALUES (
|
|
NULL,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
$stmt_insert_histuser = $pdo->prepare($this->resolveTablenamesInSqlString($sql_insert_histuser));
|
|
$stmt_insert_histuser->execute(array($newUserIdForHist,'admin',1,0,0,0,0,0,0,0,0,1,1));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, '3', $newRefIdForHist);
|
|
}
|
|
|
|
function createBillProductsTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%billproducts%` (
|
|
`queueid` INT( 10 ) NOT NULL,
|
|
`billid` INT(10) NOT NULL,
|
|
FOREIGN KEY (queueid) REFERENCES %queue%(id),
|
|
FOREIGN KEY (billid) REFERENCES %bill%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
}
|
|
|
|
/*
|
|
* Create the queue table:
|
|
* action: P=Pay, S=Storno
|
|
*/
|
|
function createQueueTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%queue%` (
|
|
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`tablenr` INT( 3 ) NOT NULL ,
|
|
`productid` INT( 10 ) NULL ,
|
|
`pricelevel` INT( 3 ) NOT NULL ,
|
|
`price` DECIMAL (5,2) NOT NULL,
|
|
`productname` VARCHAR( 150 ) NULL,
|
|
`ordertime` DATETIME NULL ,
|
|
`anoption` VARCHAR( 150 ) NULL ,
|
|
`readytime` DATETIME NOT NULL,
|
|
`delivertime` DATETIME NULL,
|
|
`payinprogress` INT(3) NOT NULL,
|
|
`paidtime` DATETIME NULL,
|
|
`billid` INT(10),
|
|
`toremove` INT(3) NOT NULL,
|
|
`cooking` INT(10) NULL,
|
|
`workprinted` INT(2) NOT NULL,
|
|
`action` VARCHAR(3) NOT NULL,
|
|
FOREIGN KEY (tablenr) REFERENCES %resttables%(id),
|
|
FOREIGN KEY (pricelevel) REFERENCES %pricelevel%(id),
|
|
FOREIGN KEY (productid) REFERENCES %products%(id),
|
|
FOREIGN KEY (billid) REFERENCES %bill%(id),
|
|
FOREIGN KEY (cooking) REFERENCES %user%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
}
|
|
|
|
function createProdTypeTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%prodtype%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`name` VARCHAR ( 150 ) NOT NULL,
|
|
`usekitchen` INT(1) NOT NULL,
|
|
`usesupplydesk` INT(1) NOT NULL,
|
|
`kind` INT(2) NOT NULL,
|
|
`sorting` INT(2) NULL,
|
|
`reference` INT (10) NULL,
|
|
`removed` INT(1) NULL,
|
|
FOREIGN KEY (reference) REFERENCES %prodtype%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
}
|
|
|
|
|
|
function createProductTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%products%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`shortname` VARCHAR ( 150 ) NOT NULL,
|
|
`longname` VARCHAR ( 150 ) NOT NULL,
|
|
`priceA` DECIMAL (5,2) NULL,
|
|
`priceB` DECIMAL (5,2) NULL,
|
|
`priceC` DECIMAL (5,2) NULL,
|
|
`category` INT(3) NULL,
|
|
`sorting` INT(2) NULL,
|
|
`available` INT(2) NOT NULL,
|
|
`audio` VARCHAR ( 150 ) NULL,
|
|
`removed` INT(1) NULL,
|
|
FOREIGN KEY (category) REFERENCES %prodtype%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
}
|
|
|
|
|
|
function createUserTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%user%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`username` VARCHAR ( 150 ) NOT NULL,
|
|
`userpassword` VARCHAR ( 150 ) NOT NULL,
|
|
`is_admin` INT (2) NOT NULL,
|
|
`right_waiter` INT (2) NOT NULL,
|
|
`right_kitchen` INT (2) NOT NULL,
|
|
`right_bar` INT (2) NOT NULL,
|
|
`right_supply` INT (2) NOT NULL,
|
|
`right_paydesk` INT (2) NOT NULL,
|
|
`right_statistics` INT (2) NOT NULL,
|
|
`right_bill` INT (2) NOT NULL,
|
|
`right_products` INT (2) NOT NULL,
|
|
`right_manager` INT (2) NOT NULL,
|
|
`lastmodule` VARCHAR ( 30 ) NULL,
|
|
`ordervolume` INT (2) NULL,
|
|
`active` INT (2) NOT NULL
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
}
|
|
|
|
function createPaymentTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%payment%` (
|
|
`id` INT (3) NOT NULL UNIQUE,
|
|
`name` VARCHAR ( 20 ) NOT NULL
|
|
) ENGINE = InnoDb
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
|
|
$sql = "INSERT INTO %payment% (id,name) VALUES (?,?)";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
|
|
$stmt->execute(array('1', 'Barzahlung'));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
|
|
$stmt->execute(array('2', 'EC-Kartenzahlung'));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('3', 'Kreditkartenzahlung'));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('4', 'Rechnung'));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('5', 'Ueberweisung'));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('6', 'Lastschrift'));
|
|
}
|
|
|
|
function createHistTables($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%hist%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`date` DATETIME NOT NULL ,
|
|
`action` INT ( 2 ) NOT NULL,
|
|
`refid` INT (10) NOT NULL
|
|
) ENGINE = InnoDb
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
|
|
$sql = "
|
|
CREATE TABLE `%histprod%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`prodid` INT (10) NOT NULL,
|
|
`shortname` VARCHAR ( 150 ) NOT NULL,
|
|
`longname` VARCHAR ( 150 ) NOT NULL,
|
|
`priceA` DECIMAL (5,2) NULL,
|
|
`priceB` DECIMAL (5,2) NULL,
|
|
`priceC` DECIMAL (5,2) NULL,
|
|
`sorting` INT(2) NULL,
|
|
`available` INT(2) NOT NULL,
|
|
`audio` VARCHAR ( 150 ) NULL,
|
|
FOREIGN KEY (prodid) REFERENCES %products%(id)
|
|
) ENGINE = InnoDb
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
|
|
$sql = "
|
|
CREATE TABLE `%histconfig%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`configid` INT (10) ,
|
|
`setting` VARCHAR ( 10000 ),
|
|
FOREIGN KEY (configid) REFERENCES %config%(id)
|
|
) ENGINE = InnoDb
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
|
|
$sql = "
|
|
CREATE TABLE `%histuser%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`userid` INT (10) ,
|
|
`username` VARCHAR ( 150 ) NOT NULL,
|
|
`is_admin` INT (2) NOT NULL,
|
|
`right_waiter` INT (2) NOT NULL,
|
|
`right_kitchen` INT (2) NOT NULL,
|
|
`right_bar` INT (2) NOT NULL,
|
|
`right_supply` INT (2) NOT NULL,
|
|
`right_paydesk` INT (2) NOT NULL,
|
|
`right_statistics` INT (2) NOT NULL,
|
|
`right_bill` INT (2) NOT NULL,
|
|
`right_products` INT (2) NOT NULL,
|
|
`right_manager` INT (2) NOT NULL,
|
|
`active` INT (2) NOT NULL,
|
|
FOREIGN KEY (userid) REFERENCES %user%(id)
|
|
) ENGINE = InnoDb
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
|
|
$sql = "
|
|
CREATE TABLE `%histactions%` (
|
|
`id` INT (3) NOT NULL,
|
|
`name` VARCHAR ( 20 ) NOT NULL,
|
|
`description` VARCHAR ( 150 ) NULL
|
|
) ENGINE = InnoDb
|
|
";
|
|
$this->doSQL($pdo,$sql);
|
|
|
|
$this->defineHistActions($pdo);
|
|
}
|
|
|
|
public function defineHistActions ($pdo) {
|
|
$sql = "INSERT INTO %histactions% (id,name,description) VALUES (?,?,?)";
|
|
$stmt = $pdo->prepare($this->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 createRoomTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%room%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`roomname` VARCHAR ( 150 ) NOT NULL,
|
|
`removed` INT(2) NULL,
|
|
`sorting` INT(2) NULL
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function createRestTables($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%resttables%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`tableno` VARCHAR ( 150 ) NOT NULL,
|
|
`roomid` INT ( 10 ) NOT NULL,
|
|
`removed` INT(2) NULL,
|
|
`sorting` INT(2) NULL,
|
|
FOREIGN KEY (roomid) REFERENCES %room%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
|
|
$sql = "INSERT INTO `%room%` (`id`, `roomname`) VALUES (NULL,?)";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('Raum 1'));
|
|
$roomId = $pdo->lastInsertId();
|
|
|
|
$sql = "INSERT INTO `%resttables%` (`id` , `tableno`, `roomid`) VALUES (NULL ,?,?)";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('Tisch 1',$roomId));
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute(array('Tisch 2',$roomId));
|
|
}
|
|
|
|
function createBillTable($pdo)
|
|
{
|
|
$sql = "
|
|
CREATE TABLE `%bill%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`billdate` DATETIME NOT NULL ,
|
|
`content` VARCHAR ( 50000 ) ,
|
|
`brutto` DECIMAL (5,2) NULL,
|
|
`netto` DECIMAL (5,2) NULL,
|
|
`tableid` VARCHAR ( 150 ) NOT NULL,
|
|
`closingid` INT(4) NULL,
|
|
`status` VARCHAR(2) NULL,
|
|
`paymentid` INT(2) NULL,
|
|
`userid` INT(3) NULL,
|
|
`ref` INT(10) NULL,
|
|
`tax` DECIMAL (5,2) NOT NULL,
|
|
FOREIGN KEY (closingid) REFERENCES %closing%(id),
|
|
FOREIGN KEY (paymentid) REFERENCES %payment%(id),
|
|
FOREIGN KEY (userid) REFERENCES %user%(id),
|
|
FOREIGN KEY (ref) REFERENCES %bill%(id)
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
|
|
// insert dummy entry so that select query with closing works
|
|
date_default_timezone_set('Europe/Berlin');
|
|
$currentTime = date('Y-m-d H:i:s');
|
|
$billInsertSql = "INSERT INTO `%bill%` (`id` , `billdate`,`content`,`brutto`,`tableid`,`paymentid`,`tax`) VALUES ( '0', '$currentTime' , '', '', '-1', NULL, '0.00')";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($billInsertSql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function createPriceLevelTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%pricelevel%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`name` VARCHAR ( 10000 ) ,
|
|
`info` VARCHAR ( 10000 )
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function createConfigTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%config%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`name` VARCHAR ( 1000 ) ,
|
|
`setting` VARCHAR ( 10000 )
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function createClosingTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%closing%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`closingdate` DATETIME NOT NULL ,
|
|
`remark` VARCHAR ( 10000 )
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function createPrintJobsTable($pdo) {
|
|
$sql = "
|
|
CREATE TABLE `%printjobs%` (
|
|
`id` INT (10) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
|
`content` VARCHAR ( 50000 ) NOT NULL ,
|
|
`type` INT (2) NOT NULL
|
|
) ENGINE = InnoDb ;
|
|
";
|
|
$stmt = $pdo->prepare($this->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
}
|
|
|
|
function resolveTablenamesInSqlString($sqlString) {
|
|
$out = str_replace("%queue%",$this->prefix . "queue",$sqlString);
|
|
$out = str_replace("%products%",$this->prefix . "products",$out);
|
|
$out = str_replace("%user%",$this->prefix . "user",$out);
|
|
$out = str_replace("%room%",$this->prefix . "room",$out);
|
|
$out = str_replace("%resttables%",$this->prefix . "resttables",$out);
|
|
$out = str_replace("%bill%",$this->prefix . "bill",$out);
|
|
$out = str_replace("%pricelevel%",$this->prefix . "pricelevel",$out);
|
|
$out = str_replace("%config%",$this->prefix . "config",$out);
|
|
$out = str_replace("%closing%",$this->prefix . "closing",$out);
|
|
$out = str_replace("%printjobs%",$this->prefix . "printjob",$out);
|
|
$out = str_replace("%hist%",$this->prefix . "hist",$out);
|
|
$out = str_replace("%histprod%",$this->prefix . "histprod",$out);
|
|
$out = str_replace("%histconfig%",$this->prefix . "histconfig",$out);
|
|
$out = str_replace("%histuser%",$this->prefix . "histuser",$out);
|
|
$out = str_replace("%histactions%",$this->prefix . "histactions",$out);
|
|
$out = str_replace("%payment%",$this->prefix . "payment",$out);
|
|
$out = str_replace("%billproducts%",$this->prefix . "billproducts",$out);
|
|
return (str_replace("%prodtype%",$this->prefix . "prodtype",$out));
|
|
}
|
|
|
|
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 .= "define ( 'MYSQL_HOST','$host' );";
|
|
$userlines = "define ( 'MYSQL_USER', '$user' );";
|
|
$dbpasslines = "define ( 'MYSQL_PASSWORD', '$password' );";
|
|
$dblines = "define ( 'MYSQL_DB', '$db' );";
|
|
$prefixlines = "define ('TAB_PREFIX', '$prefix');";
|
|
$configText = "$errorlevel\n$hostlines\n$userlines\n$dbpasslines\n$dblines\n$prefixlines\n?>";
|
|
file_put_contents("../php/config.php", $configText);
|
|
}
|
|
}
|
|
$command = $_GET["command"];
|
|
if ($command == 'checkWriteAccess') {
|
|
$checker = new Installer();
|
|
$checker->checkWriteAccess();
|
|
} else if ($command == 'testDbConnection') {
|
|
$admin = new Admin();
|
|
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 Admin();
|
|
$pdo = $admin->openDbAndReturnPdo($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password']);
|
|
$admin->setPdo($pdo);
|
|
$admin->setPrefix($_POST['prefix']);
|
|
$admin->createTables();
|
|
$admin->insertAdminUser($_POST['adminpass']);
|
|
$admin->writeConfigFile($_POST['host'],$_POST['db'],$_POST['user'],$_POST['password'],$_POST['prefix']);
|
|
echo json_encode("OK");
|
|
}
|
|
?>
|