r11: Basic bug reporting (new bug only) is done :-).
[bugdar.git] / newreport.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 if (!($bugsys->userinfo['permissions'] & CANSUBMITBUGS))
16 {
17 echo 'NO permission';
18 exit;
19 }
20
21 // ###################################################################
22
23 if (empty($_REQUEST['do']))
24 {
25 $_REQUEST['do'] = 'add';
26 }
27
28 // ###################################################################
29
30 if ($_POST['do'] == 'insert')
31 {
32 sanitize(array(
33 'product' => INT,
34 'component' => INT,
35 'version' => INT,
36 'summary' => STR_NOHTML,
37 'severity' => INT,
38 'priority' => INT,
39 'status' => INT,
40 'resolution' => INT,
41 'assignedto' => INT,
42 'comment' => STR)
43 );
44
45 // check permissions on various input values
46 if (!($bugsys->userinfo['permissions'] & CANCHANGESTATUS))
47 {
48 $vars['priority'] = $bugsys->options['defaultpriority'];
49 $vars['status'] = $bugsys->options['defaultstatus'];
50 $vars['resolution'] = $bugsys->options['defaultresolve'];
51 }
52 else
53 {
54 if (!$bugsys->datastore['priority']["$vars[priority]"])
55 {
56 $vars['priority'] = $bugsys->options['defaultpriority'];
57 }
58 if (!$bugsys->datastore['status']["$vars[status]"])
59 {
60 $vars['status'] = $bugsys->options['defaultstatus'];
61 }
62 if (!$bugsys->datastore['resolution']["$vars[resolution]"])
63 {
64 $vars['resolution'] = $bugsys->options['defaultresolve'];
65 }
66 }
67 if (!($bugsys->userinfo['permissions'] & CANASSIGN))
68 {
69 $vars['assignedto'] = $bugsys->options['defaultassign'];
70 }
71 else
72 {
73 // assigned person is not a dev or a valid user
74 if (!$bugsys->datastore['assignto']["$vars[assignedto]"]['userid'])
75 {
76 $vars['assignedto'] = $bugsys->options['defaultassign'];
77 }
78 }
79
80 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
81 {
82 echo 'there was a problem selecting the product, component, or version';
83 exit;
84 }
85 if (!$vars['summary'])
86 {
87 echo 'please enter a bug title';
88 exit;
89 }
90 if (!$vars['comment'])
91 {
92 echo 'please enter a bug description';
93 exit;
94 }
95 $product = $bugsys->datastore['product']["$vars[product]"];
96 if (!$product)
97 {
98 echo 'please select a valid product';
99 exit;
100 }
101 $version = $bugsys->datastore['version']["$vars[version]"];
102 if (!$version)
103 {
104 echo 'please select a valid version';
105 exit;
106 }
107 // no component
108 if ($vars['component'] == -1)
109 {
110 // not global version and version.productid != product.productid
111 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
112 {
113 echo 'invalid version specified';
114 exit;
115 }
116 }
117 // using a component
118 else
119 {
120 $component = $bugsys->datastore['product']["$vars[component]"];
121 // component has the right mother
122 if ($component['componentmother'] == $product['productid'])
123 {
124 // version.productid != {component.productid | product.productid}
125 if ($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid'])
126 {
127 echo 'invalid version specified';
128 exit;
129 }
130 }
131 else
132 {
133 echo 'invalid component specified';
134 exit;
135 }
136 }
137
138 if (!$bugsys->options['allowhtml'])
139 {
140 $vars['comment'] = htmlspecialcharslike($vars['comment']);
141 }
142
143 // create the bug report
144 $DB_sql->query("
145 INSERT INTO " . TABLE_PREFIX . "bug
146 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto)
147 VALUES
148 (" . $bugsys->userinfo['userid'] . ", $vars[product], $vars[component], $vars[version],
149 '" . addslasheslike($vars['summary']) . "', $vars[severity], $vars[priority], $vars[status], $vars[assignedto]
150 )"
151 );
152
153 $bugid = $DB_sql->insert_id();
154
155 // insert the comment to the database
156 $DB_sql->query("
157 INSERT INTO " . TABLE_PREFIX . "comment
158 (bugid, userid, dateline, comment ## comment_parsed -- not using, ATM ###
159 )
160 VALUES
161 ($bugid, " . $bugsys->userinfo['userid'] . ",
162 " . time() . ", '" . addslasheslike($vars['comment']) . "'
163 )"
164 );
165
166 echo 'bug is done!';
167 }
168
169 // ###################################################################
170
171 if ($_REQUEST['do'] == 'add')
172 {
173 sanitize(array(
174 'product' => INT,
175 'component' => INT,
176 'version' => INT)
177 );
178
179 // the user can hit the back button without reposting data...
180 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
181 {
182 $method = 'get';
183 }
184 else
185 {
186 $method = 'post';
187 }
188
189 echo '<form name="newbug" action="newreport.php" method="' . $method . '">';
190
191 $do = 'add';
192
193 if (!$vars['product'])
194 {
195 echo '<strong>Product:</strong> <select name="product">';
196 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC");
197 while ($product = $DB_sql->fetch_array($products))
198 {
199 echo "<option value=\"$product[productid]\">$product[title]</option>";
200 }
201 echo '</select>';
202 }
203 else if (!$vars['component'])
204 {
205 echo '<strong>Component:</strong> <select name="component"><option value="-1">No Component</option>';
206 $components = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE componentmother IN ($vars[product]) ORDER BY displayorder ASC");
207 while ($component = $DB_sql->fetch_array($components))
208 {
209 echo "<option value=\"$component[productid]\">$component[title]</option>";
210 }
211 echo '</select>';
212 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
213 }
214 else if (!$vars['version'])
215 {
216 echo '<strong>Version:</strong> <select name="version">';
217 $versions = $DB_sql->query("
218 SELECT version.*, product.componentmother, product.title AS productname
219 FROM " . TABLE_PREFIX . "version AS version
220 LEFT JOIN " . TABLE_PREFIX . "product ON (product.productid = version.productid)
221 WHERE version.productid IN (0, $vars[product]" . iff($vars['component'] != -1, ", $vars[component]", '') . ")
222 ORDER BY version.productid, version.displayorder ASC"
223 );
224
225 while ($version = $DB_sql->fetch_array($versions))
226 {
227 $versionlist["$version[productid]"][] = $version;
228 $lookup["$version[productid]"] = array('componentmother' => $version['componentmother'], 'productname' => $version['productname']);
229 }
230
231 foreach ($versionlist AS $productid => $versions)
232 {
233 $prepend = '-- ';
234 // global version
235 if ($productid == 0)
236 {
237 echo '<optgroup label="Global Versions">';
238 }
239 // component
240 else if ($lookup["$productid"]['componentmother'])
241 {
242 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
243 }
244 else
245 {
246 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
247 }
248
249 foreach ($versions AS $version)
250 {
251 echo '<option value="' . $version['versionid'] . '">' . $prepend . $version['version'] . '</option>';
252 }
253
254 echo '</optgroup>';
255 }
256
257 echo '</select>';
258 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
259 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
260 }
261 else
262 {
263 $do = 'insert';
264 echo '<div><strong>Summary/Title:</strong> <input type="text" name="summary" size="25" /></div>';
265
266 echo '<div><strong>Severity:</strong> <select name="severity">';
267 foreach ($bugsys->datastore['severity'] AS $severity)
268 {
269 echo '<option value="' . $severity['severityid'] . '">' . $severity['severity'] . '</option>';
270 }
271 echo '</select></div>';
272
273 if ($bugsys->userinfo['permissions'] & CANCHANGESTATUS)
274 {
275 echo '<div><strong>Priority:</strong> <select name="priority">';
276 foreach ($bugsys->datastore['priority'] AS $priority)
277 {
278 echo '<option value="' . $priority['priorityid'] . '">' . $priority['priority'] . '</option>';
279 }
280 echo '</select></div>';
281
282 echo '<div><strong>Status:</strong> <select name="status">';
283 foreach ($bugsys->datastore['status'] AS $status)
284 {
285 echo '<option value="' . $status['statusid'] . '">' . $status['status'] . '</option>';
286 }
287 echo '</select></div>';
288
289 echo '<div><strong>Resolution:</strong> <select name="resolution">';
290 foreach ($bugsys->datastore['resolution'] AS $resolution)
291 {
292 echo '<option value="' . $resolution['resolutionid'] . '">' . $resolution['resolution'] . '</option>';
293 }
294 echo '</select></div>';
295 }
296
297 if ($bugsys->userinfo['permissions'] & CANASSIGN)
298 {
299 echo '<div><strong>Assigned to:</strong> <select name="assignedto"><option value="0">No Assignment</option>';
300 foreach ($bugsys->datastore['assignto'] AS $dev)
301 {
302 fetch_user_display_name($dev);
303 echo '<option value="' . $dev['userid'] . '">' . $dev['displayname'] . iff($dev['showemail'], ' <' . $dev['email'] . '>', '') . '</option>';
304 }
305 echo '</select></div>';
306 }
307
308 echo '<div><strong>Detailed description:</strong><div><textarea name="comment" rows="15" cols="75"></textarea></div></div>';
309
310 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
311 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
312 echo '<input type="hidden" name="version" value="' . $vars['version'] . '" />';
313 }
314
315 echo '<div><input type="hidden" name="do" value="' . $do . '" /><input type="submit" name="submit" value=" Proceed " /></div>';
316
317 echo '</form>';
318 }
319
320 /*=====================================================================*\
321 || ###################################################################
322 || # $HeadURL$
323 || # $Id$
324 || ###################################################################
325 \*=====================================================================*/
326 ?>