Remove includes/class_api_error.php and all of the places we require() it
[bugdar.git] / showreport.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 'showreport',
24 'showreport_attachment',
25 'showreport_comment',
26 'quicksearch',
27 'bugfield_static_text'
28 );
29
30 define('SVN', '$Id$');
31
32 $focus['showreport'] = 'focus';
33
34 require_once('./global.php');
35 require_once('./includes/functions_product.php');
36
37 $bugid = $input->inputClean('bugid', TYPE_UINT);
38
39 // ###################################################################
40
41 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
42 {
43 if (!empty($bugid))
44 {
45 if ($db->queryFirst("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
46 {
47 header("Location: showreport.php?bugid=$bugid");
48 exit;
49 }
50 else
51 {
52 $error = L_INVALID_ID;
53 }
54 }
55
56 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
57 exit;
58 }
59
60 // ###################################################################
61
62 // -------------------------------------------------------------------
63 // get the report
64 $bug = $db->queryFirst("
65 SELECT bug.*, user.email, user.displayname, user.showemail
66 FROM " . TABLE_PREFIX . "bug AS bug
67 LEFT JOIN " . TABLE_PREFIX . "user AS user
68 ON (bug.userid = user.userid)
69 WHERE bug.bugid = $bugid"
70 );
71
72 if (!is_array($bug))
73 {
74 $message->error(L_INVALID_ID);
75 }
76
77 if (!check_bug_permissions($bug))
78 {
79 $message->errorPermission();
80 }
81
82 $show['edit'] = ((can_perform('caneditown', $bug['product']) AND bugdar::$userinfo['userid'] == $bug['userid'] AND $bug['userid'] != 0) OR (can_perform('caneditother', $bug['product']) AND bugdar::$userinfo['userid'] != $bug['userid']));
83 $show['delete'] = can_perform('candeletedata', $bug['product']);
84
85 // ###################################################################
86 // edit display
87 if ($show['edit'])
88 {
89 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
90
91 $show['changestatus'] = (can_perform('canchangestatus', $bug['product']) ? true : false);
92 if (can_perform('canchangestatus', $bug['product']))
93 {
94 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
95 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
96 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
97 }
98 else
99 {
100 $bug['status'] = bugdar::$datastore['status']["$bug[status]"]['status'];
101 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
102 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
103 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
104 }
105
106 $show['assign'] = (can_perform('canassign', $bug['product']));
107 if (can_perform('canassign', $bug['product']) && is_array(bugdar::$datastore['assignto']))
108 {
109 foreach (bugdar::$datastore['assignto'] as $dev)
110 {
111 $tpl = new BSTemplate('selectoption');
112 $tpl->vars = array(
113 'value' => $dev['userid'],
114 'label' => construct_user_display($dev, false),
115 'selected' => ($dev['userid'] == $bug['assignedto'])
116 );
117 $select['dev'] .= $tpl->evaluate()->getTemplate();
118 }
119 }
120
121 $productSelect = ConstructProductSelect('canviewbugs', "$bug[product],$bug[component],$bug[version]");
122
123 if ($bug['duplicateof'])
124 {
125 $duplicate = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
126 }
127
128 if ($bug['dependency'])
129 {
130 $depends = array();
131 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
132 foreach ($dependencies as $dependency)
133 {
134 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
135 }
136 $dependencies = implode(' ', $depends);
137 }
138
139 $select['automations'] = '';
140 $show['automations'] = false;
141 if (is_array(bugdar::$datastore['automation']))
142 {
143 foreach (bugdar::$datastore['automation'] as $action)
144 {
145 $tpl = new BSTemplate('selectoption');
146 $tpl->vars = array(
147 'label' => $action['name'],
148 'value' => $action['actionid'],
149 'selected' => false
150 );
151 $select['automation'] .= $tpl->evaluate()->getTemplate();
152 $show['automations'] = true;
153 }
154 if ($show['automations'])
155 {
156 $tpl = new BSTemplate('selectoption');
157 $tpl->vars = array(
158 'label' => '',
159 'value' => 0,
160 'selected' => true
161 );
162 $select['automation'] = $tpl->evaluate()->getTemplate() . $select['automation'];
163 }
164 }
165 }
166
167 // ###################################################################
168 // non-edit display
169 else
170 {
171 // -------------------------------------------------------------------
172 // prep display
173 $bug['status'] = bugdar::$datastore['status']["$bug[status]"]['status'];
174 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
175 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
176 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
177
178 $assigninfo = bugdar::$datastore['assignto']["$bug[assignedto]"];
179 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
180
181 $duplicateof = $db->queryFirst("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
182
183 $dupelist = array();
184 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
185 foreach ($duplicates as $duplicate)
186 {
187 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
188 }
189 $dupelist = implode(', ', $dupelist);
190
191 if ($bug['dependency'])
192 {
193 $depends = array();
194 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
195 foreach ($dependencies as $dependency)
196 {
197 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
198 }
199 $dependencies = implode(' ', $depends);
200 }
201 }
202
203 // ###################################################################
204 // global display items
205
206 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
207
208 $favorite = (bool)$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . bugdar::$userinfo['userid']);
209 $favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
210
211 $bug['userinfo'] = construct_user_display($bug);
212 $bug['datetime'] = $datef->format(bugdar::$options['dateformat'], $bug['dateline']);
213 $bug['productid'] = $bug['product'];
214 $bug['product'] = bugdar::$datastore['product']["$bug[product]"]['title'];
215 $bug['componentid'] = $bug['component'];
216 $bug['component'] = ($bug['component'] ? bugdar::$datastore['product']["$bug[component]"]['title'] : '');
217 $bug['versionid'] = $bug['version'];
218 $bug['version'] = bugdar::$datastore['version']["$bug[version]"]['version'];
219
220 // ###################################################################
221 // custom field output
222
223 $fields = construct_custom_fields($bug);
224 $i = 0;
225 foreach ($fields AS $field)
226 {
227 if ($i % 2 == 0)
228 {
229 $customfields['left'] .= $field;
230 }
231 else
232 {
233 $customfields['right'] .= $field;
234 }
235 $i++;
236 }
237
238 // ###################################################################
239 // other elements
240
241 // -------------------------------------------------------------------
242 // hilight
243 $words = explode(' ', $input->in['hilight']);
244 foreach ($words AS $word)
245 {
246 if (trim($word))
247 {
248 $word = preg_quote($input->unsanitize($word));
249 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
250 }
251 }
252
253 // -------------------------------------------------------------------
254 // attachments
255 $show['getattachments'] = ((can_perform('cangetattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
256 $show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
257 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
258
259 if ($show['getattachments'] OR $show['putattachments'])
260 {
261 $attachments_fetch = $db->query("
262 SELECT attachment.attachmentid, attachment.filename,
263 attachment.description, attachment.dateline,
264 attachment.userid, attachment.obsolete, user.email,
265 user.showemail, user.displayname
266 FROM " . TABLE_PREFIX . "attachment AS attachment
267 LEFT JOIN " . TABLE_PREFIX . "user AS user
268 ON (attachment.userid = user.userid)
269 WHERE attachment.bugid = $bug[bugid]
270 ORDER BY attachment.dateline"
271 );
272
273 $attaches = false;
274 foreach ($attachments_fetch as $attachment)
275 {
276 $attaches = true;
277 $show['editattach'] = ((can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == bugdar::$userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? true : false);
278 $attachment['date'] = $datef->format(bugdar::$options['dateformat'], $attachment['dateline']);
279 $attachment['user'] = construct_user_display($attachment, false);
280 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
281 }
282
283 $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
284 }
285
286 // -------------------------------------------------------------------
287 // votes
288
289 $vote = $db->queryFirst("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
290
291 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
292 if ($vote['total'] != 0)
293 {
294 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
295 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
296 }
297 else
298 {
299 $vote['forpercent'] = 0;
300 $vote['againstpercent'] = 0;
301 }
302
303 $show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
304
305 // -------------------------------------------------------------------
306 // get comments
307 $comments_fetch = $db->query("
308 SELECT comment.*, user.email, user.showemail, user.displayname
309 FROM " . TABLE_PREFIX . "comment AS comment
310 LEFT JOIN " . TABLE_PREFIX . "user AS user
311 ON (comment.userid = user.userid)
312 WHERE comment.bugid = $bug[bugid]" . (!can_perform('canviewhidden', $bug['productid']) ? "
313 AND !hidden" : '') . "
314 ORDER BY comment.dateline ASC"
315 );
316 foreach ($comments_fetch as $comment)
317 {
318 $comment['posttime'] = $datef->format(bugdar::$options['dateformat'], $comment['dateline']);
319 $comment['postby'] = construct_user_display($comment);
320 $show['editcomment'] = ((can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
321
322 BSApp::debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']));
323 BSApp::debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
324 BSApp::debug('$show[editcomment]: ' . $show['editcomment']);
325
326 if (is_array($hilight))
327 {
328 foreach ($hilight AS $id => $find)
329 {
330 $find = "#($find)#i";
331 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
332 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
333 }
334 }
335
336 $tpl = new BSTemplate('showreport_comment');
337 $tpl->vars = array('comment' => $comment);
338 $comments .= $tpl->evaluate()->getTemplate();
339 }
340
341 $show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
342
343 $bug['summary_title'] = $bug['summary'];
344 if (is_array($hilight) AND !$show['edit'])
345 {
346 foreach ($hilight AS $id => $find)
347 {
348 $find = "#($find)#i";
349 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
350 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
351 }
352 }
353
354 $tpl = new BSTemplate('showreport');
355 $tpl->vars = array(
356 'bug' => $bug,
357 'comments' => $comments,
358 'select' => $select,
359 'vote' => $vote,
360 'favoritetext' => $favoritetext,
361 'customfields' => $customfields
362 );
363 $tpl->evaluate()->flush();
364
365 /*=====================================================================*\
366 || ###################################################################
367 || # $HeadURL$
368 || # $Id$
369 || ###################################################################
370 \*=====================================================================*/
371 ?>