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