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