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