r924: Making sure that we have an APIError() callback set
[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/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 (!((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']))
46 {
47 $message->error_permission();
48 }
49
50 if (!$bug)
51 {
52 $message->error($lang->getlex('error_invalid_id'));
53 }
54
55 if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
56 {
57 $message->error_permission();
58 }
59
60 // setup logging
61 require_once('./includes/class_logging.php');
62 $log = new Logging;
63 $log->set_bugid($bug['bugid']);
64
65 $bugfields = array(
66 'duplicateof',
67 'dependency',
68 'hidden',
69 'summary',
70 'status',
71 'severity',
72 'priority',
73 'versionid' => 'version',
74 'assignedto' => 'assignto',
75 'resolution',
76 'productid' => 'product',
77 'componentid' => 'component'
78 );
79
80 $notif = new NotificationCenter;
81
82 // ###################################################################
83
84 if ($_POST['do'] == 'update')
85 {
86 $bugapi = new BugAPI($bugsys);
87 $bugapi->set('bugid', $bugsys->in['bugid']);
88 $bugapi->set_condition();
89 $bugapi->dorelations = array();
90 $bugapi->fetch();
91
92 $log->add_data(true, $bugapi->objdata, $bugfields);
93
94 // -------------------------------------------------------------------
95 // handle autoaction
96 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('autoaction', TYPE_UINT));
97 if ($autoaction)
98 {
99 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
100
101 foreach ($autoaction['fields']['builtin'] AS $field => $value)
102 {
103 $bugsys->in["$field"] = $value;
104 }
105
106 foreach ($autoaction['fields']['custom'] AS $field => $value)
107 {
108 $bugsys->in["field$field"] = $value;
109 }
110 }
111
112 // -------------------------------------------------------------------
113 // do update stuff
114 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
115
116 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
117 $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies));
118
119 $bugapi->set('summary', $bugsys->in['summary']);
120 $bugapi->set('severity', $bugsys->in['severity']);
121 $bugapi->set('duplicateof', $bugsys->in['duplicateof']);
122 $bugapi->set('dependency', $dependencies);
123 $bugapi->set('productid', $pcv['product']);
124 $bugapi->set('componentid', $pcv['component']);
125 $bugapi->set('versionid', $pcv['version']);
126 $bugapi->set('hidden', $bugsys->in['hidden']);
127
128 if (can_perform('canchangestatus', $bug['productid']))
129 {
130 $bugapi->set('priority', $bugsys->in['priority']);
131 $bugapi->set('status', $bugsys->in['status']);
132 $bugapi->set('resolution', $bugsys->in['resolution']);
133 }
134 if (can_perform('canassign', $bug['productid']))
135 {
136 $bugapi->set('assignedto', $bugsys->in['assignedto']);
137 }
138
139 $notif->set_bug_data($bugapi->objdata, $bugapi->values);
140
141 // -------------------------------------------------------------------
142 // process comment stuff
143 if ($bugsys->in['comment'])
144 {
145 if (!empty($bugsys->in['comment']) AND $autoaction['comment'])
146 {
147 $commenttext = $bugsys->in['comment'] . "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
148 }
149 else if (empty($bugsys->in['comment']) AND $autoaction['comment'])
150 {
151 $commenttext = $autoaction['comment'];
152 }
153 else
154 {
155 $commenttext = $bugsys->in['comment'];
156 }
157
158 $comment = new CommentAPI($bugsys);
159 $comment->set('bugid', $bugsys->in['bugid']);
160 $comment->set('userid', $bugsys->userinfo['userid']);
161 $comment->set('comment', $commenttext);
162 $comment->insert();
163
164 $notif->send_new_comment_notice($comment->values);
165
166 $bugapi->set('lastposttime', $comment->values['dateline']);
167 $bugapi->set('lastpostby', $bugsys->userinfo['userid']);
168 $bugapi->set('lastpostbyname', $bugsys->userinfo['displayname']);
169 $bugapi->set('hiddenlastposttime', $comment->values['dateline']);
170 $bugapi->set('hiddenlastpostby', $bugsys->userinfo['userid']);
171 $bugapi->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
172
173 if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
174 {
175 $bugapi->update();
176 $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
177 }
178 }
179
180 // -------------------------------------------------------------------
181 // handle logging and perform updates
182
183 if ($fields = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"))
184 {
185 $log->add_data(true, $fields, array('bugid'), true, 'custom');
186 }
187
188 $log->add_data(false, $bugapi->values, $bugfields);
189
190 process_custom_fields($bug['bugid']);
191
192 $bugapi->update();
193
194 // -------------------------------------------------------------------
195 // do diff history
196
197 $fieldsnew = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
198 $log->add_data(false, $fieldsnew, array('bugid'), true, 'custom');
199
200 $log->update_history();
201
202 $notif->send_bug_changes_notice($fields, $fieldsnew);
203
204 $notif->finalize();
205
206 $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
207 }
208
209 /*=====================================================================*\
210 || ###################################################################
211 || # $HeadURL$
212 || # $Id$
213 || ###################################################################
214 \*=====================================================================*/
215 ?>