r1048: Converting all $lang->string() stuff to use the gettext call
[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($lang->getlex('error_invalid_id'));
38 }
39
40 if (($bug['hidden'] AND !can_perform('canviewhidden', $bug['product'])) OR !can_perform('canviewbugs', $bug['product']))
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 'version' => 'version',
52 'product' => 'product',
53 'component' => 'product'
54 );
55 $lookupkeys = array_keys($lookupfields);
56
57 // ###################################################################
58
59 $customfields = $db->query("
60 SELECT bugfield.*
61 FROM " . TABLE_PREFIX . "bugfield AS bugfield
62 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
63 ON (bugfield.fieldid = permission.fieldid)
64 WHERE permission.mask <> 0
65 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
66 );
67
68 while ($field = $db->fetch_array($customfields))
69 {
70 $fieldlist["custom.field$field[fieldid]"] = sprintf(_('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
71 }
72
73 // ###################################################################
74
75 $logs = array();
76 $logs_fetch = $db->query("
77 SELECT history.*, user.userid, user.email, user.displayname, user.showemail
78 FROM " . TABLE_PREFIX . "history AS history
79 LEFT JOIN " . TABLE_PREFIX . "user AS user
80 ON (user.userid = history.userid)
81 WHERE bugid = $bug[bugid]"
82 );
83 while ($log = $db->fetch_array($logs_fetch))
84 {
85 $log['date'] = $datef->format($bugsys->options['dateformat'], $log['dateline']);
86 $log['user'] = construct_user_display($log);
87
88 $logs["$log[dateline]"]["$log[historyid]"] = $log;
89 ksort($logs["$log[dateline]"]);
90 }
91
92 ksort($logs);
93
94 foreach ($logs AS $dateline => $logitems)
95 {
96 $show['group'] = true;
97
98 foreach ($logitems AS $log)
99 {
100 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
101 {
102 continue;
103 }
104
105 $funct->exec_swap_bg('', $stylevar['alt_colour']);
106 $bgcolour = $funct->bgcolour;
107
108 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
109 {
110 if ($matches[1] == 'comment')
111 {
112 $log['field'] = sprintf(_('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
113 }
114 else if ($matches[1] == 'attachment')
115 {
116 $log['field'] = sprintf(_('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
117 }
118 }
119 else if (preg_match('#^custom.field([0-9]+?)#', $log['field'], $matches))
120 {
121 if ($fieldlist["$log[field]"])
122 {
123 $log['field'] = $fieldlist["$log[field]"];
124 }
125 }
126 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
127 {
128 $log['field'] = ucwords($matches[1]);
129
130 if (in_array($matches[1], $lookupkeys))
131 {
132 $lookup = $lookupfields["$matches[1]"];
133 $log['original'] = $bugsys->datastore[ $lookupfields["$lookup"] ]["$log[original]"]["$lookup"];
134 $log['changed'] = $bugsys->datastore[ $lookupfields["$lookup"] ]["$log[changed]"]["$lookup"];
135 }
136 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
137 {
138 if ($log['original'])
139 {
140 $user = new UserAPI($bugsys);
141 $user->set('userid', $log['original']);
142 $user->set_condition();
143 $user->fetch();
144 $log['original'] = construct_user_display($user->objdata);
145 }
146
147 if ($log['changed'])
148 {
149 $user = new UserAPI($bugsys);
150 $user->set('userid', $log['changed']);
151 $user->set_condition();
152 $user->fetch();
153 $log['changed'] = construct_user_display($user->objdata);
154 }
155 }
156 }
157
158 eval('$history .= "' . $template->fetch('history_bit') . '";');
159 $show['group'] = false;
160 }
161 }
162
163 eval('$template->flush("' . $template->fetch('history') . '");');
164
165 /*=====================================================================*\
166 || ###################################################################
167 || # $HeadURL$
168 || # $Id$
169 || ###################################################################
170 \*=====================================================================*/
171 ?>