]> src.bluestatic.org Git - bugdar.git/blob - showhistory.php
Renaming admin/setting.php to admin/settings.php
[bugdar.git] / showhistory.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 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
28 $focus['showreport'] = 'focus';
29
30 require_once('./global.php');
31 require_once('./includes/api_user.php');
32
33 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->inputClean('bugid', TYPE_UINT));
34 if (!$bug)
35 {
36 $message->error(L_INVALID_ID);
37 }
38
39 if (!check_bug_permissions($bug))
40 {
41 $message->errorPermission();
42 }
43
44 $lookupfields = array(
45 'status' => 'status',
46 'priority' => 'priority',
47 'severity' => 'severity',
48 'resolution' => 'resolution',
49 'version' => 'version',
50 'product' => 'title',
51 'component' => 'title'
52 );
53
54 // ###################################################################
55
56 $customfields = $db->query("
57 SELECT bugfield.*, MAX(permission.mask) AS mask
58 FROM " . TABLE_PREFIX . "bugfield AS bugfield
59 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
60 ON (bugfield.fieldid = permission.fieldid)
61 WHERE mask <> 0
62 AND permission.usergroupid IN (" . bugdar::$userinfo['usergroupid'] . (sizeof(bugdar::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar::$userinfo['groupids']) : '') . ")
63 GROUP BY (bugfield.fieldid)"
64 );
65
66 foreach ($customfields as $field)
67 {
68 $fieldlist["$field[fieldid]"] = sprintf(T('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 foreach ($logs_fetch as $log)
82 {
83 $log['date'] = $datef->format(bugdar::$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 $toKill = array();
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 $toKill[] = $log['historyid'];
103 continue;
104 }
105
106 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
107 {
108 if ($matches[1] == 'comment')
109 {
110 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
111 }
112 else if ($matches[1] == 'attachment')
113 {
114 $log['field'] = sprintf(T('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 else
124 {
125 continue;
126 }
127 }
128 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
129 {
130 $log['field'] = ucwords($matches[1]);
131
132 if (isset($lookupfields["$matches[1]"]))
133 {
134 $lookup = $matches[1];
135 $log['original'] = bugdar::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
136 $log['changed'] = bugdar::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
137 }
138 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
139 {
140 if ($log['original'])
141 {
142 $user = new UserAPI();
143 $user->set('userid', $log['original']);
144 $user->setCondition();
145 $user->fetch();
146 $log['original'] = construct_user_display($user->record);
147 }
148
149 if ($log['changed'])
150 {
151 $user = new UserAPI();
152 $user->set('userid', $log['changed']);
153 $user->setCondition();
154 $user->fetch();
155 $log['changed'] = construct_user_display($user->record);
156 }
157 }
158 }
159
160 BSFunctions::swap_css_classes('', 'altcolor');
161
162 $tpl = new BSTemplate('history_bit');
163 $tpl->vars = array(
164 'bgcolor' => BSFunctions::$cssClass,
165 'log' => $log
166 );
167 $history .= $tpl->evaluate()->getTemplate();
168 $show['group'] = false;
169 }
170 }
171
172 // we can now remove all useless logs
173 if (sizeof($toKill) > 0)
174 {
175 $db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE historyid IN (" . implode(',', $toKill) . ")");
176 }
177
178 $tpl = new BSTemplate('history');
179 $tpl->vars = array(
180 'history' => $history,
181 'bug' => $bug
182 );
183 $tpl->evaluate()->flush();
184
185 ?>