2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 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 ©2002 - 2007, Blue Static
53 private $attachmentid = 0;
59 private $commentid = 0;
62 * The original data to compare against
65 private $original = array();
71 private $modified = array();
74 * Compared/diff'd data
77 private $compared = array();
80 * Sets the bug ID for the current logging instance
82 * @param integer New bug ID
84 public function setBugId($id)
86 $this->bugid
= BSApp
::$input->clean($id, TYPE_UINT
);
90 * Sets the attachment ID for the current logging instance
92 * @param integer New attachment ID
94 public function setAttachmentId($id)
96 $this->attachmentid
= BSApp
::$input->clean($id, TYPE_UINT
);
100 * Sets the current comment ID to be logged
102 * @param integer New comment ID
104 public function setCommentId($id)
106 $this->commentid
= BSApp
::$input->clean($id, TYPE_UINT
);
110 * Assigns data into the $this->original or $this->modified array based
111 * on the passed arrays of information and the fields to add (and what
112 * name to add them under), and any prefix
114 * @param bool TRUE for original, FALSE for modified
115 * @param array Data array
116 * @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')
117 * @param bool If TRUE, then the list of fields is used to exclude, not include
118 * @param string Field prefix
120 public function addData($orig, $data, $fields, $exclude = false
, $prefix = '')
122 $array = ($orig ?
'original' : 'modified');
125 if ($exclude == false
)
127 foreach ($fields as $fname => $fdisplay)
129 if (is_numeric($fname))
134 $this->{$array}["$prefix$fdisplay"] = array('name' => $fname, 'value' => $data["$fname"]);
139 foreach ($data as $fname => $value)
141 if (!in_array($fname, $fields))
143 $this->{$array}["$prefix$fname"] = array('name' => $fname, 'value' => $value);
150 * Populates the $this->compared array as a diff between the original
151 * and modified data. This is then used to create the databse queries.
153 private function _compareArrays()
155 foreach ($this->modified
AS $key => $value)
157 if ($this->original
["$key"] != $value && !($value['value'] == '' && $this->original
["$key"]['value'] == '0') && !($this->original
["$key"]['value'] == '' && $value['value'] == '0'))
159 $this->compared
["$key"] = array('old' => $this->original
["$key"]['value'], 'new' => $this->modified
["$key"]['value']);
165 * Runs $this->_compareArrays() and then takes the result and prepares
166 * it for insertion into the history database.
168 public function updateHistory()
170 $this->_compareArrays();
172 foreach ($this->compared
as $field => $values)
175 INSERT INTO " . TABLE_PREFIX
. "history
176 (bugid, attachmentid, commentid, dateline, userid, field, original, changed)
178 (" . BSApp
::$input->clean($this->bugid
, TYPE_UINT
) . ", " . BSApp
::$input->clean($this->attachmentid
, TYPE_UINT
) . ",
179 " . BSApp
::$input->clean($this->commentid
, TYPE_UINT
) . ", " . TIMENOW
. ", " . bugdar
::$userinfo['userid'] . ",
180 '" . BSApp
::$db->escapeString($field) . "', '" . BSApp
::$db->escapeString($values['old']) . "',
181 '" . BSApp
::$db->escapeString($values['new']) . "'
188 * Returns an array of the fields commonly ignored
190 * @return array Fields ignored in logging
192 public function getCommonFields()
199 'hiddenlastposttime',
201 'hiddenlastpostbyname'
206 /*=====================================================================*\
207 || ###################################################################
210 || ###################################################################
211 \*=====================================================================*/