r260: Fixed a bug where we were logging the bugid itself as a custom_* thing
[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 $fetchtemplates = array(
14 'editreport',
15 'pcv_select_row'
16 );
17
18 require_once('./global.php');
19
20 $bug = $db->query_first("
21 SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
22 FROM " . TABLE_PREFIX . "bug AS bug
23 LEFT JOIN " . TABLE_PREFIX . "user AS user
24 ON (bug.userid = user.userid)
25 LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
26 ON (bug.bugid = bugvaluefill.bugid)
27 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
28 );
29
30 if (!$bug)
31 {
32 $message->error('alert: bad bug');
33 }
34
35 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
36 {
37 $message->error_permission();
38 }
39
40 if ($bug['hidden'] AND !can_perform('canviewhidden'))
41 {
42 $message->error_permission();
43 }
44
45 // setup logging
46 require_once('./includes/class_history.php');
47 $log = new History();
48 $log->bugid = $bug['bugid'];
49
50 // ###################################################################
51
52 if (empty($_REQUEST['do']))
53 {
54 $_REQUEST['do'] = 'edit';
55 }
56
57 // ###################################################################
58
59 if ($_POST['do'] == 'update')
60 {
61 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
62
63 if (!$bugsys->in['summary'])
64 {
65 $message->error('you need to enter a summary');
66 }
67 if (!$pcv)
68 {
69 $message->error('invalid product/component/version');
70 }
71
72 $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
73 $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
74
75 process_custom_fields($bug['bugid']);
76
77 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
78 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
79
80 $db->query("
81 UPDATE " . TABLE_PREFIX . "bug
82 SET summary = '" . $bugsys->in['summary'] . "',
83 priority = " . intval($bugsys->in['priority']) . ",
84 status = " . intval($bugsys->in['status']) . ",
85 severity = " . intval($bugsys->in['severity']) . ",
86 resolution = " . intval($bugsys->in['resolution']) . ",
87 assignedto = " . intval($bugsys->in['assignedto']) . ",
88 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
89 dependency = '$dependencies',
90 productid = " . $pcv['product'] . ",
91 componentid = " . $pcv['component'] . ",
92 versionid = " . $pcv['version'] . ",
93 hidden = " . intval($bugsys->in['hidden']) . "
94 WHERE bugid = $bug[bugid]"
95 );
96
97 // -------------------------------------------------------------------
98 // do diff history
99
100 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
101 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
102
103 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
104 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
105
106 $lookupindex = array(
107 'status' => 'status',
108 'severity' => 'severity',
109 'priority' => 'priority',
110 'versionid' => 'version',
111 'assignedto' => 'assignto',
112 'resolution' => 'resolution',
113 'productid' => 'product',
114 'componentid' => 'product'
115 );
116
117 $log->language = 'log_update_bug';
118
119 foreach ($diff AS $num => $diffs)
120 {
121 foreach ($diffs AS $key => $value)
122 {
123 if (!isset($lookupindex["$key"]))
124 {
125 continue;
126 }
127
128 $ref = $lookupindex["$key"];
129 $temp =& $bugsys->datastore["$ref"]["$value"];
130 $thevalue = $temp["$ref"];
131 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
132
133 if ($key == 'assignedto')
134 {
135 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
136 $idbit = '';
137 }
138 else if ($key == 'productid' OR $key == 'componentid')
139 {
140 $ref = 'product';
141 $thevalue = $temp['title'];
142 }
143
144 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
145 }
146 }
147
148 foreach ($diff[1] AS $key => $value)
149 {
150 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
151 }
152
153 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
154 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
155
156 if ($noinitialcustom === false)
157 {
158 $canallowempty = true;
159 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
160 while ($box = $db->fetch_array($checkbox))
161 {
162 $boxlist[] = $box['shortname'];
163 }
164 }
165
166 foreach ($diff2[1] AS $key => $value)
167 {
168 if (in_array($key, $boxlist) AND $canallowempty)
169 {
170 $log->allowempty = true;
171 }
172 else
173 {
174 $log->allowempty = false;
175 }
176
177 if ($key == 'bugid')
178 {
179 continue;
180 }
181
182 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
183 }
184
185 $log->allowempty = false;
186
187 // -------------------------------------------------------------------
188 // process comment stuff
189
190 if (!$bugsys->in['firstcomment'])
191 {
192 $message->error('you need to enter some text in the first comment');
193 }
194
195 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
196
197 if (!$bugsys->options['allowhtml'])
198 {
199 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
200 }
201
202 // we could pass this as a GET param, but that's unsafe
203 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
204
205 $db->query("
206 UPDATE " . TABLE_PREFIX . "comment
207 SET comment = '" . $bugsys->in['firstcomment'] . "',
208 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
209 WHERE commentid = $firstcomment[commentid]"
210 );
211
212 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
213 }
214
215 // ###################################################################
216
217 if ($_REQUEST['do'] == 'edit')
218 {
219 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
220
221 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
222 if (can_perform('canchangestatus'))
223 {
224 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
225 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
226 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
227 }
228
229 $show['assign'] = ((can_perform('canassign')) ? true : false);
230 if (can_perform('canassign'))
231 {
232 foreach ($bugsys->datastore['assignto'] AS $dev)
233 {
234 $value = $dev['userid'];
235 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
236 $label = construct_user_display($dev, false);
237 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
238 }
239 }
240
241 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
242
243 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
244
245 $customfields = construct_custom_fields($bug);
246
247 if ($bug['duplicateof'])
248 {
249 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
250 }
251
252 if ($bug['dependency'])
253 {
254 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
255 while ($dependency = $db->fetch_array($dependencies))
256 {
257 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" alt=\"$dependency[summary]\">$dependency[bugid]</a>";
258 }
259 $dependencies = implode(' ', $depends);
260 }
261
262 eval('$template->flush("' . $template->fetch('editreport') . '");');
263 }
264
265 /*=====================================================================*\
266 || ###################################################################
267 || # $HeadURL$
268 || # $Id$
269 || ###################################################################
270 \*=====================================================================*/
271 ?>