Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / bug_actiongroup.php
blob4e70bb13437d0e6b626baaed9a525b543a0d5c66
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This page allows actions to be performed an an array of bugs
20 * @package MantisBT
21 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
25 * @uses core.php
26 * @uses access_api.php
27 * @uses authentication_api.php
28 * @uses bug_api.php
29 * @uses bugnote_api.php
30 * @uses category_api.php
31 * @uses config_api.php
32 * @uses constant_inc.php
33 * @uses custom_field_api.php
34 * @uses event_api.php
35 * @uses form_api.php
36 * @uses gpc_api.php
37 * @uses helper_api.php
38 * @uses html_api.php
39 * @uses lang_api.php
40 * @uses print_api.php
41 * @uses string_api.php
42 * @uses utility_api.php
43 * @uses version_api.php
46 require_once( 'core.php' );
47 require_api( 'access_api.php' );
48 require_api( 'authentication_api.php' );
49 require_api( 'bug_api.php' );
50 require_api( 'bugnote_api.php' );
51 require_api( 'category_api.php' );
52 require_api( 'config_api.php' );
53 require_api( 'constant_inc.php' );
54 require_api( 'custom_field_api.php' );
55 require_api( 'event_api.php' );
56 require_api( 'form_api.php' );
57 require_api( 'gpc_api.php' );
58 require_api( 'helper_api.php' );
59 require_api( 'html_api.php' );
60 require_api( 'lang_api.php' );
61 require_api( 'print_api.php' );
62 require_api( 'string_api.php' );
63 require_api( 'utility_api.php' );
64 require_api( 'version_api.php' );
66 auth_ensure_user_authenticated();
67 helper_begin_long_process();
69 $f_action = gpc_get_string( 'action' );
70 $f_custom_field_id = gpc_get_int( 'custom_field_id', 0 );
71 $f_bug_arr = gpc_get_int_array( 'bug_arr', array() );
72 $f_bug_notetext = gpc_get_string( 'bugnote_text', '' );
73 $f_bug_noteprivate = gpc_get_bool( 'private' );
74 $t_form_name = 'bug_actiongroup_' . $f_action;
75 form_security_validate( $t_form_name );
77 $t_custom_group_actions = config_get( 'custom_group_actions' );
79 foreach( $t_custom_group_actions as $t_custom_group_action ) {
80 if ( $f_action == $t_custom_group_action['action'] ) {
81 require_once( $t_custom_group_action['action_page'] );
82 exit;
86 $t_failed_ids = array();
88 if ( 0 != $f_custom_field_id ) {
89 $t_custom_field_def = custom_field_get_definition( $f_custom_field_id );
92 foreach( $f_bug_arr as $t_bug_id ) {
93 bug_ensure_exists( $t_bug_id );
94 $t_bug = bug_get( $t_bug_id, true );
96 if( $t_bug->project_id != helper_get_current_project() ) {
97 # in case the current project is not the same project of the bug we are viewing...
98 # ... override the current project. This to avoid problems with categories and handlers lists etc.
99 $g_project_override = $t_bug->project_id;
100 /** @todo (thraxisp) the next line goes away if the cache was smarter and used project */
101 config_flush_cache(); # flush the config cache so that configs are refetched
104 $t_status = $t_bug->status;
106 switch ( $f_action ) {
108 case 'CLOSE':
109 $t_closed = config_get( 'bug_closed_status_threshold' );
110 if ( access_can_close_bug( $t_bug_id ) &&
111 ( $t_status < $t_closed ) &&
112 bug_check_workflow( $t_status, $t_closed ) ) {
114 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $f_bug_id, $t_bug_data, $f_bugnote_text ) ); */
115 bug_close( $t_bug_id, $f_bug_notetext, $f_bug_noteprivate );
116 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
117 } else {
118 if ( !access_can_close_bug( $t_bug_id ) ) {
119 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
120 } else {
121 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_status' );
124 break;
126 case 'DELETE':
127 if ( access_has_bug_level( config_get( 'delete_bug_threshold' ), $t_bug_id ) ) {
128 event_signal( 'EVENT_BUG_DELETED', array( $t_bug_id ) );
129 bug_delete( $t_bug_id );
130 } else {
131 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
133 break;
135 case 'MOVE':
136 if ( access_has_bug_level( config_get( 'move_bug_threshold' ), $t_bug_id ) ) {
137 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
138 $f_project_id = gpc_get_int( 'project_id' );
139 bug_set_field( $t_bug_id, 'project_id', $f_project_id );
140 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
141 } else {
142 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
144 break;
146 case 'COPY':
147 $f_project_id = gpc_get_int( 'project_id' );
149 if ( access_has_project_level( config_get( 'report_bug_threshold' ), $f_project_id ) ) {
150 bug_copy( $t_bug_id, $f_project_id, true, true, true, true, true, true );
151 } else {
152 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
154 break;
156 case 'ASSIGN':
157 $f_assign = gpc_get_int( 'assign' );
158 if ( ON == config_get( 'auto_set_status_to_assigned' ) ) {
159 $t_assign_status = config_get( 'bug_assigned_status' );
160 } else {
161 $t_assign_status = $t_status;
163 # check that new handler has rights to handle the issue, and
164 # that current user has rights to assign the issue
165 $t_threshold = access_get_status_threshold( $t_assign_status, bug_get_field( $t_bug_id, 'project_id' ) );
166 if ( access_has_bug_level( $t_threshold , $t_bug_id, $f_assign ) &&
167 access_has_bug_level( config_get( 'update_bug_assign_threshold', config_get( 'update_bug_threshold' ) ), $t_bug_id ) &&
168 bug_check_workflow($t_status, $t_assign_status ) ) {
169 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
170 bug_assign( $t_bug_id, $f_assign, $f_bug_notetext, $f_bug_noteprivate );
171 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
172 } else {
173 if ( bug_check_workflow($t_status, $t_assign_status ) ) {
174 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
175 } else {
176 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_status' );
179 break;
181 case 'RESOLVE':
182 $t_resolved_status = config_get( 'bug_resolved_status_threshold' );
183 if ( access_has_bug_level( access_get_status_threshold( $t_resolved_status, bug_get_field( $t_bug_id, 'project_id' ) ), $t_bug_id ) &&
184 ( $t_status < $t_resolved_status ) &&
185 bug_check_workflow($t_status, $t_resolved_status ) ) {
186 $f_resolution = gpc_get_int( 'resolution' );
187 $f_fixed_in_version = gpc_get_string( 'fixed_in_version', '' );
188 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
189 bug_resolve( $t_bug_id, $f_resolution, $f_fixed_in_version, $f_bug_notetext, null, null, $f_bug_noteprivate );
190 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
191 } else {
192 if ( ( $t_status < $t_resolved_status ) &&
193 bug_check_workflow($t_status, $t_resolved_status ) ) {
194 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
195 } else {
196 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_status' );
199 break;
201 case 'UP_PRIOR':
202 if ( access_has_bug_level( config_get( 'update_bug_threshold' ), $t_bug_id ) ) {
203 $f_priority = gpc_get_int( 'priority' );
204 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
205 bug_set_field( $t_bug_id, 'priority', $f_priority );
206 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
207 } else {
208 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
210 break;
212 case 'UP_STATUS':
213 $f_status = gpc_get_int( 'status' );
214 $t_project = bug_get_field( $t_bug_id, 'project_id' );
215 if ( access_has_bug_level( access_get_status_threshold( $f_status, $t_project ), $t_bug_id ) ) {
216 if ( TRUE == bug_check_workflow($t_status, $f_status ) ) {
217 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
218 bug_set_field( $t_bug_id, 'status', $f_status );
220 # Add bugnote if supplied
221 if ( !is_blank( $f_bug_notetext ) ) {
222 bugnote_add( $t_bug_id, $f_bug_notetext, null, $f_bug_noteprivate );
225 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
226 } else {
227 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_status' );
229 } else {
230 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
232 break;
234 case 'UP_CATEGORY':
235 $f_category_id = gpc_get_int( 'category' );
236 if ( access_has_bug_level( config_get( 'update_bug_threshold' ), $t_bug_id ) ) {
237 if ( category_exists( $f_category_id ) ) {
238 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
239 bug_set_field( $t_bug_id, 'category_id', $f_category_id );
240 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
241 } else {
242 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_category' );
244 } else {
245 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
247 break;
249 case 'UP_FIXED_IN_VERSION':
250 $f_fixed_in_version = gpc_get_string( 'fixed_in_version' );
251 $t_project_id = bug_get_field( $t_bug_id, 'project_id' );
252 $t_success = false;
254 if ( access_has_bug_level( config_get( 'update_bug_threshold' ), $t_bug_id ) ) {
255 if ( version_get_id( $f_fixed_in_version, $t_project_id ) !== false ) {
256 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
257 bug_set_field( $t_bug_id, 'fixed_in_version', $f_fixed_in_version );
258 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
259 $t_success = true;
263 if ( !$t_success ) {
264 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
266 break;
268 case 'UP_TARGET_VERSION':
269 $f_target_version = gpc_get_string( 'target_version' );
270 $t_project_id = bug_get_field( $t_bug_id, 'project_id' );
271 $t_success = false;
273 if ( access_has_bug_level( config_get( 'roadmap_update_threshold' ), $t_bug_id ) ) {
274 if ( version_get_id( $f_target_version, $t_project_id ) !== false ) {
275 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
276 bug_set_field( $t_bug_id, 'target_version', $f_target_version );
277 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
278 $t_success = true;
282 if ( !$t_success ) {
283 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
285 break;
287 case 'VIEW_STATUS':
288 if ( access_has_bug_level( config_get( 'change_view_status_threshold' ), $t_bug_id ) ) {
289 $f_view_status = gpc_get_int( 'view_status' );
290 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
291 bug_set_field( $t_bug_id, 'view_state', $f_view_status );
292 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
293 } else {
294 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
296 break;
298 case 'SET_STICKY':
299 if ( access_has_bug_level( config_get( 'set_bug_sticky_threshold' ), $t_bug_id ) ) {
300 $f_sticky = bug_get_field( $t_bug_id, 'sticky' );
301 // The new value is the inverted old value
302 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
303 bug_set_field( $t_bug_id, 'sticky', intval( !$f_sticky ) );
304 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
305 } else {
306 $t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
308 break;
310 case 'CUSTOM':
311 if ( 0 === $f_custom_field_id ) {
312 trigger_error( ERROR_GENERIC, ERROR );
315 /** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
316 $t_form_var = "custom_field_$f_custom_field_id";
317 $t_custom_field_value = gpc_get_custom_field( $t_form_var, $t_custom_field_def['type'], null );
318 custom_field_set_value( $f_custom_field_id, $t_bug_id, $t_custom_field_value );
319 helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
320 break;
322 default:
323 trigger_error( ERROR_GENERIC, ERROR );
326 // Bug Action Event
327 event_signal( 'EVENT_BUG_ACTION', array( $f_action, $t_bug_id ) );
330 form_security_purge( $t_form_name );
332 $t_redirect_url = 'view_all_bug_page.php';
334 if ( count( $t_failed_ids ) > 0 ) {
335 html_page_top();
337 echo '<div align="center"><br />';
338 echo '<table class="width75">';
339 $separator = lang_get( 'word_separator' );
340 foreach( $t_failed_ids as $t_id => $t_reason ) {
341 $label = sprintf( lang_get( 'label' ), string_get_bug_view_link( $t_id ) ) . $separator;
342 printf( "<tr><td width=\"50%%\">%s%s</td><td>%s</td></tr>\n", $label, bug_get_field( $t_id, 'summary' ), $t_reason );
344 echo '</table><br />';
345 print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
346 echo '</div>';
348 html_page_bottom();
349 } else {
350 print_header_redirect( $t_redirect_url );