SOAP API: do not try to unserialize an invalid filter
[mantis.git] / bug_set_sponsorship.php
bloba8822f5d30f1f25102b1a0c0b7f73c026981d71b
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 - 2011 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 /**
41 * MantisBT Core API's
43 require_once( 'core.php' );
44 require_api( 'access_api.php' );
45 require_api( 'authentication_api.php' );
46 require_api( 'bug_api.php' );
47 require_api( 'config_api.php' );
48 require_api( 'constant_inc.php' );
49 require_api( 'current_user_api.php' );
50 require_api( 'form_api.php' );
51 require_api( 'gpc_api.php' );
52 require_api( 'helper_api.php' );
53 require_api( 'lang_api.php' );
54 require_api( 'print_api.php' );
55 require_api( 'sponsorship_api.php' );
56 require_api( 'user_api.php' );
57 require_api( 'utility_api.php' );
59 form_security_validate( 'bug_set_sponsorship' );
61 # anonymous users are not allowed to sponsor issues
62 if ( current_user_is_anonymous() ) {
63 access_denied();
66 $f_bug_id = gpc_get_int( 'bug_id' );
67 $f_amount = gpc_get_int( 'amount' );
69 $t_bug = bug_get( $f_bug_id, true );
70 if( $t_bug->project_id != helper_get_current_project() ) {
71 # in case the current project is not the same project of the bug we are viewing...
72 # ... override the current project. This to avoid problems with categories and handlers lists etc.
73 $g_project_override = $t_bug->project_id;
76 if ( config_get( 'enable_sponsorship' ) == OFF ) {
77 trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR );
80 access_ensure_bug_level( config_get( 'sponsor_threshold' ), $f_bug_id );
82 helper_ensure_confirmed(
83 sprintf( lang_get( 'confirm_sponsorship' ), $f_bug_id, sponsorship_format_amount( $f_amount ) ),
84 lang_get( 'sponsor_issue' ) );
86 if ( $f_amount == 0 ) {
87 # if amount == 0, delete sponsorship by current user (if any)
88 $t_sponsorship_id = sponsorship_get_id( $f_bug_id );
89 if ( $t_sponsorship_id !== false ) {
90 sponsorship_delete( $t_sponsorship_id );
92 } else {
93 # add sponsorship
94 $t_user = auth_get_current_user_id();
95 if ( is_blank( user_get_email( $t_user ) ) ) {
96 trigger_error( ERROR_SPONSORSHIP_SPONSOR_NO_EMAIL, ERROR );
97 } else {
98 $sponsorship = new SponsorshipData;
99 $sponsorship->bug_id = $f_bug_id;
100 $sponsorship->user_id = $t_user;
101 $sponsorship->amount = $f_amount;
103 sponsorship_set( $sponsorship );
107 form_security_purge( 'bug_set_sponsorship' );
109 print_header_redirect_view( $f_bug_id );