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