r252: Making it so that custom bug fields work better and will operate with language...
[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_field_names($hist2[0]);
76 process_custom_fields($bug['bugid']);
77
78 $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
79 $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
80
81 $db->query("
82 UPDATE " . TABLE_PREFIX . "bug
83 SET summary = '" . $bugsys->in['summary'] . "',
84 priority = " . intval($bugsys->in['priority']) . ",
85 status = " . intval($bugsys->in['status']) . ",
86 severity = " . intval($bugsys->in['severity']) . ",
87 resolution = " . intval($bugsys->in['resolution']) . ",
88 assignedto = " . intval($bugsys->in['assignedto']) . ",
89 duplicateof = " . intval($bugsys->in['duplicateof']) . ",
90 dependency = '$dependencies',
91 productid = " . $pcv['product'] . ",
92 componentid = " . $pcv['component'] . ",
93 versionid = " . $pcv['version'] . ",
94 hidden = " . intval($bugsys->in['hidden']) . "
95 WHERE bugid = $bug[bugid]"
96 );
97
98 // -------------------------------------------------------------------
99 // do diff history
100
101 $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
102 $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
103
104 process_custom_field_names($hist2[1]);
105
106 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
107 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
108
109 $lookupindex = array(
110 'status' => 'status',
111 'severity' => 'severity',
112 'priority' => 'priority',
113 'versionid' => 'version',
114 'assignedto' => 'assignto',
115 'resolution' => 'resolution',
116 'productid' => 'product',
117 'componentid' => 'product'
118 );
119
120 $log->language = 'log_update_bug';
121
122 foreach ($diff AS $num => $diffs)
123 {
124 foreach ($diffs AS $key => $value)
125 {
126 if (!isset($lookupindex["$key"]))
127 {
128 continue;
129 }
130
131 $ref = $lookupindex["$key"];
132 $temp =& $bugsys->datastore["$ref"]["$value"];
133 $thevalue = $temp["$ref"];
134 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
135
136 if ($key == 'assignedto')
137 {
138 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
139 $idbit = '';
140 }
141 else if ($key == 'productid' OR $key == 'componentid')
142 {
143 $ref = 'product';
144 $thevalue = $temp['title'];
145 }
146
147 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
148 }
149 }
150
151 foreach ($diff[1] AS $key => $value)
152 {
153 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
154 }
155
156 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
157 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
158
159 if ($noinitialcustom === false)
160 {
161 $canallowempty = true;
162 $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
163 while ($box = $db->fetch_array($checkbox))
164 {
165 $boxlist[] = $box['shortname'];
166 }
167 }
168
169 foreach ($diff2[1] AS $key => $value)
170 {
171 if (in_array($key, $boxlist) AND $canallowempty)
172 {
173 $log->allowempty = true;
174 }
175 else
176 {
177 $log->allowempty = false;
178 }
179
180 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
181 }
182
183 $log->allowempty = false;
184
185 // -------------------------------------------------------------------
186 // process comment stuff
187
188 if (!$bugsys->in['firstcomment'])
189 {
190 $message->error('you need to enter some text in the first comment');
191 }
192
193 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
194
195 if (!$bugsys->options['allowhtml'])
196 {
197 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
198 }
199
200 // we could pass this as a GET param, but that's unsafe
201 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
202
203 $db->query("
204 UPDATE " . TABLE_PREFIX . "comment
205 SET comment = '" . $bugsys->in['firstcomment'] . "',
206 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
207 WHERE commentid = $firstcomment[commentid]"
208 );
209
210 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
211 }
212
213 // ###################################################################
214
215 if ($_REQUEST['do'] == 'edit')
216 {
217 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
218
219 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
220 if (can_perform('canchangestatus'))
221 {
222 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
223 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
224 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
225 }
226
227 $show['assign'] = ((can_perform('canassign')) ? true : false);
228 if (can_perform('canassign'))
229 {
230 foreach ($bugsys->datastore['assignto'] AS $dev)
231 {
232 $value = $dev['userid'];
233 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
234 $label = construct_user_display($dev, false);
235 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
236 }
237 }
238
239 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
240
241 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
242
243 $customfields = construct_custom_fields($bug);
244
245 if ($bug['duplicateof'])
246 {
247 $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
248 }
249
250 if ($bug['dependency'])
251 {
252 $dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
253 while ($dependency = $db->fetch_array($dependencies))
254 {
255 $depends[] = "<a href=\"showreport.php?bugid=$dependency[bugid]\" alt=\"$dependency[summary]\">$dependency[bugid]</a>";
256 }
257 $dependencies = implode(' ', $depends);
258 }
259
260 eval('$template->flush("' . $template->fetch('editreport') . '");');
261 }
262
263 /*=====================================================================*\
264 || ###################################################################
265 || # $HeadURL$
266 || # $Id$
267 || ###################################################################
268 \*=====================================================================*/
269 ?>