r218: Duplicates are now done
[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 * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
65
66 $duplicates = $db->query("SELECT * 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 // -------------------------------------------------------------------
74 // custom fields
75 $customfields = '';
76
77 $allfields = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield");
78 while ($field = $db->fetch_array($allfields))
79 {
80 $fieldlist["$field[shortname]"] = $field;
81 }
82
83 $fieldvalues = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
84
85 foreach ($fieldvalues AS $shortname => $value)
86 {
87 if ($shortname == 'bugid')
88 {
89 continue;
90 }
91
92 $field =& $fieldlist["$shortname"];
93
94 $customfields .= "<div><strong>$field[name]:</strong> ";
95
96 if (is_null($value))
97 {
98 $value = $field['defaultvalue'];
99 }
100
101 if ($field['type'] == 'input_text' OR $field['type'] == 'textarea' OR $field['type'] == 'select_single')
102 {
103 $customfields .= $value;
104 }
105 else if ($field['type'] == 'input_checkbox')
106 {
107 $customfields .= (($value) ? 'True' : 'False');
108 }
109 $customfields .= "</div>\n\n";
110 }
111
112 // -------------------------------------------------------------------
113 // hilight
114 $words = explode(' ', $bugsys->in['hilight']);
115 foreach ($words AS $word)
116 {
117 if (trim($word))
118 {
119 $word = preg_quote($bugsys->unsanitize($word));
120 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
121 }
122 }
123
124 // -------------------------------------------------------------------
125 // attachments
126 $show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
127 $show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
128
129 if ($show['getattachments'] OR $show['putattachments'])
130 {
131 $attachments_fetch = $db->query("
132 SELECT attachment.*, user.email, user.showemail,
133 user.displayname
134 FROM " . TABLE_PREFIX . "attachment AS attachment
135 LEFT JOIN " . TABLE_PREFIX . "user AS user
136 ON (attachment.userid = user.userid)
137 WHERE attachment.bugid = $bug[bugid]
138 ORDER BY attachment.dateline"
139 );
140 while ($attachment = $db->fetch_array($attachments_fetch))
141 {
142 $show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
143 $attachment['date'] = datelike('standard', $attachment['dateline']);
144 $attachment['user'] = construct_user_display($attachment, false);
145 eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
146 }
147 }
148
149 // -------------------------------------------------------------------
150 // get comments
151 $comments_fetch = $db->query("
152 SELECT comment.*, user.email, user.showemail, user.displayname
153 FROM " . TABLE_PREFIX . "comment AS comment
154 LEFT JOIN " . TABLE_PREFIX . "user AS user
155 ON (comment.userid = user.userid)
156 WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
157 AND !hidden" : '') . "
158 ORDER BY comment.dateline ASC"
159 );
160 while ($comment = $db->fetch_array($comments_fetch))
161 {
162 $comment['posttime'] = datelike('standard', $comment['dateline']);
163 $comment['postby'] = construct_user_display($comment);
164 $show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
165
166 if (is_array($hilight))
167 {
168 foreach ($hilight AS $id => $find)
169 {
170 $find = "#($find)#";
171 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
172 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
173 }
174 }
175
176 eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
177 }
178
179 $show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
180
181 if (is_array($hilight))
182 {
183 foreach ($hilight AS $id => $find)
184 {
185 $find = "#($find)#";
186 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
187 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
188 }
189 }
190
191 eval('$template->flush("' . $template->fetch('SHOWREPORT') . '");');
192
193 /*=====================================================================*\
194 || ###################################################################
195 || # $HeadURL$
196 || # $Id$
197 || ###################################################################
198 \*=====================================================================*/
199 ?>