r1392: Lots of work going into making the custom fields part of the bug table and...
[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 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 WHERE bug.bugid = " . $bugsys->input_clean('bugid', TYPE_UINT)
41 );
42
43 if (!$bug)
44 {
45 $message->error(L_INVALID_ID);
46 }
47
48 if (!check_bug_permissions($bug))
49 {
50 $message->error_permission();
51 }
52
53 // setup logging
54 require_once('./includes/class_logging.php');
55 $log = new Logging;
56 $log->set_bugid($bug['bugid']);
57
58 $excludeFields = array(
59 'bugid',
60 'lastposttime',
61 'lastpostby',
62 'lastpostbyname',
63 'hiddenlastposttime',
64 'hiddenlastpostby',
65 'hiddenlastpostbyname',
66 );
67
68 $notif = new NotificationCenter;
69
70 $bugapi = new BugAPI($bugsys);
71 $bugapi->set('bugid', $bugsys->in['bugid']);
72 $bugapi->set_condition();
73 $bugapi->dorelations = array();
74 $bugapi->fetch();
75
76 // ###################################################################
77
78 if ($_POST['do'] == 'kill')
79 {
80 if (!can_perform('candeletedata', $bug['product']))
81 {
82 $message->error_permission();
83 }
84
85 $bugapi->delete();
86
87 $message->redirect(_('The entire bug has been deleted.'), 'index.php');
88 }
89
90 // ###################################################################
91
92 if ($_REQUEST['do'] == 'delete')
93 {
94 if (!can_perform('candeletedata', $bug['product']))
95 {
96 $message->error_permission();
97 }
98
99 $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']));
100 }
101
102 // ###################################################################
103
104 if ($_POST['do'] == 'update')
105 {
106 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']))
107 {
108 $message->error_permission();
109 }
110
111 $log->add_data(true, $bugapi->objdata, $excludeFields, true);
112
113 // -------------------------------------------------------------------
114 // handle automations
115 $automation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $bugsys->input_clean('automation', TYPE_UINT));
116 if ($automation)
117 {
118 $automation['fields'] = unserialize($automation['fieldchanges']);
119
120 if (is_array($automation['fields']['builtin']))
121 {
122 foreach ($automation['fields']['builtin'] AS $field => $value)
123 {
124 $bugsys->in["$field"] = $value;
125 }
126 }
127
128 if (is_array($automation['fields']['custom']))
129 {
130 foreach ($automation['fields']['custom'] AS $field => $value)
131 {
132 $bugsys->in["field$field"] = $value;
133 }
134 }
135 }
136
137 // -------------------------------------------------------------------
138 // process comment stuff
139 if ($bugsys->in['comment'] OR $automation['comment'])
140 {
141 if (!empty($bugsys->in['comment']) AND $automation['comment'])
142 {
143 $commenttext = $bugsys->in['comment'] . "\n\n" . _('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
144 }
145 else if (empty($bugsys->in['comment']) AND $automation['comment'])
146 {
147 $commenttext = $automation['comment'];
148 }
149 else
150 {
151 $commenttext = $bugsys->in['comment'];
152 }
153
154 $comment = new CommentAPI($bugsys);
155 $comment->set('bugid', $bugsys->in['bugid']);
156 $comment->set('userid', $bugsys->userinfo['userid']);
157 $comment->set('comment', $commenttext);
158 $comment->set('parselinks', $bugsys->in['parselinks']);
159 $comment->insert();
160
161 // we redefine the bug data later, but it needs to be here in order to generate the user list
162 $notif->set_bug_data($bugapi->objdata);
163 $notif->send_new_comment_notice($comment->values);
164
165 $bugapi->set('lastposttime', $comment->values['dateline']);
166 $bugapi->set('lastpostby', $bugsys->userinfo['userid']);
167 $bugapi->set('lastpostbyname', $bugsys->userinfo['displayname']);
168 $bugapi->set('hiddenlastposttime', $comment->values['dateline']);
169 $bugapi->set('hiddenlastpostby', $bugsys->userinfo['userid']);
170 $bugapi->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
171
172 if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
173 {
174 $bugapi->update();
175 $notif->finalize();
176 $message->redirect(_('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
177 }
178 }
179
180 // -------------------------------------------------------------------
181 // do update stuff
182 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
183 $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies));
184
185 $bugapi->set('summary', $bugsys->in['summary']);
186 $bugapi->set('severity', $bugsys->in['severity']);
187 $bugapi->set('duplicateof', $bugsys->in['duplicateof']);
188 $bugapi->set('dependency', $dependencies);
189 $bugapi->set('hidden', $bugsys->in['hidden']);
190
191 $product = explode(',', $bugsys->in['product']);
192 $bugapi->set('product', $product[0]);
193 $bugapi->set('component', $product[1]);
194 $bugapi->set('version', $product[2]);
195
196 if (can_perform('canchangestatus', $bug['product']))
197 {
198 $bugapi->set('priority', $bugsys->in['priority']);
199 $bugapi->set('status', $bugsys->in['status']);
200 $bugapi->set('resolution', $bugsys->in['resolution']);
201 }
202 if (can_perform('canassign', $bug['product']))
203 {
204 $bugapi->set('assignedto', $bugsys->in['assignedto']);
205 }
206
207 process_custom_fields($bugapi, $message, false);
208
209 // -------------------------------------------------------------------
210 // handle logging and perform updates
211
212 $notif->set_bug_data($bugapi->objdata, $bugapi->values);
213 $log->add_data(false, $bugapi->values, $excludeFields, true);
214
215 $bugapi->update();
216
217 // -------------------------------------------------------------------
218 // do diff history
219
220 $log->update_history();
221
222 $notif->send_bug_changes_notice();
223
224 $notif->finalize();
225
226 $message->redirect(_('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
227 }
228
229 /*=====================================================================*\
230 || ###################################################################
231 || # $HeadURL$
232 || # $Id$
233 || ###################################################################
234 \*=====================================================================*/
235 ?>