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