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