r253: Getting the new cusotm fields to work again
[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 // -------------------------------------------------------------------
84 // custom fields
85 $customfields = '';
86
87 $allfields = $db->query("
88 SELECT bugfield.*
89 FROM " . TABLE_PREFIX . "bugfield AS bugfield
90 LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
91 ON (bugfield.fieldid = permission.fieldid)
92 WHERE permission.mask <> 0
93 AND permission.usergroupid = {$bugsys->userinfo['usergroupid']}"
94 );
95 while ($field = $db->fetch_array($allfields))
96 {
97 $fieldlist["$field[fieldid]"] = $field;
98 }
99
100 $fieldvalues = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
101
102 foreach ($fieldlist AS $fieldid => $field)
103 {
104 if (is_null($fieldvalues["field$fieldid"]))
105 {
106 if ($field['type'] == 'select_single')
107 {
108 if ($field['usedefault'])
109 {
110 $temp = unserialize($field['selects']);
111 $value = trim($temp[0]);
112 echo 'using default';
113 }
114 else
115 {
116 echo 'no default';
117 continue;
118 }
119 }
120 else
121 {
122 $value = $field['defaultvalue'];
123 }
124 }
125 else
126 {
127 $value = $fieldvalues["field$fieldid"];
128 }
129
130 $customfields .= "<div><strong>$field[name]:</strong> ";
131
132 if ($field['type'] == 'input_text' OR $field['type'] == 'select_single')
133 {
134 $customfields .= $value;
135 }
136 else if ($field['type'] == 'input_checkbox')
137 {
138 $customfields .= (($value) ? 'True' : 'False');
139 }
140 $customfeilds .= "</div>\n\n";
141 }
142
143 // -------------------------------------------------------------------
144 // hilight
145 $words = explode(' ', $bugsys->in['hilight']);
146 foreach ($words AS $word)
147 {
148 if (trim($word))
149 {
150 $word = preg_quote($bugsys->unsanitize($word));
151 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
152 }
153 }
154
155 // -------------------------------------------------------------------
156 // attachments
157 $show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
158 $show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
159
160 if ($show['getattachments'] OR $show['putattachments'])
161 {
162 $attachments_fetch = $db->query("
163 SELECT attachment.*, user.email, user.showemail,
164 user.displayname
165 FROM " . TABLE_PREFIX . "attachment AS attachment
166 LEFT JOIN " . TABLE_PREFIX . "user AS user
167 ON (attachment.userid = user.userid)
168 WHERE attachment.bugid = $bug[bugid]
169 ORDER BY attachment.dateline"
170 );
171 while ($attachment = $db->fetch_array($attachments_fetch))
172 {
173 $show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
174 $attachment['date'] = datelike('standard', $attachment['dateline']);
175 $attachment['user'] = construct_user_display($attachment, false);
176 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
177 }
178 }
179
180 // -------------------------------------------------------------------
181 // get comments
182 $comments_fetch = $db->query("
183 SELECT comment.*, user.email, user.showemail, user.displayname
184 FROM " . TABLE_PREFIX . "comment AS comment
185 LEFT JOIN " . TABLE_PREFIX . "user AS user
186 ON (comment.userid = user.userid)
187 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
188 AND !hidden" : '') . "
189 ORDER BY comment.dateline ASC"
190 );
191 while ($comment = $db->fetch_array($comments_fetch))
192 {
193 $comment['posttime'] = datelike('standard', $comment['dateline']);
194 $comment['postby'] = construct_user_display($comment);
195 $show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
196
197 if (is_array($hilight))
198 {
199 foreach ($hilight AS $id => $find)
200 {
201 $find = "#($find)#";
202 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
203 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
204 }
205 }
206
207 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
208 }
209
210 $show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
211
212 if (is_array($hilight))
213 {
214 foreach ($hilight AS $id => $find)
215 {
216 $find = "#($find)#";
217 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
218 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
219 }
220 }
221
222 eval('$template->flush("' . $template->fetch('SHOWREPORT') . '");');
223
224 /*=====================================================================*\
225 || ###################################################################
226 || # $HeadURL$
227 || # $Id$
228 || ###################################################################
229 \*=====================================================================*/
230 ?>