<?php

// xcom_server.php
// -----------------------------------------------------------------------------
// Designed to serve XComponent requests made using0 AJAX
//
// Project    > dmABS
// Copyright  > (C) Digital Mail Limited (2005-2009)
// Author     > RAK for DML
// -----------------------------------------------------------------------------

ob_start();

// Override the standard definition of DMX_SELF
$dmx_self = $_SERVER['HTTP_REFERER'];
if (strpos($dmx_self, '?') !== FALSE) $dmx_self = substr($dmx_self, 0, strpos($dmx_self, '?'));
if (strpos($dmx_self, '#') !== FALSE) $dmx_self = substr($dmx_self, 0, strpos($dmx_self, '#'));
define('DMX_SELF', $dmx_self);

// Call in the XComponents engine and options file
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) :
						'.'
				)
		)
	);
include(DOCROOT . '/dmx/dmx_options.php');
include(DOCROOT . '/dmx/core/php/dmx_shop_handler.php');
include(DOCROOT . '/dmx/core/php/dmx_shop_components.php');

// Input
$family  		= isset($_POST['family']) 			? $_POST['family'] 			: NULL;
$xclass 	 	= isset($_POST['xclass']) 			? $_POST['xclass'] 			: NULL;
$name 	 		= isset($_POST['name']) 			? $_POST['name'] 			: NULL;
$skip_dmshop 	= isset($_POST['skip_dmshop']) 		? $_POST['skip_dmshop'] 	: NULL;
$timeoutignore	= isset($_POST['timeoutignore']) 	? $_POST['timeoutignore'] 	: NULL;

// Override location of service graphics library?
if (isset($_POST['dmx_glib'])) $dmx_options['glib'] = $_POST['dmx_glib'];

unset($_POST['family'], $_POST['xclass'], $_POST['name'], $_POST['dmx_glib'], $_POST['skip_dmshop']); // Don't unset timeoutignore
$xparams = $_POST;

// Initialise environment
dmx_initialise_trolley($skip_dmshop);

// Render the XComponent
if ($family && $xclass && $name) dmx_render($family.'.'.$xclass, $name, $xparams);

ob_flush();

?>