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