r24: Initial SVN for editcomment.php and editreport.php.
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # [#]app[#] [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14
15 sanitize(array('bugid' => INT));
16
17 $bug = $DB_sql->query_first("
18 SELECT bug.*, user.email, user.displayname, user.showemail
19 FROM " . TABLE_PREFIX . "bug AS bug
20 LEFT JOIN " . TABLE_PREFIX . "user AS user
21 ON (bug.userid = user.userid)
22 WHERE bug.bugid = $vars[bugid]"
23 );
24
25 if (!$bug)
26 {
27 echo 'alert: bad bug';
28 exit;
29 }
30
31 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
32 {
33 echo 'no permission';
34 exit;
35 }
36
37 // ###################################################################
38
39 if (empty($_REQUEST['do']))
40 {
41 $_REQUEST['do'] = 'edit';
42 }
43
44 // ###################################################################
45 /*
46 #*# do these later once we have delete permissions figured out
47 if ($_REQUEST['do'] == 'kill')
48 {
49 // run code to remove item in database
50 }
51
52 // ###################################################################
53
54 if ($_REQUEST['do'] == 'delete')
55 {
56 // display delete confirmation message
57 }*/
58
59 // ###################################################################
60
61 if ($_POST['do'] == 'update')
62 {
63 sanitize(array(
64 'summary' => STR_NOHTML,
65 'priority' => INT,
66 'status' => INT,
67 'resolution' => INT,
68 'assignedto' => INT,
69 'changeproduct' => STR)
70 );
71
72 $DB_sql->query("
73 UPDATE " . TABLE_PREFIX . "bug
74 SET summary = '" . addslasheslike($vars['summary']) . "',
75 priority = $vars[priority], status = $vars[status],
76 resolution = $vars[resolution],
77 assignedto = $vars[assignedto]
78 WHERE bugid = $bug[bugid]"
79 );
80
81 echo 'done with update bug';
82
83 if ($vars['changeproduct'])
84 {
85 $_REQUEST['do'] = 'editproduct';
86 }
87 }
88
89 // ###################################################################
90
91 if ($_REQUEST['do'] == 'edit')
92 {
93 echo '<form name="editreport" action="editreport.php" method="post">';
94 echo '<input type="hidden" name="do" value="update" /><input type="hidden" name="bugid" value="' . $bug['bugid'] . '" />';
95 echo "<div><strong>Bug ID:</strong> $bug[bugid]</div>";
96 echo "<div><strong>Summary/title:</strong> <input type=\"text\" name=\"summary\" value=\"$bug[summary]\" size=\"35\" />";
97 if (can_perform('canchangestatus'))
98 {
99 echo '<div><strong>Priority:</strong> <select name="priority">';
100 foreach ($bugsys->datastore['priority'] AS $priority)
101 {
102 echo '<option value="' . $priority['priorityid'] . '"' . iff($priority['priorityid'] == $bug['priority'], ' selected="selected"') . '>' . $priority['priority'] . '</option>';
103 }
104 echo '</select></div>';
105
106 echo '<div><strong>Status:</strong> <select name="status">';
107 foreach ($bugsys->datastore['status'] AS $status)
108 {
109 echo '<option value="' . $status['statusid'] . '"' . iff($status['statusid'] == $bug['status'], ' selected="selected"') . '>' . $status['status'] . '</option>';
110 }
111 echo '</select></div>';
112
113 echo '<div><strong>Resolution:</strong> <select name="resolution">';
114 foreach ($bugsys->datastore['resolution'] AS $resolution)
115 {
116 echo '<option value="' . $resolution['resolutionid'] . '"' . iff($resolution['resolutionid'] == $bug['resolution'], ' selected="selected"') . '>' . $resolution['resolution'] . '</option>';
117 }
118 echo '</select></div>';
119 }
120 if (can_perform('canassign'))
121 {
122 echo '<div><strong>Assigned to:</strong> <select name="assignedto"><option value="0"' . iff(!$bug['assignedto'], ' selected="selected"') . '>No Assignment</option>';
123 foreach ($bugsys->datastore['assignto'] AS $dev)
124 {
125 echo '<option value="' . $dev['userid'] . '"' . iff($dev['userid'] == $bug['assignedto'], ' selected="selected"') . '>' . construct_user_display($dev, false) . '</option>';
126 }
127 echo '</select></div>';
128 }
129 echo '<div><input type="submit" name="changeproduct" value="Change Product and Version Information" />';
130 echo '<div><input type="submit" name="submit" value="Save Changes" /></div></form>';
131 }
132
133 // ###################################################################
134
135 if ($_POST['do'] == 'updateproduct')
136 {
137 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
138
139 var_dump($vars);
140
141 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
142 {
143 echo 'there was a problem selecting the product, component, or version';
144 exit;
145 }
146 $product = $bugsys->datastore['product']["$vars[product]"];
147 if (!$product)
148 {
149 echo 'please select a valid product';
150 exit;
151 }
152 $version = $bugsys->datastore['version']["$vars[version]"];
153 if (!$version)
154 {
155 echo 'please select a valid version';
156 exit;
157 }
158 // no component
159 if ($vars['component'] == -1)
160 {
161 // not global version and version.productid != product.productid
162 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
163 {
164 echo 'invalid version specified';
165 exit;
166 }
167 }
168 // using a component
169 else
170 {
171 $component = $bugsys->datastore['product']["$vars[component]"];
172 // component has the right mother
173 if ($component['componentmother'] == $product['productid'])
174 {
175 // version.productid != {component.productid | product.productid}
176 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
177 {
178 echo 'invalid version specified';
179 exit;
180 }
181 }
182 else
183 {
184 echo 'invalid component specified';
185 exit;
186 }
187 }
188
189 // good-to-go
190 $DB_sql->query("UPDATE " . TABLE_PREFIX . "bug SET productid = $vars[product], componentid = $vars[component], versionid = $vars[version] WHERE bugid = $bug[bugid]");
191
192 echo 'changed product info';
193 }
194
195 // ###################################################################
196
197 if ($_REQUEST['do'] == 'editproduct')
198 {
199 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
200
201 // the user can hit the back button without reposting data...
202 if (!$vars['product'] OR !$vars['component'])
203 {
204 $method = 'get';
205 }
206 else
207 {
208 $method = 'post';
209 }
210
211 echo '<form name="newbug" action="editreport.php" method="' . $method . '">';
212
213 $do = 'editproduct';
214
215 if (!$vars['product'])
216 {
217 echo '<strong>Product:</strong> <select name="product">';
218 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC");
219 while ($product = $DB_sql->fetch_array($products))
220 {
221 echo "<option value=\"$product[productid]\">$product[title]</option>";
222 }
223 echo '</select>';
224 }
225 else if (!$vars['component'])
226 {
227 echo '<strong>Component:</strong> <select name="component"><option value="-1">No Component</option>';
228 $components = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE componentmother IN ($vars[product]) ORDER BY displayorder ASC");
229 while ($component = $DB_sql->fetch_array($components))
230 {
231 echo "<option value=\"$component[productid]\">$component[title]</option>";
232 }
233 echo '</select>';
234 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
235 }
236 else if (!$vars['version'])
237 {
238 echo '<strong>Version:</strong> <select name="version">';
239 $versions = $DB_sql->query("
240 SELECT version.*, product.componentmother, product.title AS productname
241 FROM " . TABLE_PREFIX . "version AS version
242 LEFT JOIN " . TABLE_PREFIX . "product ON (product.productid = version.productid)
243 WHERE version.productid IN (0, $vars[product]" . iff($vars['component'] != -1, ", $vars[component]", '') . ")
244 ORDER BY version.productid, version.displayorder ASC"
245 );
246
247 while ($version = $DB_sql->fetch_array($versions))
248 {
249 $versionlist["$version[productid]"][] = $version;
250 $lookup["$version[productid]"] = array('componentmother' => $version['componentmother'], 'productname' => $version['productname']);
251 }
252
253 foreach ($versionlist AS $productid => $versions)
254 {
255 $prepend = '-- ';
256 // global version
257 if ($productid == 0)
258 {
259 echo '<optgroup label="Global Versions">';
260 }
261 // component
262 else if ($lookup["$productid"]['componentmother'])
263 {
264 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
265 }
266 else
267 {
268 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
269 }
270
271 foreach ($versions AS $version)
272 {
273 echo '<option value="' . $version['versionid'] . '">' . $prepend . $version['version'] . '</option>';
274 }
275
276 echo '</optgroup>';
277 }
278
279 echo '</select>';
280 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
281 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
282 $do = 'updateproduct';
283 }
284
285 echo '<input type="hidden" name="bugid" value="' . $bug['bugid'] . '" />';
286 echo '<div><input type="hidden" name="do" value="' . $do . '" /><input type="submit" name="submit" value="Change Product and Version Information" /></div>';
287 echo '</form>';
288 }
289
290 /*=====================================================================*\
291 || ###################################################################
292 || # $HeadURL$
293 || # $Id$
294 || ###################################################################
295 \*=====================================================================*/
296 ?>