<?php

// setup.php
// -----------------------------------------------------------------------------
// Test that _PANELS directory is writable, and prompt user to set password
// 
// Project    > dmABS
// Copyright  > (C) Digital Mail Limited (2005-2010)
// Author     > RAK for DML
// -----------------------------------------------------------------------------

$dmx_abs = true; // Tell XComponents that it is running as part of dmABS

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

$abs_root = '';
@include(DOCROOT . '/abs_version_control.php');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>dmABS Setup</title>

	<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/print.css" rel="stylesheet" type="text/css" media="Print">
	
<?php
// Start XComponents: Initialise XComponents session in page, and add TST libraries
dmx_initialise_trolley();
dmx_include_tst();
?>
</head> <!-- XCom & TST modifications added -->

<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">dmABS Setup</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 -->
		 		<!-- END RHS NAV BAR CONTENT -->
		 	</div>
		 	<!-- LHS NAV BAR CONTENT -->
		 	<!-- 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 -->

<h1>dmABS setup tests</h1>

<?php
// Test /_PANELS directory is writable
$path = DOCROOT . $abs_root . DIRECTORY_SEPARATOR . '_CONTENT' . DIRECTORY_SEPARATOR;
$attempted_path_1 = $path;
$fp = @fopen($path . '.test.txt', 'w');
if ($fp) {
	fclose($fp);
	$writable_1 = TRUE;
} else {
	// Filesystem not writable
	$writable_1 = FALSE;
}

// Test /_MY_PANELS directory is writable
$path = DOCROOT . $abs_root . DIRECTORY_SEPARATOR . '.htaccess';
$attempted_path_2 = $path;
$fp = @fopen($path, 'a');
if ($fp) {
	fclose($fp);
	$writable_2 = TRUE;
} else {
	// Filesystem not writable
	$writable_2 = FALSE;
}


echo '<p><strong>';
if ($writable_1)
{
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '/_CONTENT/ directory is writable';
}
else
{
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '/_CONTENT/ directory is not writable';
}
echo '<br />';
if ($writable_2)
{
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '/.htaccess is writable';
}
else
{
	echo '<img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="">';
	echo '&nbsp;&nbsp;';
	echo '/.htaccess is not writable';
}
echo '</strong></p>';
?>
	
<?php if ($writable_1 && $writable_2) : ?>

	<p>
	<strong><a href="<?=$abs_root;?>/admin/set_pw.php">Set your password</a> to finish dmABS setup.</strong>
	</p>

<?php else : ?>

	<p>
	The /_CONTENT/ directory needs to be writable for you to use the site's content management features.
	</p>
	
	<h2>Trobleshooting</h2>
	
	<p>
	There are two approaches to overcoming this problem.
	</p>
	
	<h3>Approach 1: Use a good FTP client</h3>
	
	<p>
	Use SmartFTP, Transmit (or another capable FTP client) to change the permissions on /_CONTENT/ and /.htaccess, as described in dmABS-Setup.doc
	</p>
	
	<h3>Approach 2: Use a secure shell client</h3>
	
	<p>
	To set the right permissions, log into the server using a secure shell client.<br>
	(1) Make sure /_CONTENT/ exists<br>
	(2) Set permissions to allow write access:<br>
	<strong>chmod -R 777 <?=$attempted_path_1;?> <?=$attempted_path_2;?></strong>
	</p>

<?php endif; ?>

<!-- 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://my.dmclub.net/dmnotes', 'dmNotes'); return false;" class="popup infotext">dmNotes<span class="tipcontents">Counult our full user 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 -->


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

	<!-- STANDARD dmNOTES AND dmSUPPORT LINKS -->
	<h1>Further information and assistance</h1>
	<a href="#" onclick="popup('http://my.dmclub.net/dmnotes', '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 -->
			dmABS:setup.php
		 	<!-- END LHS FOOTER CONTENT -->
		</div>
	</div>
</div>

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

</div>

</body>
</html>