r159: - Finished all of that logging stuff
[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 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 WHERE bug.bugid = " . intval($bugsys->in['bugid'])
26 );
27
28 if (!$bug)
29 {
30 echo 'alert: bad bug';
31 exit;
32 }
33
34 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
35 {
36 echo 'no permission';
37 exit;
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 echo 'you need to enter a summary';
76 exit;
77 }
78 if (!$pcv)
79 {
80 echo 'invalid product/component/version';
81 exit;
82 }
83
84 $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
85
86 $db->query("
87 UPDATE " . TABLE_PREFIX . "bug
88 SET summary = '" . $bugsys->in['summary'] . "',
89 priority = " . intval($bugsys->in['priority']) . ",
90 status = " . intval($bugsys->in['status']) . ",
91 severity = " . intval($bugsys->in['severity']) . ",
92 resolution = " . intval($bugsys->in['resolution']) . ",
93 assignedto = " . intval($bugsys->in['assignedto']) . ",
94 productid = " . $pcv['product'] . ",
95 componentid = " . $pcv['component'] . ",
96 versionid = " . $pcv['version'] . "
97 WHERE bugid = $bug[bugid]"
98 );
99
100 $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
101
102 $diff[0] = array_diff_assoc($hist[0], $hist[1]);
103 $diff[1] = array_diff_assoc($hist[1], $hist[0]);
104
105 $lookupindex = array(
106 'status' => 'status',
107 'severity' => 'severity',
108 'priority' => 'priority',
109 'versionid' => 'version',
110 'assignedto' => 'assignto',
111 'resolution' => 'resolution',
112 'productid' => 'product',
113 'componentid' => 'product'
114 );
115
116 $log->language = 'log_update_bug';
117
118 foreach ($diff AS $num => $diffs)
119 {
120 foreach ($diffs AS $key => $value)
121 {
122 if (!isset($lookupindex["$key"]))
123 {
124 continue;
125 }
126
127 $ref = $lookupindex["$key"];
128 $temp =& $bugsys->datastore["$ref"]["$value"];
129 $thevalue = $temp["$ref"];
130 $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
131
132 if ($key == 'assignedto')
133 {
134 $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
135 $idbit = '';
136 }
137 else if ($key == 'productid' OR $key == 'componentid')
138 {
139 $ref = 'product';
140 $thevalue = $temp['title'];
141 }
142
143 $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
144 }
145 }
146
147 foreach ($diff[1] AS $key => $value)
148 {
149 $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
150 }
151
152 if (!$bugsys->in['firstcomment'])
153 {
154 echo 'you need to enter some text in the first comment';
155 exit;
156 }
157
158 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
159
160 if (!$bugsys->options['allowhtml'])
161 {
162 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
163 }
164
165 // we could pass this as a GET param, but that's unsafe
166 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
167
168 $db->query("
169 UPDATE " . TABLE_PREFIX . "comment
170 SET comment = '" . $bugsys->in['firstcomment'] . "',
171 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
172 WHERE commentid = $firstcomment[commentid]"
173 );
174
175 if ($bugsys->in['changeproduct'])
176 {
177 $_REQUEST['do'] = 'editproduct';
178 }
179 else
180 {
181 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">done with update bug</a>";
182 }
183 }
184
185 // ###################################################################
186
187 if ($_REQUEST['do'] == 'edit')
188 {
189 foreach ($bugsys->datastore['severity'] AS $severity)
190 {
191 $value = $severity['severityid'];
192 $selected = (($severity['severityid'] == $bug['severity']) ? true : false);
193 $label = $severity['severity'];
194 eval('$select[severity] .= "' . $template->fetch('selectoption') . '";');
195 }
196
197 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
198 if (can_perform('canchangestatus'))
199 {
200 foreach ($bugsys->datastore['priority'] AS $priority)
201 {
202 $value = $priority['priorityid'];
203 $selected = (($priority['priorityid'] == $bug['priority']) ? true : false);
204 $label = $priority['priority'];
205 eval('$select[priority] .= "' . $template->fetch('selectoption') . '";');
206 }
207
208 foreach ($bugsys->datastore['status'] AS $status)
209 {
210 $value = $status['statusid'];
211 $selected = (($status['statusid'] == $bug['status']) ? true : false);
212 $label = $status['status'];
213 eval('$select[status] .= "' . $template->fetch('selectoption') . '";');
214 }
215
216 foreach ($bugsys->datastore['resolution'] AS $resolution)
217 {
218 $value = $resolution['resolutionid'];
219 $selected = (($resolution['resolutionid'] == $bug['resolution']) ? true : false);
220 $label = $resolution['resolution'];
221 eval('$select[resolution] .= "' . $template->fetch('selectoption') . '";');
222 }
223 }
224
225 $show['assign'] = ((can_perform('canassign')) ? true : false);
226 if (can_perform('canassign'))
227 {
228 foreach ($bugsys->datastore['assignto'] AS $dev)
229 {
230 $value = $dev['userid'];
231 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
232 $label = construct_user_display($dev, false);
233 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
234 }
235 }
236
237 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
238
239 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
240
241 eval('$template->flush("' . $template->fetch('editreport') . '");');
242 }
243
244 /*=====================================================================*\
245 || ###################################################################
246 || # $HeadURL$
247 || # $Id$
248 || ###################################################################
249 \*=====================================================================*/
250 ?>