r323: Removed editreport.tpl from the cache cycle
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2002-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2002 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 define('SVN', '$Id$');
14
15 $focus['showreport'] = 'focus';
16
17 require_once('./global.php');
18
19 $bug = $db->query_first("
20 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
21 FROM " . TABLE_PREFIX . "bug AS bug
22 LEFT JOIN " . TABLE_PREFIX . "user AS user
23 ON (bug.userid = user.userid)
24 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
25 ON (bug.bugid = bugvaluefill.bugid)
26 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
27 );
28
29 if (!$bug)
30 {
31 $message->error('alert: bad bug');
32 }
33
34 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
35 {
36 $message->error_permission();
37 }
38
39 if ($bug['hidden'] AND !can_perform('canviewhidden'))
40 {
41 $message->error_permission();
42 }
43
44 // setup logging
45 require_once('./includes/class_history.php');
46 $log = new History();
47 $log->bugid = $bug['bugid'];
48
49 // ###################################################################
50
51 if (empty($_REQUEST['do']))
52 {
53 $_REQUEST['do'] = 'edit';
54 }
55
56 // ###################################################################
57
58 if ($_POST['do'] == 'update')
59 {
60 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
61
62 if (!$bugsys->in['summary'])
63 {
64 $message->error('you need to enter a summary');
65 }
66 if (!$pcv)
67 {
68 $message->error('invalid product/component/version');
69 }
70
71 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
72 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
73
74 // -------------------------------------------------------------------
75 // start updates
76
77 // auto action
78 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
79 if ($autoaction)
80 {
81 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
82
83 foreach ($autoaction['fields']['builtin'] AS $field => $value)
84 {
85 $bugsys->in["$field"] = $value;
86 }
87
88 foreach ($autoaction['fields']['custom'] AS $field => $value)
89 {
90 $bugsys->in["field$field"] = $value;
91 }
92 }
93
94 process_custom_fields($bug['bugid']);
95
96 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
97 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
98
99 // #*# need to put in permission checks here because we do not show the fields the user has no permission to change in the edit section so they'll be blank on update
100
101 $db->query("
102 UPDATE " . TABLE_PREFIX . "bug
103 SET summary = '" . $bugsys->in['summary'] . "',
104 priority = " . intval($bugsys->in['priority']) . ",
105 status = " . intval($bugsys->in['status']) . ",
106 severity = " . intval($bugsys->in['severity']) . ",
107 resolution = " . intval($bugsys->in['resolution']) . ",
108 assignedto = " . intval($bugsys->in['assignedto']) . ",
109 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
110 dependency = '$dependencies',
111 productid = " . $pcv['product'] . ",
112 componentid = " . $pcv['component'] . ",
113 versionid = " . $pcv['version'] . ",
114 hidden = " . intval($bugsys->in['hidden']) . "
115 WHERE bugid = $bug[bugid]"
116 );
117
118 // -------------------------------------------------------------------
119 // do diff history
120
121 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
122 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
123
124 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
125 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
126
127 $lookupindex = array(
128 'status' => 'status',
129 'severity' => 'severity',
130 'priority' => 'priority',
131 'versionid' => 'version',
132 'assignedto' => 'assignto',
133 'resolution' => 'resolution',
134 'productid' => 'product',
135 'componentid' => 'product'
136 );
137
138 $log->language = 'log_update_bug';
139
140 foreach ($diff AS $num => $diffs)
141 {
142 foreach ($diffs AS $key => $value)
143 {
144 if (!isset($lookupindex["$key"]))
145 {
146 continue;
147 }
148
149 $ref = $lookupindex["$key"];
150 $temp =& $bugsys->datastore["$ref"]["$value"];
151 $thevalue = $temp["$ref"];
152 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
153
154 if ($key == 'assignedto')
155 {
156 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
157 $idbit = '';
158 }
159 else if ($key == 'productid' OR $key == 'componentid')
160 {
161 $ref = 'product';
162 $thevalue = $temp['title'];
163 }
164
165 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
166 }
167 }
168
169 foreach ($diff[1] AS $key => $value)
170 {
171 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
172 }
173
174 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
175 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
176
177 if ($noinitialcustom === false)
178 {
179 $canallowempty = true;
180 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
181 while ($box = $db->fetch_array($checkbox))
182 {
183 $boxlist[] = 'field' . $box['fieldid'];
184 }
185 }
186
187 foreach ($diff2[1] AS $key => $value)
188 {
189 if (in_array($key, $boxlist) AND $canallowempty)
190 {
191 $log->allowempty = true;
192 }
193 else
194 {
195 $log->allowempty = false;
196 }
197
198 if ($key == 'bugid')
199 {
200 continue;
201 }
202
203 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
204 }
205
206 $log->allowempty = false;
207
208 // -------------------------------------------------------------------
209 // process comment stuff
210 /*
211 if (!$bugsys->in['firstcomment'])
212 {
213 $message->error('you need to enter some text in the first comment');
214 }
215
216 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
217
218 if (!$bugsys->options['allowhtml'])
219 {
220 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
221 }
222
223 // we could pass this as a GET param, but that's unsafe
224 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
225
226 $db->query("
227 UPDATE " . TABLE_PREFIX . "comment
228 SET comment = '" . $bugsys->in['firstcomment'] . "',
229 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
230 WHERE commentid = $firstcomment[commentid]"
231 );
232 */
233 // -------------------------------------------------------------------
234 // auto action comment
235
236 if ($autoaction['comment'])
237 {
238 $comment = $autoaction['comment'];
239 if (!$bugsys->options['allowhtml'])
240 {
241 $comment_parsed = $bugsys->sanitize($comment);
242 }
243
244 $db->query("
245 INSERT INTO comment
246 (bugid, userid, dateline, comment, comment_parsed)
247 VALUES
248 ($bug[bugid], " . $bugsys->userinfo['userid'] . ", " . LOG_TIME . ",
249 '" . $bugsys->escape($comment) . "',
250 '" . $bugsys->escape($comment_parsed) . "'
251 )"
252 );
253
254 $db->query("
255 UPDATE " . TABLE_PREFIX . "bug
256 SET lastposttime = " . LOG_TIME . ",
257 lastpostby = " . $bugsys->userinfo['userid'] . ",
258 hiddenlastposttime = " . LOG_TIME . ",
259 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
260 WHERE bugid = $bug[bugid]"
261 );
262 }
263
264 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
265 }
266
267 /*=====================================================================*\
268 || ###################################################################
269 || # $HeadURL$
270 || # $Id$
271 || ###################################################################
272 \*=====================================================================*/
273 ?>