r317: - added quicksearch to 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 );
19
20 define('SVN', '$Id$');
21
22 $focus['showreport'] = 'focus';
23
24 require_once('./global.php');
25
26 if (!can_perform('canviewbugs'))
27 {
28 $message->error_permission();
29 }
30
31 $bugid = intval($bugsys->in['bugid']);
32
33 // ###################################################################
34
35 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
36 {
37 if (!empty($bugid))
38 {
39 if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
40 {
41 header("Location: showreport.php?bugid=$bugid");
42 exit;
43 }
44 else
45 {
46 $error = lang::p('error_invalid_id');
47 }
48 }
49
50 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
51 exit;
52 }
53
54 // ###################################################################
55
56 // -------------------------------------------------------------------
57 // get the report
58 $bug = $db->query_first("
59 SELECT bug.*, user.displayname, user.email, user.showemail
60 FROM " . TABLE_PREFIX . "bug AS bug
61 LEFT JOIN " . TABLE_PREFIX . "user AS user
62 ON (bug.userid = user.userid)
63 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
64 );
65
66 if (!is_array($bug))
67 {
68 $message->error(lang::p('error_invalid_id'));
69 }
70
71 if ($bug['hidden'] AND !can_perform('canviewhidden'))
72 {
73 $message->error_permission();
74 }
75
76 // -------------------------------------------------------------------
77 // prep display
78 $bug['userinfo'] = construct_user_display($bug);
79 $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
80 $bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : '');
81 $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
82 $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
83 $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
84 $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
85 $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
86
87 $assigninfo = $bugsys->datastore['assignto']["$bug[assignedto]"];
88 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
89
90 $show['editreport'] = ((((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) ? true : false);
91
92 $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
93
94 $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
95 while ($duplicate = $db->fetch_array($duplicates))
96 {
97 $dupelist[] = "<a href=\"showreport.php?bugid=$duplicate[bugid]\" target=\"_blank\">$duplicate[summary]</a>";
98 }
99 $dupelist = implode(', ', $dupelist);
100
101 if ($bug['dependency'])
102 {
103 $dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
104 while ($dependency = $db->fetch_array($dependencies))
105 {
106 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" title=\"$dependency[summary]\" target=\"_blank\">$dependency[bugid]</a>";
107 }
108 $dependencies = implode(' ', $depends);
109 }
110
111 $favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
112 $favouritetext = (($favourite) ? 'Remove from Favourites' : 'Add to Favourites');
113
114 // -------------------------------------------------------------------
115 // custom fields
116 $customfields = '';
117
118 $allfields = $db->query("
119 SELECT bugfield.*
120 FROM " . TABLE_PREFIX . "bugfield AS bugfield
121 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
122 ON (bugfield.fieldid = permission.fieldid)
123 WHERE permission.mask <> 0
124 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
125 );
126 while ($field = $db->fetch_array($allfields))
127 {
128 $fieldlist["$field[fieldid]"] = $field;
129 }
130
131 $fieldvalues = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
132
133 foreach ($fieldlist AS $fieldid => $field)
134 {
135 if (is_null($fieldvalues["field$fieldid"]))
136 {
137 if ($field['type'] == 'select_single')
138 {
139 if ($field['usedefault'])
140 {
141 $temp = unserialize($field['selects']);
142 $value = trim($temp[0]);
143 }
144 else
145 {
146 continue;
147 }
148 }
149 else
150 {
151 $value = $field['defaultvalue'];
152 }
153 }
154 else
155 {
156 $value = $fieldvalues["field$fieldid"];
157 }
158
159 $customfields .= "<div><strong>$field[name]:</strong> ";
160
161 if ($field['type'] == 'input_text' OR $field['type'] == 'select_single')
162 {
163 $customfields .= $value;
164 }
165 else if ($field['type'] == 'input_checkbox')
166 {
167 $customfields .= (($value) ? 'True' : 'False');
168 }
169 $customfields .= "</div>\n\n";
170 }
171
172 // -------------------------------------------------------------------
173 // hilight
174 $words = explode(' ', $bugsys->in['hilight']);
175 foreach ($words AS $word)
176 {
177 if (trim($word))
178 {
179 $word = preg_quote($bugsys->unsanitize($word));
180 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
181 }
182 }
183
184 // -------------------------------------------------------------------
185 // attachments
186 $show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
187 $show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
188
189 if ($show['getattachments'] OR $show['putattachments'])
190 {
191 $attachments_fetch = $db->query("
192 SELECT attachment.*, user.email, user.showemail,
193 user.displayname
194 FROM " . TABLE_PREFIX . "attachment AS attachment
195 LEFT JOIN " . TABLE_PREFIX . "user AS user
196 ON (attachment.userid = user.userid)
197 WHERE attachment.bugid = $bug[bugid]
198 ORDER BY attachment.dateline"
199 );
200 while ($attachment = $db->fetch_array($attachments_fetch))
201 {
202 $show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
203 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
204 $attachment['user'] = construct_user_display($attachment, false);
205 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
206 }
207 }
208
209 // -------------------------------------------------------------------
210 // votes
211
212 $vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
213
214 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
215 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
216 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
217
218 $show['vote'] = ((can_perform('canvote') AND !$vote['uservote']) ? true : false);
219
220 // -------------------------------------------------------------------
221 // get comments
222 $comments_fetch = $db->query("
223 SELECT comment.*, user.email, user.showemail, user.displayname
224 FROM " . TABLE_PREFIX . "comment AS comment
225 LEFT JOIN " . TABLE_PREFIX . "user AS user
226 ON (comment.userid = user.userid)
227 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
228 AND !hidden" : '') . "
229 ORDER BY comment.dateline ASC"
230 );
231 while ($comment = $db->fetch_array($comments_fetch))
232 {
233 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
234 $comment['postby'] = construct_user_display($comment);
235 $show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
236
237 if (is_array($hilight))
238 {
239 foreach ($hilight AS $id => $find)
240 {
241 $find = "#($find)#";
242 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
243 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
244 }
245 }
246
247 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
248 }
249
250 $show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
251
252 if (is_array($hilight))
253 {
254 foreach ($hilight AS $id => $find)
255 {
256 $find = "#($find)#";
257 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
258 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
259 }
260 }
261
262 eval('$template->flush("' . $template->fetch('SHOWREPORT') . '");');
263
264 /*=====================================================================*\
265 || ###################################################################
266 || # $HeadURL$
267 || # $Id$
268 || ###################################################################
269 \*=====================================================================*/
270 ?>