<?php

// index.php
// -------------------------------------------------------------------------------------------------
// The XComponents 'server compatibility subsite' homepage
// This page tests the PHP version, and whether the PHP cURL module is installed
// 
// Project    > dmClubNewYear08:C37
// Copyright  > (C) Digital Mail Limited (2005-2008)
// Author     > RAK for DML
// -------------------------------------------------------------------------------------------------

// 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');

// -------------------------------------------------------------------------------------------------

if (isset($_GET['submit']))
{
	$value = isset($_GET['xcom_debugging']) ? 1 : 0;
	$dmx_debug_settings->xcom = $value;
	setcookie('dmx_debug_settings', $json->encode($dmx_debug_settings), false, '/');
}
else
{
	$value = $dmx_debug_settings->xcom;
}
$checked = $value ? 'checked' : '';
$status  = $value ? 'enabled' : 'disabled';

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Server Configuration Testpage</title>

	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta name="Copyright" content="Digital Mail Limited 2005-2010">

	<link href="/dmx/core/b0/css/core_dmclub.css" rel="stylesheet" type="text/css" media="All">
	<link href="/dmx/core/b0/css/over_dmclub.css" rel="stylesheet" type="text/css" media="All">
	<link href="/dmx/core/b0/css/core.css" rel="stylesheet" type="text/css" media="All">
	<link href="/dmx/core/b0/css/over.css" rel="stylesheet" type="text/css" media="All">
	<link href="/dmx/core/b0/css/print.css" rel="stylesheet" type="text/css" media="Print">
	<!--[if lt IE 7]>
		<link href="/dmx/core/b0/css/ie6.css" rel="stylesheet" type="text/css" media="All" />
	<![endif]-->
	
	<script language="javascript" src="/dmx/core/js/mootools-1.2.4-core-yc.js" type="text/javascript"></script>
	<script language="javascript" src="/dmx/core/js/mootools-1.2.4.2-more.js" type="text/javascript"></script>
	<script language="javascript" src="/dmx/core/b0/js/b0_interface.js" type="text/javascript"></script>

	<script language="javascript">
	
	// Set up page initialisation event handler
	if (window.addEventListener)
	{
		window.addEventListener('load', b0_interface_init, true); // W3C
	}
	else if (window.attachEvent)
	{
		window.attachEvent('onload', b0_interface_init); // IE  - Quirks Mode
	}
	else
	{
		window.onload = b0_interface_init;
	}

	</script>

	<script language="javascript" type="text/javascript">
	<!-- 
	function kill_session()
	{
		// Kill the dmShop session, and XComponents session
		Cookie.dispose('dmb1_backup_session_ref');
		Cookie.dispose('DMXSessionID');
		alert('Session backup cookie deleted');
	}
	//-->
	</script>
	
	<style type="text/css">
	
	.ness
	{
		color: red;
		font-weight: normal;
		font-variant: normal;
		font-size: 16px;
	}
	
	
	</style>

</head>

<body>
<div class="dmb0">

<a name="top"></a>

<!-- ************** -->
<!-- HEADER SECTION -->
<!-- ************** -->

<!-- MAIN HEADER BAR AND BRANDING -->
<div id="header_bar">
	<div class="content" align="center">
		<table width="100%" cellpadding="0" cellspacing="0" border="0" class="limit_width_700">
			<tr>
				<td style="width: 99%; vertical-align: middle;" class="title">Server test page</td>
				<td><img src="/dmx/core/b0/images/dmclub_header/dmclub_better_biz.gif" alt="better business through  innovative telecoms" width="164" height="71" border="0"></td>
				<td><img src="/dmx/core/b0/images/dmclub_header/dmclub_logo.gif" alt="dmClub logo" width="63" height="71" border="0"></td>
			</tr>
			<tr>
				<td></td>
				<td colspan="2"><img src="/dmx/core/b0/images/dmclub_header/dmclub_highlight.gif" alt="" width="227" height="8" border="0"></td>
			</tr>
		</table>
	</div>
</div>
<!-- END MAIN HEADER BAR AND BRANDING -->

<!-- NAV BAR -->
<div id="nav_bar">
	<div class="content" align="center">
		<div class="limit_width_700">
		 	<div style="float: right">
		 		<!-- RHS NAV BAR CONTENT -->
		 		<a href="" onclick="kill_session(); return false;">Kill XComponents Session</a>
		 		<!-- END RHS NAV BAR CONTENT -->
		 	</div>
		 	<!-- LHS NAV BAR CONTENT -->
		 	<a href="/dmx/demo/index.php">XCom Demo</a><a href="/dmx/edi/index.php">EDI Demo</a><a href="/dmx/server/index.php">Server Tests</a><a href="/dmx/tst/index.html">TST Diagnostics</a><a href="/dmx/core/b0/demo/index.html">Brand Zero</a>
		 	<!-- END LHS NAV BAR CONTENT -->
		 	&nbsp;
		</div>
	</div>
</div>
<!-- END NAV BAR -->

<!-- ERROR MESSAGE BAR -->
<div id="err_msg_bar" style="display: none;">
	<div class="content" align="center">
		<div class="limit_width_700"></div>
	</div>
</div>
<!-- END ERROR MESSAGE BAR -->

<!-- ****************** -->
<!-- END HEADER SECTION -->
<!-- ****************** -->


<!-- ******************* -->
<!-- PAGE BODY CONTAINER -->
<!-- ******************* -->

<div class="content" align="center">
<div class="limit_width_700">

<!-- BODY CONTENT STARTS HERE -->

<?php

echo '<p><strong>';
if (isset($dmx_version)) {
	echo '<h1>Server Configuration Tests <small>(XComponents-' . $dmx_version . ')</small></h1>';
} else {
	echo '<h1>Server Configuration Tests</h1>';
}
echo '</strong></p>';

// Test IP address
$ip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : gethostbyname($_SERVER['SERVER_NAME']);
echo '<p><strong>';
if ($ip) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'Server IP address: ' . $ip;
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'Server IP address unavailable';
}
echo '</strong></p>';

// Test PHP environment
echo '<h3>PHP version and server API</h3>';

// Test PHP version
$version = phpversion();
echo '<p><strong>';
if ($version > 4.09) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
}
echo '&nbsp;&nbsp;';
echo 'PHP version ' . $version;
echo '</strong></p>';

echo '<p><strong>';
if (substr(PHP_SAPI, 0, 3) == 'cgi') {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'PHP is running as a CGI process';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'PHP is running as a web server module under ' . PHP_SAPI;
}
echo '</strong></p>';

?>

<h3>PHP library tests</h3>

<?php

// Test PCRE
echo '<p><strong>';
if (function_exists('preg_grep')) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'PCRE library is installed';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'PCRE library is not installed';
}
echo '</strong></p>';

// Test cURL
echo '<p><strong>';
if (function_exists('curl_init')) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'cURL is installed';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'cURL is not installed';
}
echo '</strong></p>';

// Test cURL - FOLLOW_LOCATION
echo '<p><strong>';
if (function_exists('curl_init')) {
	$ch = curl_init();
	if (@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE)) {
		echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
		echo '&nbsp;&nbsp;';
		echo 'cURL will follow location headers (redirects) <i class="ness">*</i>';
	} else {
		echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
		echo '&nbsp;&nbsp;';
		echo 'cURL will not follow location headers (redirects) <i class="ness">*</i>';
	}
} else {
	echo 'cURL options not tested (as cURL is not installed)';
}
echo '</strong></p>';

// Test MySQL
echo '<p><strong>';
if (function_exists('mysql_connect')) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'MySQL is supported <i class="ness">*</i>';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'MySQL is not installed <i class="ness">*</i>';
}
echo '</strong></p>';

// Test mcrypt
echo '<p><strong>';
if (function_exists('mcrypt_encrypt')) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'mcrypt is installed <i class="ness">*</i>';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'mcrypt is not installed <i class="ness">*</i>';
}
echo '</strong></p>';

?>

<p>
<i class="ness">*</i> = not essential for the current version of XComponents / dmABS.
</p>

<p>
Display full <a href="phpinfo.php">PHP environment details</a>
&nbsp; | &nbsp;
<a href="" onclick="$('add_tests').style.display = 'block'; return false;">Show additional tests</a>
</p>

<div id="add_tests" style="display: none;">

<h3>Additional tests: Resolving the path to the document root</h3>

<p>
This is vital for calling in the standard XComponent libraries. Don't worry if not all of the following 3 tests are passed: if at least one green tick is shown dmShop should still run.
</p>

<?php

// Test availability of $_SERVER['DOCUMENT_ROOT']
$docroot = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : NULL;
echo '<p><strong>';
if ($docroot !== NULL) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'DOCUMENT_ROOT\'] = ' . $docroot;
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'DOCUMENT_ROOT\'] unavailable';
}
echo '</strong></p>';

// Test availability of $_SERVER['SCRIPT_FILENAME']
$script_filename = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : NULL;
echo '<p><strong>';
if ($script_filename !== NULL) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'SCRIPT_FILENAME\'] = ' . $script_filename;
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'SCRIPT_FILENAME\'] unavailable';
}
echo '</strong></p>';

// Test availability of $_SERVER['PHP_SELF']
$phpself = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : NULL;
echo '<p><strong>';
if ($phpself !== NULL) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'PHP_SELF\'] = ' . $phpself;
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '$_SERVER[\'PHP_SELF\'] unavailable';
}
echo '</strong></p>';

?>

</div>

<h2>App Server Tests</h2>

<?php

$i = 1;

// 'Ping' each dmShop server, then do a simple dmShop protocol request
foreach($dmx_protocol['dmshop']['server_urls'] as $url)
{
	$domain = substr($url, 0, strrpos($url, '/'));
	$spurl = $domain . '/ping.htm';
	echo('<h3>dmShop Server ' . $i . ': ' . $domain . '</h3>');
	echo '<p><strong>';
	$http = new HTTP;
	$http->url = $spurl;
	$http->request();
	if ($http->result->response_code > 0) {
		echo('<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">');
		echo('&nbsp;&nbsp;');
		echo('Web server responding (' . (round($http->result->total_time * 1000)) . 'ms)<br />');
	} else {
		echo('<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">');
		echo('&nbsp;&nbsp;');
		echo('Not responding<br /></strong></p>');
		continue;
	}
	$dmshop = new PWP($url, $dmx_protocol['dmshop']['prot_ver']);
	$dmshop->client_app_version = $dmx_version;
	$dmshop->_R['Cmd'] 		 = 'ContinueTrolley';
	$dmshop->_R['TrolleyID'] = 'I_DONT_EXIST'; 
	$result = $dmshop->request();
	if ($dmshop->result->status) {
		echo('<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">');
		echo('&nbsp;&nbsp;');
		echo('App server replying in dmShop protocol (' . (round($dmshop->result->total_time * 1000)) . 'ms)');
		echo('</strong> &mdash; ' . $dmshop->result->response['AppServer'] . ' / ' . $dmshop->result->response['TimeTaken'] . '<strong><br />');
	} else {
		echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
		echo '&nbsp;&nbsp;';
		echo 'Not replying in dmShop protocol<br />';
	}
	echo '</strong></p>';
	$i++;
}

?>

<?php

// 'Ping' TST server
$url = 'http://my.dmclub.net/dmb1_tst/StepSess.cfm?dmb1_SessRef=0';
$domain = substr($url, 0, strrpos($url, '/'));
$spurl = $domain . '/ping.htm';

$http = new HTTP;
$http->url = $spurl;
$http->request();
echo('<h3>TST Server: ' . $domain . '</h3>');
echo '<p><strong>';
if ($http->result->response_code > 0) {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'Web server responding (' . (round($http->result->total_time * 1000)) . 'ms)<br />';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'Not responding';
}
$http = new HTTP;
$http->url = $url;
$http->request();
if ($http->result->response == 'StepSess:dmb1_SessRef doesn\'t exist') {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'App server replying in TST protocol (' . (round($http->result->total_time * 1000)) . 'ms)';
} else {
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo 'Not responding';
}
echo '</strong></p>';

?>

<h2>XComponent debugging</h2>

<p>
<b>Use this control to switch XComponent debugging on or off.</b><br>
Note that pages must include the 'Benchmarks' and/or 'Debug' XComponents for debugging to be displayed.
</p>

<form action="" method="get">
<table style="width: 100%;">
<tr><td colspan="4" class="divider"><img src="/dmx/core/b0/images/clear.gif" width="1" height="1" alt=""></td></tr>
<tr>
	<td class="cell2i"><strong>Debugging <?=$status;?></strong></td>
	<td class="cell2i" style="text-align: right;">Display debugging&nbsp;&nbsp;</td>
	<td class="cell2f">
		<input type="checkbox" name="xcom_debugging" <?=$checked;?>>
	</td>
	<td class="cell1f" style="text-align: right;">
		<input name="submit" type="submit" value="Set">
	</td>
</tr>
<tr><td colspan="4" class="divider"><img src="/dmx/core/b0/images/clear.gif" width="1" height="1" alt=""></td></tr>
</table>
</form>

<p>
<a href="/dmx/demo/">Go to demo site homepage</a>
</p>

<!-- END BODY CONTENT -->

<!-- HELP AREA -->         
<a name="help"></a>
<div id="help">
	
	<!-- STANDARD HELP HEADER BAR -->
	<div id="help_header_bar">
		<div style="float: right">
			<!-- RHS LINKS IN HELP HEADER BAR -->
			<a href="#" onclick="popup('http://notes.dmclub.net', 'dmNotes'); return false;" class="popup infotext">dmNotes<span class="tipcontents">Counsult our full user<br />guide for more details</span></a><a href="#" onclick="popup('http://my.dmclub.net/dmSupport_R13S13/dmSupportDetails.cfm', 'dmSupport'); return false;" class="popup infotext">dmSupport<span class="tipcontents">Contact our helpdesk</span></a>
			<!-- END RHS LINKS IN HELP HEADER BAR -->
		</div>
		<!-- LHS HELP HEADER BAR CONTENT -->
		<span class="title">Help for this page</span>
		<!-- END LHS HELP HEADER BAR CONTENT -->
	</div>
	<!-- END STANDARD HELP HEADER BAR -->
	
	<div id="help_contents">
	<!-- VARIABLE HELP AREA CONTENT -->

<h2>Cookie scope and duration</h2>

<p>
<b>Scope: </b>The cookies set by this page only affect the display of debugging information for sessions on the computer and web browser you are currently using.
</p>

<p>
<b>Duration: </b>All cookies set by this page are set to expire as soon as you quit this web browser.
</p>

	<!-- END VARIABLE HELP AREA CONTENT -->

	<!-- STANDARD dmNOTES AND dmSUPPORT LINKS -->
	<h1>Further information and assistance</h1>
	<a href="#" onclick="popup('http://notes.dmclub.net', 'dmNotes'); return false;" class="popup">dmNotes:</a> Consult our full user guide for more details<br />
	<a href="#" onclick="popup('http://my.dmclub.net/dmSupport_R13S13/dmSupportDetails.cfm', 'dmSupport'); return false;" class="popup">dmSupport:</a> Contact our helpdesk with a technical enquiry, a question or your comments
	<!-- END STANDARD dmNOTES AND dmSUPPORT LINKS -->
	</div>

</div>
<!-- END HELP AREA -->

</div>
</div>

<!-- *********************** -->
<!-- END PAGE BODY CONTAINER -->
<!-- *********************** -->

<!-- ********** -->
<!-- FOOTER BAR -->
<!-- ********** -->

<br style="clear: both;">
<div id="footer_bar">
	<div class="content" align="center">
		<div class="limit_width_700">
		 	<div style="float: right">
		 		<!-- RHS FOOTER CONTENT -->
		 		<!-- Standard back to top link -->
		 		&nbsp;&nbsp;&nbsp;<a href="#top">back to top</a>
		 		<!-- END RHS FOOTER CONTENT -->
		 	</div>
		 	<!-- LHS FOOTER CONTENT -->
			dmx:server:index.php:S01_C07
		 	<!-- END LHS FOOTER CONTENT -->
		</div>
	</div>
</div>

<!-- ************** -->
<!-- END FOOTER BAR -->
<!-- ************** -->

</div>

</body>
</html>