r972: Rebranding from Iris Studios to Blue Static
[bugdar.git] / showreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 = $bugsys->input_clean('bugid', TYPE_UINT);
38
39 // ###################################################################
40
41 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
42 {
43 if (!empty($bugid))
44 {
45 if ($db->query_first("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 = $lang->getlex('error_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->query_first("
65 SELECT bugvaluefill.*, 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 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
70 ON (bug.bugid = bugvaluefill.bugid)
71 WHERE bug.bugid = $bugid"
72 );
73
74 if (!can_perform('canviewbugs', $bug['product']))
75 {
76 $message->error_permission();
77 }
78
79 $show['edit'] = ((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid'] AND $bug['userid'] != 0) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid']));
80 $show['delete'] = can_perform('candeletedata', $bug['product']);
81
82 if (!is_array($bug))
83 {
84 $message->error($lang->getlex('error_invalid_id'));
85 }
86
87 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['product']))
88 {
89 $message->error_permission();
90 }
91
92 // ###################################################################
93 // global display items
94
95 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
96
97 $favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
98 $favouritetext = (($favourite) ? $lang->string('Remove from Favourites') : $lang->string('Add to Favourites'));
99
100 $bug['userinfo'] = construct_user_display($bug);
101 $bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
102 $bug['product'] = $bugsys->datastore['product']["$bug[product]"]['title'];
103 $bug['component'] = (($bug['component']) ? $bugsys->datastore['product']["$bug[component]"]['title'] : '');
104 $bug['version'] = $bugsys->datastore['version']["$bug[version]"]['version'];
105
106 // ###################################################################
107 // edit display
108 if ($show['edit'])
109 {
110 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
111
112 $show['changestatus'] = ((can_perform('canchangestatus', $bug['product'])) ? true : false);
113 if (can_perform('canchangestatus', $bug['product']))
114 {
115 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
116 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
117 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
118 }
119 else
120 {
121 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
122 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
123 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
124 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
125 }
126
127 $show['assign'] = ((can_perform('canassign', $bug['product'])) ? true : false);
128 if (can_perform('canassign', $bug['product']) AND is_array($bugsys->datastore['assignto']))
129 {
130 foreach ($bugsys->datastore['assignto'] AS $dev)
131 {
132 $value = $dev['userid'];
133 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
134 $label = construct_user_display($dev, false);
135 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
136 }
137 }
138
139 $pcv_select = construct_pcv_select('canviewbugs', "p$bug[product]c$bug[component]v$bug[version]");
140
141 if ($bug['duplicateof'])
142 {
143 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
144 }
145
146 if ($bug['dependency'])
147 {
148 $depends = array();
149 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
150 while ($dependency = $db->fetch_array($dependencies))
151 {
152 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
153 }
154 $dependencies = implode(' ', $depends);
155 }
156
157 $select['autoactions'] = '';
158 $show['autoactions'] = false;
159 if (is_array($bugsys->datastore['autoaction']))
160 {
161 foreach ($bugsys->datastore['autoaction'] AS $action)
162 {
163 $label = $action['name'];
164 $value = $action['actionid'];
165 $selected = false;
166 eval('$select[autoaction] .= "' . $template->fetch('selectoption') . '";');
167 $show['autoactions'] = true;
168 }
169 if ($show['autoactions'])
170 {
171 $label = '';
172 $value = 0;
173 $selected = true;
174 eval('$select[autoaction] = "' . $template->fetch('selectoption') . '" . $select[autoaction];');
175 }
176 }
177 }
178
179 // ###################################################################
180 // non-edit display
181 else
182 {
183 // -------------------------------------------------------------------
184 // prep display
185 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
186 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
187 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
188 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
189
190 $assigninfo = $bugsys->datastore['assignto']["$bug[assignedto]"];
191 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
192
193 $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
194
195 $dupelist = array();
196 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
197 while ($duplicate = $db->fetch_array($duplicates))
198 {
199 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
200 }
201 $dupelist = implode(', ', $dupelist);
202
203 if ($bug['dependency'])
204 {
205 $depends = array();
206 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
207 while ($dependency = $db->fetch_array($dependencies))
208 {
209 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
210 }
211 $dependencies = implode(' ', $depends);
212 }
213 }
214
215 // ###################################################################
216 // custom field output
217
218 $fields = construct_custom_fields($bug);
219 $i = 0;
220 foreach ($fields AS $field)
221 {
222 if ($i % 2 == 0)
223 {
224 $customfields['left'] .= $field;
225 }
226 else
227 {
228 $customfields['right'] .= $field;
229 }
230 $i++;
231 }
232
233 // ###################################################################
234 // other elements
235
236 // -------------------------------------------------------------------
237 // hilight
238 $words = explode(' ', $bugsys->in['hilight']);
239 foreach ($words AS $word)
240 {
241 if (trim($word))
242 {
243 $word = preg_quote($bugsys->unsanitize($word));
244 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
245 }
246 }
247
248 // -------------------------------------------------------------------
249 // attachments
250 $show['getattachments'] = ((can_perform('cangetattach', $bug['product']) OR can_perform('caneditattach', $bug['product'])) ? true : false);
251 $show['putattachments'] = ((can_perform('canputattach', $bug['product']) OR can_perform('caneditattach', $bug['product'])) ? true : false);
252 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
253
254 if ($show['getattachments'] OR $show['putattachments'])
255 {
256 $attachments_fetch = $db->query("
257 SELECT attachment.attachmentid, attachment.filename,
258 attachment.description, attachment.dateline,
259 attachment.userid, attachment.obsolete, user.email,
260 user.showemail, user.displayname
261 FROM " . TABLE_PREFIX . "attachment AS attachment
262 LEFT JOIN " . TABLE_PREFIX . "user AS user
263 ON (attachment.userid = user.userid)
264 WHERE attachment.bugid = $bug[bugid]
265 ORDER BY attachment.dateline"
266 );
267
268 $attaches = false;
269 while ($attachment = $db->fetch_array($attachments_fetch))
270 {
271 $attaches = true;
272 $show['editattach'] = ((can_perform('caneditattach', $bug['product']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['product']))) ? true : false);
273 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
274 $attachment['user'] = construct_user_display($attachment, false);
275 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
276 }
277
278 $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
279 }
280
281 // -------------------------------------------------------------------
282 // votes
283
284 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
285
286 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
287 if ($vote['total'] != 0)
288 {
289 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
290 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
291 }
292 else
293 {
294 $vote['forpercent'] = 0;
295 $vote['againstpercent'] = 0;
296 }
297
298 $show['vote'] = ((can_perform('canvote', $bug['product']) AND !$vote['uservote']) ? true : false);
299
300 // -------------------------------------------------------------------
301 // get comments
302 $comments_fetch = $db->query("
303 SELECT comment.*, user.email, user.showemail, user.displayname
304 FROM " . TABLE_PREFIX . "comment AS comment
305 LEFT JOIN " . TABLE_PREFIX . "user AS user
306 ON (comment.userid = user.userid)
307 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden', $bug['product'])) ? "
308 AND !hidden" : '') . "
309 ORDER BY comment.dateline ASC"
310 );
311 while ($comment = $db->fetch_array($comments_fetch))
312 {
313 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
314 $comment['postby'] = construct_user_display($comment);
315 $show['editcomment'] = ((can_perform('caneditownreply', $bug['product']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['product']) AND $bugsys->userinfo['userid'] != $comment['userid']));
316
317 $bugsys->debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['product']) AND $bugsys->userinfo['userid'] == $comment['userid']));
318 $bugsys->debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['product']) AND $bugsys->userinfo['userid'] != $comment['userid']));
319 $bugsys->debug('$show[editcomment]: ' . $show['editcomment']);
320
321 if (is_array($hilight))
322 {
323 foreach ($hilight AS $id => $find)
324 {
325 $find = "#($find)#i";
326 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
327 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
328 }
329 }
330
331 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
332 }
333
334 $show['newreply'] = ((can_perform('canpostcomments', $bug['product'])) ? true : false);
335
336 $bug['summary_title'] = $bug['summary'];
337 if (is_array($hilight) AND !$show['edit'])
338 {
339 foreach ($hilight AS $id => $find)
340 {
341 $find = "#($find)#i";
342 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
343 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
344 }
345 }
346
347 eval('$template->flush("' . $template->fetch('showreport') . '");');
348
349 /*=====================================================================*\
350 || ###################################################################
351 || # $HeadURL$
352 || # $Id$
353 || ###################################################################
354 \*=====================================================================*/
355 ?>