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