r765: Say hello to the GPL
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 define('SVN', '$Id$');
23
24 $focus['showreport'] = 'focus';
25
26 require_once('./global.php');
27 require_once('./includes/functions_product.php');
28
29 $bug = $db->query_first("
30 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
31 FROM " . TABLE_PREFIX . "bug AS bug
32 LEFT JOIN " . TABLE_PREFIX . "user AS user
33 ON (bug.userid = user.userid)
34 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
35 ON (bug.bugid = bugvaluefill.bugid)
36 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
37 );
38
39 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']))
40 {
41 $message->error_permission();
42 }
43
44 if (!$bug)
45 {
46 $message->error($lang->getlex('error_invalid_id'));
47 }
48
49 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
50 {
51 $message->error_permission();
52 }
53
54 // setup logging
55 require_once('./includes/class_history.php');
56 $log = new History();
57 $log->bugid = $bug['bugid'];
58
59 // ###################################################################
60
61 if ($_POST['do'] == 'update')
62 {
63 // -------------------------------------------------------------------
64 // process comment stuff
65 if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
66 {
67 $hascomment = (!empty($bugsys->in['comment'])) ? true : false;
68
69 if ($hascomment OR $autoaction['comment'])
70 {
71 if ($hascomment AND $autoaction['comment'])
72 {
73 $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
74 }
75 else if (!$hascomment AND $autoaction['comment'])
76 {
77 $bugsys->in['comment'] = $autoaction['comment'];
78 }
79
80 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
81
82 if (!$bugsys->options['allowhtml'])
83 {
84 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
85 }
86
87 $time = TIMENOW;
88
89 $db->query("
90 INSERT INTO " . TABLE_PREFIX . "comment
91 (bugid, userid, dateline, comment, comment_parsed)
92 VALUES
93 (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ",
94 $time, '" . $bugsys->in['comment'] . "',
95 '" . nl2br($bugsys->in['comment_parsed']) . "'
96 )"
97 );
98
99 $commentid = $db->insert_id();
100
101 $db->query("
102 UPDATE " . TABLE_PREFIX . "bug
103 SET lastposttime = $time,
104 lastpostby = " . $bugsys->userinfo['userid'] . ",
105 hiddenlastposttime = $time,
106 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
107 WHERE bugid = " . intval($bugsys->in['bugid'])
108 );
109
110 if ($hascomment)
111 {
112 $log->arguments = array($commentid);
113 $log->log();
114 }
115 }
116
117 $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
118 }
119
120 // -------------------------------------------------------------------
121 // do update stuff
122 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
123
124 if (!$bugsys->in['summary'])
125 {
126 $message->error($lang->string('You need to enter a summary for this bug.'));
127 }
128 if (!$pcv)
129 {
130 $message->error($lang->string('Invalid product/component/version selected.'));
131 }
132
133 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
134 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
135
136 // -------------------------------------------------------------------
137 // start updates
138
139 // auto action
140 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
141 if ($autoaction)
142 {
143 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
144
145 foreach ($autoaction['fields']['builtin'] AS $field => $value)
146 {
147 $bugsys->in["$field"] = $value;
148 }
149
150 foreach ($autoaction['fields']['custom'] AS $field => $value)
151 {
152 $bugsys->in["field$field"] = $value;
153 }
154 }
155
156 process_custom_fields($bug['bugid']);
157
158 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
159 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
160
161 $db->query("
162 UPDATE " . TABLE_PREFIX . "bug
163 SET summary = '" . $bugsys->in['summary'] . "',
164 severity = " . intval($bugsys->in['severity']) . "," .
165 (can_perform('canchangestatus', $bug['productid']) ? "
166 priority = " . intval($bugsys->in['priority']) . ",
167 status = " . intval($bugsys->in['status']) . ",
168 resolution = " . intval($bugsys->in['resolution']) . ","
169 : '') . "
170 " . (can_perform('canassign', $bug['productid']) ? "assignedto = " . intval($bugsys->in['assignedto']) . "," : '') . "
171 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
172 dependency = '$dependencies',
173 productid = " . $pcv['product'] . ",
174 componentid = " . $pcv['component'] . ",
175 versionid = " . $pcv['version'] . ",
176 hidden = " . intval($bugsys->in['hidden']) . "
177 WHERE bugid = $bug[bugid]"
178 );
179
180 // -------------------------------------------------------------------
181 // do diff history
182
183 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
184 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
185
186 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
187 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
188
189 $lookupindex = array(
190 'status' => 'status',
191 'severity' => 'severity',
192 'priority' => 'priority',
193 'versionid' => 'version',
194 'assignedto' => 'assignto',
195 'resolution' => 'resolution',
196 'productid' => 'product',
197 'componentid' => 'product'
198 );
199
200 foreach ($diff AS $num => $diffs)
201 {
202 foreach ($diffs AS $key => $value)
203 {
204 if (!isset($lookupindex["$key"]))
205 {
206 continue;
207 }
208
209 $ref = $lookupindex["$key"];
210 $temp =& $bugsys->datastore["$ref"]["$value"];
211 $thevalue = $temp["$ref"];
212 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
213
214 if ($key == 'assignedto')
215 {
216 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
217 $idbit = '';
218 }
219 else if ($key == 'productid' OR $key == 'componentid')
220 {
221 $ref = 'product';
222 $thevalue = $temp['title'];
223 }
224
225 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
226 }
227 }
228
229 foreach ($diff[1] AS $key => $value)
230 {
231 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
232 }
233
234 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
235 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
236
237 if ($noinitialcustom === false)
238 {
239 $canallowempty = true;
240 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
241 while ($box = $db->fetch_array($checkbox))
242 {
243 $boxlist[] = 'field' . $box['fieldid'];
244 }
245 }
246
247 foreach ($diff2[1] AS $key => $value)
248 {
249 if (in_array($key, $boxlist) AND $canallowempty)
250 {
251 $log->allowempty = true;
252 }
253 else
254 {
255 $log->allowempty = false;
256 }
257
258 if ($key == 'bugid')
259 {
260 continue;
261 }
262
263 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
264 }
265
266 $log->allowempty = false;
267
268 // -------------------------------------------------------------------
269 // more comment
270 $hascomment = (!empty($bugsys->in['comment'])) ? true : false;
271
272 if ($hascomment OR $autoaction['comment'])
273 {
274 if ($hascomment AND $autoaction['comment'])
275 {
276 $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
277 }
278 else if (!$hascomment AND $autoaction['comment'])
279 {
280 $bugsys->in['comment'] = $autoaction['comment'];
281 }
282
283 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
284
285 if (!$bugsys->options['allowhtml'])
286 {
287 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
288 }
289
290 $time = TIMENOW;
291
292 $db->query("
293 INSERT INTO " . TABLE_PREFIX . "comment
294 (bugid, userid, dateline, comment, comment_parsed)
295 VALUES
296 (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ",
297 $time, '" . $bugsys->in['comment'] . "',
298 '" . nl2br($bugsys->in['comment_parsed']) . "'
299 )"
300 );
301
302 $commentid = $db->insert_id();
303
304 $db->query("
305 UPDATE " . TABLE_PREFIX . "bug
306 SET lastposttime = $time,
307 lastpostby = " . $bugsys->userinfo['userid'] . ",
308 hiddenlastposttime = $time,
309 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
310 WHERE bugid = " . intval($bugsys->in['bugid'])
311 );
312 }
313
314
315 $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
316 }
317
318 /*=====================================================================*\
319 || ###################################################################
320 || # $HeadURL$
321 || # $Id$
322 || ###################################################################
323 \*=====================================================================*/
324 ?>