r765: Say hello to the GPL
[bugdar.git] / newreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'newreport',
24 );
25
26 define('SVN', '$Id$');
27
28 $focus['newreport'] = 'focus';
29
30 require_once('./global.php');
31 require_once('./includes/functions_product.php');
32
33 if (!can_perform('cansubmitbugs', intval($bugsys->in['productid'])))
34 {
35 $message->error_permission();
36 }
37
38 // ###################################################################
39
40 if (empty($_REQUEST['do']))
41 {
42 $_REQUEST['do'] = 'add';
43 }
44
45 // ###################################################################
46
47 if ($_POST['do'] == 'insert')
48 {
49 // -------------------------------------------------------------------
50 // check permissions on various input values
51 if (!can_perform('canchangestatus', intval($bugsys->in['productid'])))
52 {
53 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
54 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
55 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
56 }
57 else
58 {
59 if (!$bugsys->datastore['priority'][ $bugsys->in['priority'] ])
60 {
61 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
62 }
63 if (!$bugsys->datastore['status'][ $bugsys->in['status'] ])
64 {
65 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
66 }
67 if (!$bugsys->datastore['resolution'][ $bugsys->in['resolution'] ])
68 {
69 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
70 }
71 }
72 if (!can_perform('canassign', intval($bugsys->in['productid'])))
73 {
74 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
75 }
76 else
77 {
78 // assigned person is not a dev or a valid user
79 if (!$bugsys->datastore['assignto'][ $bugsys->in['assignedto'] ]['userid'])
80 {
81 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
82 }
83 }
84
85 // -------------------------------------------------------------------
86 // product/component/version stuff
87 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
88
89 // -------------------------------------------------------------------
90 // sanity checks
91 if (!$pcv)
92 {
93 $message->items[] = $lang->string('Invalid product/component/version selected.');
94 }
95 if (!$bugsys->in['summary'])
96 {
97 $message->items[] = $lang->string('Please enter a title for the bug');
98 }
99 if (!$bugsys->in['comment'])
100 {
101 $message->items[] = $lang->string('Please fill in the bug\'s description field');
102 }
103
104 if (!$message->items)
105 {
106 // -------------------------------------------------------------------
107 // data clean and insert
108 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
109
110 if (!$bugsys->options['allowhtml'])
111 {
112 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
113 }
114
115 // create the bug report
116 $db->query("
117 INSERT INTO " . TABLE_PREFIX . "bug
118 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
119 VALUES
120 (" . $bugsys->userinfo['userid'] . ", " . $pcv['product'] . ", " . $pcv['component'] . ", " . $pcv['version'] . ",
121 '" . $bugsys->in['summary'] . "', " . intval($bugsys->in['severity']) . ", " . intval($bugsys->in['priority']) . ",
122 " . intval($bugsys->in['status']) . ", " . intval($bugsys->in['assignedto']) . ", " . intval($bugsys->in['resolution']) . "
123 )"
124 );
125
126 $bugid = $db->insert_id();
127
128 $time = TIMENOW;
129
130 // insert the comment to the database
131 $db->query("
132 INSERT INTO " . TABLE_PREFIX . "comment
133 (bugid, userid, dateline, comment, comment_parsed)
134 VALUES
135 ($bugid, " . $bugsys->userinfo['userid'] . ",
136 $time, '" . $bugsys->in['comment'] . "',
137 '" . nl2br($bugsys->in['comment_parsed']) . "'
138 )"
139 );
140
141 $initialreport = $db->insert_id();
142
143 $db->query("
144 UPDATE " . TABLE_PREFIX . "bug
145 SET dateline = $time,
146 initialreport = $initialreport,
147 lastposttime = $time,
148 lastpostby = " . $bugsys->userinfo['userid'] . ",
149 hiddenlastposttime = $time,
150 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
151 WHERE bugid = $bugid"
152 );
153
154 $db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES ($bugid, 0, 0)");
155
156 $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=$bugid" : 'newreport.php'));
157 }
158 else
159 {
160 $show['errors'] = true;
161 $_REQUEST['do'] = 'add';
162 $message->error_list_process();
163 }
164 }
165
166 // ###################################################################
167
168 if ($_REQUEST['do'] == 'add')
169 {
170 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
171
172 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
173
174 if (can_perform('canchangestatus'))
175 {
176 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
177 $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
178 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
179 }
180
181 $show['assign'] = ((can_perform('canassign')) ? true : false);
182
183 if (can_perform('canassign'))
184 {
185 foreach ($bugsys->datastore['assignto'] AS $dev)
186 {
187 $value = $dev['userid'];
188 $label = construct_user_display($dev, false);
189 $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
190 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
191 }
192 }
193
194 // custom fields
195 $fields = construct_custom_fields(null, true);
196 $i = 0;
197 foreach ($fields AS $field)
198 {
199 if ($i % 2 == 0)
200 {
201 $customfields['left'] .= $field;
202 }
203 else
204 {
205 $customfields['right'] .= $field;
206 }
207 $i++;
208 }
209
210 $pcv_select = construct_pcv_select('cansubmitbugs', $bugsys->in['pcv_select']);
211
212 $reporter = construct_user_display($bugsys->userinfo);
213
214 eval('$template->flush("' . $template->fetch('newreport') . '");');
215 }
216
217 /*=====================================================================*\
218 || ###################################################################
219 || # $HeadURL$
220 || # $Id$
221 || ###################################################################
222 \*=====================================================================*/
223 ?>