Migrate 4 builtin fields to fields2: priority, resolution, severity, status.
[bugdar.git] / showreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 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 2 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
31 $focus['showreport'] = 'focus';
32
33 require_once('./global.php');
34 require_once('./includes/functions_product.php');
35
36 $bugid = $bugsys->input_clean('bugid', TYPE_UINT);
37
38 // ###################################################################
39
40 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
41 {
42 if (!empty($bugid))
43 {
44 if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
45 {
46 header("Location: showreport.php?bugid=$bugid");
47 exit;
48 }
49 else
50 {
51 $error = L_INVALID_ID;
52 }
53 }
54
55 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
56 exit;
57 }
58
59 // ###################################################################
60
61 // -------------------------------------------------------------------
62 // get the report
63 $bug = $db->query_first("
64 SELECT bug.*, user.email, user.displayname, user.showemail
65 FROM " . TABLE_PREFIX . "bug AS bug
66 LEFT JOIN " . TABLE_PREFIX . "user AS user
67 ON (bug.userid = user.userid)
68 WHERE bug.bugid = $bugid"
69 );
70
71 if (!is_array($bug))
72 {
73 $message->error(L_INVALID_ID);
74 }
75
76 if (!check_bug_permissions($bug))
77 {
78 $message->errorPermission();
79 }
80
81 $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']));
82 $show['delete'] = can_perform('candeletedata', $bug['product']);
83
84 // ###################################################################
85 // edit display
86 if ($show['edit'])
87 {
88 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
89
90 $show['changestatus'] = (can_perform('canchangestatus', $bug['product']) ? true : false);
91 if (can_perform('canchangestatus', $bug['product']))
92 {
93 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
94 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
95 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
96 }
97 else
98 {
99 $bug['status'] = Bugdar::$datastore['status']["$bug[status]"]['status'];
100 $bug['resolution'] = Bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
101 $bug['severity'] = Bugdar::$datastore['severity']["$bug[severity]"]['severity'];
102 $bug['priority'] = Bugdar::$datastore['priority']["$bug[priority]"]['priority'];
103 }
104
105 $show['assign'] = (can_perform('canassign', $bug['product']) ? true : false);
106 if (can_perform('canassign', $bug['product']) AND is_array(Bugdar::$datastore['assignto']))
107 {
108 foreach (Bugdar::$datastore['assignto'] AS $dev)
109 {
110 $value = $dev['userid'];
111 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
112 $label = construct_user_display($dev, false);
113 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
114 }
115 }
116
117 $productSelect = ConstructProductSelect('canviewbugs', "$bug[product],$bug[component],$bug[version]");
118
119 if ($bug['duplicateof'])
120 {
121 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
122 }
123
124 if ($bug['dependency'])
125 {
126 $depends = array();
127 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
128 while ($dependency = $db->fetch_array($dependencies))
129 {
130 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
131 }
132 $dependencies = implode(' ', $depends);
133 }
134
135 $select['automations'] = '';
136 $show['automations'] = false;
137 if (is_array(Bugdar::$datastore['automation']))
138 {
139 foreach (Bugdar::$datastore['automation'] AS $action)
140 {
141 $label = $action['name'];
142 $value = $action['actionid'];
143 $selected = false;
144 eval('$select[automation] .= "' . $template->fetch('selectoption') . '";');
145 $show['automations'] = true;
146 }
147 if ($show['automations'])
148 {
149 $label = '';
150 $value = 0;
151 $selected = true;
152 eval('$select[automation] = "' . $template->fetch('selectoption') . '" . $select[automation];');
153 }
154 }
155 }
156
157 // ###################################################################
158 // non-edit display
159 else
160 {
161 // -------------------------------------------------------------------
162 // prep display
163 $bug['status'] = Bugdar::$datastore['status']["$bug[status]"]['status'];
164 $bug['resolution'] = Bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
165 $bug['severity'] = Bugdar::$datastore['severity']["$bug[severity]"]['severity'];
166 $bug['priority'] = Bugdar::$datastore['priority']["$bug[priority]"]['priority'];
167
168 $assigninfo = Bugdar::$datastore['assignto']["$bug[assignedto]"];
169 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
170
171 $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
172
173 $dupelist = array();
174 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
175 while ($duplicate = $db->fetch_array($duplicates))
176 {
177 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
178 }
179 $dupelist = implode(', ', $dupelist);
180
181 if ($bug['dependency'])
182 {
183 $depends = array();
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 // global display items
195
196 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
197
198 $favorite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
199 $favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
200
201 $bug['userinfo'] = construct_user_display($bug);
202 $bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
203 $bug['productid'] = $bug['product'];
204 $bug['product'] = Bugdar::$datastore['product']["$bug[product]"]['title'];
205 $bug['componentid'] = $bug['component'];
206 $bug['component'] = ($bug['component'] ? Bugdar::$datastore['product']["$bug[component]"]['title'] : '');
207 $bug['versionid'] = $bug['version'];
208 $bug['version'] = Bugdar::$datastore['version']["$bug[version]"]['version'];
209
210 // ###################################################################
211 // custom field output
212
213 $fields = construct_custom_fields($bug);
214 $i = 0;
215 foreach ($fields AS $field)
216 {
217 if ($i % 2 == 0)
218 {
219 $customfields['left'] .= $field;
220 }
221 else
222 {
223 $customfields['right'] .= $field;
224 }
225 $i++;
226 }
227
228 // ###################################################################
229 // other elements
230
231 // -------------------------------------------------------------------
232 // hilight
233 $words = explode(' ', $bugsys->in['hilight']);
234 foreach ($words AS $word)
235 {
236 if (trim($word))
237 {
238 $word = preg_quote($bugsys->unsanitize($word));
239 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
240 }
241 }
242
243 // -------------------------------------------------------------------
244 // attachments
245 $show['getattachments'] = ((can_perform('cangetattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
246 $show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
247 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
248
249 if ($show['getattachments'] OR $show['putattachments'])
250 {
251 $attachments_fetch = $db->query("
252 SELECT attachment.attachmentid, attachment.filename,
253 attachment.description, attachment.dateline,
254 attachment.userid, attachment.obsolete, user.email,
255 user.showemail, user.displayname
256 FROM " . TABLE_PREFIX . "attachment AS attachment
257 LEFT JOIN " . TABLE_PREFIX . "user AS user
258 ON (attachment.userid = user.userid)
259 WHERE attachment.bugid = $bug[bugid]
260 ORDER BY attachment.dateline"
261 );
262
263 $attaches = false;
264 while ($attachment = $db->fetch_array($attachments_fetch))
265 {
266 $attaches = true;
267 $show['editattach'] = ((can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? true : false);
268 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
269 $attachment['user'] = construct_user_display($attachment, false);
270 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
271 }
272
273 $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
274 }
275
276 // -------------------------------------------------------------------
277 // votes
278
279 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
280
281 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
282 if ($vote['total'] != 0)
283 {
284 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
285 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
286 }
287 else
288 {
289 $vote['forpercent'] = 0;
290 $vote['againstpercent'] = 0;
291 }
292
293 $show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
294
295 // -------------------------------------------------------------------
296 // get comments
297 $comments_fetch = $db->query("
298 SELECT comment.*, user.email, user.showemail, user.displayname
299 FROM " . TABLE_PREFIX . "comment AS comment
300 LEFT JOIN " . TABLE_PREFIX . "user AS user
301 ON (comment.userid = user.userid)
302 WHERE comment.bugid = $bug[bugid]" . (!can_perform('canviewhidden', $bug['productid']) ? "
303 AND !hidden" : '') . "
304 ORDER BY comment.dateline ASC"
305 );
306 $description = null;
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('$temp = "' . $template->fetch('showreport_comment') . '";');
328 if ($description == null)
329 {
330 $description = $temp;
331 }
332 else
333 {
334 $comments .= $temp;
335 }
336 }
337
338 $show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
339
340 $bug['summary_title'] = $bug['summary'];
341 if (is_array($hilight) AND !$show['edit'])
342 {
343 foreach ($hilight AS $id => $find)
344 {
345 $find = "#($find)#i";
346 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
347 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
348 }
349 }
350
351 eval('$template->flush("' . $template->fetch('showreport') . '");');
352