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