r303: Added SVN constant to user files; now ISSO debug information shows SVN details.
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2002-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2002 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'editreport',
15 'pcv_select_row'
16 );
17
18 define('SVN', '$Id$');
19
20 require_once('./global.php');
21
22 $bug = $db->query_first("
23 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
24 FROM " . TABLE_PREFIX . "bug AS bug
25 LEFT JOIN " . TABLE_PREFIX . "user AS user
26 ON (bug.userid = user.userid)
27 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
28 ON (bug.bugid = bugvaluefill.bugid)
29 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
30 );
31
32 if (!$bug)
33 {
34 $message->error('alert: bad bug');
35 }
36
37 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
38 {
39 $message->error_permission();
40 }
41
42 if ($bug['hidden'] AND !can_perform('canviewhidden'))
43 {
44 $message->error_permission();
45 }
46
47 // setup logging
48 require_once('./includes/class_history.php');
49 $log = new History();
50 $log->bugid = $bug['bugid'];
51
52 // ###################################################################
53
54 if (empty($_REQUEST['do']))
55 {
56 $_REQUEST['do'] = 'edit';
57 }
58
59 // ###################################################################
60
61 if ($_POST['do'] == 'update')
62 {
63 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
64
65 if (!$bugsys->in['summary'])
66 {
67 $message->error('you need to enter a summary');
68 }
69 if (!$pcv)
70 {
71 $message->error('invalid product/component/version');
72 }
73
74 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
75 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
76
77 // -------------------------------------------------------------------
78 // start updates
79
80 // auto action
81 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
82 if ($autoaction)
83 {
84 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
85
86 foreach ($autoaction['fields']['builtin'] AS $field => $value)
87 {
88 $bugsys->in["$field"] = $value;
89 }
90
91 foreach ($autoaction['fields']['custom'] AS $field => $value)
92 {
93 $bugsys->in["field$field"] = $value;
94 }
95 }
96
97 process_custom_fields($bug['bugid']);
98
99 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
100 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
101
102 // #*# need to put in permission checks here because we do not show the fields the user has no permission to change in the edit section so they'll be blank on update
103
104 $db->query("
105 UPDATE " . TABLE_PREFIX . "bug
106 SET summary = '" . $bugsys->in['summary'] . "',
107 priority = " . intval($bugsys->in['priority']) . ",
108 status = " . intval($bugsys->in['status']) . ",
109 severity = " . intval($bugsys->in['severity']) . ",
110 resolution = " . intval($bugsys->in['resolution']) . ",
111 assignedto = " . intval($bugsys->in['assignedto']) . ",
112 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
113 dependency = '$dependencies',
114 productid = " . $pcv['product'] . ",
115 componentid = " . $pcv['component'] . ",
116 versionid = " . $pcv['version'] . ",
117 hidden = " . intval($bugsys->in['hidden']) . "
118 WHERE bugid = $bug[bugid]"
119 );
120
121 // -------------------------------------------------------------------
122 // do diff history
123
124 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
125 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
126
127 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
128 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
129
130 $lookupindex = array(
131 'status' => 'status',
132 'severity' => 'severity',
133 'priority' => 'priority',
134 'versionid' => 'version',
135 'assignedto' => 'assignto',
136 'resolution' => 'resolution',
137 'productid' => 'product',
138 'componentid' => 'product'
139 );
140
141 $log->language = 'log_update_bug';
142
143 foreach ($diff AS $num => $diffs)
144 {
145 foreach ($diffs AS $key => $value)
146 {
147 if (!isset($lookupindex["$key"]))
148 {
149 continue;
150 }
151
152 $ref = $lookupindex["$key"];
153 $temp =& $bugsys->datastore["$ref"]["$value"];
154 $thevalue = $temp["$ref"];
155 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
156
157 if ($key == 'assignedto')
158 {
159 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
160 $idbit = '';
161 }
162 else if ($key == 'productid' OR $key == 'componentid')
163 {
164 $ref = 'product';
165 $thevalue = $temp['title'];
166 }
167
168 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
169 }
170 }
171
172 foreach ($diff[1] AS $key => $value)
173 {
174 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
175 }
176
177 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
178 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
179
180 if ($noinitialcustom === false)
181 {
182 $canallowempty = true;
183 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
184 while ($box = $db->fetch_array($checkbox))
185 {
186 $boxlist[] = 'field' . $box['fieldid'];
187 }
188 }
189
190 foreach ($diff2[1] AS $key => $value)
191 {
192 if (in_array($key, $boxlist) AND $canallowempty)
193 {
194 $log->allowempty = true;
195 }
196 else
197 {
198 $log->allowempty = false;
199 }
200
201 if ($key == 'bugid')
202 {
203 continue;
204 }
205
206 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
207 }
208
209 $log->allowempty = false;
210
211 // -------------------------------------------------------------------
212 // process comment stuff
213
214 if (!$bugsys->in['firstcomment'])
215 {
216 $message->error('you need to enter some text in the first comment');
217 }
218
219 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
220
221 if (!$bugsys->options['allowhtml'])
222 {
223 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
224 }
225
226 // we could pass this as a GET param, but that's unsafe
227 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
228
229 $db->query("
230 UPDATE " . TABLE_PREFIX . "comment
231 SET comment = '" . $bugsys->in['firstcomment'] . "',
232 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
233 WHERE commentid = $firstcomment[commentid]"
234 );
235
236 // -------------------------------------------------------------------
237 // auto action comment
238
239 if ($autoaction['comment'])
240 {
241 $comment = $autoaction['comment'];
242 if (!$bugsys->options['allowhtml'])
243 {
244 $comment_parsed = $bugsys->sanitize($comment);
245 }
246
247 $db->query("
248 INSERT INTO comment
249 (bugid, userid, dateline, comment, comment_parsed)
250 VALUES
251 ($bug[bugid], " . $bugsys->userinfo['userid'] . ", " . LOG_TIME . ",
252 '" . $bugsys->escape($comment) . "',
253 '" . $bugsys->escape($comment_parsed) . "'
254 )"
255 );
256
257 $db->query("
258 UPDATE " . TABLE_PREFIX . "bug
259 SET lastposttime = " . LOG_TIME . ",
260 lastpostby = " . $bugsys->userinfo['userid'] . ",
261 hiddenlastposttime = " . LOG_TIME . ",
262 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
263 WHERE bugid = $bug[bugid]"
264 );
265 }
266
267 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
268 }
269
270 // ###################################################################
271
272 if ($_REQUEST['do'] == 'edit')
273 {
274 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
275
276 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
277 if (can_perform('canchangestatus'))
278 {
279 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
280 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
281 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
282 }
283
284 $show['assign'] = ((can_perform('canassign')) ? true : false);
285 if (can_perform('canassign'))
286 {
287 foreach ($bugsys->datastore['assignto'] AS $dev)
288 {
289 $value = $dev['userid'];
290 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
291 $label = construct_user_display($dev, false);
292 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
293 }
294 }
295
296 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
297
298 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
299
300 $customfields = construct_custom_fields($bug);
301
302 if ($bug['duplicateof'])
303 {
304 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
305 }
306
307 if ($bug['dependency'])
308 {
309 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
310 while ($dependency = $db->fetch_array($dependencies))
311 {
312 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" alt=\"$dependency[summary]\">$dependency[bugid]</a>";
313 }
314 $dependencies = implode(' ', $depends);
315 }
316
317 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
318 $select['autoactions'] = '';
319 $show['autoactions'] = false;
320 while ($action = $db->fetch_array($actions))
321 {
322 $label = $action['name'];
323 $value = $action['actionid'];
324 $selected = false;
325 eval('$select[autoaction] .= "' . $bugsys->template->fetch('selectoption') . '";');
326 $show['autoactions'] = true;
327 }
328 if ($show['autoactions'])
329 {
330 $label = '';
331 $value = 0;
332 $selected = true;
333 eval('$select[autoaction] = "' . $bugsys->template->fetch('selectoption') . '" . $select[autoaction];');
334 }
335
336 eval('$template->flush("' . $template->fetch('editreport') . '");');
337 }
338
339 /*=====================================================================*\
340 || ###################################################################
341 || # $HeadURL$
342 || # $Id$
343 || ###################################################################
344 \*=====================================================================*/
345 ?>