r52: Fixed bug in includes/functions.php with construct_pcv_select() that didn't...
[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 'pcv_select' => STR,
39 'summary' => STR_NOHTML,
40 'severity' => INT,
41 'priority' => INT,
42 'status' => INT,
43 'resolution' => INT,
44 'assignedto' => INT,
45 'comment' => STR)
46 );
47
48 // -------------------------------------------------------------------
49 // check permissions on various input values
50 if (!can_perform('canchangestatus'))
51 {
52 $vars['priority'] = $bugsys->options['defaultpriority'];
53 $vars['status'] = $bugsys->options['defaultstatus'];
54 $vars['resolution'] = $bugsys->options['defaultresolve'];
55 }
56 else
57 {
58 if (!$bugsys->datastore['priority']["$vars[priority]"])
59 {
60 $vars['priority'] = $bugsys->options['defaultpriority'];
61 }
62 if (!$bugsys->datastore['status']["$vars[status]"])
63 {
64 $vars['status'] = $bugsys->options['defaultstatus'];
65 }
66 if (!$bugsys->datastore['resolution']["$vars[resolution]"])
67 {
68 $vars['resolution'] = $bugsys->options['defaultresolve'];
69 }
70 }
71 if (!can_perform('canassign'))
72 {
73 $vars['assignedto'] = $bugsys->options['defaultassign'];
74 }
75 else
76 {
77 // assigned person is not a dev or a valid user
78 if (!$bugsys->datastore['assignto']["$vars[assignedto]"]['userid'])
79 {
80 $vars['assignedto'] = $bugsys->options['defaultassign'];
81 }
82 }
83
84 // -------------------------------------------------------------------
85 // product/component/version stuff
86 $vars['pcv'] = parse_pcv_select($vars['pcv_select']);
87
88 print_r($vars);
89
90 // -------------------------------------------------------------------
91 // sanity checks
92 if (!is_array($vars['pcv']))
93 {
94 echo 'there was a problem selecting the product, component, or version';
95 exit;
96 }
97 if (!$vars['summary'])
98 {
99 echo 'please enter a bug title';
100 exit;
101 }
102 if (!$vars['comment'])
103 {
104 echo 'please enter a bug description';
105 exit;
106 }
107
108 // -------------------------------------------------------------------
109 // pcv validation
110 $product = $bugsys->datastore['product'][ $vars['pcv']['product'] ];
111 if (!$product)
112 {
113 echo 'please select a valid product';
114 exit;
115 }
116 $version = $bugsys->datastore['version'][ $vars['pcv']['version'] ];
117 if (!$version)
118 {
119 echo 'please select a valid version';
120 exit;
121 }
122 // no component
123 if ($vars['pcv']['component'] == 0)
124 {
125 // not global version and version.productid != product.productid
126 if ($version['productid'] != 0 AND $version['productid'] != $product['productid'])
127 {
128 echo 'invalid version specified';
129 exit;
130 }
131 }
132 // using a component
133 else
134 {
135 $component = $bugsys->datastore['product'][ $vars['pcv']['component'] ];
136 // component has the right mother
137 if ($component['componentmother'] == $product['productid'])
138 {
139 // version.productid != {component.productid | product.productid}
140 if (($version['productid'] != $component['productid'] AND $version['productid'] != $product['productid']) AND $version['productid'] != 0)
141 {
142 echo 'invalid version specified';
143 exit;
144 }
145 }
146 else
147 {
148 echo 'invalid component specified';
149 exit;
150 }
151 }
152
153 // -------------------------------------------------------------------
154 // data clean and insert
155 $vars['comment_parsed'] = $vars['comment'];
156
157 if (!$bugsys->options['allowhtml'])
158 {
159 $vars['comment_parsed'] = htmlspecialcharslike($vars['comment_parsed']);
160 }
161
162 // create the bug report
163 $DB_sql->query("
164 INSERT INTO " . TABLE_PREFIX . "bug
165 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
166 VALUES
167 (" . $bugsys->userinfo['userid'] . ", " . $vars['pcv']['product'] . ", " . $vars['pcv']['component'] . ", " . $vars['pcv']['version'] . ",
168 '" . addslasheslike($vars['summary']) . "', $vars[severity], $vars[priority], $vars[status], $vars[assignedto], $vars[resolution]
169 )"
170 );
171
172 $bugid = $DB_sql->insert_id();
173
174 $time = time();
175
176 // insert the comment to the database
177 $DB_sql->query("
178 INSERT INTO " . TABLE_PREFIX . "comment
179 (bugid, userid, dateline, comment, comment_parsed)
180 VALUES
181 ($bugid, " . $bugsys->userinfo['userid'] . ",
182 $time, '" . addslasheslike($vars['comment']) . "',
183 '" . addslasheslike(nl2br($vars['comment_parsed'])) . "'
184 )"
185 );
186
187 $initialreport = $DB_sql->insert_id();
188
189 $DB_sql->query("UPDATE " . TABLE_PREFIX . "bug SET dateline = $time, initialreport = $initialreport, lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bugid");
190
191 echo "<a href=\"showreport.php?bugid=$bugid\">bug is done!</a>";
192 }
193
194 // ###################################################################
195
196 if ($_REQUEST['do'] == 'add')
197 {
198 foreach ($bugsys->datastore['severity'] AS $severity)
199 {
200 $value = $severity['severityid'];
201 $label = $severity['severity'];
202 eval('$select[severity] .= "' . $tpl->fetch('selectoption') . '";');
203 }
204
205 $show['changestatus'] = iff(can_perform('canchangestatus'), true, false);
206
207 if (can_perform('canchangestatus'))
208 {
209 foreach ($bugsys->datastore['priority'] AS $priority)
210 {
211 $value = $priority['priorityid'];
212 $label = $priority['priority'];
213 eval('$select[priority] .= "' . $tpl->fetch('selectoption') . '";');
214 }
215
216 foreach ($bugsys->datastore['status'] AS $status)
217 {
218 $value = $status['statusid'];
219 $label = $status['status'];
220 eval('$select[status] .= "' . $tpl->fetch('selectoption') . '";');
221 }
222
223 foreach ($bugsys->datastore['resolution'] AS $resolution)
224 {
225 $value = $resolution['resolutionid'];
226 $label = $resolution['resolution'];
227 eval('$select[resolution] .= "' . $tpl->fetch('selectoption') . '";');
228 }
229 }
230
231 $show['assign'] = iff(can_perform('canassign'), true, false);
232
233 if (can_perform('canassign'))
234 {
235 foreach ($bugsys->datastore['assignto'] AS $dev)
236 {
237 $value = $dev['userid'];
238 $label = construct_user_display($dev, false);
239 eval('$select[dev] .= "' . $tpl->fetch('selectoption') . '";');
240 }
241 }
242
243 $pcv_select = construct_pcv_select();
244
245 eval('$tpl->flush("' . $tpl->fetch('newreport') . '");');
246 }
247
248 /*=====================================================================*\
249 || ###################################################################
250 || # $HeadURL$
251 || # $Id$
252 || ###################################################################
253 \*=====================================================================*/
254 ?>