From 74829e1a721252733980d16ae69153e2ec6f6ec3 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Tue, 19 Jan 2010 15:11:32 +0000
Subject: [PATCH] Fixed: FS#838 - DNS serial is updated by viewing records.
 Changed: removed datalog update function in tform.inc.php and just left the
 stub function there for legacy support with a call to the new function in the
 db_mysql.inc.php.

---
 interface/lib/classes/db_mysql.inc.php | 37 +++++++++++++++++---------
 interface/lib/classes/tform.inc.php    | 27 +++++--------------
 interface/web/dns/dns_soa_edit.php     |  9 +++++++
 3 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/interface/lib/classes/db_mysql.inc.php b/interface/lib/classes/db_mysql.inc.php
index ed35b419b..9c4871f61 100644
--- a/interface/lib/classes/db_mysql.inc.php
+++ b/interface/lib/classes/db_mysql.inc.php
@@ -217,23 +217,14 @@ class db {
     }
 	*/
 	
-	//** Function to fill the datalog with a full differential record.
-	public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) {
-		global $app,$conf;
-
-		// Insert backticks only for incomplete table names.
-		if(stristr($db_table,'.')) {
-			$escape = '';
-		} else {
-			$escape = '`';
-		}
-
+	public function diffrec($record_old, $record_new) {
 		$diffrec_full = array();
 		$diff_num = 0;
 
 		if(is_array($record_old) && count($record_old) > 0) {
 			foreach($record_old as $key => $val) {
-				if(!isset($record_new[$key]) || $record_new[$key] != $val) {
+				// if(!isset($record_new[$key]) || $record_new[$key] != $val) {
+				if($record_new[$key] != $val) {
 					// Record has changed
 					$diffrec_full['old'][$key] = $val;
 					$diffrec_full['new'][$key] = $record_new[$key];
@@ -257,12 +248,34 @@ class db {
 			}
 		}
 		
+		return array('diff_num' => $diff_num, 'diff_rec' => $diffrec_full);
+		
+	}
+	
+	//** Function to fill the datalog with a full differential record.
+	public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) {
+		global $app,$conf;
+
+		// Insert backticks only for incomplete table names.
+		if(stristr($db_table,'.')) {
+			$escape = '';
+		} else {
+			$escape = '`';
+		}
+
+		$tmp = $this->diffrec($record_old, $record_new);
+		$diffrec_full = $tmp['diff_rec'];
+		$diff_num = $tmp['diff_num'];
+		unset($tmp);
+		
 		// Insert the server_id, if the record has a server_id
 		$server_id = (isset($record_old["server_id"]) && $record_old["server_id"] > 0)?$record_old["server_id"]:0;
 		if(isset($record_new["server_id"])) $server_id = $record_new["server_id"];
 		
 
 		if($diff_num > 0) {
+			//print_r($diff_num);
+			//print_r($diffrec_full);
 			$diffstr = $app->db->quote(serialize($diffrec_full));
 			$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
 			$dbidx = $primary_field.":".$primary_id;
diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index 3d29591f8..28f5d6943 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -1017,7 +1017,11 @@ class tform {
 
         function datalogSave($action,$primary_id, $record_old, $record_new) {
                 global $app,$conf;
-
+				
+				$app->db->datalogSave($this->formDef['db_table'], $action, $this->formDef['db_table_idx'], $primary_id, $record_old, $record_new);
+				return true;
+				
+				/*
                 // Add backticks for incomplete table names.
                 if(stristr($this->formDef['db_table'],'.')) {
                         $escape = '';
@@ -1026,26 +1030,6 @@ class tform {
                 }
 
                 $this->diffrec = array();
-				/*
-                if(is_array($record_new) && count($record_new) > 0) {
-                        foreach($record_new as $key => $val) {
-                                if(@$record_old[$key] != $val) {
-										// Record has changed
-                                        $diffrec[$key] = array('old' => @$record_old[$key],
-                                                               'new' => $val);
-                                }
-                        }
-                } elseif(is_array($record_old)) {
-                        foreach($record_old as $key => $val) {
-                                if($record_new[$key] != $val) {
-										// Record has changed
-                                        $diffrec[$key] = array('new' => $record_new[$key],
-                                                               'old' => $val);
-                                }
-                        }
-                }
-				$this->diffrec = $diffrec;
-				*/
 				
 				// Full diff records for ISPConfig, they have a different format then the simple diffrec
 				$diffrec_full = array();
@@ -1098,6 +1082,7 @@ class tform {
                 }
 
                 return true;
+				*/
 
         }
 
diff --git a/interface/web/dns/dns_soa_edit.php b/interface/web/dns/dns_soa_edit.php
index defdb9747..d2eb15854 100644
--- a/interface/web/dns/dns_soa_edit.php
+++ b/interface/web/dns/dns_soa_edit.php
@@ -135,9 +135,11 @@ class page_action extends tform_actions {
 			}
 		}
 		
+		/*
 		// Update the serial number of the SOA record
 		$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
 		$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
+		*/
 		
 		
 		//* Check if soa, ns and mbox have a dot at the end
@@ -176,6 +178,13 @@ class page_action extends tform_actions {
 	function onAfterUpdate() {
 		global $app, $conf;
 		
+		$tmp = $app->db->diffrec($this->oldDataRecord,$app->tform->getDataRecord($this->id));
+		if($tmp['diff_num'] > 0) {
+			// Update the serial number of the SOA record
+			$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = ".$this->id);
+			$app->db->query("UPDATE dns_soa SET serial = '".$app->validate_dns->increase_serial($soa["serial"])."' WHERE id = ".$this->id);
+		}
+		
 		// make sure that the record belongs to the client group and not the admin group when a dmin inserts it
 		if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
 			$client_group_id = intval($this->dataRecord["client_group_id"]);
-- 
GitLab