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