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