211 lines
8.3 KiB
PHP
211 lines
8.3 KiB
PHP
<?php
|
|
require_once ('dbutils.php');
|
|
require_once ('globals.php');
|
|
|
|
class HistFiller {
|
|
var $dbutils;
|
|
|
|
function __construct() {
|
|
$this->dbutils = new DbUtils();
|
|
}
|
|
|
|
|
|
public function defineHistActions () {
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$sql = "INSERT INTO %histactions% (id,name,description) VALUES (?,?,?)";
|
|
$stmt = $pdo->prepare($this->dbutils->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'));
|
|
}
|
|
|
|
public function readUserTableAndSendToHist() {
|
|
$sql = "SELECT * FROM %user%";
|
|
$this->readSqlUserTableAndSendToHist($sql,'3');
|
|
}
|
|
|
|
public function updateOneUser($userid) {
|
|
$sql = "SELECT * FROM %user% WHERE id='$userid'";
|
|
$this->readSqlUserTableAndSendToHist($sql,'8');
|
|
}
|
|
|
|
/*
|
|
* Read the complete user table and fill in these values to the histtable
|
|
*/
|
|
private function readSqlUserTableAndSendToHist($sql_query, $histaction) {
|
|
$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,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$pdo->beginTransaction();
|
|
|
|
$stmt_query = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_query));
|
|
$stmt_insert_histuser = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histuser));
|
|
|
|
$stmt_query->execute();
|
|
$result = $stmt_query->fetchAll();
|
|
foreach($result as $row){
|
|
$stmt_insert_histuser->execute(array($row['id'], $row['username'],
|
|
$row['is_admin'],$row['right_waiter'],$row['right_kitchen'],$row['right_bar'],
|
|
$row['right_supply'],$row['right_paydesk'],$row['right_statistics'],$row['right_bill'],
|
|
$row['right_products'],$row['right_manager'],$row['active']));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, $histaction, $newRefIdForHist);
|
|
}
|
|
$pdo->commit();
|
|
}
|
|
|
|
public function updateUserInHist($userid,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rManager,$active)
|
|
{
|
|
$this->updateOrCreateUserInHist($userid,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,
|
|
$rBill,$rProducts,$rManager,$active,'8');
|
|
}
|
|
|
|
public function createUserInHist($lastId,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rManager)
|
|
{
|
|
$this->updateOrCreateUserInHist($lastId,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,
|
|
$rBill,$rProducts,$rManager,'1','7');
|
|
}
|
|
|
|
public function updateOrCreateUserInHist($id,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rManager,
|
|
$active,$histaction) {
|
|
|
|
$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,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$pdo->beginTransaction();
|
|
$stmt_insert_histuser = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histuser));
|
|
$stmt_insert_histuser->execute(array($id,$username,
|
|
$isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rManager,
|
|
$active));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, $histaction, $newRefIdForHist);
|
|
$pdo->commit();
|
|
}
|
|
|
|
/*
|
|
* Read the complete products table and fill in these values to the histtable
|
|
*/
|
|
public function readProdTableAndSendToHist($pdo) {
|
|
$sql_query = "SELECT * FROM %products% WHERE removed is null";
|
|
|
|
$sql_insert_histprod = "INSERT INTO %histprod% (id,prodid,shortname,longname,
|
|
priceA,priceB,priceC,sorting,available) VALUES (
|
|
NULL,?,?,?,?,?,?,?,?)";
|
|
|
|
$stmt_query = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_query));
|
|
$stmt_insert_histprod = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histprod));
|
|
|
|
$stmt_query->execute();
|
|
$result = $stmt_query->fetchAll();
|
|
foreach($result as $row){
|
|
$stmt_insert_histprod->execute(array($row['id'], $row['shortname'],
|
|
$row['longname'],$row['priceA'],$row['priceB'],$row['priceC'],
|
|
$row['sorting'],$row['available']));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, '1', $newRefIdForHist);
|
|
}
|
|
}
|
|
|
|
public function updateProdInHist($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available,$audioFile) {
|
|
$this->updateOrCreateProdInHist($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available, '4',$audioFile);
|
|
}
|
|
|
|
public function createProdInHist($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available,$audioFile) {
|
|
$this->updateOrCreateProdInHist($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available, '5',$audioFile);
|
|
}
|
|
|
|
public function updateOrCreateProdInHist($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available, $histaction,$audioFile) {
|
|
|
|
$sql_insert_histprod = "INSERT INTO %histprod% (id,prodid,shortname,longname,
|
|
priceA,priceB,priceC,sorting,available,audio) VALUES (
|
|
NULL,?,?,?,?,?,?,?,?,?)";
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$pdo->beginTransaction();
|
|
$stmt_insert_histprod = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histprod));
|
|
$stmt_insert_histprod->execute(array($prodid,$shortname,$longname,
|
|
$priceA,$priceB,$priceC,$sorting,$available,$audioFile));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, $histaction, $newRefIdForHist);
|
|
$pdo->commit();
|
|
}
|
|
|
|
public function updateConfigInHist($theItem, $theValue) {
|
|
$sql_find_id = "SELECT id FROM %config% WHERE name='$theItem'";
|
|
|
|
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (NULL,?,?)";
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$pdo->beginTransaction();
|
|
|
|
$stmt_query = $pdo->query($this->dbutils->resolveTablenamesInSqlString($sql_find_id));
|
|
$row =$stmt_query->fetchObject();
|
|
$theConfigId = $row->id;
|
|
|
|
$stmt_insert_histconfig = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histconfig));
|
|
$stmt_insert_histconfig->execute(array($theConfigId,"$theValue"));
|
|
$newRefIdForHist = $pdo->lastInsertId();
|
|
$this->insertIntoHist($pdo, '6', $newRefIdForHist);
|
|
$pdo->commit();
|
|
}
|
|
/*
|
|
* Read the complete config table and fill in these values to the histtable
|
|
*/
|
|
public function readConfigTableAndSendToHist() {
|
|
$sql_query = "SELECT * FROM %config%";
|
|
|
|
$sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (
|
|
NULL,?,?)";
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
$pdo->beginTransaction();
|
|
|
|
$stmt_query = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_query));
|
|
$stmt_insert_histconfig = $pdo->prepare($this->dbutils->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);
|
|
}
|
|
$pdo->commit();
|
|
}
|
|
|
|
private function insertIntoHist($pdo,$action,$refIdForHist) {
|
|
// current time
|
|
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->dbutils->resolveTablenamesInSqlString($sql_insert_hist));
|
|
$stmt_insert_hist->execute(array($currentTime, $action, $refIdForHist));
|
|
}
|
|
|
|
}
|
|
|
|
?>
|