<?php
	
// abs_run.php
// -------------------------------------------------------------------------------------------------
// PHP executed on every page
//
// Project    > A16-dmABS-1.5-Feb09
// Copyright  > (C) Digital Mail Limited (2005 - 2009)
// Author     > Richard Knight (RAK) for DML
// -------------------------------------------------------------------------------------------------

// Let XComponents know they are running inside dmABS
$dmx_options['abs'] = TRUE;

// Initialse abs debugging buffer
$dmx_debug_settings->abs = isset($dmx_debug_settings->abs) ? $dmx_debug_settings->abs : $abs_debug_level;
$abs_debug = new debug($dmx_debug_settings->abs);

// -------------------------------------------------------------------------------------------------
// GET SITE OPTIONS

$abs_opt = abs_get_site_options($abs_sitemode);

// -------------------------------------------------------------------------------------------------
// AUTHORISATION

// Is the user an authorised site administrator?
$abs_authorised = 	ABS_AUTH_METHOD == 'PHP-SESSION'
					&& isset($_SESSION['ABS_AUTH']['status'])
					&& $_SESSION['ABS_AUTH']['status']
					&& abs_get_ip() == $_SESSION['ABS_AUTH']['ip'];

// Do we need to revalidate?
if ($abs_authorised && (time() - $_SESSION['ABS_AUTH']['timestamp'] > ABS_SESSION_DURATION))
{
	$_SESSION['ABS_AUTH']['status'] = FALSE;
	session_write_close();
	header('LOCATION: ' . $abs_root . '/admin/login.php?abs_state=revalidate&destination=' . $_SERVER['PHP_SELF']);
	exit;
}

// -------------------------------------------------------------------------------------------------
// UK-GEO 0207 switcher

if (isset($_GET['dmx_areacode'])) $_SESSION['ABS']['last_areacode'] = $_GET['dmx_areacode'];

// -------------------------------------------------------------------------------------------------
// TOOLBAR

$abs_toolbar_display = isset($dmx_debug_settings->toolbar_show) && $dmx_debug_settings->toolbar_show ? 'block' : 'none';

if (!isset($abs_toolbar_extras)) $abs_toolbar_extras = array();

// -------------------------------------------------------------------------------------------------
// SET PATHS OF VARIOUS RESOURCES

// Set location of adapting bodies (including trailing slash)
$abs_adapt_body = DOCROOT . $abs_root . '/common/adaptingbody/';

// Set location of areacode sidepage
$abs_areacodes = DOCROOT . $abs_root . '/common/sp_areacodes.php';

// Set location of call cost explorer sidepage
$abs_callcostexplorer = DOCROOT . $abs_root . '/common/sp_callcostexplorer.php';

// Set location of typical invoice sidepage
$abs_typinv = DOCROOT . $abs_root . '/common/sp_typinv.php';

// Set location of tariffguide sidepage
$abs_tariffguide = DOCROOT . $abs_root . '/common/sp_tariffguide.php';

// -------------------------------------------------------------------------------------------------
// EASY SEO

$abs_res = abs_read_easy_seo_data();
$abs_seo = $abs_res['seo'];
if (isset($abs_res['invalid'])) $abs_invalid_urls = $abs_res['invalid'];

$abs_seo_key = substr($_SERVER['PHP_SELF'], 0, -4); // Drop the '.php'
if (isset($abs_seo[$abs_seo_key]))
{
	$abs_title 			= $abs_seo[$abs_seo_key]['title'];
	$abs_description 	= $abs_seo[$abs_seo_key]['description'];
	$abs_keywords	 	= $abs_seo[$abs_seo_key]['keywords'];
}
else
{
	$abs_title 			= NULL;
	$abs_description 	= NULL;
	$abs_keywords 		= NULL;
}

// -------------------------------------------------------------------------------------------------
// LOOK FOR ABS FOCUS CHANGE

// Overlay NumberChooser memory, but only for the properties present
// Thses paramters are designed to be used in intra-site links, and do not reset NumberChooser memory,
// unlike NCP coming from outside dmABS

$abs_nc_focus = array();
if (isset($_REQUEST['abs_service'])) 	$abs_nc_focus['service'] 	= $_REQUEST['abs_service'];
if (isset($_REQUEST['abs_plan'])) 		$abs_nc_focus['plan']		= $_REQUEST['abs_plan'];
if (isset($_REQUEST['abs_gold'])) 		$abs_nc_focus['gold']		= $_REQUEST['abs_gold'];
if (isset($_REQUEST['abs_areacode'])) 	$abs_nc_focus['areacode']	= $_REQUEST['abs_areacode'];

if (!empty($abs_nc_focus)) dmx_update_nc_memory(NULL, $abs_nc_focus);

// -------------------------------------------------------------------------------------------------
// PANELS AND SUBSTITUTIONS

// Resolve content version (so we know which panels directory to use) and editmode_status
$abs_content = abs_resolve_version();

// Include panel class, and initialise it
require_once(DOCROOT . '/dmx/core/php/class/panel.class.php');
$panel = new Panel(
	DOCROOT . $abs_root . '/_CONTENT',
	$abs_content['version'],
	$abs_content['default'],
	$abs_content['today']
);
$panel->pan_globals  = array('abs_root', 'abs_opt', 'abs_subject', 'abs_number'); // Place these variables in scope of panel renderer
$panel->js_interface = 'abs_editable'; // Push panel names into 'abs_editable' javascript object

// Include substitution class, and generate substitutions
require_once(DOCROOT . '/dmx/core/php/class/substitutions.class.php');
$abs_glos = new Substitutions();
abs_compile_substitutions();

// -------------------------------------------------------------------------------------------------
// CONTENT HELPERS

// Analyse URL
$abs_path = abs_analyse_path($_SERVER['PHP_SELF']);

// Try to determine page subject
$abs_subject = abs_get_page_subject();
if ($abs_subject['range']) $abs_convpath = $abs_root . '/numbers/' . strtolower($abs_subject['range']); // For convenience

$abs_current_tariff 	= isset($abs_xparams['tariffs']) 		? $abs_xparams['tariffs'] 		: NULL;
$abs_numberchooser_name = $abs_current_tariff 					? 'nc_' . $abs_subject['range']	: NULL;
$abs_xstate 			= dmx_expose_nc_state($abs_current_tariff, $abs_numberchooser_name);

// Is this the first dmABS the user has loaded (as far as we can tell)?
// Used to preload flowbox images in footer.php
$abs_site_entry = !isset($_REQUEST['dmb1_SessRef']) && !isset($_COOKIE['dmb1_backup_session_ref']);

// Decide text colour for header block
$abs_header_text_col = abs_decide_text_colour($abs_opt['header_block_colour']);

// Set background image override for header block if one has been specified
$abs_header_bg = isset($abs_opt['header_bg']) && $abs_opt['header_bg'] != ''
				? '#header { background-image: url(' . $abs_opt['header_bg'] . "); }\n" :
				  "/* No header background override */\n";

// -------------------------------------------------------------------------------------------------
// CHAT

// Get WhosOn Chat status
if ($abs_opt['whoson'] == 'ON')
{
	$abs_temp = dmx_execute_get($abs_opt['whoson'] . '/chat/' . $_SERVER['HTTP_HOST'] . '.htm', array(), 3);
	$abs_chat_status = $abs_temp['status'];
}

?>