1<?php 2# MantisBT - A PHP based bugtracking system 3 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. 8# 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. 13# 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/>. 16 17/** 18 * Set sponsorship on a bug 19 * 20 * @package MantisBT 21 * @copyright Copyright 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 22 * @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net 23 * @link http://www.mantisbt.org 24 * 25 * @uses core.php 26 * @uses access_api.php 27 * @uses authentication_api.php 28 * @uses bug_api.php 29 * @uses config_api.php 30 * @uses constant_inc.php 31 * @uses current_user_api.php 32 * @uses form_api.php 33 * @uses gpc_api.php 34 * @uses helper_api.php 35 * @uses lang_api.php 36 * @uses print_api.php 37 * @uses sponsorship_api.php 38 * @uses user_api.php 39 * @uses utility_api.php 40 */ 41 42require_once( 'core.php' ); 43require_api( 'access_api.php' ); 44require_api( 'authentication_api.php' ); 45require_api( 'bug_api.php' ); 46require_api( 'config_api.php' ); 47require_api( 'constant_inc.php' ); 48require_api( 'current_user_api.php' ); 49require_api( 'form_api.php' ); 50require_api( 'gpc_api.php' ); 51require_api( 'helper_api.php' ); 52require_api( 'lang_api.php' ); 53require_api( 'print_api.php' ); 54require_api( 'sponsorship_api.php' ); 55require_api( 'user_api.php' ); 56require_api( 'utility_api.php' ); 57 58form_security_validate( 'bug_set_sponsorship' ); 59 60# anonymous users are not allowed to sponsor issues 61if( current_user_is_anonymous() ) { 62 access_denied(); 63} 64 65$f_bug_id = gpc_get_int( 'bug_id' ); 66$f_amount = gpc_get_int( 'amount' ); 67 68$t_bug = bug_get( $f_bug_id, true ); 69if( $t_bug->project_id != helper_get_current_project() ) { 70 # in case the current project is not the same project of the bug we are viewing... 71 # ... override the current project. This to avoid problems with categories and handlers lists etc. 72 $g_project_override = $t_bug->project_id; 73} 74 75if( config_get( 'enable_sponsorship' ) == OFF ) { 76 trigger_error( ERROR_SPONSORSHIP_NOT_ENABLED, ERROR ); 77} 78 79access_ensure_bug_level( config_get( 'sponsor_threshold' ), $f_bug_id ); 80 81helper_ensure_confirmed( 82 sprintf( lang_get( 'confirm_sponsorship' ), $f_bug_id, sponsorship_format_amount( $f_amount ) ), 83 lang_get( 'sponsor_issue' ) ); 84 85if( $f_amount == 0 ) { 86 # if amount == 0, delete sponsorship by current user (if any) 87 $t_sponsorship_id = sponsorship_get_id( $f_bug_id ); 88 if( $t_sponsorship_id !== false ) { 89 sponsorship_delete( $t_sponsorship_id ); 90 } 91} else { 92 # add sponsorship 93 $t_user = auth_get_current_user_id(); 94 if( is_blank( user_get_email( $t_user ) ) ) { 95 trigger_error( ERROR_SPONSORSHIP_SPONSOR_NO_EMAIL, ERROR ); 96 } else { 97 $t_sponsorship = new SponsorshipData; 98 $t_sponsorship->bug_id = $f_bug_id; 99 $t_sponsorship->user_id = $t_user; 100 $t_sponsorship->amount = $f_amount; 101 102 sponsorship_set( $t_sponsorship ); 103 } 104} 105 106form_security_purge( 'bug_set_sponsorship' ); 107 108print_header_redirect_view( $f_bug_id ); 109