<?php

/**
 * <pre>
 * Invision Power Services
 * Admin control panel gateway index.php file
 * Last Updated: $Date: 2010-01-27 20:50:40 -0500 (Wed, 27 Jan 2010) $
 * </pre>
 *
 * @author 		$Author: bfarber $
 * @copyright	(c) 2001 - 2009 Invision Power Services, Inc.
 * @license		http://www.invisionpower.com/community/board/license.html
 * @package		Invision Power Board
 * @version		$Rev: 183 $
 *
 */

/**
 * You must define the path to your IPB installation here, with a trailing slash.
 * THIS IS A PATH, NOT A URL.  So, for example if this file is located in the root
 * of your site at /home/account/public_html and your forums are in a subfolder
 * named forums, you would set this to /home/account/public_html/forums/
 */
$path_to_ipb	= './forums/';


/**
 * This is the flag in the URL for database friendly URLs.  You must have a flag here
 * (i.e. do not try to set this as an empty string).  This also needs to be updated in
 * admin/applications_addon/ips/ccs/app_class_ccs.php as well.
 */

define( 'DATABASE_FURL_MARKER', '_' );




/**
 * ------------------------------------------------------------------------------------------
 * No editing below this line
 * ------------------------------------------------------------------------------------------
 */
define( 'CCS_GATEWAY_CALLED', true );
define( 'IPB_THIS_SCRIPT', 'public' );
require_once( $path_to_ipb . 'initdata.php' );

//-----------------------------------------
// Get request uri
//-----------------------------------------

$uri	= $_SERVER['REQUEST_URI']  ? $_SERVER['REQUEST_URI']  : @getenv('REQUEST_URI');

//-----------------------------------------
// Does URI have /index.php/ in it?
//-----------------------------------------

if( strpos( $uri, basename(__FILE__) . '/' ) !== false )
{
	$myUri	= substr( $uri, ( strpos( $uri, basename(__FILE__) . '/' ) + ( strlen( basename(__FILE__) ) + 1 ) ) );
}
else
{
	$myUri	= $uri;
}

//-----------------------------------------
// Does URI have db marker in it
//-----------------------------------------

if( strpos( $myUri, '/' . DATABASE_FURL_MARKER . '/' ) !== false )
{
	$myUri	= substr( $myUri, 0, ( strpos( $myUri, '/' . DATABASE_FURL_MARKER . '/' ) ) );
}

//-----------------------------------------
// Trim off trailing slash, if present
//-----------------------------------------

$myUri	= rtrim( $myUri, '/' );

//-----------------------------------------
// What about ?key=value?
// PHP already sets GET, but need to fix page name
//-----------------------------------------

if( strpos( $myUri, '?' ) !== false )
{
	$parameters	= substr( $myUri, strpos( $myUri, '?' ) );
	$myUri		= substr( $myUri, 0, ( strlen($myUri) - strlen($parameters) ) );
}

//-----------------------------------------
// Sort out folders
//-----------------------------------------

$uriBits	= explode( '/', $myUri );
$myFolder	= '';

if( count($uriBits) > 1 )
{
	$myUri		= array_pop($uriBits);
	$myFolder	= count($uriBits) ? '/' . implode( '/', $uriBits ) : '';
	$myFolder	= ( $myFolder == '/' ) ? '' : $myFolder;
}

//-----------------------------------------
// Set appropriate params for IPB
//-----------------------------------------

$_GET['app']		= $_POST['app']		= $_REQUEST['app']		= 'ccs';
$_GET['module']		= $_POST['module']	= $_REQUEST['module']	= 'pages';
$_GET['section']	= $_POST['section']	= $_REQUEST['section']	= 'pages';
$_GET['page']		= $_POST['page']	= $_REQUEST['page']		= $myUri;
$_GET['folder']		= $_POST['folder']	= $_REQUEST['folder']	= $myFolder;

//-----------------------------------------
// Include registry and controller, and off we go
//-----------------------------------------

require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );
require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );

ipsController::run();

exit();