<?php

// index.php
// -----------------------------------------------------------------------------
// Redirect user to page in parent directory,
// determined by last directory name in URL, preserving the query string
// eg Send /numbers/0845/ to /numbers/0845.php
//
// Project    > A16-dmABS-1.5-Feb09
// Copyright  > (C) Digital Mail Limited (2005 - 2009)
// Author     > RAK for DML
// -----------------------------------------------------------------------------

define('MOD_PHP', substr(PHP_SAPI, 0, 3) != 'cgi'); // Are we running as mod_php?
define('DOCROOT', 
	MOD_PHP && isset($_SERVER['DOCUMENT_ROOT']) ? 
		$_SERVER['DOCUMENT_ROOT'] : 
		(
			MOD_PHP && isset($_SERVER['SCRIPT_FILENAME']) ? 
				substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])) : 
				(
					substr(str_repeat('../', count(explode('/', preg_replace('_/+_', '/', $_SERVER['PHP_SELF'])))-2), 0, -1) != '' ?
						substr(str_repeat('../', count(explode('/', preg_replace('_/+_', '/', $_SERVER['PHP_SELF'])))-2), 0, -1) :
						'.'
				)
		)
	);
$abs_root = '';
@include(DOCROOT . '/abs_version_control.php');
include_once(DOCROOT . $abs_root . '/common/abs_lib.php');
$abs_path = abs_analyse_path($_SERVER['PHP_SELF']);
$pagepath = implode('/', array_slice($abs_path['full'], 0, count($abs_path['full'])-2));
$pagename = $abs_path['full'][count($abs_path['full'])-2] . '.php'; // Generate pagename from final directory in URL
$query_string = $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
header('LOCATION: ' . $abs_root . '/' . $pagepath . '/' . $pagename . $query_string); // Forward user to page
exit;

?>