r28: Added links to bug report after performing an action.
[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 (!can_perform('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 (!can_perform('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 (!can_perform('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']) AND $version['productid'] != 0)
126 {
127 echo 'invalid version specified';
128 exit;
129 }
130 }
131 else
132 {
133 echo 'invalid component specified';
134 exit;
135 }
136 }
137
138 $vars['comment_parsed'] = $vars['comment'];
139
140 if (!$bugsys->options['allowhtml'])
141 {
142 $vars['comment_parsed'] = htmlspecialcharslike($vars['comment_parsed']);
143 }
144
145 // create the bug report
146 $DB_sql->query("
147 INSERT INTO " . TABLE_PREFIX . "bug
148 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
149 VALUES
150 (" . $bugsys->userinfo['userid'] . ", $vars[product], $vars[component], $vars[version],
151 '" . addslasheslike($vars['summary']) . "', $vars[severity], $vars[priority], $vars[status], $vars[assignedto], $vars[resolution]
152 )"
153 );
154
155 $bugid = $DB_sql->insert_id();
156
157 $time = time();
158
159 // insert the comment to the database
160 $DB_sql->query("
161 INSERT INTO " . TABLE_PREFIX . "comment
162 (bugid, userid, dateline, comment, comment_parsed)
163 VALUES
164 ($bugid, " . $bugsys->userinfo['userid'] . ",
165 $time, '" . addslasheslike($vars['comment']) . "',
166 '" . addslasheslike(nl2br($vars['comment_parsed'])) . "'
167 )"
168 );
169
170 $initialreport = $DB_sql->insert_id();
171
172 $DB_sql->query("UPDATE " . TABLE_PREFIX . "bug SET dateline = $time, initialreport = $initialreport, lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bugid");
173
174 echo "<a href=\"showreport.php?bugid=$bugid\">bug is done!</a>";
175 }
176
177 // ###################################################################
178
179 if ($_REQUEST['do'] == 'add')
180 {
181 sanitize(array(
182 'product' => INT,
183 'component' => INT,
184 'version' => INT)
185 );
186
187 // the user can hit the back button without reposting data...
188 if (!$vars['product'] OR !$vars['component'] OR !$vars['version'])
189 {
190 $method = 'get';
191 }
192 else
193 {
194 $method = 'post';
195 }
196
197 echo '<form name="newbug" action="newreport.php" method="' . $method . '">';
198
199 $do = 'add';
200
201 if (!$vars['product'])
202 {
203 echo '<strong>Product:</strong> <select name="product">';
204 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE !componentmother ORDER BY displayorder ASC");
205 while ($product = $DB_sql->fetch_array($products))
206 {
207 echo "<option value=\"$product[productid]\">$product[title]</option>";
208 }
209 echo '</select>';
210 }
211 else if (!$vars['component'])
212 {
213 echo '<strong>Component:</strong> <select name="component"><option value="-1">No Component</option>';
214 $components = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE componentmother IN ($vars[product]) ORDER BY displayorder ASC");
215 while ($component = $DB_sql->fetch_array($components))
216 {
217 echo "<option value=\"$component[productid]\">$component[title]</option>";
218 }
219 echo '</select>';
220 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
221 }
222 else if (!$vars['version'])
223 {
224 echo '<strong>Version:</strong> <select name="version">';
225 $versions = $DB_sql->query("
226 SELECT version.*, product.componentmother, product.title AS productname
227 FROM " . TABLE_PREFIX . "version AS version
228 LEFT JOIN " . TABLE_PREFIX . "product ON (product.productid = version.productid)
229 WHERE version.productid IN (0, $vars[product]" . iff($vars['component'] != -1, ", $vars[component]", '') . ")
230 ORDER BY version.productid, version.displayorder ASC"
231 );
232
233 while ($version = $DB_sql->fetch_array($versions))
234 {
235 $versionlist["$version[productid]"][] = $version;
236 $lookup["$version[productid]"] = array('componentmother' => $version['componentmother'], 'productname' => $version['productname']);
237 }
238
239 foreach ($versionlist AS $productid => $versions)
240 {
241 $prepend = '-- ';
242 // global version
243 if ($productid == 0)
244 {
245 echo '<optgroup label="Global Versions">';
246 }
247 // component
248 else if ($lookup["$productid"]['componentmother'])
249 {
250 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
251 }
252 else
253 {
254 echo '<optgroup label="' . $lookup["$productid"]['productname'] . '">';
255 }
256
257 foreach ($versions AS $version)
258 {
259 echo '<option value="' . $version['versionid'] . '">' . $prepend . $version['version'] . '</option>';
260 }
261
262 echo '</optgroup>';
263 }
264
265 echo '</select>';
266 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
267 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
268 }
269 else
270 {
271 $do = 'insert';
272 echo '<div><strong>Summary/Title:</strong> <input type="text" name="summary" size="25" /></div>';
273
274 echo '<div><strong>Severity:</strong> <select name="severity">';
275 foreach ($bugsys->datastore['severity'] AS $severity)
276 {
277 echo '<option value="' . $severity['severityid'] . '">' . $severity['severity'] . '</option>';
278 }
279 echo '</select></div>';
280
281 if (can_perform('canchangestatus'))
282 {
283 echo '<div><strong>Priority:</strong> <select name="priority">';
284 foreach ($bugsys->datastore['priority'] AS $priority)
285 {
286 echo '<option value="' . $priority['priorityid'] . '">' . $priority['priority'] . '</option>';
287 }
288 echo '</select></div>';
289
290 echo '<div><strong>Status:</strong> <select name="status">';
291 foreach ($bugsys->datastore['status'] AS $status)
292 {
293 echo '<option value="' . $status['statusid'] . '">' . $status['status'] . '</option>';
294 }
295 echo '</select></div>';
296
297 echo '<div><strong>Resolution:</strong> <select name="resolution">';
298 foreach ($bugsys->datastore['resolution'] AS $resolution)
299 {
300 echo '<option value="' . $resolution['resolutionid'] . '">' . $resolution['resolution'] . '</option>';
301 }
302 echo '</select></div>';
303 }
304
305 if (can_perform('canassign'))
306 {
307 echo '<div><strong>Assigned to:</strong> <select name="assignedto"><option value="0">No Assignment</option>';
308 foreach ($bugsys->datastore['assignto'] AS $dev)
309 {
310 echo '<option value="' . $dev['userid'] . '">' . construct_user_display($dev, false) . '</option>';
311 }
312 echo '</select></div>';
313 }
314
315 echo '<div><strong>Detailed description:</strong><div><textarea name="comment" rows="15" cols="75"></textarea></div></div>';
316
317 echo '<input type="hidden" name="product" value="' . $vars['product'] . '" />';
318 echo '<input type="hidden" name="component" value="' . $vars['component'] . '" />';
319 echo '<input type="hidden" name="version" value="' . $vars['version'] . '" />';
320 }
321
322 echo '<div><input type="hidden" name="do" value="' . $do . '" /><input type="submit" name="submit" value=" Proceed " /></div>';
323
324 echo '</form>';
325 }
326
327 /*=====================================================================*\
328 || ###################################################################
329 || # $HeadURL$
330 || # $Id$
331 || ###################################################################
332 \*=====================================================================*/
333 ?>