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