r204: We now diff and log custom bug fields. This page is getting really query heavy...
[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 // setup logging
41 require_once('./includes/class_history.php');
42 $log = new History();
43 $log->bugid = $bug['bugid'];
44
45 // ###################################################################
46
47 if (empty($_REQUEST['do']))
48 {
49 $_REQUEST['do'] = 'edit';
50 }
51
52 // ###################################################################
53 /*
54 #*# do these later once we have delete permissions figured out
55 if ($_REQUEST['do'] == 'kill')
56 {
57 // run code to remove item in database
58 }
59
60 // ###################################################################
61
62 if ($_REQUEST['do'] == 'delete')
63 {
64 // display delete confirmation message
65 }*/
66
67 // ###################################################################
68
69 if ($_POST['do'] == 'update')
70 {
71 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
72
73 if (!$bugsys->in['summary'])
74 {
75 $message->error('you need to enter a summary');
76 }
77 if (!$pcv)
78 {
79 $message->error('invalid product/component/version');
80 }
81
82 $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
83 $hist2[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
84
85 process_custom_fields($bug['bugid']);
86
87 $db->query("
88 UPDATE " . TABLE_PREFIX . "bug
89 SET summary = '" . $bugsys->in['summary'] . "',
90 priority = " . intval($bugsys->in['priority']) . ",
91 status = " . intval($bugsys->in['status']) . ",
92 severity = " . intval($bugsys->in['severity']) . ",
93 resolution = " . intval($bugsys->in['resolution']) . ",
94 assignedto = " . intval($bugsys->in['assignedto']) . ",
95 productid = " . $pcv['product'] . ",
96 componentid = " . $pcv['component'] . ",
97 versionid = " . $pcv['version'] . "
98 WHERE bugid = $bug[bugid]"
99 );
100
101 // -------------------------------------------------------------------
102 // do diff history
103
104 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
105 $hist2[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
106
107 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
108 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
109
110 $lookupindex = array(
111 'status' => 'status',
112 'severity' => 'severity',
113 'priority' => 'priority',
114 'versionid' => 'version',
115 'assignedto' => 'assignto',
116 'resolution' => 'resolution',
117 'productid' => 'product',
118 'componentid' => 'product'
119 );
120
121 $log->language = 'log_update_bug';
122
123 foreach ($diff AS $num => $diffs)
124 {
125 foreach ($diffs AS $key => $value)
126 {
127 if (!isset($lookupindex["$key"]))
128 {
129 continue;
130 }
131
132 $ref = $lookupindex["$key"];
133 $temp =& $bugsys->datastore["$ref"]["$value"];
134 $thevalue = $temp["$ref"];
135 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
136
137 if ($key == 'assignedto')
138 {
139 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
140 $idbit = '';
141 }
142 else if ($key == 'productid' OR $key == 'componentid')
143 {
144 $ref = 'product';
145 $thevalue = $temp['title'];
146 }
147
148 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
149 }
150 }
151
152 foreach ($diff[1] AS $key => $value)
153 {
154 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
155 }
156
157 $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
158 $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
159
160 foreach ($diff2[1] AS $key => $value)
161 {
162 $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
163 }
164
165 // -------------------------------------------------------------------
166 // process comment stuff
167
168 if (!$bugsys->in['firstcomment'])
169 {
170 $message->error('you need to enter some text in the first comment');
171 }
172
173 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
174
175 if (!$bugsys->options['allowhtml'])
176 {
177 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
178 }
179
180 // we could pass this as a GET param, but that's unsafe
181 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
182
183 $db->query("
184 UPDATE " . TABLE_PREFIX . "comment
185 SET comment = '" . $bugsys->in['firstcomment'] . "',
186 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
187 WHERE commentid = $firstcomment[commentid]"
188 );
189
190 $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]");
191 }
192
193 // ###################################################################
194
195 if ($_REQUEST['do'] == 'edit')
196 {
197 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
198
199 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
200 if (can_perform('canchangestatus'))
201 {
202 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
203 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
204 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
205 }
206
207 $show['assign'] = ((can_perform('canassign')) ? true : false);
208 if (can_perform('canassign'))
209 {
210 foreach ($bugsys->datastore['assignto'] AS $dev)
211 {
212 $value = $dev['userid'];
213 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
214 $label = construct_user_display($dev, false);
215 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
216 }
217 }
218
219 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
220
221 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
222
223 $customfields = construct_custom_fields($bug);
224
225 eval('$template->flush("' . $template->fetch('editreport') . '");');
226 }
227
228 /*=====================================================================*\
229 || ###################################################################
230 || # $HeadURL$
231 || # $Id$
232 || ###################################################################
233 \*=====================================================================*/
234 ?>