r1337: Adding the option to allow parsing of links in comment text
[bugdar.git] / newreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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/class_notification.php');
33 require_once('./includes/api_bug.php');
34 require_once('./includes/api_comment.php');
35
36 require_once('./includes/class_api_error.php');
37 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
38
39 $product = explode(',', $bugsys->in['product']);
40 if (!can_perform('cansubmitbugs', $product[0]))
41 {
42 $message->error_permission();
43 }
44
45 // ###################################################################
46
47 if (empty($_REQUEST['do']))
48 {
49 $_REQUEST['do'] = 'add';
50 }
51
52 // ###################################################################
53
54 if ($_POST['do'] == 'insert')
55 {
56 $bug = new BugAPI($bugsys);
57 $comment = new CommentAPI($bugsys);
58
59 $notif = new NotificationCenter;
60
61 $bug->set('userid', $bugsys->userinfo['userid']);
62 $bug->set('username', $bugsys->userinfo['displayname']);
63 $bug->set('summary', $bugsys->in['summary']);
64 $bug->set('severity', $bugsys->in['severity']);
65
66 $comment->set('userid', $bugsys->userinfo['userid']);
67 $comment->set('comment', $bugsys->in['comment']);
68 $comment->set('parselinks', $bugsys->in['parselinks']);
69
70 // -------------------------------------------------------------------
71 // check permissions on various input values
72 if (!can_perform('canchangestatus', $bugsys->in['product']))
73 {
74 $bug->set('priority', $bugsys->options['defaultpriority']);
75 $bug->set('status', $bugsys->options['defaultstatus']);
76 $bug->set('resolution', $bugsys->options['defaultresolve']);
77 }
78 else
79 {
80 $bug->set('priority', $bugsys->in['priority']);
81 $bug->set('status', $bugsys->in['status']);
82 $bug->set('resolution', $bugsys->in['resolution']);
83 }
84 if (!can_perform('canassign', $bugsys->in['product']))
85 {
86 $bug->set('assignedto', $bugsys->options['defaultassign']);
87 }
88 else
89 {
90 // assigned person is not a dev or a valid user
91 $bug->set('assignedto', $bugsys->in['assignedto']);
92 }
93
94 $product = explode(',', $bugsys->in['product']);
95 $bug->set('product', $product[0]);
96 $bug->set('component', $product[1]);
97 $bug->set('version', $product[2]);
98
99 $cfields = process_custom_fields(null, $message, true);
100
101 if (!$message->items)
102 {
103 $bug->insert();
104
105 $comment->set('bugid', $bug->insertid);
106 $comment->insert();
107
108 $notif->send_new_bug_notice($bug->values, $comment->values);
109
110 $bug = new BugAPI($bugsys); // need to destroy because update will think the insert fields need to be changed, too
111 $bug->dorelations = array();
112 $bug->set('bugid', $comment->values['bugid']);
113 $bug->set_condition();
114 $bug->fetch();
115 $bug->set('dateline', $comment->values['dateline']);
116 $bug->set('initialreport', $comment->insertid);
117 $bug->set('lastposttime', $comment->values['dateline']);
118 $bug->set('lastpostby', $bugsys->userinfo['userid']);
119 $bug->set('lastpostbyname', $bugsys->userinfo['displayname']);
120 $bug->set('hiddenlastposttime', $comment->values['dateline']);
121 $bug->set('hiddenlastpostby', $bugsys->userinfo['userid']);
122 $bug->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
123 $bug->update();
124
125 if ($cfields)
126 {
127 $db->query(sprintf($cfields, $comment->values['bugid']));
128 }
129
130 $notif->set_bug_data($bug->objdata);
131
132 $notif->finalize();
133
134 $message->redirect(_('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
135 }
136 else
137 {
138 $show['errors'] = true;
139 $_REQUEST['do'] = 'add';
140 $message->error_list_process();
141 }
142 }
143
144 // ###################################################################
145
146 if ($_REQUEST['do'] == 'add')
147 {
148 if (!is_array($bugsys->datastore['product']))
149 {
150 $message->error(_('No products have been setup, therefore no bugs can be added.'));
151 }
152 if (!is_array($bugsys->datastore['version']))
153 {
154 $message->error(_('No versions have been setup underneath your product(s), therefore no bugs can be added.'));
155 }
156
157 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
158
159 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
160
161 if (can_perform('canchangestatus'))
162 {
163 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
164 $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
165 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
166 }
167
168 $show['assign'] = ((can_perform('canassign')) ? true : false);
169
170 if (can_perform('canassign'))
171 {
172 foreach ($bugsys->datastore['assignto'] AS $dev)
173 {
174 $value = $dev['userid'];
175 $label = construct_user_display($dev, false);
176 $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
177 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
178 }
179 }
180
181 // custom fields
182 $fields = construct_custom_fields($bugsys->in, true);
183 $i = 0;
184 foreach ($fields AS $field)
185 {
186 if ($i % 2 == 0)
187 {
188 $customfields['left'] .= $field;
189 }
190 else
191 {
192 $customfields['right'] .= $field;
193 }
194 $i++;
195 }
196
197 $productSelect = ConstructProductSelect('cansubmitbugs', $bugsys->in['product']);
198
199 $reporter = construct_user_display($bugsys->userinfo);
200
201 eval('$template->flush("' . $template->fetch('newreport') . '");');
202 }
203
204 /*=====================================================================*\
205 || ###################################################################
206 || # $HeadURL$
207 || # $Id$
208 || ###################################################################
209 \*=====================================================================*/
210 ?>