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