r324: Comment adding is now done on showreport.php
[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 ($_POST['do'] == 'update')
52 {
53 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
54
55 if (!$bugsys->in['summary'])
56 {
57 $message->error('you need to enter a summary');
58 }
59 if (!$pcv)
60 {
61 $message->error('invalid product/component/version');
62 }
63
64 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
65 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
66
67 // -------------------------------------------------------------------
68 // start updates
69
70 // auto action
71 $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
72 if ($autoaction)
73 {
74 $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
75
76 foreach ($autoaction['fields']['builtin'] AS $field => $value)
77 {
78 $bugsys->in["$field"] = $value;
79 }
80
81 foreach ($autoaction['fields']['custom'] AS $field => $value)
82 {
83 $bugsys->in["field$field"] = $value;
84 }
85 }
86
87 process_custom_fields($bug['bugid']);
88
89 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
90 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
91
92 // #*# 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
93
94 $db->query("
95 UPDATE " . TABLE_PREFIX . "bug
96 SET summary = '" . $bugsys->in['summary'] . "',
97 priority = " . intval($bugsys->in['priority']) . ",
98 status = " . intval($bugsys->in['status']) . ",
99 severity = " . intval($bugsys->in['severity']) . ",
100 resolution = " . intval($bugsys->in['resolution']) . ",
101 assignedto = " . intval($bugsys->in['assignedto']) . ",
102 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
103 dependency = '$dependencies',
104 productid = " . $pcv['product'] . ",
105 componentid = " . $pcv['component'] . ",
106 versionid = " . $pcv['version'] . ",
107 hidden = " . intval($bugsys->in['hidden']) . "
108 WHERE bugid = $bug[bugid]"
109 );
110
111 // -------------------------------------------------------------------
112 // do diff history
113
114 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
115 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
116
117 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
118 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
119
120 $lookupindex = array(
121 'status' => 'status',
122 'severity' => 'severity',
123 'priority' => 'priority',
124 'versionid' => 'version',
125 'assignedto' => 'assignto',
126 'resolution' => 'resolution',
127 'productid' => 'product',
128 'componentid' => 'product'
129 );
130
131 $log->language = 'log_update_bug';
132
133 foreach ($diff AS $num => $diffs)
134 {
135 foreach ($diffs AS $key => $value)
136 {
137 if (!isset($lookupindex["$key"]))
138 {
139 continue;
140 }
141
142 $ref = $lookupindex["$key"];
143 $temp =& $bugsys->datastore["$ref"]["$value"];
144 $thevalue = $temp["$ref"];
145 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
146
147 if ($key == 'assignedto')
148 {
149 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
150 $idbit = '';
151 }
152 else if ($key == 'productid' OR $key == 'componentid')
153 {
154 $ref = 'product';
155 $thevalue = $temp['title'];
156 }
157
158 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
159 }
160 }
161
162 foreach ($diff[1] AS $key => $value)
163 {
164 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
165 }
166
167 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
168 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
169
170 if ($noinitialcustom === false)
171 {
172 $canallowempty = true;
173 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
174 while ($box = $db->fetch_array($checkbox))
175 {
176 $boxlist[] = 'field' . $box['fieldid'];
177 }
178 }
179
180 foreach ($diff2[1] AS $key => $value)
181 {
182 if (in_array($key, $boxlist) AND $canallowempty)
183 {
184 $log->allowempty = true;
185 }
186 else
187 {
188 $log->allowempty = false;
189 }
190
191 if ($key == 'bugid')
192 {
193 continue;
194 }
195
196 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
197 }
198
199 $log->allowempty = false;
200
201 // -------------------------------------------------------------------
202 // process comment stuff
203
204 $hascomment = (!empty($bugsys->in['comment'])) ? true : false;
205
206 if ($hascomment OR $autoaction['comment'])
207 {
208 if ($hascomment AND $autoaction['comment'])
209 {
210 $bugsys->in['comment'] .= "\n\n--------------- AUTOMATIC RESPONSE ---------------\n" . $autoaction['comment'];
211 }
212 else if (!$hascomment AND $autoaction['comment'])
213 {
214 $bugsys->in['comment'] = $autoaction['comment'];
215 }
216
217 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
218
219 if (!$bugsys->options['allowhtml'])
220 {
221 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
222 }
223
224 $time = TIMENOW;
225
226 $db->query("
227 INSERT INTO " . TABLE_PREFIX . "comment
228 (bugid, userid, dateline, comment, comment_parsed)
229 VALUES
230 (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ",
231 $time, '" . $bugsys->in['comment'] . "',
232 '" . nl2br($bugsys->in['comment_parsed']) . "'
233 )"
234 );
235
236 $commentid = $db->insert_id();
237
238 $db->query("
239 UPDATE " . TABLE_PREFIX . "bug
240 SET lastposttime = $time,
241 lastpostby = " . $bugsys->userinfo['userid'] . ",
242 hiddenlastposttime = $time,
243 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
244 WHERE bugid = " . intval($bugsys->in['bugid'])
245 );
246
247 if ($hascomment)
248 {
249 $log->language = 'log_new_comment';
250 $log->arguments = array($commentid);
251 $log->log();
252 }
253 }
254
255 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
256 }
257
258 /*=====================================================================*\
259 || ###################################################################
260 || # $HeadURL$
261 || # $Id$
262 || ###################################################################
263 \*=====================================================================*/
264 ?>