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