r537: Need to include functions_product.php
[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 define('SVN', '$Id$');
14
15 $focus['showreport'] = 'focus';
16
17 require_once('./global.php');
18 require_once('./includes/functions_product.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 (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['productid']))
31 {
32 $message->error_permission();
33 }
34
35 if (!$bug)
36 {
37 $message->error($lang->getlex('error_invalid_id'));
38 }
39
40 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
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 ($_POST['do'] == 'update')
53 {
54 // -------------------------------------------------------------------
55 // process comment stuff
56 if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
57 {
58 $hascomment = (!empty($bugsys->in['comment'])) ? true : false;
59
60 if ($hascomment OR $autoaction['comment'])
61 {
62 if ($hascomment AND $autoaction['comment'])
63 {
64 $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
65 }
66 else if (!$hascomment AND $autoaction['comment'])
67 {
68 $bugsys->in['comment'] = $autoaction['comment'];
69 }
70
71 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
72
73 if (!$bugsys->options['allowhtml'])
74 {
75 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
76 }
77
78 $time = TIMENOW;
79
80 $db->query("
81 INSERT INTO " . TABLE_PREFIX . "comment
82 (bugid, userid, dateline, comment, comment_parsed)
83 VALUES
84 (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ",
85 $time, '" . $bugsys->in['comment'] . "',
86 '" . nl2br($bugsys->in['comment_parsed']) . "'
87 )"
88 );
89
90 $commentid = $db->insert_id();
91
92 $db->query("
93 UPDATE " . TABLE_PREFIX . "bug
94 SET lastposttime = $time,
95 lastpostby = " . $bugsys->userinfo['userid'] . ",
96 hiddenlastposttime = $time,
97 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
98 WHERE bugid = " . intval($bugsys->in['bugid'])
99 );
100
101 if ($hascomment)
102 {
103 $log->arguments = array($commentid);
104 $log->log();
105 }
106 }
107
108 $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
109 }
110
111 // -------------------------------------------------------------------
112 // do update stuff
113 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
114
115 if (!$bugsys->in['summary'])
116 {
117 $message->error($lang->string('You need to enter a summary for this bug.'));
118 }
119 if (!$pcv)
120 {
121 $message->error($lang->string('Invalid product/component/version selected.'));
122 }
123
124 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
125 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
126
127 // -------------------------------------------------------------------
128 // start updates
129
130 // auto action
131 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
132 if ($autoaction)
133 {
134 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
135
136 foreach ($autoaction['fields']['builtin'] AS $field => $value)
137 {
138 $bugsys->in["$field"] = $value;
139 }
140
141 foreach ($autoaction['fields']['custom'] AS $field => $value)
142 {
143 $bugsys->in["field$field"] = $value;
144 }
145 }
146
147 process_custom_fields($bug['bugid']);
148
149 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
150 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
151
152 $db->query("
153 UPDATE " . TABLE_PREFIX . "bug
154 SET summary = '" . $bugsys->in['summary'] . "',
155 severity = " . intval($bugsys->in['severity']) . "," .
156 (can_perform('canchangestatus', $bug['productid']) ? "
157 priority = " . intval($bugsys->in['priority']) . ",
158 status = " . intval($bugsys->in['status']) . ",
159 resolution = " . intval($bugsys->in['resolution']) . ","
160 : '') . "
161 " . (can_perform('canassign', $bug['productid']) ? "assignedto = " . intval($bugsys->in['assignedto']) . "," : '') . "
162 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
163 dependency = '$dependencies',
164 productid = " . $pcv['product'] . ",
165 componentid = " . $pcv['component'] . ",
166 versionid = " . $pcv['version'] . ",
167 hidden = " . intval($bugsys->in['hidden']) . "
168 WHERE bugid = $bug[bugid]"
169 );
170
171 // -------------------------------------------------------------------
172 // do diff history
173
174 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
175 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
176
177 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
178 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
179
180 $lookupindex = array(
181 'status' => 'status',
182 'severity' => 'severity',
183 'priority' => 'priority',
184 'versionid' => 'version',
185 'assignedto' => 'assignto',
186 'resolution' => 'resolution',
187 'productid' => 'product',
188 'componentid' => 'product'
189 );
190
191 foreach ($diff AS $num => $diffs)
192 {
193 foreach ($diffs AS $key => $value)
194 {
195 if (!isset($lookupindex["$key"]))
196 {
197 continue;
198 }
199
200 $ref = $lookupindex["$key"];
201 $temp =& $bugsys->datastore["$ref"]["$value"];
202 $thevalue = $temp["$ref"];
203 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
204
205 if ($key == 'assignedto')
206 {
207 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
208 $idbit = '';
209 }
210 else if ($key == 'productid' OR $key == 'componentid')
211 {
212 $ref = 'product';
213 $thevalue = $temp['title'];
214 }
215
216 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
217 }
218 }
219
220 foreach ($diff[1] AS $key => $value)
221 {
222 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
223 }
224
225 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
226 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
227
228 if ($noinitialcustom === false)
229 {
230 $canallowempty = true;
231 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
232 while ($box = $db->fetch_array($checkbox))
233 {
234 $boxlist[] = 'field' . $box['fieldid'];
235 }
236 }
237
238 foreach ($diff2[1] AS $key => $value)
239 {
240 if (in_array($key, $boxlist) AND $canallowempty)
241 {
242 $log->allowempty = true;
243 }
244 else
245 {
246 $log->allowempty = false;
247 }
248
249 if ($key == 'bugid')
250 {
251 continue;
252 }
253
254 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
255 }
256
257 $log->allowempty = false;
258
259 // -------------------------------------------------------------------
260 // more comment
261 $hascomment = (!empty($bugsys->in['comment'])) ? true : false;
262
263 if ($hascomment OR $autoaction['comment'])
264 {
265 if ($hascomment AND $autoaction['comment'])
266 {
267 $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
268 }
269 else if (!$hascomment AND $autoaction['comment'])
270 {
271 $bugsys->in['comment'] = $autoaction['comment'];
272 }
273
274 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
275
276 if (!$bugsys->options['allowhtml'])
277 {
278 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
279 }
280
281 $time = TIMENOW;
282
283 $db->query("
284 INSERT INTO " . TABLE_PREFIX . "comment
285 (bugid, userid, dateline, comment, comment_parsed)
286 VALUES
287 (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ",
288 $time, '" . $bugsys->in['comment'] . "',
289 '" . nl2br($bugsys->in['comment_parsed']) . "'
290 )"
291 );
292
293 $commentid = $db->insert_id();
294
295 $db->query("
296 UPDATE " . TABLE_PREFIX . "bug
297 SET lastposttime = $time,
298 lastpostby = " . $bugsys->userinfo['userid'] . ",
299 hiddenlastposttime = $time,
300 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
301 WHERE bugid = " . intval($bugsys->in['bugid'])
302 );
303 }
304
305
306 $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
307 }
308
309 /*=====================================================================*\
310 || ###################################################################
311 || # $HeadURL$
312 || # $Id$
313 || ###################################################################
314 \*=====================================================================*/
315 ?>