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 \*=====================================================================*/
22 $fetchtemplates = array(
27 define('SVN', '$Id$');
29 $focus['showreport'] = 'focus';
31 require_once('./global.php');
32 require_once('./includes/api_user.php');
34 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . $bugsys->input_clean('bugid', TYPE_UINT
));
37 $message->error(L_INVALID_ID
);
40 if (!check_bug_permissions($bug))
42 $message->errorPermission();
45 $lookupfields = array(
47 'priority' => 'priority',
48 'severity' => 'severity',
49 'resolution' => 'resolution',
50 'version' => 'version',
52 'component' => 'title'
55 // ###################################################################
57 $customfields = $db->query("
58 SELECT bugfield.*, MAX(permission.mask) AS mask
59 FROM " . TABLE_PREFIX
. "bugfield AS bugfield
60 LEFT JOIN " . TABLE_PREFIX
. "bugfieldpermission AS permission
61 ON (bugfield.fieldid = permission.fieldid)
63 AND permission.usergroupid IN ({bugdar::$userinfo['usergroupid']}" . (sizeof(bugdar
::$userinfo['groupids']) != 0 ?
',' . implode(',', bugdar
::$userinfo['groupids']) : '') . ")
64 GROUP BY (bugfield.fieldid)"
67 foreach ($customfields as $field)
69 $fieldlist["$field[fieldid]"] = sprintf(T('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
72 // ###################################################################
75 $logs_fetch = $db->query("
76 SELECT history.*, user.userid, user.email, user.displayname, user.showemail
77 FROM " . TABLE_PREFIX
. "history AS history
78 LEFT JOIN " . TABLE_PREFIX
. "user AS user
79 ON (user.userid = history.userid)
80 WHERE bugid = $bug[bugid]"
82 foreach ($logs_fetch as $log)
84 $log['date'] = $datef->format(bugdar
::$options['dateformat'], $log['dateline']);
85 $log['user'] = construct_user_display($log);
87 $logs["$log[dateline]"]["$log[historyid]"] = $log;
88 ksort($logs["$log[dateline]"]);
95 foreach ($logs AS $dateline => $logitems)
97 $show['group'] = true
;
99 foreach ($logitems AS $log)
101 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
103 $toKill[] = $log['historyid'];
107 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
109 if ($matches[1] == 'comment')
111 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
113 else if ($matches[1] == 'attachment')
115 $log['field'] = sprintf(T('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
118 else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
120 if ($fieldlist["$matches[2]"])
122 $log['field'] = $fieldlist["$matches[2]"];
129 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
131 $log['field'] = ucwords($matches[1]);
133 if (isset($lookupfields["$matches[1]"]))
135 $lookup = $matches[1];
136 $log['original'] = bugdar
::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
137 $log['changed'] = bugdar
::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
139 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
141 if ($log['original'])
143 $user = new UserAPI($bugsys);
144 $user->set('userid', $log['original']);
145 $user->set_condition();
147 $log['original'] = construct_user_display($user->objdata
);
152 $user = new UserAPI($bugsys);
153 $user->set('userid', $log['changed']);
154 $user->set_condition();
156 $log['changed'] = construct_user_display($user->objdata
);
161 BSFunctions
::swap_css_classes('', 'altcolor');
162 $bgcolor = BSFunctions
::$cssClass;
164 eval('$history .= "' . $template->fetch('history_bit') . '";');
165 $show['group'] = false
;
169 // we can now remove all useless logs
170 if (sizeof($toKill) > 0)
172 $db->query("DELETE FROM " . TABLE_PREFIX
. "history WHERE historyid IN (" . implode(',', $toKill) . ")");
175 eval('$template->flush("' . $template->fetch('history') . '");');
177 /*=====================================================================*\
178 || ###################################################################
181 || ###################################################################
182 \*=====================================================================*/