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