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