From 1aa4ab15f0548dc0dcf715a2eca1e32ed0432401 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 10 May 2006 04:43:20 +0000 Subject: [PATCH] r815: Everything for logging is *hopefully* implemented right, except Log::update_history --- editreport.php | 2 ++ includes/class_logging.php | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/editreport.php b/editreport.php index 55b7901..73462b2 100644 --- a/editreport.php +++ b/editreport.php @@ -185,6 +185,8 @@ if ($_POST['do'] == 'update') $fields = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); $log->add_data(false, $fields, array('bugid'), true, 'custom'); + $log->update_history(); + print_r($log); exit; $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]"); diff --git a/includes/class_logging.php b/includes/class_logging.php index eca4e4b..9e3798d 100644 --- a/includes/class_logging.php +++ b/includes/class_logging.php @@ -61,6 +61,13 @@ class Logging */ var $modified = array(); + /** + * Compared/diff'd data + * @var array + * @access private + */ + var $compared = array(); + // ################################################################### /** * Sets the bug ID for the current logging instance @@ -116,6 +123,49 @@ class Logging } } } + + // ################################################################### + /** + * Populates the $this->compared array as a diff between the original + * and modified data. This is then used to create the databse queries. + * + * @access private + */ + function compare_arrays() + { + $newfields = array_diff_assoc($this->modified, $this->original); + $removedfields = array_diff_assoc($this->original, $this->modified); + + foreach ($this->modified AS $key => $value) + { + if ($this->original["$key"] != $value) + { + $this->compared["$key"] = array('old' => $this->original["$key"]['value'], 'new' => $this->modified["$key"]['value']); + } + } + + foreach ($newfields AS $field) + { + $this->compared["$field"] = array('old' => null, 'new' => $this->modified["$field"]['value']); + } + + foreach ($removedfields AS $field) + { + $this->compared["$field"] = array('old' => $this->original["$field"]['value'], 'new' => null); + } + } + + // ################################################################### + /** + * Runs $this->compare_arrays() and then takes the result and prepares + * it for insertion into the history database. + * + * @access public + */ + function update_history() + { + $this->compare_arrays(); + } } /*=====================================================================*\ -- 2.22.5