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')); $stmt->execute(array('9', 'DbSave', 'Komplettsicherung der Datenbank')); $stmt->execute(array('10', 'DbRestore', 'Wiederherstellung der Datenbank aus einer Sicherungskopie')); } 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_reservation,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_reservation'],$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,$rReservation,$rRat,$rChangeprice,$rManager,$active) { $this->updateOrCreateUserInHist($userid,$username, $isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat, $rBill,$rProducts,$rReservation,$rRat,$rChangeprice,$rManager,$active,'8'); } public function createUserInHist($lastId,$username, $isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rRes,$rRat,$rChangeprice,$rManager) { $this->updateOrCreateUserInHist($lastId,$username, $isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat, $rBill,$rProducts,$rRes,$rRat,$rChangeprice,$rManager,'1','7'); } public function updateOrCreateUserInHist($id,$username, $isAdmin,$rWaiter,$rKitchen,$rBar,$rSupply,$rPayDesk,$rStat,$rBill,$rProducts,$rRes,$rRat,$rChangeprice,$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_reservation`,`right_rating`,`right_changeprice`,`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,$rRes,$rRat,$rChangeprice,$rManager, $active)); $newRefIdForHist = $pdo->lastInsertId(); $this->insertIntoHist($pdo, $histaction, $newRefIdForHist); $pdo->commit(); } public function insertSaveHistEntry($pdo) { $this->insertIntoHist($pdo, 9, null); } public function insertRestoreHistEntry($pdo) { $this->insertIntoHist($pdo, 10, null); } public function readAllProdsAndFillHistByDb($pdo) { $sql = "SELECT id FROM %products% WHERE removed is null"; $stmt = $pdo->prepare(DbUtils::substTableAlias($sql)); $stmt->execute(array()); $result = $stmt->fetchAll(); foreach ($result as $aProd) { $prodid = $aProd["id"]; $sql = "SELECT GROUP_CONCAT(%extras%.name) as extraslist FROM %extras%,%extrasprods% WHERE %extrasprods%.prodid=? AND %extrasprods%.extraid=%extras%.id"; $stmt = $pdo->prepare(DbUtils::substTableAlias($sql)); $stmt->execute(array($prodid)); $row =$stmt->fetchObject(); $extrasList = $row->extraslist; $sql = "INSERT INTO %histprod% (id,prodid,shortname,longname,priceA,priceB,priceC,tax,sorting,available,extras) "; $sql .= "SELECT null,id as prodid,shortname,longname,priceA,priceB,priceC,tax,sorting,available,'$extrasList' as extras FROM %products% "; $sql .= "WHERE %products%.id=?"; $stmt = $pdo->prepare(DbUtils::substTableAlias($sql)); $stmt->execute(array($prodid)); $newRefIdForHist = $pdo->lastInsertId(); $this->insertIntoHist($pdo, '1', $newRefIdForHist); } } /* * 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,tax,sorting,available,favorite) 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['tax'],$row['sorting'],$row['available'],'0')); $newRefIdForHist = $pdo->lastInsertId(); $this->insertIntoHist($pdo, '1', $newRefIdForHist); } } public function updateProdInHist($pdo,$prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available,$audioFile,$favorite,$histextra) { $this->updateOrCreateProdInHist($pdo,$prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available, '4',$audioFile,$favorite,$histextra); } public function createProdInHist($pdo,$prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available,$audioFile,$favorite) { $this->updateOrCreateProdInHist($pdo,$prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available, '5',$audioFile,$favorite,null); } public function updateOrCreateProdInHist($pdo,$prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available, $histaction,$audioFile,$favorite,$histextra) { $sql_insert_histprod = "INSERT INTO %histprod% (id,prodid,shortname,longname, priceA,priceB,priceC,tax,sorting,available,audio,favorite,extras) VALUES ( NULL,?,?,?,?,?,?,?,?,?,?,?,?)"; if (is_null($pdo)) { $pdo = $this->dbutils->openDbAndReturnPdo(); } $stmt_insert_histprod = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql_insert_histprod)); $stmt_insert_histprod->execute(array($prodid,$shortname,$longname, $priceA,$priceB,$priceC,$tax,$sorting,$available,$audioFile,$favorite,$histextra)); $newRefIdForHist = $pdo->lastInsertId(); $this->insertIntoHist($pdo, $histaction, $newRefIdForHist); } public function updateConfigInHist($pdo,$theItem, $theValue) { $sql_find_id = "SELECT id FROM %config% WHERE name='$theItem'"; $sql_insert_histconfig = "INSERT INTO %histconfig% (id,configid,setting) VALUES (NULL,?,?)"; $pdo->beginTransaction(); $stmt_query = $pdo->query(DbUtils::substTableAlias($sql_find_id)); $row =$stmt_query->fetchObject(); $theConfigId = $row->id; $stmt_insert_histconfig = $pdo->prepare(DbUtils::substTableAlias($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) { date_default_timezone_set(DbUtils::getTimeZone()); $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(DbUtils::substTableAlias($sql_insert_hist)); $stmt_insert_hist->execute(array($currentTime, $action, $refIdForHist)); } } ?>