<?php
// 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 code starts here
$abs_root = '';
@include(DOCROOT . '/abs_version_control.php');
$abs_auth_page = 'login';
include(DOCROOT . $abs_root . '/common/authenticate.php');
include(DOCROOT . $abs_root . '/common/header.php');
?>

<!-- MAIN CONTENT AREA -->
<div id="main_area" onmouseover="sub_menu_hide();">
	<div id="main_area_content">
		
		<div class="main_column">
		<!-- ----------------- -->
		<!-- BEGIN MAIN COLUMN -->
		<!-- ----------------- -->
			
<?php if (isset($_REQUEST['abs_state']) && $_REQUEST['abs_state'] == 'revalidate') : ?>

	<h1>Revalidate to continue using site administrator functions</h1>
	
	<p>
	<b>Some time has passed since you last logged in, so please re-enter your username and password.</b> This security measure is a defence against leaving your browser open and forgetting to logout.
	</p>
	
<?php elseif (isset($_REQUEST['abs_state']) && $_REQUEST['abs_state'] == 'force_login') : ?>
	
	<h1>Please login using your existing username and password</h1>
	
	<p>
	<b>To change your password you must know your password.</b>
	</p>

<?php else : ?>

	<h1>Login to use {SUB:company_brandname}'s admin area</h1>
	
	<p>
	<b>Please enter your username and password.</b>
	</p>

<?php endif; ?>

<?php if ($screen == 'login_failure') : ?>
	<p>
	<strong>The username and password you entered were invalid.</strong> Try again...
	</p>
<?php endif; ?>

<!-- <script src="<?=$abs_root;?>/js/md5.js" language="javascript" type="text/javascript"></script> -->
<script src="<?=$abs_root;?>/js/sha1.js" language="javascript" type="text/javascript"></script>
<!-- <script src="<?=$abs_root;?>/js/sha1_alternative.js" language="javascript" type="text/javascript"></script> -->
<script language="javascript" type="text/javascript">
<!--

var abs_form_submitted = false;

function abs_encrypt(method)
{
	if (abs_form_submitted) return;
	switch (method)
	{
		case 'MD5':
			// Encrypt username and password using MD5 before transmission to server
			document.login_form.un.value = hex_md5(abs_trim(document.login_form.username.value));
			document.login_form.pw.value = hex_md5(abs_trim(document.login_form.password.value));
			break;
			
		case 'SHA1':
		default:
			// Encrypt username and password using SHA1 before transmission to server
			document.login_form.un.value = hex_sha1(abs_trim(document.login_form.username.value));
			document.login_form.pw.value = hex_sha1(abs_trim(document.login_form.password.value));
			break;
	}
	document.login_form.username.value = document.login_form.password.value = '';
	document.login_form.sbut.value = 'contacting server...';
	document.login_form.submit();
	abs_form_submitted = true;
}

function abs_trim(str)
{
	// Trim a string
	if (str.charAt(0) == ' ')
	{
		str = aba_trim(str.substring(1));
  	}
  	if (str.charAt(str.length-1) == ' ')
  	{
		str = abs_trim(str.substring(0, str.length-1));
	}
	return str;
}

// -->
</script>

<form name="login_form" method="post" action="<?=$_SERVER['PHP_SELF'];?>" onsubmit="abs_encrypt('SHA1'); return false;">
<input type="hidden" name="abs_action" value="login">
<input type="hidden" name="destination" value="<?=$abs_destination;?>">
<input type="hidden" name="encrypted" value="1">
<input type="hidden" name="key" value="<?=$abs_auth_key;?>">
<input type="hidden" name="un" value="">
<input type="hidden" name="pw" value="">
<div style="width: 100%; margin: 5px 0px; clear: both;">
	<div style="width: 15%; text-align: right; float: left; margin: 3px 0px; padding: 4px 10px 0px 0px;">Username</div>
	<div style="margin: 3px 0px; float: left;"><input type="text" name="username" size="20"></div>
</div>
<div style="width: 100%; margin: 5px 0px; clear: both;">
	<div style="width: 15%; text-align: right; float: left; margin: 3px 0px; padding: 4px 10px 0px 0px;">Password</div>
	<div style="margin: 3px 0px; float: left;"><input type="password" name="password" size="20"></div>
</div>
<div style="width: 100%; margin: 5px 0px; clear: both;">
	<div style="width: 15%; text-align: right; float: left; margin: 3px 0px; padding: 4px 10px 0px 0px;"></div>
	<div style="margin: 3px 0px;"><input type="submit" name="sbut" value="login"></div>
</div>
</form>

<br clear="all">

<?php if (isset($_REQUEST['abs_state']) && $_REQUEST['abs_state'] == 'revalidate') : ?>

<p>Alternatively <a href="#" onclick="document.logout_form.submit(); return false;">logout</a> to continue browsing the site normally.

<form name="logout_form" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<input type="hidden" name="abs_action" value="logout">
<input type="hidden" name="destination" value="<?=$abs_destination;?>">
<input type="hidden" name="key" value="<?=$abs_auth_key;?>">
</form>

<?php endif; ?>

		<!-- --------------- -->
		<!-- END MAIN COLUMN -->
		<!-- --------------- -->
		</div>
		
		<div class="sidebar">
		<!-- ------- -->
		<!-- SIDEBAR -->
		<!-- ------- -->
					
<div class="sidebar_box_heading">
	<h2>Security info</h2>
</div>
<div class="sidebar_box_content">
	<div>
		<br>
		<p>
		<strong>Password encryption:</strong>
		Your username and password are encrypted before transmission to the server. Both are scrambled using a one-way hash algorithm, making it very difficult to convert them back to clear text.
		</p>
		<p>
		<strong>Access duration:</strong>
		Every time you login you have access to the content management controls for two hours, after which you will be asked for your username and password again. This prevents network snoopers from defacing you site by reactivating old sessions. 
		</p>
	</div>
</div>

		<!-- ----------- -->
		<!-- END SIDEBAR -->
		<!-- ----------- -->
		</div>
		
	</div>
</div>
<!-- END MAIN CONTENT AREA -->

<br style="clear: both;">
<br>

<?php include(DOCROOT . $abs_root . '/common/footer.php'); ?>
