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