r33: Named product Renapsus.
[bugdar.git] / editreport.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Renapsus [#]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 if ($vars['changeproduct'])
82 {
83 $_REQUEST['do'] = 'editproduct';
84 }
85 else
86 {
87 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">done with update bug</a>";
88 }
89 }
90
91 // ###################################################################
92
93 if ($_REQUEST['do'] == 'edit')
94 {
95 echo '<form name="editreport" action="editreport.php" method="post">';
96 echo '<input type="hidden" name="do" value="update" /><input type="hidden" name="bugid" value="' . $bug['bugid'] . '" />';
97 echo "<div><strong>Bug ID:</strong> $bug[bugid]</div>";
98 echo "<div><strong>Summary/title:</strong> <input type=\"text\" name=\"summary\" value=\"$bug[summary]\" size=\"35\" />";
99 if (can_perform('canchangestatus'))
100 {
101 echo '<div><strong>Priority:</strong> <select name="priority">';
102 foreach ($bugsys->datastore['priority'] AS $priority)
103 {
104 echo '<option value="' . $priority['priorityid'] . '"' . iff($priority['priorityid'] == $bug['priority'], ' selected="selected"') . '>' . $priority['priority'] . '</option>';
105 }
106 echo '</select></div>';
107
108 echo '<div><strong>Status:</strong> <select name="status">';
109 foreach ($bugsys->datastore['status'] AS $status)
110 {
111 echo '<option value="' . $status['statusid'] . '"' . iff($status['statusid'] == $bug['status'], ' selected="selected"') . '>' . $status['status'] . '</option>';
112 }
113 echo '</select></div>';
114
115 echo '<div><strong>Resolution:</strong> <select name="resolution">';
116 foreach ($bugsys->datastore['resolution'] AS $resolution)
117 {
118 echo '<option value="' . $resolution['resolutionid'] . '"' . iff($resolution['resolutionid'] == $bug['resolution'], ' selected="selected"') . '>' . $resolution['resolution'] . '</option>';
119 }
120 echo '</select></div>';
121 }
122 if (can_perform('canassign'))
123 {
124 echo '<div><strong>Assigned to:</strong> <select name="assignedto"><option value="0"' . iff(!$bug['assignedto'], ' selected="selected"') . '>No Assignment</option>';
125 foreach ($bugsys->datastore['assignto'] AS $dev)
126 {
127 echo '<option value="' . $dev['userid'] . '"' . iff($dev['userid'] == $bug['assignedto'], ' selected="selected"') . '>' . construct_user_display($dev, false) . '</option>';
128 }
129 echo '</select></div>';
130 }
131 echo '<div><input type="submit" name="changeproduct" value="Change Product and Version Information" />';
132 echo '<div><input type="submit" name="submit" value="Save Changes" /></div></form>';
133 }
134
135 // ###################################################################
136
137 if ($_POST['do'] == 'updateproduct')
138 {
139 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
140
141 var_dump($vars);
142
143 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
144 {
145 echo 'there was a problem selecting the product, component, or version';
146 exit;
147 }
148 $product = $bugsys->datastore['product']["$vars[product]"];
149 if (!$product)
150 {
151 echo 'please select a valid product';
152 exit;
153 }
154 $version = $bugsys->datastore['version']["$vars[version]"];
155 if (!$version)
156 {
157 echo 'please select a valid version';
158 exit;
159 }
160 // no component
161 if ($vars['component'] == -1)
162 {
163 // not global version and version.productid != product.productid
164 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
165 {
166 echo 'invalid version specified';
167 exit;
168 }
169 }
170 // using a component
171 else
172 {
173 $component = $bugsys->datastore['product']["$vars[component]"];
174 // component has the right mother
175 if ($component['componentmother'] == $product['productid'])
176 {
177 // version.productid != {component.productid | product.productid}
178 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
179 {
180 echo 'invalid version specified';
181 exit;
182 }
183 }
184 else
185 {
186 echo 'invalid component specified';
187 exit;
188 }
189 }
190
191 // good-to-go
192 $DB_sql->query("UPDATE " . TABLE_PREFIX . "bug SET productid = $vars[product], componentid = $vars[component], versionid = $vars[version] WHERE bugid = $bug[bugid]");
193
194 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">changed product info</a>";
195 }
196
197 // ###################################################################
198
199 if ($_REQUEST['do'] == 'editproduct')
200 {
201 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
202
203 // the user can hit the back button without reposting data...
204 if (!$vars['product'] OR !$vars['component'])
205 {
206 $method = 'get';
207 }
208 else
209 {
210 $method = 'post';
211 }
212
213 echo '<form name="newbug" action="editreport.php" method="' . $method . '">';
214
215 $do = 'editproduct';
216
217 if (!$vars['product'])
218 {
219 echo '<strong>Product:</strong> <select name="product">';
220 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC");
221 while ($product = $DB_sql->fetch_array($products))
222 {
223 echo "<option value=\"$product[productid]\">$product[title]</option>";
224 }
225 echo '</select>';
226 }
227 else if (!$vars['component'])
228 {
229 echo '<strong>Component:</strong> <select name="component"><option value="-1">No Component</option>';
230 $components = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE componentmother IN ($vars[product]) ORDER BY displayorder ASC");
231 while ($component = $DB_sql->fetch_array($components))
232 {
233 echo "<option value=\"$component[productid]\">$component[title]</option>";
234 }
235 echo '</select>';
236 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
237 }
238 else if (!$vars['version'])
239 {
240 echo '<strong>Version:</strong> <select name="version">';
241 $versions = $DB_sql->query("
242 SELECT version.*, product.componentmother, product.title AS productname
243 FROM " . TABLE_PREFIX . "version AS version
244 LEFT JOIN " . TABLE_PREFIX . "product ON (product.productid = version.productid)
245 WHERE version.productid IN (0, $vars[product]" . iff($vars['component'] != -1, ", $vars[component]", '') . ")
246 ORDER BY version.productid, version.displayorder ASC"
247 );
248
249 while ($version = $DB_sql->fetch_array($versions))
250 {
251 $versionlist["$version[productid]"][] = $version;
252 $lookup["$version[productid]"] = array('componentmother' => $version['componentmother'], 'productname' => $version['productname']);
253 }
254
255 foreach ($versionlist AS $productid => $versions)
256 {
257 $prepend = '-- ';
258 // global version
259 if ($productid == 0)
260 {
261 echo '<optgroup label="Global Versions">';
262 }
263 // component
264 else if ($lookup["$productid"]['componentmother'])
265 {
266 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
267 }
268 else
269 {
270 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
271 }
272
273 foreach ($versions AS $version)
274 {
275 echo '<option value="' . $version['versionid'] . '">' . $prepend . $version['version'] . '</option>';
276 }
277
278 echo '</optgroup>';
279 }
280
281 echo '</select>';
282 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
283 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
284 $do = 'updateproduct';
285 }
286
287 echo '<input type="hidden" name="bugid" value="' . $bug['bugid'] . '" />';
288 echo '<div><input type="hidden" name="do" value="' . $do . '" /><input type="submit" name="submit" value="Change Product and Version Information" /></div>';
289 echo '</form>';
290 }
291
292 /*=====================================================================*\
293 || ###################################################################
294 || # $HeadURL$
295 || # $Id$
296 || ###################################################################
297 \*=====================================================================*/
298 ?>