]> src.bluestatic.org Git - bugdar.git/blob - showhistory.php
We were hitting an infinite loop with isso_pre_parse_hook
[bugdar.git] / showhistory.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'history',
24 'history_bit'
25 );
26
27 define('SVN', '$Id$');
28
29 $focus['showreport'] = 'focus';
30
31 require_once('./global.php');
32 require_once('./includes/api_user.php');
33
34 $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->input_clean('bugid', TYPE_UINT));
35 if (!$bug)
36 {
37 $message->error(L_INVALID_ID);
38 }
39
40 if (!check_bug_permissions($bug))
41 {
42 $message->errorPermission();
43 }
44
45 $lookupfields = array(
46 'status' => 'status',
47 'priority' => 'priority',
48 'severity' => 'severity',
49 'resolution' => 'resolution',
50 'version' => 'version',
51 'product' => 'title',
52 'component' => 'title'
53 );
54
55 // ###################################################################
56
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)
62 WHERE mask <> 0
63 AND permission.usergroupid IN ({bugdar::$userinfo['usergroupid']}" . (sizeof(bugdar::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar::$userinfo['groupids']) : '') . ")
64 GROUP BY (bugfield.fieldid)"
65 );
66
67 foreach ($customfields as $field)
68 {
69 $fieldlist["$field[fieldid]"] = sprintf(T('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
70 }
71
72 // ###################################################################
73
74 $logs = array();
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]"
81 );
82 foreach ($logs_fetch as $log)
83 {
84 $log['date'] = $datef->format(bugdar::$options['dateformat'], $log['dateline']);
85 $log['user'] = construct_user_display($log);
86
87 $logs["$log[dateline]"]["$log[historyid]"] = $log;
88 ksort($logs["$log[dateline]"]);
89 }
90
91 ksort($logs);
92
93 $toKill = array();
94
95 foreach ($logs AS $dateline => $logitems)
96 {
97 $show['group'] = true;
98
99 foreach ($logitems AS $log)
100 {
101 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
102 {
103 $toKill[] = $log['historyid'];
104 continue;
105 }
106
107 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
108 {
109 if ($matches[1] == 'comment')
110 {
111 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
112 }
113 else if ($matches[1] == 'attachment')
114 {
115 $log['field'] = sprintf(T('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
116 }
117 }
118 else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
119 {
120 if ($fieldlist["$matches[2]"])
121 {
122 $log['field'] = $fieldlist["$matches[2]"];
123 }
124 else
125 {
126 continue;
127 }
128 }
129 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
130 {
131 $log['field'] = ucwords($matches[1]);
132
133 if (isset($lookupfields["$matches[1]"]))
134 {
135 $lookup = $matches[1];
136 $log['original'] = bugdar::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
137 $log['changed'] = bugdar::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
138 }
139 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
140 {
141 if ($log['original'])
142 {
143 $user = new UserAPI($bugsys);
144 $user->set('userid', $log['original']);
145 $user->set_condition();
146 $user->fetch();
147 $log['original'] = construct_user_display($user->objdata);
148 }
149
150 if ($log['changed'])
151 {
152 $user = new UserAPI($bugsys);
153 $user->set('userid', $log['changed']);
154 $user->set_condition();
155 $user->fetch();
156 $log['changed'] = construct_user_display($user->objdata);
157 }
158 }
159 }
160
161 BSFunctions::swap_css_classes('', 'altcolor');
162 $bgcolor = BSFunctions::$cssClass;
163
164 eval('$history .= "' . $template->fetch('history_bit') . '";');
165 $show['group'] = false;
166 }
167 }
168
169 // we can now remove all useless logs
170 if (sizeof($toKill) > 0)
171 {
172 $db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE historyid IN (" . implode(',', $toKill) . ")");
173 }
174
175 eval('$template->flush("' . $template->fetch('history') . '");');
176
177 /*=====================================================================*\
178 || ###################################################################
179 || # $HeadURL$
180 || # $Id$
181 || ###################################################################
182 \*=====================================================================*/
183 ?>