r868: We now actually send emails out. This means that the notification system is...
[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/class_notification.php');
33 require_once('./includes/api_bug.php');
34 require_once('./includes/api_comment.php');
35
36 if (!can_perform('cansubmitbugs', intval($bugsys->in['productid'])))
37 {
38 $message->error_permission();
39 }
40
41 // ###################################################################
42
43 if (empty($_REQUEST['do']))
44 {
45 $_REQUEST['do'] = 'add';
46 }
47
48 // ###################################################################
49
50 if ($_POST['do'] == 'insert')
51 {
52 $bug = new BugAPI($bugsys);
53 $comment = new CommentAPI($bugsys);
54
55 $notif = new NotificationCenter;
56
57 $bug->set('userid', $bugsys->userinfo['userid']);
58 $bug->set('username', $bugsys->userinfo['displayname']);
59 $bug->set('summary', $bugsys->in['summary']);
60 $bug->set('severity', $bugsys->in['severity']);
61
62 $comment->set('userid', $bugsys->userinfo['userid']);
63 $comment->set('comment', $bugsys->in['comment']);
64
65 // -------------------------------------------------------------------
66 // check permissions on various input values
67 if (!can_perform('canchangestatus', intval($bugsys->in['productid'])))
68 {
69 $bug->set('priority', $bugsys->options['defaultpriority']);
70 $bug->set('status', $bugsys->options['defaultstatus']);
71 $bug->set('resolution', $bugsys->options['defaultresolve']);
72 }
73 else
74 {
75 $bug->set('priority', $bugsys->in['priority']);
76 $bug->set('status', $bugsys->in['status']);
77 $bug->set('resolution', $bugsys->in['resolution']);
78 }
79 if (!can_perform('canassign', intval($bugsys->in['productid'])))
80 {
81 $bug->set('assignedto', $bugsys->options['defaultassign']);
82 }
83 else
84 {
85 // assigned person is not a dev or a valid user
86 $bug->set('assignedto', $bugsys->in['assignedto']);
87 }
88
89 // -------------------------------------------------------------------
90 // product/component/version stuff
91 $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
92 if (!$pcv)
93 {
94 $message->add_error($lang->string('Invalid product/component/version selected.'));
95 }
96 $bug->set('productid', $pcv['product']);
97 $bug->set('componentid', $pcv['component']);
98 $bug->set('versionid', $pcv['version']);
99
100 if (!$message->items)
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 $notif->finalize();
110
111 $bug = new BugAPI($bugsys); // need to destroy because update will think the insert fields need to be changed, too
112 $bug->set('bugid', $comment->values['bugid']);
113 $bug->set_condition();
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 $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
125 }
126 else
127 {
128 $show['errors'] = true;
129 $_REQUEST['do'] = 'add';
130 $message->error_list_process();
131 }
132 }
133
134 // ###################################################################
135
136 if ($_REQUEST['do'] == 'add')
137 {
138 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
139
140 $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
141
142 if (can_perform('canchangestatus'))
143 {
144 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
145 $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
146 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
147 }
148
149 $show['assign'] = ((can_perform('canassign')) ? true : false);
150
151 if (can_perform('canassign'))
152 {
153 foreach ($bugsys->datastore['assignto'] AS $dev)
154 {
155 $value = $dev['userid'];
156 $label = construct_user_display($dev, false);
157 $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
158 eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
159 }
160 }
161
162 // custom fields
163 $fields = construct_custom_fields(null, true);
164 $i = 0;
165 foreach ($fields AS $field)
166 {
167 if ($i % 2 == 0)
168 {
169 $customfields['left'] .= $field;
170 }
171 else
172 {
173 $customfields['right'] .= $field;
174 }
175 $i++;
176 }
177
178 $pcv_select = construct_pcv_select('cansubmitbugs', $bugsys->in['pcv_select']);
179
180 $reporter = construct_user_display($bugsys->userinfo);
181
182 eval('$template->flush("' . $template->fetch('newreport') . '");');
183 }
184
185 /*=====================================================================*\
186 || ###################################################################
187 || # $HeadURL$
188 || # $Id$
189 || ###################################################################
190 \*=====================================================================*/
191 ?>