]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_logging.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 - [#]year[#], Blue Static
55 var $attachmentid = 0;
65 * The original data to compare against
69 var $original = array();
76 var $modified = array();
79 * Compared/diff'd data
83 var $compared = array();
85 // ###################################################################
87 * Sets the bug ID for the current logging instance
91 * @param integer New bug ID
93 function set_bugid($id)
96 $this->bugid
= $bugsys->clean($id, TYPE_UINT
);
99 // ###################################################################
101 * Sets the attachment ID for the current logging instance
105 * @param integer New attachment ID
107 function set_attachmentid($id)
110 $this->attachmentid
= $bugsys->clean($id, TYPE_UINT
);
113 // ###################################################################
115 * Sets the current comment ID to be logged
119 * @param integer New comment ID
121 function set_commentid($id)
124 $this->commentid
= $bugsys->clean($id, TYPE_UINT
);
127 // ###################################################################
129 * Assigns data into the $this->original or $this->modified array based
130 * on the passed arrays of information and the fields to add (and what
131 * name to add them under), and any prefix
135 * @param bool TRUE for original, FALSE for modified
136 * @param array Data array
137 * @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')
138 * @param bool If TRUE, then the list of fields is used to exclude, not include
139 * @param string Field prefix
141 function add_data($orig, $data, $fields, $exclude = false, $prefix = '')
143 $array = ($orig ? 'original' : 'modified');
146 if ($exclude == false)
148 foreach ($fields AS $fname => $fdisplay)
150 if (is_numeric($fname))
155 $this->{$
array}["$prefix$fdisplay"] = array('name' => $fname, 'value' => $data["$fname"]);
160 foreach ($data AS $fname => $value)
162 if (!in_array($fname, $fields))
164 $this->{$
array}["$prefix$fname"] = array('name' => $fname, 'value' => $value);
170 // ###################################################################
172 * Populates the $this->compared array as a diff between the original
173 * and modified data. This is then used to create the databse queries.
177 function compare_arrays()
179 $newfields = array_diff_assoc($this->modified, $this->original);
180 $removedfields = array_diff_assoc($this->original, $this->modified);
182 foreach ($this->modified AS $key => $value)
184 if ($this->original["$key"] != $value AND !($value['value'] == '' AND $this->original
["$key"]['value'] == '0') AND !($this->original["$key"]['value'] == '' AND $value['value'] == '0'))
186 $this->compared
["$key"] = array('old' => $this->original["$key"]['value'], 'new' => $this->modified
["$key"]['value']);
190 foreach ($newfields AS $field)
192 $this->compared["$field"] = array('old' => null, 'new' => $this->modified
["$field"]['value']);
195 foreach ($removedfields AS $field)
197 $this->compared["$field"] = array('old' => $this->original
["$field"]['value'], 'new' => null);
201 // ###################################################################
203 * Runs $this->compare_arrays() and then takes the result and prepares
204 * it for insertion into the history database.
208 function update_history()
212 $this->compare_arrays();
214 foreach ($this->compared AS $field => $values)
217 INSERT INTO
" . TABLE_PREFIX . "history
218 (bugid
, attachmentid
, commentid
, dateline
, userid
, field
, original
, changed
)
220 (" . $bugsys->clean($this->bugid, TYPE_UINT) . ", " . $bugsys->clean($this->attachmentid, TYPE_UINT) . ",
221 " . $bugsys->clean($this->commentid, TYPE_UINT) . ", " . TIMENOW . ", " . $bugsys->userinfo['userid'] . ",
222 '" . $bugsys->db->escape_string($field) . "', '" . $bugsys->db->escape_string($values['old
']) . "',
223 '" . $bugsys->db->escape_string($values['new']) . "'
230 /*=====================================================================*\
231 || ###################################################################
234 || ###################################################################
235 \*=====================================================================*/