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