]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_logging.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
25 DELETE FROM history WHERE field IN ('lastposttime', 'lastpostby', 'hiddenlastposttime', 'hiddenlastpostby')
32 * This class is used to record changes in a bug's fields, comments, and
36 * @copyright Copyright (c)2004 - 2009, Blue Static
52 private $attachmentid = 0;
58 private $commentid = 0;
61 * The original data to compare against
64 private $original = array();
70 private $modified = array();
73 * Compared/diff'd data
76 private $compared = array();
79 * Sets the bug ID for the current logging instance
81 * @param integer New bug ID
83 public function setBugId($id)
85 $this->bugid
= BSApp
::$input->clean($id, TYPE_UINT
);
89 * Sets the attachment ID for the current logging instance
91 * @param integer New attachment ID
93 public function setAttachmentId($id)
95 $this->attachmentid
= BSApp
::$input->clean($id, TYPE_UINT
);
99 * Sets the current comment ID to be logged
101 * @param integer New comment ID
103 public function setCommentId($id)
105 $this->commentid
= BSApp
::$input->clean($id, TYPE_UINT
);
109 * Assigns data into the $this->original or $this->modified array based
110 * on the passed arrays of information and the fields to add (and what
111 * name to add them under), and any prefix
113 * @param bool TRUE for original, FALSE for modified
114 * @param array Data array
115 * @param array List of fields in the data array to add; in format of array('field name' => 'display name', 'display name 2', 'display name 3')
116 * @param bool If TRUE, then the list of fields is used to exclude, not include
117 * @param string Field prefix
119 public function addData($orig, $data, $fields, $exclude = false, $prefix = '')
121 $array = ($orig ? 'original' : 'modified');
124 if ($exclude == false)
126 foreach ($fields as $fname => $fdisplay)
128 if (is_numeric($fname))
133 $this->{$
array}["$prefix$fdisplay"] = array('name' => $fname, 'value' => $data["$fname"]);
138 foreach ($data as $fname => $value)
140 if (!in_array($fname, $fields))
142 $this->{$
array}["$prefix$fname"] = array('name' => $fname, 'value' => $value);
149 * Populates the $this->compared array as a diff between the original
150 * and modified data. This is then used to create the databse queries.
152 private function _compareArrays()
154 foreach ($this->modified AS $key => $value)
156 if ($this->original["$key"] != $value && !($value['value'] == '' && $this->original
["$key"]['value'] == '0') && !($this->original["$key"]['value'] == '' && $value['value'] == '0'))
158 $this->compared
["$key"] = array('old' => $this->original["$key"]['value'], 'new' => $this->modified
["$key"]['value']);
164 * Runs $this->_compareArrays() and then takes the result and prepares
165 * it for insertion into the history database.
167 public function updateHistory()
169 $this->_compareArrays();
171 foreach ($this->compared as $field => $values)
174 INSERT INTO
" . TABLE_PREFIX . "history
175 (bugid
, attachmentid
, commentid
, dateline
, userid
, field
, original
, changed
)
177 (" . BSApp::$input->clean($this->bugid, TYPE_UINT) . ", " . BSApp::$input->clean($this->attachmentid, TYPE_UINT) . ",
178 " . BSApp::$input->clean($this->commentid, TYPE_UINT) . ", " . TIMENOW . ", " . bugdar::$userinfo['userid'] . ",
179 '" . BSApp::$db->escapeString($field) . "', '" . BSApp::$db->escapeString($values['old
']) . "',
180 '" . BSApp::$db->escapeString($values['new']) . "'
187 * Returns an array of the fields commonly ignored
189 * @return array Fields ignored in logging
191 public function getCommonFields()
198 'hiddenlastposttime',
200 'hiddenlastpostbyname'