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