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