r794: Forgot to remove the comment insert query
[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 require_once('./includes/api_bug.php');
33 require_once('./includes/api_comment.php');
34
35 if (!can_perform('cansubmitbugs', intval($bugsys->in['productid'])))
36 {
37 $message->error_permission();
38 }
39
40 // ###################################################################
41
42 if (empty($_REQUEST['do']))
43 {
44 $_REQUEST['do'] = 'add';
45 }
46
47 // ###################################################################
48
49 if ($_POST['do'] == 'insert')
50 {
51 $bug = new BugAPI($bugsys);
52
53 // -------------------------------------------------------------------
54 // check permissions on various input values
55 if (!can_perform('canchangestatus', intval($bugsys->in['productid'])))
56 {
57 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
58 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
59 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
60 }
61 else
62 {
63 if (!$bugsys->datastore['priority'][ $bugsys->in['priority'] ])
64 {
65 $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
66 }
67 if (!$bugsys->datastore['status'][ $bugsys->in['status'] ])
68 {
69 $bugsys->in['status'] = $bugsys->options['defaultstatus'];
70 }
71 if (!$bugsys->datastore['resolution'][ $bugsys->in['resolution'] ])
72 {
73 $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
74 }
75 }
76 if (!can_perform('canassign', intval($bugsys->in['productid'])))
77 {
78 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
79 }
80 else
81 {
82 // assigned person is not a dev or a valid user
83 if (!$bugsys->datastore['assignto'][ $bugsys->in['assignedto'] ]['userid'])
84 {
85 $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
86 }
87 }
88
89 // -------------------------------------------------------------------
90 // product/component/version stuff
91 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
92
93 // -------------------------------------------------------------------
94 // sanity checks
95 if (!$pcv)
96 {
97 $message->items[] = $lang->string('Invalid product/component/version selected.');
98 }
99 if (!$bugsys->in['summary'])
100 {
101 $message->items[] = $lang->string('Please enter a title for the bug');
102 }
103 if (!$bugsys->in['comment'])
104 {
105 $message->items[] = $lang->string('Please fill in the bug\'s description field');
106 }
107
108 if (!$message->items)
109 {
110 // -------------------------------------------------------------------
111 // data clean and insert
112 $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
113
114 if (!$bugsys->options['allowhtml'])
115 {
116 $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
117 }
118
119 // create the bug report
120 $db->query("
121 INSERT INTO " . TABLE_PREFIX . "bug
122 (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
123 VALUES
124 (" . $bugsys->userinfo['userid'] . ", " . $pcv['product'] . ", " . $pcv['component'] . ", " . $pcv['version'] . ",
125 '" . $bugsys->in['summary'] . "', " . intval($bugsys->in['severity']) . ", " . intval($bugsys->in['priority']) . ",
126 " . intval($bugsys->in['status']) . ", " . intval($bugsys->in['assignedto']) . ", " . intval($bugsys->in['resolution']) . "
127 )"
128 );
129
130 $bugid = $db->insert_id();
131
132 $comment = new CommentAPI($bugsys);
133 $comment->set('bugid', $bugid);
134 $comment->set('userid', $bugsys->userinfo['userid']);
135 $comment->set('comment', $_POST['comment']);
136 $comment->insert();
137
138 $time = $comment->values['dateline'];
139
140 $db->query("
141 UPDATE " . TABLE_PREFIX . "bug
142 SET dateline = $time,
143 initialreport = " . $comment->insertid . ",
144 lastposttime = $time,
145 lastpostby = " . $bugsys->userinfo['userid'] . ",
146 hiddenlastposttime = $time,
147 hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
148 WHERE bugid = $bugid"
149 );
150
151 $db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES ($bugid, 0, 0)");
152
153 $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=$bugid" : 'newreport.php'));
154 }
155 else
156 {
157 $show['errors'] = true;
158 $_REQUEST['do'] = 'add';
159 $message->error_list_process();
160 }
161 }
162
163 // ###################################################################
164
165 if ($_REQUEST['do'] == 'add')
166 {
167 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
168
169 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
170
171 if (can_perform('canchangestatus'))
172 {
173 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
174 $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
175 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
176 }
177
178 $show['assign'] = ((can_perform('canassign')) ? true : false);
179
180 if (can_perform('canassign'))
181 {
182 foreach ($bugsys->datastore['assignto'] AS $dev)
183 {
184 $value = $dev['userid'];
185 $label = construct_user_display($dev, false);
186 $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
187 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
188 }
189 }
190
191 // custom fields
192 $fields = construct_custom_fields(null, true);
193 $i = 0;
194 foreach ($fields AS $field)
195 {
196 if ($i % 2 == 0)
197 {
198 $customfields['left'] .= $field;
199 }
200 else
201 {
202 $customfields['right'] .= $field;
203 }
204 $i++;
205 }
206
207 $pcv_select = construct_pcv_select('cansubmitbugs', $bugsys->in['pcv_select']);
208
209 $reporter = construct_user_display($bugsys->userinfo);
210
211 eval('$template->flush("' . $template->fetch('newreport') . '");');
212 }
213
214 /*=====================================================================*\
215 || ###################################################################
216 || # $HeadURL$
217 || # $Id$
218 || ###################################################################
219 \*=====================================================================*/
220 ?>