Updating functions_datastore.php
[bugdar.git] / showreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©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 define('SVN', '$Id$');
31
32 $focus['showreport'] = 'focus';
33
34 require_once('./global.php');
35 require_once('./includes/functions_product.php');
36
37 $bugid = $input->inputClean('bugid', TYPE_UINT);
38
39 // ###################################################################
40
41 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
42 {
43 if (!empty($bugid))
44 {
45 if ($db->queryFirst("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 $tpl = new BSTemplate('quicksearch');
57 $tpl->vars = array('error' => $error);
58 $tpl->evaluate()->flush();
59 exit;
60 }
61
62 // ###################################################################
63
64 // -------------------------------------------------------------------
65 // get the report
66 $bug = $db->queryFirst("
67 SELECT bug.*, user.email, user.displayname, user.showemail
68 FROM " . TABLE_PREFIX . "bug AS bug
69 LEFT JOIN " . TABLE_PREFIX . "user AS user
70 ON (bug.userid = user.userid)
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->errorPermission();
82 }
83
84 $show['edit'] = ((can_perform('caneditown', $bug['product']) AND bugdar::$userinfo['userid'] == $bug['userid'] AND $bug['userid'] != 0) OR (can_perform('caneditother', $bug['product']) AND bugdar::$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'] = bugdar::$datastore['status']["$bug[status]"]['status'];
103 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
104 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
105 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
106 }
107
108 $show['assign'] = (can_perform('canassign', $bug['product']));
109 if (can_perform('canassign', $bug['product']) && is_array(bugdar::$datastore['assignto']))
110 {
111 foreach (bugdar::$datastore['assignto'] as $dev)
112 {
113 $tpl = new BSTemplate('selectoption');
114 $tpl->vars = array(
115 'value' => $dev['userid'],
116 'label' => construct_user_display($dev, false),
117 'selected' => ($dev['userid'] == $bug['assignedto'])
118 );
119 $select['dev'] .= $tpl->evaluate()->getTemplate();
120 }
121 }
122
123 $productSelect = construct_product_select('canviewbugs', "$bug[product],$bug[component],$bug[version]");
124
125 if ($bug['duplicateof'])
126 {
127 $duplicate = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
128 }
129
130 if ($bug['dependency'])
131 {
132 $depends = array();
133 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
134 foreach ($dependencies as $dependency)
135 {
136 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\">$dependency[bugid]</a>";
137 }
138 $dependencies = implode(' ', $depends);
139 }
140
141 $select['automations'] = '';
142 $show['automations'] = false;
143 if (is_array(bugdar::$datastore['automation']))
144 {
145 foreach (bugdar::$datastore['automation'] as $action)
146 {
147 $tpl = new BSTemplate('selectoption');
148 $tpl->vars = array(
149 'label' => $action['name'],
150 'value' => $action['actionid'],
151 'selected' => false
152 );
153 $select['automation'] .= $tpl->evaluate()->getTemplate();
154 $show['automations'] = true;
155 }
156 if ($show['automations'])
157 {
158 $tpl = new BSTemplate('selectoption');
159 $tpl->vars = array(
160 'label' => '',
161 'value' => 0,
162 'selected' => true
163 );
164 $select['automation'] = $tpl->evaluate()->getTemplate() . $select['automation'];
165 }
166 }
167 }
168
169 // ###################################################################
170 // non-edit display
171 else
172 {
173 // -------------------------------------------------------------------
174 // prep display
175 $bug['status'] = bugdar::$datastore['status']["$bug[status]"]['status'];
176 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
177 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
178 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
179
180 $assigninfo = bugdar::$datastore['assignto']["$bug[assignedto]"];
181 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
182
183 $duplicateof = $db->queryFirst("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
184
185 $dupelist = array();
186 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
187 foreach ($duplicates as $duplicate)
188 {
189 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
190 }
191 $dupelist = implode(', ', $dupelist);
192
193 if ($bug['dependency'])
194 {
195 $depends = array();
196 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
197 foreach ($dependencies as $dependency)
198 {
199 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
200 }
201 $dependencies = implode(' ', $depends);
202 }
203 }
204
205 // ###################################################################
206 // global display items
207
208 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
209
210 $favorite = (bool)$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . bugdar::$userinfo['userid']);
211 $favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
212
213 $bug['userinfo'] = construct_user_display($bug);
214 $bug['datetime'] = $datef->format(bugdar::$options['dateformat'], $bug['dateline']);
215 $bug['productid'] = $bug['product'];
216 $bug['product'] = bugdar::$datastore['product']["$bug[product]"]['title'];
217 $bug['componentid'] = $bug['component'];
218 $bug['component'] = ($bug['component'] ? bugdar::$datastore['product']["$bug[component]"]['title'] : '');
219 $bug['versionid'] = $bug['version'];
220 $bug['version'] = bugdar::$datastore['version']["$bug[version]"]['version'];
221
222 // ###################################################################
223 // custom field output
224
225 $fields = construct_custom_fields($bug);
226 $i = 0;
227 foreach ($fields AS $field)
228 {
229 if ($i % 2 == 0)
230 {
231 $customfields['left'] .= $field;
232 }
233 else
234 {
235 $customfields['right'] .= $field;
236 }
237 $i++;
238 }
239
240 // ###################################################################
241 // other elements
242
243 // -------------------------------------------------------------------
244 // hilight
245 $words = explode(' ', $input->in['hilight']);
246 foreach ($words AS $word)
247 {
248 if (trim($word))
249 {
250 $word = preg_quote($input->unsanitize($word));
251 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
252 }
253 }
254
255 // -------------------------------------------------------------------
256 // attachments
257 $show['getattachments'] = (can_perform('cangetattach', $bug['productid']) || can_perform('caneditattach', $bug['productid']));
258 $show['putattachments'] = (can_perform('canputattach', $bug['productid']) || can_perform('caneditattach', $bug['productid']));
259 $show['attachments'] = ($show['getattachments'] || $show['putattachments']);
260
261 if ($show['getattachments'] || $show['putattachments'])
262 {
263 $attachments_fetch = $db->query("
264 SELECT attachment.attachmentid, attachment.filename,
265 attachment.description, attachment.dateline,
266 attachment.userid, attachment.obsolete, user.email,
267 user.showemail, user.displayname
268 FROM " . TABLE_PREFIX . "attachment AS attachment
269 LEFT JOIN " . TABLE_PREFIX . "user AS user
270 ON (attachment.userid = user.userid)
271 WHERE attachment.bugid = $bug[bugid]
272 ORDER BY attachment.dateline"
273 );
274
275 $attaches = false;
276 foreach ($attachments_fetch as $attachment)
277 {
278 $attaches = true;
279 $show['editattach'] = (can_perform('caneditattach', $bug['productid']) || ($attachment['userid'] == bugdar::$userinfo['userid'] && can_perform('canputattach', $bug['productid'])));
280 $attachment['date'] = $datef->format(bugdar::$options['dateformat'], $attachment['dateline']);
281 $attachment['user'] = construct_user_display($attachment, false);
282
283 $tpl = new BSTemplate('showreport_attachment');
284 $tpl->vars = array(
285 'attachment' => $attachment
286 );
287 $attachments .= $tpl->evaluate()->getTemplate();
288 }
289
290 $show['attachments'] = ($show['putattachments'] && $attaches);
291 }
292
293 // -------------------------------------------------------------------
294 // votes
295
296 $vote = $db->queryFirst("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
297
298 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
299 if ($vote['total'] != 0)
300 {
301 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
302 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
303 }
304 else
305 {
306 $vote['forpercent'] = 0;
307 $vote['againstpercent'] = 0;
308 }
309
310 $show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
311
312 // -------------------------------------------------------------------
313 // get comments
314 $comments_fetch = $db->query("
315 SELECT comment.*, user.email, user.showemail, user.displayname
316 FROM " . TABLE_PREFIX . "comment AS comment
317 LEFT JOIN " . TABLE_PREFIX . "user AS user
318 ON (comment.userid = user.userid)
319 WHERE comment.bugid = $bug[bugid]" . (!can_perform('canviewhidden', $bug['productid']) ? "
320 AND !hidden" : '') . "
321 ORDER BY comment.dateline ASC"
322 );
323 foreach ($comments_fetch as $comment)
324 {
325 $comment['posttime'] = $datef->format(bugdar::$options['dateformat'], $comment['dateline']);
326 $comment['postby'] = construct_user_display($comment);
327 $show['editcomment'] = ((can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
328
329 BSApp::debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']));
330 BSApp::debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
331 BSApp::debug('$show[editcomment]: ' . $show['editcomment']);
332
333 if (is_array($hilight))
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 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
340 }
341 }
342
343 $tpl = new BSTemplate('showreport_comment');
344 $tpl->vars = array('comment' => $comment);
345 $comments .= $tpl->evaluate()->getTemplate();
346 }
347
348 $show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
349
350 $bug['summary_title'] = $bug['summary'];
351 if (is_array($hilight) AND !$show['edit'])
352 {
353 foreach ($hilight AS $id => $find)
354 {
355 $find = "#($find)#i";
356 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
357 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
358 }
359 }
360
361 $tpl = new BSTemplate('showreport');
362 $tpl->vars = array(
363 'bug' => $bug,
364 'comments' => $comments,
365 'select' => $select,
366 'vote' => $vote,
367 'favoritetext' => $favoritetext,
368 'customfields' => $customfields,
369 'attachments' => $attachments,
370 'productSelect' => $productSelect
371 );
372 $tpl->evaluate()->flush();
373
374 /*=====================================================================*\
375 || ###################################################################
376 || # $HeadURL$
377 || # $Id$
378 || ###################################################################
379 \*=====================================================================*/
380 ?>