r1392: Lots of work going into making the custom fields part of the bug table and...
[bugdar.git] / showhistory.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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->error_permission();
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.*
59 FROM " . TABLE_PREFIX . "bugfield AS bugfield
60 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
61 ON (bugfield.fieldid = permission.fieldid)
62 WHERE permission.mask <> 0
63 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
64 );
65
66 while ($field = $db->fetch_array($customfields))
67 {
68 $fieldlist["$field[fieldid]"] = sprintf(_('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
69 }
70
71 // ###################################################################
72
73 $logs = array();
74 $logs_fetch = $db->query("
75 SELECT history.*, user.userid, user.email, user.displayname, user.showemail
76 FROM " . TABLE_PREFIX . "history AS history
77 LEFT JOIN " . TABLE_PREFIX . "user AS user
78 ON (user.userid = history.userid)
79 WHERE bugid = $bug[bugid]"
80 );
81 while ($log = $db->fetch_array($logs_fetch))
82 {
83 $log['date'] = $datef->format($bugsys->options['dateformat'], $log['dateline']);
84 $log['user'] = construct_user_display($log);
85
86 $logs["$log[dateline]"]["$log[historyid]"] = $log;
87 ksort($logs["$log[dateline]"]);
88 }
89
90 ksort($logs);
91
92 foreach ($logs AS $dateline => $logitems)
93 {
94 $show['group'] = true;
95
96 foreach ($logitems AS $log)
97 {
98 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
99 {
100 continue;
101 }
102
103 $funct->exec_swap_bg('', $stylevar['alt_color']);
104 $bgcolor = $funct->bgcolour;
105
106 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
107 {
108 if ($matches[1] == 'comment')
109 {
110 $log['field'] = sprintf(_('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
111 }
112 else if ($matches[1] == 'attachment')
113 {
114 $log['field'] = sprintf(_('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
115 }
116 }
117 else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
118 {
119 if ($fieldlist["$matches[2]"])
120 {
121 $log['field'] = $fieldlist["$matches[2]"];
122 }
123 }
124 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
125 {
126 $log['field'] = ucwords($matches[1]);
127
128 if (isset($lookupfields["$matches[1]"]))
129 {
130 $lookup = $matches[1];
131 $log['original'] = $bugsys->datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
132 $log['changed'] = $bugsys->datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
133 }
134 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
135 {
136 if ($log['original'])
137 {
138 $user = new UserAPI($bugsys);
139 $user->set('userid', $log['original']);
140 $user->set_condition();
141 $user->fetch();
142 $log['original'] = construct_user_display($user->objdata);
143 }
144
145 if ($log['changed'])
146 {
147 $user = new UserAPI($bugsys);
148 $user->set('userid', $log['changed']);
149 $user->set_condition();
150 $user->fetch();
151 $log['changed'] = construct_user_display($user->objdata);
152 }
153 }
154 }
155
156 eval('$history .= "' . $template->fetch('history_bit') . '";');
157 $show['group'] = false;
158 }
159 }
160
161 eval('$template->flush("' . $template->fetch('history') . '");');
162
163 /*=====================================================================*\
164 || ###################################################################
165 || # $HeadURL$
166 || # $Id$
167 || ###################################################################
168 \*=====================================================================*/
169 ?>