Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / bug_set_sponsorship.php
blob94c5322b2d98e1dfa652b584daf626b3ce7e662c
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 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses core.php
24 * @uses access_api.php
25 * @uses authentication_api.php
26 * @uses bug_api.php
27 * @uses config_api.php
28 * @uses constant_inc.php
29 * @uses current_user_api.php
30 * @uses form_api.php
31 * @uses gpc_api.php
32 * @uses helper_api.php
33 * @uses lang_api.php
34 * @uses print_api.php
35 * @uses sponsorship_api.php
36 * @uses user_api.php
37 * @uses utility_api.php
40 require_once( 'core.php' );
41 require_api( 'access_api.php' );
42 require_api( 'authentication_api.php' );
43 require_api( 'bug_api.php' );
44 require_api( 'config_api.php' );
45 require_api( 'constant_inc.php' );
46 require_api( 'current_user_api.php' );
47 require_api( 'form_api.php' );
48 require_api( 'gpc_api.php' );
49 require_api( 'helper_api.php' );
50 require_api( 'lang_api.php' );
51 require_api( 'print_api.php' );
52 require_api( 'sponsorship_api.php' );
53 require_api( 'user_api.php' );
54 require_api( 'utility_api.php' );
56 form_security_validate( 'bug_set_sponsorship' );
58 # anonymous users are not allowed to sponsor issues
59 if ( current_user_is_anonymous() ) {
60 access_denied();
63 $f_bug_id = gpc_get_int( 'bug_id' );
64 $f_amount = gpc_get_int( 'amount' );
66 $t_bug = bug_get( $f_bug_id, true );
67 if( $t_bug->project_id != helper_get_current_project() ) {
68 # in case the current project is not the same project of the bug we are viewing...
69 # ... override the current project. This to avoid problems with categories and handlers lists etc.
70 $g_project_override = $t_bug->project_id;
73 if ( config_get( 'enable_sponsorship' ) == OFF ) {
74 trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR );
77 access_ensure_bug_level( config_get( 'sponsor_threshold' ), $f_bug_id );
79 helper_ensure_confirmed(
80 sprintf( lang_get( 'confirm_sponsorship' ), $f_bug_id, sponsorship_format_amount( $f_amount ) ),
81 lang_get( 'sponsor_issue' ) );
83 if ( $f_amount == 0 ) {
84 # if amount == 0, delete sponsorship by current user (if any)
85 $t_sponsorship_id = sponsorship_get_id( $f_bug_id );
86 if ( $t_sponsorship_id !== false ) {
87 sponsorship_delete( $t_sponsorship_id );
89 } else {
90 # add sponsorship
91 $t_user = auth_get_current_user_id();
92 if ( is_blank( user_get_email( $t_user ) ) ) {
93 trigger_error( ERROR_SPONSORSHIP_SPONSOR_NO_EMAIL, ERROR );
94 } else {
95 $sponsorship = new SponsorshipData;
96 $sponsorship->bug_id = $f_bug_id;
97 $sponsorship->user_id = $t_user;
98 $sponsorship->amount = $f_amount;
100 sponsorship_set( $sponsorship );
104 form_security_purge( 'bug_set_sponsorship' );
106 print_header_redirect_view( $f_bug_id );