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