r273: Field changing system is now done for auto actions.
[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 $db->query("
101 UPDATE " . TABLE_PREFIX . "bug
102 SET summary = '" . $bugsys->in['summary'] . "',
103 priority = " . intval($bugsys->in['priority']) . ",
104 status = " . intval($bugsys->in['status']) . ",
105 severity = " . intval($bugsys->in['severity']) . ",
106 resolution = " . intval($bugsys->in['resolution']) . ",
107 assignedto = " . intval($bugsys->in['assignedto']) . ",
108 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
109 dependency = '$dependencies',
110 productid = " . $pcv['product'] . ",
111 componentid = " . $pcv['component'] . ",
112 versionid = " . $pcv['version'] . ",
113 hidden = " . intval($bugsys->in['hidden']) . "
114 WHERE bugid = $bug[bugid]"
115 );
116
117 // -------------------------------------------------------------------
118 // do diff history
119
120 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
121 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
122
123 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
124 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
125
126 $lookupindex = array(
127 'status' => 'status',
128 'severity' => 'severity',
129 'priority' => 'priority',
130 'versionid' => 'version',
131 'assignedto' => 'assignto',
132 'resolution' => 'resolution',
133 'productid' => 'product',
134 'componentid' => 'product'
135 );
136
137 $log->language = 'log_update_bug';
138
139 foreach ($diff AS $num => $diffs)
140 {
141 foreach ($diffs AS $key => $value)
142 {
143 if (!isset($lookupindex["$key"]))
144 {
145 continue;
146 }
147
148 $ref = $lookupindex["$key"];
149 $temp =& $bugsys->datastore["$ref"]["$value"];
150 $thevalue = $temp["$ref"];
151 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
152
153 if ($key == 'assignedto')
154 {
155 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
156 $idbit = '';
157 }
158 else if ($key == 'productid' OR $key == 'componentid')
159 {
160 $ref = 'product';
161 $thevalue = $temp['title'];
162 }
163
164 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
165 }
166 }
167
168 foreach ($diff[1] AS $key => $value)
169 {
170 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
171 }
172
173 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
174 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
175
176 if ($noinitialcustom === false)
177 {
178 $canallowempty = true;
179 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
180 while ($box = $db->fetch_array($checkbox))
181 {
182 $boxlist[] = 'field' . $box['fieldid'];
183 }
184 }
185
186 foreach ($diff2[1] AS $key => $value)
187 {
188 if (in_array($key, $boxlist) AND $canallowempty)
189 {
190 $log->allowempty = true;
191 }
192 else
193 {
194 $log->allowempty = false;
195 }
196
197 if ($key == 'bugid')
198 {
199 continue;
200 }
201
202 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
203 }
204
205 $log->allowempty = false;
206
207 // -------------------------------------------------------------------
208 // process comment stuff
209
210 if (!$bugsys->in['firstcomment'])
211 {
212 $message->error('you need to enter some text in the first comment');
213 }
214
215 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
216
217 if (!$bugsys->options['allowhtml'])
218 {
219 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
220 }
221
222 // we could pass this as a GET param, but that's unsafe
223 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
224
225 $db->query("
226 UPDATE " . TABLE_PREFIX . "comment
227 SET comment = '" . $bugsys->in['firstcomment'] . "',
228 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
229 WHERE commentid = $firstcomment[commentid]"
230 );
231
232 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
233 }
234
235 // ###################################################################
236
237 if ($_REQUEST['do'] == 'edit')
238 {
239 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
240
241 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
242 if (can_perform('canchangestatus'))
243 {
244 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
245 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
246 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
247 }
248
249 $show['assign'] = ((can_perform('canassign')) ? true : false);
250 if (can_perform('canassign'))
251 {
252 foreach ($bugsys->datastore['assignto'] AS $dev)
253 {
254 $value = $dev['userid'];
255 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
256 $label = construct_user_display($dev, false);
257 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
258 }
259 }
260
261 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
262
263 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
264
265 $customfields = construct_custom_fields($bug);
266
267 if ($bug['duplicateof'])
268 {
269 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
270 }
271
272 if ($bug['dependency'])
273 {
274 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
275 while ($dependency = $db->fetch_array($dependencies))
276 {
277 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" alt=\"$dependency[summary]\">$dependency[bugid]</a>";
278 }
279 $dependencies = implode(' ', $depends);
280 }
281
282 $actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
283 $select['autoactions'] = '';
284 $show['autoactions'] = false;
285 while ($action = $db->fetch_array($actions))
286 {
287 $label = $action['name'];
288 $value = $action['actionid'];
289 $selected = false;
290 eval('$select[autoaction] .= "' . $bugsys->template->fetch('selectoption') . '";');
291 $show['autoactions'] = true;
292 }
293 if ($show['autoactions'])
294 {
295 $label = '';
296 $value = 0;
297 $selected = true;
298 eval('$select[autoaction] = "' . $bugsys->template->fetch('selectoption') . '" . $select[autoaction];');
299 }
300
301 eval('$template->flush("' . $template->fetch('editreport') . '");');
302 }
303
304 /*=====================================================================*\
305 || ###################################################################
306 || # $HeadURL$
307 || # $Id$
308 || ###################################################################
309 \*=====================================================================*/
310 ?>