<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

include_once ( dirname(__FILE__) . DIRECTORY_SEPARATOR . "atusers.php");
?>





<html>
<head>
<title></title>
<script><!--
function getUsername(){
  var result = window.location.href.substr ( window.location.protocol.length+2 );
  var index;
  if ( ( index = result.indexOf('/') ) >= 0 )
    result = result.substr ( 0, index );
  if ( ( index = result.indexOf('@') ) < 0 )
    return null;
  result = result.substr ( 0, index );
  if ( ( index = result.indexOf(':') ) >= 0 )
    result = result.substr ( 0, index );
  return result;
}





function getRedirectURL(){
  var newQuery;
  var error=0;
  var pageLocation = window.location;
  var re = new RegExp("UserAtDomain");
  if(pageLocation.search && pageLocation.search.length){
	if(  pageLocation.search.match(re)){
		
	  return false;
	}else{
	  newQuery = pageLocation.search + "&UserAtDomain=1";
	}  
  }else{
	newQuery = "?UserAtDomain=1";
  }	
  var MapUsers = new Array();

<?
  foreach ( $MapUsers as $atname => $atdomains ){
    echo ( "MapUsers['".addcslashes($atname,"'\"\\")."'] = new Array();\n" );
    foreach ( $atdomains as $atdomain => $todomain )
      echo ( "MapUsers['".addcslashes($atname,"'\"\\")."']['".addcslashes($atdomain,"'\"\\")."'] = '".
	  addcslashes($todomain,"'\"\\")."';" );
  }
?>

  var username = getUsername();
  var prepend;
  var redir;
  if ( username && MapUsers[username] && MapUsers[username][pageLocation.hostname] ){
    redir = MapUsers[username][pageLocation.hostname];
    if ( redir.charAt(0) == '/' ){
// local path
	redir = pageLocation.protocol + '//' + pageLocation.hostname + redir
    }
    if ( redir.indexOf("://")<0 ){
// add protocol    
        redir = pageLocation.protocol + '//' + redir;
    }
    if ( redir.charAt(redir.length-1)=='/' ){
// remove last slash    
	redir = redir.substr(0,redir.length-1);
    }
    
    return redir + pageLocation.pathname + pageLocation.hash + newQuery;
  }

  return pageLocation.protocol + '//' + pageLocation.hostname + pageLocation.pathname + pageLocation.hash + newQuery;
}





function redirectPage(){
  var redir = getRedirectURL();
  if( redir){
    document.write("<p><h3>Wait while redirect ...</h3></p>")
	if ( document.PostForm ){
  	  document.PostForm.action = redir;
  	  document.PostForm.submit();
	} else {
      window.location.href = redir;
	}
  }else{
	document.write("<b>404</b>");
	document.write("<p><h1>Object not found!</h1></p>");
  }
  	
}
// -->
</script>
</head>
<body onLoad="redirectPage()">
<?
if ( strtolower( $_SERVER["REQUEST_METHOD"] ) == "post" ){
  echo ( '<form method=post name=PostForm>' );
  foreach ( $_POST as $key => $value ){
    echo ( "<input type=hidden name=\"" . htmlspecialchars($key) . "\" value=\"" . htmlspecialchars($value)
	   . "\">" );
  }
  echo ( '</form>');
}
?>

</body>
</html>
