]> src.bluestatic.org Git - bugdar.git/blob - showhistory.php
Fix the password reset email system
[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->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->inputClean('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 $history = '';
100 foreach ($logitems AS $log)
101 {
102 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
103 {
104 $toKill[] = $log['historyid'];
105 continue;
106 }
107
108 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
109 {
110 if ($matches[1] == 'comment')
111 {
112 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
113 }
114 else if ($matches[1] == 'attachment')
115 {
116 $log['field'] = sprintf(T('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["$matches[2]"])
122 {
123 $log['field'] = $fieldlist["$matches[2]"];
124 }
125 else
126 {
127 continue;
128 }
129 }
130 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
131 {
132 $log['field'] = ucwords($matches[1]);
133
134 if (isset($lookupfields["$matches[1]"]))
135 {
136 $lookup = $matches[1];
137 $log['original'] = bugdar::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
138 $log['changed'] = bugdar::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
139 }
140 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
141 {
142 if ($log['original'])
143 {
144 $user = new UserAPI();
145 $user->set('userid', $log['original']);
146 $user->setCondition();
147 $user->fetch();
148 $log['original'] = construct_user_display($user->record);
149 }
150
151 if ($log['changed'])
152 {
153 $user = new UserAPI();
154 $user->set('userid', $log['changed']);
155 $user->setCondition();
156 $user->fetch();
157 $log['changed'] = construct_user_display($user->record);
158 }
159 }
160 }
161
162 BSFunctions::swap_css_classes('', 'altcolor');
163
164 $tpl = new BSTemplate('history_bit');
165 $tpl->vars = array(
166 'bgcolor' => BSFunctions::$cssClass,
167 'log' => $log
168 );
169 $history .= $tpl->evaluate()->getTemplate();
170 $show['group'] = false;
171 }
172 }
173
174 // we can now remove all useless logs
175 if (sizeof($toKill) > 0)
176 {
177 $db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE historyid IN (" . implode(',', $toKill) . ")");
178 }
179
180 $tpl = new BSTemplate('history');
181 $tpl->vars = array(
182 'history' => $history,
183 'bug' => $bug
184 );
185 $tpl->evaluate()->flush();
186
187 /*=====================================================================*\
188 || ###################################################################
189 || # $HeadURL$
190 || # $Id$
191 || ###################################################################
192 \*=====================================================================*/
193 ?>