r810: More logging stuff
[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 // setup new logging
62 require_once('./includes/class_logging.php');
63 $log2 = new Logging;
64 $log2->set_bugid($bug['bugid']);
65
66 $bugfields = array(
67 'duplicateof',
68 'dependency',
69 'hidden',
70 'summary',
71 'status',
72 'severity',
73 'priority',
74 'versionid' => 'version',
75 'assignedto' => 'assignto',
76 'resolution',
77 'productid' => 'product',
78 'componentid' => 'component'
79 );
80
81 // ###################################################################
82
83 if ($_POST['do'] == 'update')
84 {
85 $bugapi = new BugAPI($bugsys);
86 $bugapi->set('bugid', $bugsys->in['bugid']);
87 $bugapi->set_condition();
88 $bugapi->dorelations = array();
89 $bugapi->fetch();
90
91 $log2->add_data(true, $bugapi->objdata, $bugfields);
92
93 // -------------------------------------------------------------------
94 // handle autoaction
95 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('autoaction', TYPE_UINT));
96 if ($autoaction)
97 {
98 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
99
100 foreach ($autoaction['fields']['builtin'] AS $field => $value)
101 {
102 $bugsys->in["$field"] = $value;
103 }
104
105 foreach ($autoaction['fields']['custom'] AS $field => $value)
106 {
107 $bugsys->in["field$field"] = $value;
108 }
109 }
110
111 // -------------------------------------------------------------------
112 // process comment stuff
113 if ($bugsys->in['comment'])
114 {
115 if (!empty($bugsys->in['comment']) AND $autoaction['comment'])
116 {
117 $commenttext = $bugsys->in['comment'] . "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
118 }
119 else if (empty($bugsys->in['comment']) AND $autoaction['comment'])
120 {
121 $commenttext = $autoaction['comment'];
122 }
123 else
124 {
125 $commenttext = $bugsys->in['comment'];
126 }
127
128 $comment = new CommentAPI($bugsys);
129 $comment->set('bugid', $bugsys->in['bugid']);
130 $comment->set('userid', $bugsys->userinfo['userid']);
131 $comment->set('comment', $commenttext);
132 $comment->insert();
133
134 $bugapi->set('lastposttime', $comment->values['dateline']);
135 $bugapi->set('lastpostby', $bugsys->userinfo['userid']);
136 $bugapi->set('hiddenlastposttime', $comment->values['dateline']);
137 $bugapi->set('hiddenlastpostby', $bugsys->userinfo['userid']);
138
139 if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
140 {
141 $bugapi->update();
142 $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
143 }
144 }
145
146 // -------------------------------------------------------------------
147 // do update stuff
148 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
149
150 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
151
152 // -------------------------------------------------------------------
153 // start updates
154
155 process_custom_fields($bug['bugid']);
156
157 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
158 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
159
160 $bugapi->set('summary', $bugsys->in['summary']);
161 $bugapi->set('severity', $bugsys->in['severity']);
162 $bugapi->set('duplicateof', $bugsys->in['duplicateof']);
163 $bugapi->set('dependency', $dependencies);
164 $bugapi->set('productid', $pcv['product']);
165 $bugapi->set('componentid', $pcv['component']);
166 $bugapi->set('versionid', $pcv['version']);
167 $bugapi->set('hidden', $bugsys->in['hidden']);
168
169 if (can_perform('canchangestatus', $bug['productid']))
170 {
171 $bugapi->set('priority', $bugsys->in['priority']);
172 $bugapi->set('status', $bugsys->in['status']);
173 $bugapi->set('resolution', $bugsys->in['resolution']);
174 }
175 if (can_perform('canassign', $bug['productid']))
176 {
177 $bugapi->set('assignedto', $bugsys->in['assignedto']);
178 }
179
180 $log2->add_data(false, $bugapi->values, $bugfields);
181 print_r($log2); exit;
182
183 $bugapi->update();
184
185 // -------------------------------------------------------------------
186 // do diff history
187
188 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
189
190 $diff[0] = array_diff_assoc($bugapi->objdata, $bugapi->values);
191 $diff[1] = array_diff_assoc($bugapi->values, $bugapi->objdata);
192
193 $lookupindex = array(
194 'status' => 'status',
195 'severity' => 'severity',
196 'priority' => 'priority',
197 'versionid' => 'version',
198 'assignedto' => 'assignto',
199 'resolution' => 'resolution',
200 'productid' => 'product',
201 'componentid' => 'product'
202 );
203
204 foreach ($diff AS $num => $diffs)
205 {
206 foreach ($diffs AS $key => $value)
207 {
208 if (!isset($lookupindex["$key"]))
209 {
210 continue;
211 }
212
213 $ref = $lookupindex["$key"];
214 $temp =& $bugsys->datastore["$ref"]["$value"];
215 $thevalue = $temp["$ref"];
216 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
217
218 if ($key == 'assignedto')
219 {
220 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
221 $idbit = '';
222 }
223 else if ($key == 'productid' OR $key == 'componentid')
224 {
225 $ref = 'product';
226 $thevalue = $temp['title'];
227 }
228
229 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
230 }
231 }
232
233 foreach ($diff[1] AS $key => $value)
234 {
235 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
236 }
237
238 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
239 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
240
241 if ($noinitialcustom === false)
242 {
243 $canallowempty = true;
244 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
245 while ($box = $db->fetch_array($checkbox))
246 {
247 $boxlist[] = 'field' . $box['fieldid'];
248 }
249 }
250
251 foreach ($diff2[1] AS $key => $value)
252 {
253 if (in_array($key, $boxlist) AND $canallowempty)
254 {
255 $log->allowempty = true;
256 }
257 else
258 {
259 $log->allowempty = false;
260 }
261
262 if ($key == 'bugid')
263 {
264 continue;
265 }
266
267 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
268 }
269
270 $log->allowempty = false;
271
272 $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
273 }
274
275 /*=====================================================================*\
276 || ###################################################################
277 || # $HeadURL$
278 || # $Id$
279 || ###################################################################
280 \*=====================================================================*/
281 ?>