<?php

// clientside_redirect.php
// -----------------------------------------------------------------------------
// Trigger a client side redirect to URL specified in $destination
// This is use to handle transfers between domains while running a
// Google Analytics session
//
// Project    > dmClubNewYear08:C37
// Copyright  > (C) Digital Mail Limited (2005 / 2006)
// Author     > Richard Knight (RAK) for DML
// -----------------------------------------------------------------------------

// Get the filkesystem address of the webserver's document root directory
define('MOD_PHP', substr(PHP_SAPI, 0, 3) != 'cgi'); // Are we running as mod_php?
define('DOCROOT', 
	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) :
						'.'
				)
		)
	);

// Get the Google Analytics account number and destination URL
$ganal_accno  = $_GET['ganal_accno'];
$trans_rep    = urldecode($_GET['ganal_trans_rep']);
$destination  = urldecode($_GET['url']);
$session_ref  = isset($_GET['dmb1_SessRef']) ? $_GET['dmb1_SessRef'] : 'UNKNOWN';

// Our debug flag for Google Analytics ecommerce reporting
$debug = FALSE;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Transfer to dmAccount</title>
	<meta name="generator" content="BBEdit 8.5">
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta name="Date" content="14-07-2009">
	<meta name="Copyright" content="Digital Mail Limited 2005-2009">

	<!-- TST JS -->
	<script language="javascript" src="/dmx/core/js/page_init_wrapper.js" type="text/javascript"></script>
	<script language="javascript" src="/dmx/core/js/core.js" type="text/javascript"></script>
	<script language="javascript" src="/dmx/core/tst/js/tst.js" type="text/javascript"></script>
	<script language="javascript" src="/dmx/tst/tst_options.js" type="text/javascript"></script>
	<!-- END TST JS -->

</head> 

<body>

<script language="javascript" type="text/javascript">
<!--
var url = '<?=$destination;?>';
var dmb1_session_ref = '<?=$session_ref;?>';
var t = tst_add_session_data(url);
var url = t[1];
var params = new Object(); // Append session data to URL
params.ganal_accno = '<?=$ganal_accno;?>';	
var transfer_url = dmb1_append_param_to_url(url, params);
// -->
</script>

<!-- Google Analytics code -->
<script src="http://www.google-analytics.com/urchin.js" language="javascript" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
<!--
_uacct = '<?=$ganal_accno;?>';
_udn = 'none';
_ulink = 1;
urchinTracker();
// -->
</script>
<!-- End Google Analytics code -->


<?php if ($debug) : ?>

	<h1>Google Transaction Report Data for <?=$ganal_accno;?></h1>
	
	<pre>
	<?=$trans_rep;?>
	</pre>
	
	<p>
	<b>TRANSFER URL</b>
	</p>
	
	<pre>
	<script language="javascript">
	<!--
	var temp = transfer_url.replace(/\?|&/g, '\n');
	document.write(temp);
	// -->
	</script>
	</pre>

<?php endif; ?>

<!-- GOOGLE ANALYTICS ORDER REPORTING IN HIDDEN FORM -->
<form style="display: none;" name="utmform">
<textarea id="utmtrans"><?=$trans_rep;?></textarea>
<script language="javascript">document.write('<input type="text" name="transfer_url" value="' + transfer_url + '">')</script>
</form>
<!-- END GOOGLE ANALYTICS ORDER REPORTING IN HIDDEN FORM -->

</body>
</html>