Fix DB_MySQL_PDO::escape_binary().
[bugdar.git] / newreport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)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
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 require_once('./includes/class_api_error.php');
36 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
37
38 $product = explode(',', $bugsys->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($bugsys);
56 $comment = new CommentAPI($bugsys);
57
58 $notif = new NotificationCenter();
59
60 $bug->set('userid', $bugsys->userinfo['userid']);
61 $bug->set('username', $bugsys->userinfo['displayname']);
62 $bug->set('summary', $bugsys->in['summary']);
63 $bug->set('severity', $bugsys->in['severity']);
64
65 $comment->set('userid', $bugsys->userinfo['userid']);
66 $comment->set('comment', $bugsys->in['comment']);
67 $comment->set('parselinks', $bugsys->in['parselinks']);
68
69 // -------------------------------------------------------------------
70 // check permissions on various input values
71 if (!can_perform('canchangestatus', $bugsys->in['product']))
72 {
73 $bug->set('priority', $bugsys->options['defaultpriority']);
74 $bug->set('status', $bugsys->options['defaultstatus']);
75 $bug->set('resolution', $bugsys->options['defaultresolve']);
76 }
77 else
78 {
79 $bug->set('priority', $bugsys->in['priority']);
80 $bug->set('status', $bugsys->in['status']);
81 $bug->set('resolution', $bugsys->in['resolution']);
82 }
83 if (!can_perform('canassign', $bugsys->in['product']))
84 {
85 $bug->set('assignedto', $bugsys->options['defaultassign']);
86 }
87 else
88 {
89 // assigned person is not a dev or a valid user
90 $bug->set('assignedto', $bugsys->in['assignedto']);
91 }
92
93 $product = explode(',', $bugsys->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($bugsys); // need to destroy because update will think the insert fields need to be changed, too
110 $bug->dorelations = array();
111 $bug->set('bugid', $comment->values['bugid']);
112 $bug->set_condition();
113 $bug->fetch();
114 $bug->set('dateline', $comment->values['dateline']);
115 $bug->set('initialreport', $comment->insertid);
116 $bug->set('lastposttime', $comment->values['dateline']);
117 $bug->set('lastpostby', $bugsys->userinfo['userid']);
118 $bug->set('lastpostbyname', $bugsys->userinfo['displayname']);
119 $bug->set('hiddenlastposttime', $comment->values['dateline']);
120 $bug->set('hiddenlastpostby', $bugsys->userinfo['userid']);
121 $bug->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
122 $bug->update();
123
124 $notif->set_bug_data($bug->objdata);
125
126 $notif->finalize();
127
128 $message->redirect(T('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
129 }
130 else
131 {
132 $show['errors'] = true;
133 $_REQUEST['do'] = 'add';
134 }
135 }
136
137 // ###################################################################
138
139 if ($_REQUEST['do'] == 'add')
140 {
141 if (!is_array(bugdar::$datastore['product']))
142 {
143 $message->error(T('No products have been setup, therefore no bugs can be added.'));
144 }
145 if (!is_array(bugdar::$datastore['version']))
146 {
147 $message->error(T('No versions have been setup underneath your product(s), therefore no bugs can be added.'));
148 }
149
150 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
151
152 $show['changestatus'] = can_perform('canchangestatus');
153
154 if (can_perform('canchangestatus'))
155 {
156 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
157 $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
158 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
159 }
160
161 $show['assign'] = can_perform('canassign');
162
163 if (can_perform('canassign'))
164 {
165 foreach (bugdar::$datastore['assignto'] AS $dev)
166 {
167 $value = $dev['userid'];
168 $label = construct_user_display($dev, false);
169 $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
170 eval('$select["dev"] .= "' . $template->fetch('selectoption') . '";');
171 }
172 }
173
174 // custom fields
175 $fields = construct_custom_fields($bugsys->in, true);
176 $i = 0;
177 foreach ($fields AS $field)
178 {
179 if ($i % 2 == 0)
180 {
181 $customfields['left'] .= $field;
182 }
183 else
184 {
185 $customfields['right'] .= $field;
186 }
187 $i++;
188 }
189
190 $productSelect = ConstructProductSelect('cansubmitbugs', $bugsys->in['product'], false);
191
192 $reporter = construct_user_display($bugsys->userinfo);
193
194 eval('$template->flush("' . $template->fetch('newreport') . '");');
195 }
196