r148: Can you say muffining unelelegant? There has GOT to be a better way to do this
[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 }
134
135 log_action($bug['bugid'], 'log_update_bug', array(), $diff[0], $diff[1]);
136
137 if (!$bugsys->in['firstcomment'])
138 {
139 echo 'you need to enter some text in the first comment';
140 exit;
141 }
142
143 $bugsys->in['comment_parsed'] = $bugsys->in['firstcomment'];
144
145 if (!$bugsys->options['allowhtml'])
146 {
147 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
148 }
149
150 // we could pass this as a GET param, but that's unsafe
151 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
152
153 $db->query("
154 UPDATE " . TABLE_PREFIX . "comment
155 SET comment = '" . $bugsys->in['firstcomment'] . "',
156 comment_parsed = '" . nl2br($bugsys->in['comment_parsed']) . "'
157 WHERE commentid = $firstcomment[commentid]"
158 );
159
160 if ($bugsys->in['changeproduct'])
161 {
162 $_REQUEST['do'] = 'editproduct';
163 }
164 else
165 {
166 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">done with update bug</a>";
167 }
168 }
169
170 // ###################################################################
171
172 if ($_REQUEST['do'] == 'edit')
173 {
174 foreach ($bugsys->datastore['severity'] AS $severity)
175 {
176 $value = $severity['severityid'];
177 $selected = (($severity['severityid'] == $bug['severity']) ? true : false);
178 $label = $severity['severity'];
179 eval('$select[severity] .= "' . $template->fetch('selectoption') . '";');
180 }
181
182 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
183 if (can_perform('canchangestatus'))
184 {
185 foreach ($bugsys->datastore['priority'] AS $priority)
186 {
187 $value = $priority['priorityid'];
188 $selected = (($priority['priorityid'] == $bug['priority']) ? true : false);
189 $label = $priority['priority'];
190 eval('$select[priority] .= "' . $template->fetch('selectoption') . '";');
191 }
192
193 foreach ($bugsys->datastore['status'] AS $status)
194 {
195 $value = $status['statusid'];
196 $selected = (($status['statusid'] == $bug['status']) ? true : false);
197 $label = $status['status'];
198 eval('$select[status] .= "' . $template->fetch('selectoption') . '";');
199 }
200
201 foreach ($bugsys->datastore['resolution'] AS $resolution)
202 {
203 $value = $resolution['resolutionid'];
204 $selected = (($resolution['resolutionid'] == $bug['resolution']) ? true : false);
205 $label = $resolution['resolution'];
206 eval('$select[resolution] .= "' . $template->fetch('selectoption') . '";');
207 }
208 }
209
210 $show['assign'] = ((can_perform('canassign')) ? true : false);
211 if (can_perform('canassign'))
212 {
213 foreach ($bugsys->datastore['assignto'] AS $dev)
214 {
215 $value = $dev['userid'];
216 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
217 $label = construct_user_display($dev, false);
218 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
219 }
220 }
221
222 $pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
223
224 $firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
225
226 eval('$template->flush("' . $template->fetch('editreport') . '");');
227 }
228
229 /*=====================================================================*\
230 || ###################################################################
231 || # $HeadURL$
232 || # $Id$
233 || ###################################################################
234 \*=====================================================================*/
235 ?>