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 Active Project 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 config_api.php 27 * @uses constant_inc.php 28 * @uses current_user_api.php 29 * @uses filter_api.php 30 * @uses gpc_api.php 31 * @uses helper_api.php 32 * @uses html_api.php 33 * @uses lang_api.php 34 * @uses print_api.php 35 * @uses project_api.php 36 * @uses string_api.php 37 * @uses utility_api.php 38 */ 39 40require_once( 'core.php' ); 41require_api( 'config_api.php' ); 42require_api( 'constant_inc.php' ); 43require_api( 'current_user_api.php' ); 44require_api( 'filter_api.php' ); 45require_api( 'gpc_api.php' ); 46require_api( 'helper_api.php' ); 47require_api( 'html_api.php' ); 48require_api( 'lang_api.php' ); 49require_api( 'print_api.php' ); 50require_api( 'project_api.php' ); 51require_api( 'string_api.php' ); 52require_api( 'utility_api.php' ); 53 54$f_project_id = gpc_get_string( 'project_id' ); 55$f_make_default = gpc_get_bool( 'make_default' ); 56$f_ref = gpc_get_string( 'ref', '' ); 57 58$c_ref = string_prepare_header( $f_ref ); 59 60$t_project = explode( ';', $f_project_id ); 61$t_top = $t_project[0]; 62$t_bottom = $t_project[count( $t_project ) - 1]; 63 64if( ALL_PROJECTS != $t_bottom ) { 65 project_ensure_exists( $t_bottom ); 66} 67 68# Set default project 69if( $f_make_default ) { 70 current_user_set_default_project( $t_top ); 71} 72 73helper_set_current_project( $f_project_id ); 74 75# redirect to 'same page' when switching projects. 76 77# for proxies that clear out HTTP_REFERER 78if( !is_blank( $c_ref ) ) { 79 $t_redirect_url = $c_ref; 80} else if( !isset( $_SERVER['HTTP_REFERER'] ) || is_blank( $_SERVER['HTTP_REFERER'] ) ) { 81 $t_redirect_url = config_get_global( 'default_home_page' ); 82} else { 83 $t_home_page = config_get_global( 'default_home_page' ); 84 85 # Check that referrer matches our address after squashing case (case insensitive compare) 86 $t_path = rtrim( config_get_global( 'path' ), '/' ); 87 if( preg_match( '@^(' . $t_path . ')/(?:/*([^\?#]*))(.*)?$@', $_SERVER['HTTP_REFERER'], $t_matches ) ) { 88 $t_referrer_page = $t_matches[2]; 89 $t_param = $t_matches[3]; 90 91 # if view_all_bug_page, pass on filter 92 if( strcasecmp( 'view_all_bug_page.php', $t_referrer_page ) == 0 ) { 93 $t_source_filter_id = filter_db_get_project_current( $t_bottom ); 94 $t_redirect_url = 'view_all_set.php?type=' . FILTER_ACTION_GENERALIZE; 95 96 if( $t_source_filter_id !== null ) { 97 $t_redirect_url = 'view_all_set.php?type=' . FILTER_ACTION_LOAD . '&source_query_id=' . $t_source_filter_id; 98 } 99 } else if( stripos( $t_referrer_page, '_page.php' ) !== false ) { 100 switch( $t_referrer_page ) { 101 case 'bug_view_page.php': 102 case 'bug_view_advanced_page.php': 103 case 'bug_update_page.php': 104 case 'bug_change_status_page.php': 105 $t_path = $t_home_page; 106 break; 107 default: 108 $t_path = $t_referrer_page . $t_param; 109 break; 110 } 111 $t_redirect_url = $t_path; 112 } else if( $t_referrer_page == 'plugin.php' ) { 113 $t_redirect_url = $t_referrer_page . $t_param; # redirect to same plugin page 114 } else { 115 $t_redirect_url = $t_home_page; 116 } 117 } else { 118 $t_redirect_url = $t_home_page; 119 } 120} 121 122print_header_redirect( $t_redirect_url, true, true ); 123 124layout_page_header( null, $t_redirect_url ); 125 126layout_page_begin(); 127 128html_operation_successful( $t_redirect_url ); 129 130layout_page_end(); 131