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