r1389: Forgot to add the template diff
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright 2002-[#]year[#] Blue Static
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/class_notification.php');
29 require_once('./includes/api_bug.php');
30 require_once('./includes/api_comment.php');
31
32 require_once('./includes/class_api_error.php');
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
34
35 $bug = $db->query_first("
36 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
37 FROM " . TABLE_PREFIX . "bug AS bug
38 LEFT JOIN " . TABLE_PREFIX . "user AS user
39 ON (bug.userid = user.userid)
40 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
41 ON (bug.bugid = bugvaluefill.bugid)
42 WHERE bug.bugid = " . $bugsys->input_clean('bugid', TYPE_UINT)
43 );
44
45 if (!$bug)
46 {
47 $message->error(L_INVALID_ID);
48 }
49
50 if (!check_bug_permissions($bug))
51 {
52 $message->error_permission();
53 }
54
55 // setup logging
56 require_once('./includes/class_logging.php');
57 $log = new Logging;
58 $log->set_bugid($bug['bugid']);
59
60 $bugfields = array(
61 'duplicateof',
62 'dependency',
63 'hidden',
64 'summary',
65 'status',
66 'severity',
67 'priority',
68 'version',
69 'assignedto' => 'assignto',
70 'resolution',
71 'product',
72 'component'
73 );
74
75 $notif = new NotificationCenter;
76
77 $bugapi = new BugAPI($bugsys);
78 $bugapi->set('bugid', $bugsys->in['bugid']);
79 $bugapi->set_condition();
80 $bugapi->dorelations = array();
81 $bugapi->fetch();
82
83 // ###################################################################
84
85 if ($_POST['do'] == 'kill')
86 {
87 if (!can_perform('candeletedata', $bug['product']))
88 {
89 $message->error_permission();
90 }
91
92 $bugapi->delete();
93
94 $message->redirect(_('The entire bug has been deleted.'), 'index.php');
95 }
96
97 // ###################################################################
98
99 if ($_REQUEST['do'] == 'delete')
100 {
101 if (!can_perform('candeletedata', $bug['product']))
102 {
103 $message->error_permission();
104 }
105
106 $message->confirm(_('Are you sure you want to delete this bug? Doing so will <strong>destroy</strong> all associated data, including comments, attachments, and votes. We strongly recommend only deleting span records and nothing else as users may wish to go back and look at any bug to check its status.'), 'editreport.php', 'kill', _('Delete Bug Permanently'), 'showreport.php?bugid=' . $bug['bugid'], array('bugid' => $bug['bugid']));
107 }
108
109 // ###################################################################
110
111 if ($_POST['do'] == 'update')
112 {
113 if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['product']))
114 {
115 $message->error_permission();
116 }
117
118 $log->add_data(true, $bugapi->objdata, $bugfields);
119
120 // -------------------------------------------------------------------
121 // handle automations
122 $automation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $bugsys->input_clean('automation', TYPE_UINT));
123 if ($automation)
124 {
125 $automation['fields'] = unserialize($automation['fieldchanges']);
126
127 if (is_array($automation['fields']['builtin']))
128 {
129 foreach ($automation['fields']['builtin'] AS $field => $value)
130 {
131 $bugsys->in["$field"] = $value;
132 }
133 }
134
135 if (is_array($automation['fields']['custom']))
136 {
137 foreach ($automation['fields']['custom'] AS $field => $value)
138 {
139 $bugsys->in["field$field"] = $value;
140 }
141 }
142 }
143
144 // -------------------------------------------------------------------
145 // process comment stuff
146 if ($bugsys->in['comment'] OR $automation['comment'])
147 {
148 if (!empty($bugsys->in['comment']) AND $automation['comment'])
149 {
150 $commenttext = $bugsys->in['comment'] . "\n\n" . _('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
151 }
152 else if (empty($bugsys->in['comment']) AND $automation['comment'])
153 {
154 $commenttext = $automation['comment'];
155 }
156 else
157 {
158 $commenttext = $bugsys->in['comment'];
159 }
160
161 $comment = new CommentAPI($bugsys);
162 $comment->set('bugid', $bugsys->in['bugid']);
163 $comment->set('userid', $bugsys->userinfo['userid']);
164 $comment->set('comment', $commenttext);
165 $comment->insert();
166
167 // we redefine the bug data later, but it needs to be here in order to generate the user list
168 $notif->set_bug_data($bugapi->objdata);
169 $notif->send_new_comment_notice($comment->values);
170
171 $bugapi->set('lastposttime', $comment->values['dateline']);
172 $bugapi->set('lastpostby', $bugsys->userinfo['userid']);
173 $bugapi->set('lastpostbyname', $bugsys->userinfo['displayname']);
174 $bugapi->set('hiddenlastposttime', $comment->values['dateline']);
175 $bugapi->set('hiddenlastpostby', $bugsys->userinfo['userid']);
176 $bugapi->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
177
178 if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
179 {
180 $bugapi->update();
181 $notif->finalize();
182 $message->redirect(_('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
183 }
184 }
185
186 // -------------------------------------------------------------------
187 // do update stuff
188 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
189
190 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
191 $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies));
192
193 $bugapi->set('summary', $bugsys->in['summary']);
194 $bugapi->set('severity', $bugsys->in['severity']);
195 $bugapi->set('duplicateof', $bugsys->in['duplicateof']);
196 $bugapi->set('dependency', $dependencies);
197 $bugapi->set('product', $pcv['product']);
198 $bugapi->set('component', $pcv['component']);
199 $bugapi->set('version', $pcv['version']);
200 $bugapi->set('hidden', $bugsys->in['hidden']);
201
202 if (can_perform('canchangestatus', $bug['product']))
203 {
204 $bugapi->set('priority', $bugsys->in['priority']);
205 $bugapi->set('status', $bugsys->in['status']);
206 $bugapi->set('resolution', $bugsys->in['resolution']);
207 }
208 if (can_perform('canassign', $bug['product']))
209 {
210 $bugapi->set('assignedto', $bugsys->in['assignedto']);
211 }
212
213 $notif->set_bug_data($bugapi->objdata, $bugapi->values);
214
215 // -------------------------------------------------------------------
216 // handle logging and perform updates
217
218 if ($fields = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"))
219 {
220 $log->add_data(true, $fields, array('bugid'), true, 'custom');
221 }
222
223 $log->add_data(false, $bugapi->values, $bugfields);
224
225 process_custom_fields($bug['bugid'], $message, false);
226
227 $bugapi->update();
228
229 // -------------------------------------------------------------------
230 // do diff history
231
232 $fieldsnew = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
233 $log->add_data(false, $fieldsnew, array('bugid'), true, 'custom');
234
235 $log->update_history();
236
237 $notif->send_bug_changes_notice($fields, $fieldsnew);
238
239 $notif->finalize();
240
241 $message->redirect(_('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
242 }
243
244 /*=====================================================================*\
245 || ###################################################################
246 || # $HeadURL$
247 || # $Id$
248 || ###################################################################
249 \*=====================================================================*/
250 ?>