r322: You can now edit fields on showreport.php
[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 'pcv_select_row'
19 );
20
21 define('SVN', '$Id$');
22
23 $focus['showreport'] = 'focus';
24
25 require_once('./global.php');
26
27 if (!can_perform('canviewbugs'))
28 {
29 $message->error_permission();
30 }
31
32 $show['edit'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $bug['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) ? true : false;
33
34 $bugid = intval($bugsys->in['bugid']);
35
36 // ###################################################################
37
38 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
39 {
40 if (!empty($bugid))
41 {
42 if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
43 {
44 header("Location: showreport.php?bugid=$bugid");
45 exit;
46 }
47 else
48 {
49 $error = lang::p('error_invalid_id');
50 }
51 }
52
53 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
54 exit;
55 }
56
57 // ###################################################################
58
59 // -------------------------------------------------------------------
60 // get the report
61 $bug = $db->query_first("
62 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
63 FROM " . TABLE_PREFIX . "bug AS bug
64 LEFT JOIN " . TABLE_PREFIX . "user AS user
65 ON (bug.userid = user.userid)
66 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
67 ON (bug.bugid = bugvaluefill.bugid)
68 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
69 );
70
71 if (!is_array($bug))
72 {
73 $message->error(lang::p('error_invalid_id'));
74 }
75
76 if ($bug['hidden'] AND !can_perform('canviewhidden'))
77 {
78 $message->error_permission();
79 }
80
81 // ###################################################################
82 // global display items
83
84 $favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
85 $favouritetext = (($favourite) ? 'Remove from Favourites' : 'Add to Favourites');
86
87
88 // ###################################################################
89 // edit display
90 if ($show['edit'])
91 {
92 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
93
94 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
95 if (can_perform('canchangestatus'))
96 {
97 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
98 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
99 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
100 }
101
102 $show['assign'] = ((can_perform('canassign')) ? true : false);
103 if (can_perform('canassign'))
104 {
105 foreach ($bugsys->datastore['assignto'] AS $dev)
106 {
107 $value = $dev['userid'];
108 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
109 $label = construct_user_display($dev, false);
110 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
111 }
112 }
113
114 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
115
116 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
117
118 $customfields = construct_custom_fields($bug);
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 $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 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
136 $select['autoactions'] = '';
137 $show['autoactions'] = false;
138 while ($action = $db->fetch_array($actions))
139 {
140 $label = $action['name'];
141 $value = $action['actionid'];
142 $selected = false;
143 eval('$select[autoaction] .= "' . $bugsys->template->fetch('selectoption') . '";');
144 $show['autoactions'] = true;
145 }
146 if ($show['autoactions'])
147 {
148 $label = '';
149 $value = 0;
150 $selected = true;
151 eval('$select[autoaction] = "' . $bugsys->template->fetch('selectoption') . '" . $select[autoaction];');
152 }
153 }
154
155 // ###################################################################
156 // non-edit display
157 else
158 {
159 // -------------------------------------------------------------------
160 // prep display
161 $bug['userinfo'] = construct_user_display($bug);
162 $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
163 $bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : '');
164 $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
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 $show['editreport'] = ((((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) ? true : false);
174
175 $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
176
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 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
187 while ($dependency = $db->fetch_array($dependencies))
188 {
189 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
190 }
191 $dependencies = implode(' ', $depends);
192 }
193
194 // -------------------------------------------------------------------
195 // custom fields
196 $customfields = '';
197
198 $allfields = $db->query("
199 SELECT bugfield.*
200 FROM " . TABLE_PREFIX . "bugfield AS bugfield
201 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
202 ON (bugfield.fieldid = permission.fieldid)
203 WHERE permission.mask <> 0
204 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
205 );
206 while ($field = $db->fetch_array($allfields))
207 {
208 $fieldlist["$field[fieldid]"] = $field;
209 }
210
211 $fieldvalues = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
212
213 foreach ($fieldlist AS $fieldid => $field)
214 {
215 if (is_null($fieldvalues["field$fieldid"]))
216 {
217 if ($field['type'] == 'select_single')
218 {
219 if ($field['usedefault'])
220 {
221 $temp = unserialize($field['selects']);
222 $value = trim($temp[0]);
223 }
224 else
225 {
226 continue;
227 }
228 }
229 else
230 {
231 $value = $field['defaultvalue'];
232 }
233 }
234 else
235 {
236 $value = $fieldvalues["field$fieldid"];
237 }
238
239 $customfields .= "<div><strong>$field[name]:</strong> ";
240
241 if ($field['type'] == 'input_text' OR $field['type'] == 'select_single')
242 {
243 $customfields .= $value;
244 }
245 else if ($field['type'] == 'input_checkbox')
246 {
247 $customfields .= (($value) ? 'True' : 'False');
248 }
249 $customfields .= "</div>\n\n";
250 }
251 }
252
253 // ###################################################################
254 // other elements
255
256 // -------------------------------------------------------------------
257 // hilight
258 $words = explode(' ', $bugsys->in['hilight']);
259 foreach ($words AS $word)
260 {
261 if (trim($word))
262 {
263 $word = preg_quote($bugsys->unsanitize($word));
264 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
265 }
266 }
267
268 // -------------------------------------------------------------------
269 // attachments
270 $show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
271 $show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
272
273 if ($show['getattachments'] OR $show['putattachments'])
274 {
275 $attachments_fetch = $db->query("
276 SELECT attachment.*, user.email, user.showemail,
277 user.displayname
278 FROM " . TABLE_PREFIX . "attachment AS attachment
279 LEFT JOIN " . TABLE_PREFIX . "user AS user
280 ON (attachment.userid = user.userid)
281 WHERE attachment.bugid = $bug[bugid]
282 ORDER BY attachment.dateline"
283 );
284 while ($attachment = $db->fetch_array($attachments_fetch))
285 {
286 $show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
287 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
288 $attachment['user'] = construct_user_display($attachment, false);
289 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
290 }
291 }
292
293 // -------------------------------------------------------------------
294 // votes
295
296 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
297
298 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
299 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
300 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
301
302 $show['vote'] = ((can_perform('canvote') AND !$vote['uservote']) ? true : false);
303
304 // -------------------------------------------------------------------
305 // get comments
306 $comments_fetch = $db->query("
307 SELECT comment.*, user.email, user.showemail, user.displayname
308 FROM " . TABLE_PREFIX . "comment AS comment
309 LEFT JOIN " . TABLE_PREFIX . "user AS user
310 ON (comment.userid = user.userid)
311 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
312 AND !hidden" : '') . "
313 ORDER BY comment.dateline ASC"
314 );
315 while ($comment = $db->fetch_array($comments_fetch))
316 {
317 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
318 $comment['postby'] = construct_user_display($comment);
319 $show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
320
321 if (is_array($hilight))
322 {
323 foreach ($hilight AS $id => $find)
324 {
325 $find = "#($find)#";
326 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
327 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
328 }
329 }
330
331 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
332 }
333
334 $show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
335
336 if (is_array($hilight))
337 {
338 foreach ($hilight AS $id => $find)
339 {
340 $find = "#($find)#";
341 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
342 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
343 }
344 }
345
346 eval('$template->flush("' . $template->fetch('SHOWREPORT') . '");');
347
348 /*=====================================================================*\
349 || ###################################################################
350 || # $HeadURL$
351 || # $Id$
352 || ###################################################################
353 \*=====================================================================*/
354 ?>