]>
src.bluestatic.org Git - bugdar.git/blob - showhistory.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
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.
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
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 \*=====================================================================*/
22 $fetchtemplates = array(
28 $focus['showreport'] = 'focus';
30 require_once('./global.php');
31 require_once('./includes/api_user.php');
33 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "bug WHERE bugid = " . $input->inputClean('bugid', TYPE_UINT
));
36 $message->error(L_INVALID_ID
);
39 if (!check_bug_permissions($bug))
41 $message->errorPermission();
44 $lookupfields = array(
46 'priority' => 'priority',
47 'severity' => 'severity',
48 'resolution' => 'resolution',
49 'version' => 'version',
51 'component' => 'title'
54 // ###################################################################
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)
62 AND permission.usergroupid IN (" . bugdar
::$userinfo['usergroupid'] . (sizeof(bugdar
::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar
::$userinfo['groupids']) : '') . ")
63 GROUP BY (bugfield.fieldid)"
66 foreach ($customfields as $field)
68 $fieldlist["$field[fieldid]"] = sprintf(T('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
71 // ###################################################################
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]"
81 foreach ($logs_fetch as $log)
83 $log['date'] = $datef->format(bugdar
::$options['dateformat'], $log['dateline']);
84 $log['user'] = construct_user_display($log);
86 $logs["$log[dateline]"]["$log[historyid]"] = $log;
87 ksort($logs["$log[dateline]"]);
94 foreach ($logs AS $dateline => $logitems)
96 $show['group'] = true;
98 foreach ($logitems AS $log)
100 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
102 $toKill[] = $log['historyid'];
106 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
108 if ($matches[1] == 'comment')
110 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid
'], ucwords($matches[2]));
112 else if ($matches[1] == 'attachment
')
114 $log['field
'] = sprintf(T('Attachment
#2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
117 else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
119 if ($fieldlist["$matches[2]"])
121 $log['field'] = $fieldlist["$matches[2]"];
128 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
130 $log['field'] = ucwords($matches[1]);
132 if (isset($lookupfields["$matches[1]"]))
134 $lookup = $matches[1];
135 $log['original'] = bugdar
::$datastore["$lookup"]["$log[original
]"][ $lookupfields["$lookup"] ];
136 $log['changed'] = bugdar
::$datastore["$lookup"]["$log[changed
]"][ $lookupfields["$lookup"] ];
138 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
140 if ($log['original'])
142 $user = new UserAPI();
143 $user->set('userid', $log['original']);
144 $user->setCondition();
146 $log['original'] = construct_user_display($user->record
);
151 $user = new UserAPI();
152 $user->set('userid', $log['changed']);
153 $user->setCondition();
155 $log['changed'] = construct_user_display($user->record
);
160 BSFunctions
::swap_css_classes('', 'altcolor');
162 $tpl = new BSTemplate('history_bit');
164 'bgcolor' => BSFunctions
::$cssClass,
167 $history .= $tpl->evaluate()->getTemplate();
168 $show['group'] = false;
172 // we can now remove all useless logs
173 if (sizeof($toKill) > 0)
175 $db->query("DELETE FROM " . TABLE_PREFIX
. "history WHERE historyid IN (" . implode(',', $toKill) . ")");
178 $tpl = new BSTemplate('history');
180 'history' => $history,
183 $tpl->evaluate()->flush();