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