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