r373: Register language phrases
[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 'customfield_bit',
20 'bugfield_static_text'
21 );
22
23 define('SVN', '$Id$');
24
25 $focus['showreport'] = 'focus';
26
27 require_once('./global.php');
28
29 if (!can_perform('canviewbugs'))
30 {
31 $message->error_permission();
32 }
33
34 $show['edit'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $bug['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) ? true : false;
35
36 $bugid = intval($bugsys->in['bugid']);
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 = lang::p('error_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 bugvaluefill.*, 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 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
69 ON (bug.bugid = bugvaluefill.bugid)
70 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
71 );
72
73 if (!is_array($bug))
74 {
75 $message->error(lang::p('error_invalid_id'));
76 }
77
78 if ($bug['hidden'] AND !can_perform('canviewhidden'))
79 {
80 $message->error_permission();
81 }
82
83 // ###################################################################
84 // global display items
85
86 $favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
87 $favouritetext = (($favourite) ? lang::r('Remove from Favourites') : lang::r('Add to Favourites'));
88
89 $bug['userinfo'] = construct_user_display($bug);
90 $bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
91 $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
92 $bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : '');
93 $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
94
95 // ###################################################################
96 // edit display
97 if ($show['edit'])
98 {
99 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
100
101 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
102 if (can_perform('canchangestatus'))
103 {
104 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
105 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
106 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
107 }
108
109 $show['assign'] = ((can_perform('canassign')) ? true : false);
110 if (can_perform('canassign'))
111 {
112 foreach ($bugsys->datastore['assignto'] AS $dev)
113 {
114 $value = $dev['userid'];
115 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
116 $label = construct_user_display($dev, false);
117 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
118 }
119 }
120
121 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
122
123 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
124
125 if ($bug['duplicateof'])
126 {
127 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
128 }
129
130 if ($bug['dependency'])
131 {
132 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
133 while ($dependency = $db->fetch_array($dependencies))
134 {
135 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
136 }
137 $dependencies = implode(' ', $depends);
138 }
139
140 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
141 $select['autoactions'] = '';
142 $show['autoactions'] = false;
143 while ($action = $db->fetch_array($actions))
144 {
145 $label = $action['name'];
146 $value = $action['actionid'];
147 $selected = false;
148 eval('$select[autoaction] .= "' . $template->fetch('selectoption') . '";');
149 $show['autoactions'] = true;
150 }
151 if ($show['autoactions'])
152 {
153 $label = '';
154 $value = 0;
155 $selected = true;
156 eval('$select[autoaction] = "' . $template->fetch('selectoption') . '" . $select[autoaction];');
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 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
177 while ($duplicate = $db->fetch_array($duplicates))
178 {
179 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
180 }
181 $dupelist = implode(', ', $dupelist);
182
183 if ($bug['dependency'])
184 {
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 // custom field output
196
197 $fields = construct_custom_fields($bug);
198 $show['customfields'] = ($fields ? true : false);
199
200 $bugsys->debug(count($fields) % 2);
201 $i = 1;
202 foreach ($fields AS $field)
203 {
204 $bugsys->debug("i = $i");
205 if ($i == 1)
206 {
207 $left = $field;
208 }
209 else if ($i == 2)
210 {
211 $right = $field;
212 eval('$customfields .= "' . $template->fetch('customfield_bit') . '";');
213 $i = 0;
214 }
215 $i++;
216 }
217
218 if ((count($fields) % 2) != 0)
219 {
220 $bugsys->debug('no modulo for you');
221 $right = '';
222 eval('$customfields .= "' . $template->fetch('customfield_bit') . '";');
223 }
224
225 // ###################################################################
226 // other elements
227
228 // -------------------------------------------------------------------
229 // hilight
230 $words = explode(' ', $bugsys->in['hilight']);
231 foreach ($words AS $word)
232 {
233 if (trim($word))
234 {
235 $word = preg_quote($bugsys->unsanitize($word));
236 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
237 }
238 }
239
240 // -------------------------------------------------------------------
241 // attachments
242 $show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
243 $show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
244 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
245
246 if ($show['getattachments'] OR $show['putattachments'])
247 {
248 $attachments_fetch = $db->query("
249 SELECT attachment.*, user.email, user.showemail,
250 user.displayname
251 FROM " . TABLE_PREFIX . "attachment AS attachment
252 LEFT JOIN " . TABLE_PREFIX . "user AS user
253 ON (attachment.userid = user.userid)
254 WHERE attachment.bugid = $bug[bugid]
255 ORDER BY attachment.dateline"
256 );
257 while ($attachment = $db->fetch_array($attachments_fetch))
258 {
259 $show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
260 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
261 $attachment['user'] = construct_user_display($attachment, false);
262 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
263 }
264 }
265
266 // -------------------------------------------------------------------
267 // votes
268
269 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
270
271 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
272 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
273 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
274
275 $show['vote'] = ((can_perform('canvote') AND !$vote['uservote']) ? true : false);
276
277 // -------------------------------------------------------------------
278 // get comments
279 $comments_fetch = $db->query("
280 SELECT comment.*, user.email, user.showemail, user.displayname
281 FROM " . TABLE_PREFIX . "comment AS comment
282 LEFT JOIN " . TABLE_PREFIX . "user AS user
283 ON (comment.userid = user.userid)
284 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
285 AND !hidden" : '') . "
286 ORDER BY comment.dateline ASC"
287 );
288 while ($comment = $db->fetch_array($comments_fetch))
289 {
290 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
291 $comment['postby'] = construct_user_display($comment);
292 $show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
293
294 if (is_array($hilight))
295 {
296 foreach ($hilight AS $id => $find)
297 {
298 $find = "#($find)#";
299 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
300 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
301 }
302 }
303
304 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
305 }
306
307 $show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
308
309 if (is_array($hilight))
310 {
311 foreach ($hilight AS $id => $find)
312 {
313 $find = "#($find)#";
314 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
315 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
316 }
317 }
318
319 eval('$template->flush("' . $template->fetch('showreport') . '");');
320
321 /*=====================================================================*\
322 || ###################################################################
323 || # $HeadURL$
324 || # $Id$
325 || ###################################################################
326 \*=====================================================================*/
327 ?>