From e2d6ed954b42c72645aeb2476591e6d42cf48991 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Fri, 29 Jun 2007 10:32:16 -0400
Subject: [PATCH] - added basic update script - improved several functions in site module - added server classes to restart services

---
 interface/lib/classes/tform_actions.inc.php |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/interface/lib/classes/tform_actions.inc.php b/interface/lib/classes/tform_actions.inc.php
index f228e54..89d974a 100644
--- a/interface/lib/classes/tform_actions.inc.php
+++ b/interface/lib/classes/tform_actions.inc.php
@@ -102,9 +102,13 @@
                 $ext_where = '';
                 $sql = $app->tform->getSQL($this->dataRecord,$app->tform->getCurrentTab(),'UPDATE',$this->id,$ext_where);
                 if($app->tform->errorMessage == '') {
+						
+						if($app->tform->formDef['db_history'] == 'yes') {
+							$old_data_record = $app->tform->getDataRecord($this->id);
+						}
 
                         if(!empty($sql)) {
-                                $app->db->query($sql);
+                            $app->db->query($sql);
                             if($app->db->errorMessage != '') die($app->db->errorMessage);
                         }
 						
@@ -118,6 +122,14 @@
                         }
 
                         $this->onAfterUpdate();
+						
+						// Write data history (sys_datalog)
+						if($app->tform->formDef['db_history'] == 'yes') {
+							$new_data_record = $app->tform->getDataRecord($this->id);
+							$app->tform->datalogSave('UPDATE',$this->id,$old_data_record,$new_data_record);
+							unset($new_data_record);
+							unset($old_data_record);
+						}
 
                         if($_REQUEST["next_tab"] == '') {
                            $list_name = $_SESSION["s"]["form"]["return_to"];
@@ -175,6 +187,13 @@
                         }
 
                         $this->onAfterInsert();
+						
+						// Write data history (sys_datalog)
+						if($app->tform->formDef['db_history'] == 'yes') {
+							$new_data_record = $app->tform->getDataRecord($this->id);
+							$app->tform->datalogSave('INSERT',$this->id,array(),$new_data_record);
+							unset($new_data_record);
+						}
 						
 
                      if($_REQUEST["next_tab"] == '') {
@@ -260,20 +279,10 @@
                         $record_old = $app->db->queryOneRecord("SELECT * FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);
 
                         // Saving record to datalog when db_history enabled
-                        if($form["db_history"] == 'yes') {
-                                $diffrec = array();
-
-                                foreach($record_old as $key => $val) {
-                                        // Record has changed
-                                        $diffrec[$key] = array('old' => $val,
-                                                                                           'new' => '');
-                                }
-
-                                $diffstr = $app->db->quote(serialize($diffrec));
-                                $username = $app->db->quote($_SESSION["s"]["user"]["username"]);
-                                $dbidx = $app->tform->formDef['db_table_idx'].":".$this->id;
-                                $sql = "INSERT INTO sys_datalog (dbtable,dbidx,action,tstamp,user,data) VALUES ('".$app->tform->formDef['db_table']."','$dbidx','d','".time()."','$username','$diffstr')";
-                                $app->db->query($sql);
+                        if($app->tform->formDef["db_history"] == 'yes') {
+							$old_data_record = $app->tform->getDataRecord($this->id);
+							$app->tform->datalogSave('DELETE',$this->id,$old_data_record,array());
+							unset($old_data_record);
                         }
 
                         $app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = ".$this->id);

--
Gitblit v1.9.1