r1389: Forgot to add the template diff
[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' => 'product',
52 'component' => 'product'
53 );
54 $lookupkeys = array_keys($lookupfields);
55
56 // ###################################################################
57
58 $customfields = $db->query("
59 SELECT bugfield.*
60 FROM " . TABLE_PREFIX . "bugfield AS bugfield
61 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
62 ON (bugfield.fieldid = permission.fieldid)
63 WHERE permission.mask <> 0
64 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
65 );
66
67 while ($field = $db->fetch_array($customfields))
68 {
69 $fieldlist["custom.field$field[fieldid]"] = sprintf(_('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 while ($log = $db->fetch_array($logs_fetch))
83 {
84 $log['date'] = $datef->format($bugsys->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 foreach ($logs AS $dateline => $logitems)
94 {
95 $show['group'] = true;
96
97 foreach ($logitems AS $log)
98 {
99 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
100 {
101 continue;
102 }
103
104 $funct->exec_swap_bg('', $stylevar['alt_color']);
105 $bgcolor = $funct->bgcolour;
106
107 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
108 {
109 if ($matches[1] == 'comment')
110 {
111 $log['field'] = sprintf(_('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
112 }
113 else if ($matches[1] == 'attachment')
114 {
115 $log['field'] = sprintf(_('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["$log[field]"])
121 {
122 $log['field'] = $fieldlist["$log[field]"];
123 }
124 }
125 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
126 {
127 $log['field'] = ucwords($matches[1]);
128
129 if (in_array($matches[1], $lookupkeys))
130 {
131 $lookup = $lookupfields["$matches[1]"];
132 $log['original'] = $bugsys->datastore[ $lookupfields["$lookup"] ]["$log[original]"]["$lookup"];
133 $log['changed'] = $bugsys->datastore[ $lookupfields["$lookup"] ]["$log[changed]"]["$lookup"];
134 }
135 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
136 {
137 if ($log['original'])
138 {
139 $user = new UserAPI($bugsys);
140 $user->set('userid', $log['original']);
141 $user->set_condition();
142 $user->fetch();
143 $log['original'] = construct_user_display($user->objdata);
144 }
145
146 if ($log['changed'])
147 {
148 $user = new UserAPI($bugsys);
149 $user->set('userid', $log['changed']);
150 $user->set_condition();
151 $user->fetch();
152 $log['changed'] = construct_user_display($user->objdata);
153 }
154 }
155 }
156
157 eval('$history .= "' . $template->fetch('history_bit') . '";');
158 $show['group'] = false;
159 }
160 }
161
162 eval('$template->flush("' . $template->fetch('history') . '");');
163
164 /*=====================================================================*\
165 || ###################################################################
166 || # $HeadURL$
167 || # $Id$
168 || ###################################################################
169 \*=====================================================================*/
170 ?>