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