bugid = BSApp::$input->clean($id, TYPE_UINT); } /** * Sets the attachment ID for the current logging instance * * @param integer New attachment ID */ public function setAttachmentId($id) { $this->attachmentid = BSApp::$input->clean($id, TYPE_UINT); } /** * Sets the current comment ID to be logged * * @param integer New comment ID */ public function setCommentId($id) { $this->commentid = BSApp::$input->clean($id, TYPE_UINT); } /** * Assigns data into the $this->original or $this->modified array based * on the passed arrays of information and the fields to add (and what * name to add them under), and any prefix * * @param bool TRUE for original, FALSE for modified * @param array Data array * @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') * @param bool If TRUE, then the list of fields is used to exclude, not include * @param string Field prefix */ public function addData($orig, $data, $fields, $exclude = false, $prefix = '') { $array = ($orig ? 'original' : 'modified'); $prefix .= '.'; if ($exclude == false) { foreach ($fields as $fname => $fdisplay) { if (is_numeric($fname)) { $fname = $fdisplay; } $this->{$array}["$prefix$fdisplay"] = array('name' => $fname, 'value' => $data["$fname"]); } } else { foreach ($data as $fname => $value) { if (!in_array($fname, $fields)) { $this->{$array}["$prefix$fname"] = array('name' => $fname, 'value' => $value); } } } } /** * Populates the $this->compared array as a diff between the original * and modified data. This is then used to create the databse queries. */ private function _compareArrays() { foreach ($this->modified AS $key => $value) { if ($this->original["$key"] != $value && !($value['value'] == '' && $this->original["$key"]['value'] == '0') && !($this->original["$key"]['value'] == '' && $value['value'] == '0')) { $this->compared["$key"] = array('old' => $this->original["$key"]['value'], 'new' => $this->modified["$key"]['value']); } } } /** * Runs $this->_compareArrays() and then takes the result and prepares * it for insertion into the history database. */ public function updateHistory() { $this->_compareArrays(); foreach ($this->compared as $field => $values) { BSApp::$db->query(" INSERT INTO " . TABLE_PREFIX . "history (bugid, attachmentid, commentid, dateline, userid, field, original, changed) VALUES (" . BSApp::$input->clean($this->bugid, TYPE_UINT) . ", " . BSApp::$input->clean($this->attachmentid, TYPE_UINT) . ", " . BSApp::$input->clean($this->commentid, TYPE_UINT) . ", " . TIMENOW . ", " . bugdar::$userinfo['userid'] . ", '" . BSApp::$db->escapeString($field) . "', '" . BSApp::$db->escapeString($values['old']) . "', '" . BSApp::$db->escapeString($values['new']) . "' ) "); } } /** * Returns an array of the fields commonly ignored * * @return array Fields ignored in logging */ public function getCommonFields() { return array( 'bugid', 'lastposttime', 'lastpostby', 'lastpostbyname', 'hiddenlastposttime', 'hiddenlastpostby', 'hiddenlastpostbyname' ); } } ?>