r35: Presentation code moved out of PHP files and into templates. Error and stop...
[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 $fetchtemplates = array(
14 'editreport',
15 'productselect'
16 );
17
18 require_once('./global.php');
19
20 sanitize(array('bugid' => INT));
21
22 $bug = $DB_sql->query_first("
23 SELECT bug.*, user.email, user.displayname, user.showemail
24 FROM " . TABLE_PREFIX . "bug AS bug
25 LEFT JOIN " . TABLE_PREFIX . "user AS user
26 ON (bug.userid = user.userid)
27 WHERE bug.bugid = $vars[bugid]"
28 );
29
30 if (!$bug)
31 {
32 echo 'alert: bad bug';
33 exit;
34 }
35
36 if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')))
37 {
38 echo 'no permission';
39 exit;
40 }
41
42 // ###################################################################
43
44 if (empty($_REQUEST['do']))
45 {
46 $_REQUEST['do'] = 'edit';
47 }
48
49 // ###################################################################
50 /*
51 #*# do these later once we have delete permissions figured out
52 if ($_REQUEST['do'] == 'kill')
53 {
54 // run code to remove item in database
55 }
56
57 // ###################################################################
58
59 if ($_REQUEST['do'] == 'delete')
60 {
61 // display delete confirmation message
62 }*/
63
64 // ###################################################################
65
66 if ($_POST['do'] == 'update')
67 {
68 sanitize(array(
69 'summary' => STR_NOHTML,
70 'priority' => INT,
71 'status' => INT,
72 'resolution' => INT,
73 'assignedto' => INT,
74 'changeproduct' => STR)
75 );
76
77 $DB_sql->query("
78 UPDATE " . TABLE_PREFIX . "bug
79 SET summary = '" . addslasheslike($vars['summary']) . "',
80 priority = $vars[priority], status = $vars[status],
81 resolution = $vars[resolution],
82 assignedto = $vars[assignedto]
83 WHERE bugid = $bug[bugid]"
84 );
85
86 if ($vars['changeproduct'])
87 {
88 $_REQUEST['do'] = 'editproduct';
89 }
90 else
91 {
92 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">done with update bug</a>";
93 }
94 }
95
96 // ###################################################################
97
98 if ($_REQUEST['do'] == 'edit')
99 {
100 foreach ($bugsys->datastore['severity'] AS $severity)
101 {
102 $value = $severity['severityid'];
103 $selected = iff($severity['severityid'] == $bug['severity'], true, false);
104 $label = $severity['severity'];
105 eval('$select[severity] .= "' . $tpl->fetch('selectoption') . '";');
106 }
107
108 $show['changestatus'] = iff(can_perform('canchangestatus'), true, false);
109 if (can_perform('canchangestatus'))
110 {
111 foreach ($bugsys->datastore['priority'] AS $priority)
112 {
113 $value = $priority['priorityid'];
114 $selected = iff($priority['priorityid'] == $bug['priority'], true, false);
115 $label = $priority['priority'];
116 eval('$select[priority] .= "' . $tpl->fetch('selectoption') . '";');
117 }
118
119 foreach ($bugsys->datastore['status'] AS $status)
120 {
121 $value = $status['statusid'];
122 $selected = iff($status['statusid'] == $bug['status'], true, false);
123 $label = $status['status'];
124 eval('$select[status] .= "' . $tpl->fetch('selectoption') . '";');
125 }
126
127 foreach ($bugsys->datastore['resolution'] AS $resolution)
128 {
129 $value = $resolution['resolutionid'];
130 $selected = iff($resolution['resolutionid'] == $bug['resolution'], true, false);
131 $label = $resolution['resolution'];
132 eval('$select[resolution] .= "' . $tpl->fetch('selectoption') . '";');
133 }
134 }
135
136 $show['assign'] = iff(can_perform('canassign'), true, false);
137 if (can_perform('canassign'))
138 {
139 foreach ($bugsys->datastore['assignto'] AS $dev)
140 {
141 $value = $dev['userid'];
142 $selected = iff($dev['userid'] == $bug['assignedto'], true, false);
143 $label = construct_user_display($dev, false);
144 eval('$select[dev] .= "' . $tpl->fetch('selectoption') . '";');
145 }
146 }
147
148 eval('$tpl->flush("' . $tpl->fetch('editreport') . '");');
149 }
150
151 // ###################################################################
152
153 if ($_POST['do'] == 'updateproduct')
154 {
155 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
156
157 var_dump($vars);
158
159 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
160 {
161 echo 'there was a problem selecting the product, component, or version';
162 exit;
163 }
164 $product = $bugsys->datastore['product']["$vars[product]"];
165 if (!$product)
166 {
167 echo 'please select a valid product';
168 exit;
169 }
170 $version = $bugsys->datastore['version']["$vars[version]"];
171 if (!$version)
172 {
173 echo 'please select a valid version';
174 exit;
175 }
176 // no component
177 if ($vars['component'] == -1)
178 {
179 // not global version and version.productid != product.productid
180 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
181 {
182 echo 'invalid version specified';
183 exit;
184 }
185 }
186 // using a component
187 else
188 {
189 $component = $bugsys->datastore['product']["$vars[component]"];
190 // component has the right mother
191 if ($component['componentmother'] == $product['productid'])
192 {
193 // version.productid != {component.productid | product.productid}
194 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
195 {
196 echo 'invalid version specified';
197 exit;
198 }
199 }
200 else
201 {
202 echo 'invalid component specified';
203 exit;
204 }
205 }
206
207 // good-to-go
208 $DB_sql->query("UPDATE " . TABLE_PREFIX . "bug SET productid = $vars[product], componentid = $vars[component], versionid = $vars[version] WHERE bugid = $bug[bugid]");
209
210 echo "<a href=\"showreport.php?bugid=$bug[bugid]\">changed product info</a>";
211 }
212
213 // ###################################################################
214
215 if ($_REQUEST['do'] == 'editproduct')
216 {
217 sanitize(array('product' => INT, 'component' => INT, 'version' => INT));
218
219 $select['do'] = 'editproduct';
220 $select['script'] = 'editreport';
221
222 if (!$vars['product'])
223 {
224 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC");
225 while ($product = $DB_sql->fetch_array($products))
226 {
227 $value = $product['productid'];
228 $selected = iff($product['productid'] == $bug['productid'], true, false);
229 $label = $product['title'];
230 eval('$select[options] .= "' . $tpl->fetch('selectoption') . '";');
231 }
232
233 $select['display'] = 'Product';
234 $select['name'] = 'product';
235 eval('$tpl->flush("' . $tpl->fetch('productselect') . '");');
236 }
237 else if (!$vars['component'])
238 {
239 $value = '-1';
240 $selected = iff($bug['componentid'] == -1, true, false);
241 $label = 'No Component';
242 eval('$select[options] .= "' . $tpl->fetch('selectoption') . '";');
243 $components = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE componentmother IN ($vars[product]) ORDER BY displayorder ASC");
244 while ($component = $DB_sql->fetch_array($components))
245 {
246 $value = $component['productid'];
247 $selected = iff($component['productid'] == $bug['componentid'], true, false);
248 $label = $component['title'];
249 eval('$select[options] .= "' . $tpl->fetch('selectoption') . '";');
250 }
251
252 $select['display'] = 'Component';
253 $select['name'] = 'component';
254 eval('$tpl->flush("' . $tpl->fetch('productselect') . '");');
255 }
256 else if (!$vars['version'])
257 {
258 $versions = $DB_sql->query("
259 SELECT version.*, product.componentmother, product.title AS productname
260 FROM " . TABLE_PREFIX . "version AS version
261 LEFT JOIN " . TABLE_PREFIX . "product ON (product.productid = version.productid)
262 WHERE version.productid IN (0, $vars[product]" . iff($vars['component'] != -1, ", $vars[component]", '') . ")
263 ORDER BY version.productid, version.displayorder ASC"
264 );
265
266 while ($version = $DB_sql->fetch_array($versions))
267 {
268 $versionlist["$version[productid]"][] = $version;
269 $lookup["$version[productid]"] = array('componentmother' => $version['componentmother'], 'productname' => $version['productname']);
270 }
271
272 foreach ($versionlist AS $productid => $versions)
273 {
274 $prepend = '-- ';
275 // global version
276 if ($productid == 0)
277 {
278 $glabel = 'Global Versions';
279 }
280 // component
281 else if ($lookup["$productid"]['componentmother'])
282 {
283 $glabel = $lookup["$productid"]['productname'];
284 }
285 else
286 {
287 $glabel = $lookup["$productid"]['productname'];
288 }
289
290 foreach ($versions AS $version)
291 {
292 $value = $version['versionid'];
293 $selected = iff($version['versionid'] == $bug['versionid'], true, false);
294 $label = $prepend . $version['version'];
295 eval('$optbits .= "' . $tpl->fetch('selectoption') . '";');
296 }
297 eval('$select[options] .= "' . $tpl->fetch('selectoptgroup') . '";');
298 $optbits = '';
299 }
300
301 $select['display'] = 'Version';
302 $select['name'] = 'version';
303 $select['do'] = 'updateproduct';
304 $select['method'] = 'post';
305
306 eval('$tpl->flush("' . $tpl->fetch('productselect') . '");');
307 }
308 }
309
310 /*=====================================================================*\
311 || ###################################################################
312 || # $HeadURL$
313 || # $Id$
314 || ###################################################################
315 \*=====================================================================*/
316 ?>