r552: Cleaned up the attachment query so we're not grabbing the BLOB
[bugdar.git] / showreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'showreport',
15 'showreport_attachment',
16 'showreport_comment',
17 'quicksearch',
18 'bugfield_static_text'
19 );
20
21 define('SVN', '$Id$');
22
23 $focus['showreport'] = 'focus';
24
25 require_once('./global.php');
26 require_once('./includes/functions_product.php');
27
28 $bugid = intval($bugsys->in['bugid']);
29
30 // ###################################################################
31
32 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
33 {
34 if (!empty($bugid))
35 {
36 if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
37 {
38 header("Location: showreport.php?bugid=$bugid");
39 exit;
40 }
41 else
42 {
43 $error = $lang->getlex('error_invalid_id');
44 }
45 }
46
47 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
48 exit;
49 }
50
51 // ###################################################################
52
53 // -------------------------------------------------------------------
54 // get the report
55 $bug = $db->query_first("
56 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
57 FROM " . TABLE_PREFIX . "bug AS bug
58 LEFT JOIN " . TABLE_PREFIX . "user AS user
59 ON (bug.userid = user.userid)
60 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
61 ON (bug.bugid = bugvaluefill.bugid)
62 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
63 );
64
65 if (!can_perform('canviewbugs', $bug['productid']))
66 {
67 $message->error_permission();
68 }
69
70 $show['edit'] = ((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid']));
71
72 if (!is_array($bug))
73 {
74 $message->error($lang->getlex('error_invalid_id'));
75 }
76
77 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
78 {
79 $message->error_permission();
80 }
81
82 // ###################################################################
83 // global display items
84
85 $show['subscribe'] = can_perform('cansubscribe', $bug['productid']);
86
87 $favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
88 $favouritetext = (($favourite) ? $lang->string('Remove from Favourites') : $lang->string('Add to Favourites'));
89
90 $bug['userinfo'] = construct_user_display($bug);
91 $bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
92 $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
93 $bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : '');
94 $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
95
96 // ###################################################################
97 // edit display
98 if ($show['edit'])
99 {
100 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
101
102 $show['changestatus'] = ((can_perform('canchangestatus', $bug['productid'])) ? true : false);
103 if (can_perform('canchangestatus', $bug['productid']))
104 {
105 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
106 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
107 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
108 }
109 else
110 {
111 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
112 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
113 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
114 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
115 }
116
117 $show['assign'] = ((can_perform('canassign', $bug['productid'])) ? true : false);
118 if (can_perform('canassign', $bug['productid']))
119 {
120 foreach ($bugsys->datastore['assignto'] AS $dev)
121 {
122 $value = $dev['userid'];
123 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
124 $label = construct_user_display($dev, false);
125 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
126 }
127 }
128
129 $pcv_select = construct_pcv_select('canviewbugs', "p$bug[productid]c$bug[componentid]v$bug[versionid]");
130
131 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
132
133 if ($bug['duplicateof'])
134 {
135 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
136 }
137
138 if ($bug['dependency'])
139 {
140 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
141 while ($dependency = $db->fetch_array($dependencies))
142 {
143 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
144 }
145 $dependencies = implode(' ', $depends);
146 }
147
148 $select['autoactions'] = '';
149 $show['autoactions'] = false;
150 foreach ($bugsys->datastore['autoaction'] AS $action)
151 {
152 $label = $action['name'];
153 $value = $action['actionid'];
154 $selected = false;
155 eval('$select[autoaction] .= "' . $template->fetch('selectoption') . '";');
156 $show['autoactions'] = true;
157 }
158 if ($show['autoactions'])
159 {
160 $label = '';
161 $value = 0;
162 $selected = true;
163 eval('$select[autoaction] = "' . $template->fetch('selectoption') . '" . $select[autoaction];');
164 }
165 }
166
167 // ###################################################################
168 // non-edit display
169 else
170 {
171 // -------------------------------------------------------------------
172 // prep display
173 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
174 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
175 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
176 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
177
178 $assigninfo = $bugsys->datastore['assignto']["$bug[assignedto]"];
179 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
180
181 $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
182
183 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
184 while ($duplicate = $db->fetch_array($duplicates))
185 {
186 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
187 }
188 $dupelist = implode(', ', $dupelist);
189
190 if ($bug['dependency'])
191 {
192 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
193 while ($dependency = $db->fetch_array($dependencies))
194 {
195 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
196 }
197 $dependencies = implode(' ', $depends);
198 }
199 }
200
201 // ###################################################################
202 // custom field output
203
204 $fields = construct_custom_fields($bug);
205 $show['customfields'] = ($fields ? true : false);
206
207 $bugsys->debug('fields modulo: ' . count($fields) % 2);
208 $i = 1;
209 foreach ($fields AS $field)
210 {
211 $bugsys->debug("i = $i");
212 if ($i == 1)
213 {
214 $customfields['right'] .= $field;
215 }
216 else if ($i == 2)
217 {
218 $customfields['left'] .= $field;
219 $i = 0;
220 }
221 $i++;
222 }
223
224 // ###################################################################
225 // other elements
226
227 // -------------------------------------------------------------------
228 // hilight
229 $words = explode(' ', $bugsys->in['hilight']);
230 foreach ($words AS $word)
231 {
232 if (trim($word))
233 {
234 $word = preg_quote($bugsys->unsanitize($word));
235 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
236 }
237 }
238
239 // -------------------------------------------------------------------
240 // attachments
241 $show['getattachments'] = ((can_perform('cangetattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
242 $show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
243 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
244
245 if ($show['getattachments'] OR $show['putattachments'])
246 {
247 $attachments_fetch = $db->query("
248 SELECT attachment.attachmentid, attachment.filename,
249 attachment.description, attachment.dateline,
250 attachment.userid, attachment.obsolete, user.email,
251 user.showemail, user.displayname
252 FROM " . TABLE_PREFIX . "attachment AS attachment
253 LEFT JOIN " . TABLE_PREFIX . "user AS user
254 ON (attachment.userid = user.userid)
255 WHERE attachment.bugid = $bug[bugid]
256 ORDER BY attachment.dateline"
257 );
258
259 $attaches = false;
260 while ($attachment = $db->fetch_array($attachments_fetch))
261 {
262 $attaches = true;
263 $show['editattach'] = ((can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? true : false);
264 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
265 $attachment['user'] = construct_user_display($attachment, false);
266 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
267 }
268
269 $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
270 }
271
272 // -------------------------------------------------------------------
273 // votes
274
275 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
276
277 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
278 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
279 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
280
281 $show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
282
283 // -------------------------------------------------------------------
284 // get comments
285 $comments_fetch = $db->query("
286 SELECT comment.*, user.email, user.showemail, user.displayname
287 FROM " . TABLE_PREFIX . "comment AS comment
288 LEFT JOIN " . TABLE_PREFIX . "user AS user
289 ON (comment.userid = user.userid)
290 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden', $bug['productid'])) ? "
291 AND !hidden" : '') . "
292 ORDER BY comment.dateline ASC"
293 );
294 while ($comment = $db->fetch_array($comments_fetch))
295 {
296 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
297 $comment['postby'] = construct_user_display($comment);
298 $show['editcomment'] = ((can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid']));
299
300 $bugsys->debug((int)(can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']));
301 $bugsys->debug((int)(can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid']));
302 $bugsys->debug($show['editcomment']);
303
304 if (is_array($hilight))
305 {
306 foreach ($hilight AS $id => $find)
307 {
308 $find = "#($find)#";
309 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
310 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
311 }
312 }
313
314 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
315 }
316
317 $show['newreply'] = ((can_perform('canpostcomments', $bug['productid'])) ? true : false);
318
319 if (is_array($hilight))
320 {
321 foreach ($hilight AS $id => $find)
322 {
323 $find = "#($find)#";
324 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
325 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
326 }
327 }
328
329 eval('$template->flush("' . $template->fetch('showreport') . '");');
330
331 /*=====================================================================*\
332 || ###################################################################
333 || # $HeadURL$
334 || # $Id$
335 || ###################################################################
336 \*=====================================================================*/
337 ?>