<?
/*
#########################################
// new crome parameter
A cookie associated with a cross-site resource at http://iconify.design/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
*/
header('Set-Cookie: HttpOnly; SameSite=None;Secure');
#########################################


if(!isset($active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY)) $active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY = "";

if(!isset($secured_server)) $secured_server = "";
if(!isset($session_is_cron_or_system_service)) $session_is_cron_or_system_service = "";
if(!isset($tmp_domain)) $tmp_domain = "";
if(!isset($incoming_vars)) $incoming_vars = "";
if(!isset($enterprise_access_password)) $enterprise_access_password = "";
if(!isset($cookie_this_session)) $cookie_this_session = "";
if(!isset($payme)) $payme = "";
if(!isset($clear)) $clear = "";
if(!isset($language_iso2)) $language_iso2 = "";
if(!isset($incoming_vars_user_selected_language_iso2)) $incoming_vars_user_selected_language_iso2 = "";
if(!isset($enterprise_access_password)) $enterprise_access_password = "";
if(!isset($_GET['secured_server'])) $_GET['secured_server'] = "";

if(!isset($_SESSION)) $_SESSION = array();
if(!isset($_SESSION['payme'])) $_SESSION['payme'] = array();
if(!isset($_SESSION['payme']['cancel'])) $_SESSION['payme']['cancel'] = "";

if(!isset($_XXXXX_)) $_XXXXX_ = "";
if(!isset($_XXXXX_)) $_XXXXX_ = "";
if(!isset($_XXXXX_)) $_XXXXX_ = "";
if(!isset($_XXXXX_)) $_XXXXX_ = "";
if(!isset($_XXXXX_)) $_XXXXX_ = "";



if($active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY) {
	$_SERVER['HTTP_HOST'] = $active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY;
}


/// FORCE SPECIAL TEMPLATES (for crons):
# if(
# 	(!$_SERVER['HTTP_HOST'])
# 	|| (stristr($_SERVER['HTTP_HOST'],"register.blingk.net"))
# 	|| (stristr($_SERVER['HTTP_HOST'],"update.blingk.net"))
# ) {
# 	$_SERVER['HTTP_HOST'] = $active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY = "intelitruth.com";
# }







if(!isset($FORCE_templates_companies_hash)) $FORCE_templates_companies_hash = "";



if($FORCE_templates_companies_hash) {
	$templates_companies_hash = $FORCE_templates_companies_hash; // intelitruth
	$tmp_sql = "SELECT *
				FROM templates_companies
				WHERE hash = '". $FORCE_templates_companies_hash ."'
				;";
	//test("tmp_sql",$tmp_sql);
	$_XXXXX_template_company = $tmp_template_company = object_to_array_v2(readTHECASHIER($tmp_sql,""));
	//test("tmp_template_company",$tmp_template_company);
	$active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY = $tmp_template_company['domain'];	
}



//logger3("0 _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);

//logger3("900 _SESSION['session']['geo']",$_SESSION['session']['geo']);

# DEAL WITH WEERD SESSION DISRUPTIONS:
// logger3("0. _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);
// if(
// (stristr($_SERVER['REQUEST_URI'],"link_images"))
// ) {
// 	logger3("ERROR. _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);
// 	exit;
// }




if(stristr($master_config_session_logging,"ON")) {
	logger("
###################################################################################
###################################################################################
### START NEW SESSION [session.shared]
### URL: " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "
### FILENAME: " . $_SERVER['SCRIPT_FILENAME'] . "
###################################################################################
###################################################################################
	
	
	
	");
}





if(stristr($master_config_session_logging,"ON")) logger("INITIAL SESSION LOGGER = OFF");



if(stristr($master_config_session_logging,"ON")) logger3("TEST 1",$TEST);
if(stristr($master_config_session_logging,"ON")) logger3("000. _COOKIE",$_COOKIE);
if(stristr($master_config_session_logging,"ON")) logger3("000. _COOKIE['BSESSION']",$_COOKIE['BSESSION']);
if(stristr($master_config_session_logging,"ON")) logger3("000. BSESSION",$BSESSION);
if(stristr($master_config_session_logging,"ON")) logger3("TEST 2",$TEST);
if(stristr($master_config_session_logging,"ON")) logger3("000. _SESSION",showSession());
if(stristr($master_config_session_logging,"ON")) logger3("TEST 3",$TEST);

if(isset($_SESSION['template']['company']['domain'])) $tmp_domain = $_SESSION['template']['company']['domain'];

if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['template']['company']['domain']",$tmp_domain);

if(isset($_SESSION['template']['company']['domain'])) {
	
	if(stristr($master_config_session_logging,"ON")) logger3("template['company']['domain']",$_SESSION['template']['company']['domain']);
	$jumble_domain = "." . $_SESSION['template']['company']['domain'];

} else {

	//if(stristr($master_config_session_logging,"ON")) logger3("_SERVER['HTTP_HOST']",$_SERVER['HTTP_HOST']);
	//$tmp_domain = explode(".",$_SERVER['HTTP_HOST']);
	//
	//if($tmp_domain[2]) {
	//	$jumble_domain = "." . $tmp_domain[1] . "." . $tmp_domain[2];
	//} else {
	//	$jumble_domain = "." . $_SERVER['HTTP_HOST'];
	//}

	$tmp_HTTP_HOST = explode(".",$_SERVER['HTTP_HOST']);
	$tmp_HTTP_HOST_reversed = array_reverse($tmp_HTTP_HOST);
	if(strlen($tmp_HTTP_HOST_reversed[0]) > 2) {
		$jumble_domain = "." . $tmp_HTTP_HOST_reversed[1] . "." . $tmp_HTTP_HOST_reversed[0];
	} else {
		$jumble_domain = "." . $tmp_HTTP_HOST_reversed[2] . "." . $tmp_HTTP_HOST_reversed[1] . "." . $tmp_HTTP_HOST_reversed[0];
	}

}




/// force a jumble.
if($active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY) {
	$jumble_domain = "." . $_SERVER['HTTP_HOST'];
	//$_SERVER['HTTP_HOST'] = "";
}

//test("0-jumble_domain",$jumble_domain);
//if($jumble_domain = ".nsdb.com"; $jumble_domain = "nsdb.com";
//exit;
///$jumble_domain = "BANGK.com";




if(stristr($master_config_session_logging,"ON")) logger3("000. jumble_domain",$jumble_domain);


#############################################################################################
### SET SESSION COOKIE ######################################################################


//test("###############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################AA _SESSION",$_SESSION);


require_once($master_config_root_path . "shared/BSESSION.shared");




//test("########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################BB _SESSION",$_SESSION);
//test("AA _SERVER",$_SERVER);


//logger3("1 _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);

### SESSION LOG / TESTING ################

// $tmp_session_name = session_name();
// if(stristr($master_config_session_logging,"ON")) logger3("1. tmp_session_name",$tmp_session_name);
// 
// $tmp_session_id = session_id();
// if(stristr($master_config_session_logging,"ON")) logger3("1. tmp_session_id",$tmp_session_id);

//$tmp_session_status = session_status();
//if($tmp_session_status) logger3("1. tmp_session_status",$tmp_session_status);

//$tmp_session = showSession();
if(stristr($master_config_session_logging,"ON")) logger3("1. _SESSION",showSession());

###########################################





if(stristr($master_config_session_logging,"ON")) logger3("000. _COOKIE",$_COOKIE);


######################################################################
######################################################################

//echo $master_config_session_logging;

if(stristr($master_config_session_logging,"ON")) logger3("to here");

# if(stristr($master_config_session_logging,"ON")) logger3("1/ _SESSION",$session);
# if(stristr($master_config_session_logging,"ON")) logger3("1/ _SESSION['session']",$_SESSION['session']);
# if(stristr($master_config_session_logging,"ON")) logger3("1/ session",$session);
# if(stristr($master_config_session_logging,"ON")) logger3("1. _SESSION['session']",$_SESSION['session']);
# if(stristr($master_config_session_logging,"ON")) logger3("1. session",$session);

if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['payme']",$_SESSION['payme']);
if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['payme']['error']",$_SESSION['payme']['error']);

if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['test']",$_SESSION['test']);
if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['payme']['test']",$_SESSION['payme']['test']);





//logger3("901 _SESSION['session']['geo']",$_SESSION['session']['geo']);



### REGISTER THE VARS:

if(stristr($master_config_session_logging,"ON")) logger3("000 _SESSION (before register vars)",showSession());

//include($master_config_root_path . "shared/session_register_vars.shared");
//logger3("2 _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);

if(stristr($master_config_session_logging,"ON")) logger3("001 _SESSION (after register vars)",showSession());

//logger3("902 _SESSION['session']['geo']",$_SESSION['session']['geo']);


### SET SOME SESSION VARS

# TEMPLATE
//logger3("master_config_database_company_template",$master_config_database_company_template);
//test("_SESSION['template']['company']['templateid']",$_SESSION['template']['company']['templateid']);

if(!isset($_SESSION['template']['company']['templateid'])) {
	

	if(stristr($master_config_session_logging,"ON")) logger3("0_SESSION['template']",$_SESSION['template']);
	if(stristr($master_config_session_logging,"ON")) logger3("0. master_config_database_company_template']",$master_config_database_company_template);
	
	$nsdb_platform_domain_wildcard = false;
	/// LIST OF CLIENTS WITH DOMAIN NAME WILDCARDS
	if(stristr($_SERVER['HTTP_HOST'],"NSDB.com")) $nsdb_platform_domain_wildcard = true;
	
	
	
	if($active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY) $master_config_database_company_template = $active_user_session_FORCE_DOMAIN_TEMPLATE_COMPANY;
	
	
	$template = template($master_config_database_company_template,$nsdb_platform_domain_wildcard);
	if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['template']['company']",$_SESSION['template']);
	
	
	
	

	
	//logger3("_SESSION['template']",$_SESSION['template']);
	//exit;
	
	
	//logger3("template",$template);
	//exit;
	
	### ADD PAYMENT OPTIONS:
	/// NOTES: if ($_SESSION['template']['company']['payment_options'][1]) is set, then there are MULTIPLE payment options.  
	$tmp_company_payment_options = $_SESSION['template']['company']['payment_options'];
	$_SESSION['template']['company']['payment_options'] = "";
	
	$exploded_company_payment_options = explode(",",$tmp_company_payment_options);
	foreach($exploded_company_payment_options as $key => $tmp_option_value) {
		if(trim($tmp_option_value) != "") {
			$_SESSION['template']['company']['payment_options'][$key] = $tmp_option_value;
		}
		$tmp_option_value = "";
	}
	
	if(stristr($master_config_session_logging,"ON")) {
		if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['template']['company']['payment_options']",$_SESSION['template']['company']['payment_options']);
	}
	
}
//logger3("_SESSION['template']",$_SESSION['template']);
//exit;

//if(stristr($master_config_session_logging,"ON")) logger3("1. template",$_SESSION['template']);
//logger3("1_SESSION['template']",$_SESSION['template']);


# HTTP
if(
(empty($_SESSION['http'])) ||
(empty($http))
) {
	if(stristr($master_config_session_logging,"ON")) logger3("0. http",$_SESSION['http']);
	$_SESSION['http'] = $http = http($_SERVER["SERVER_PORT"]);
}
if(stristr($master_config_session_logging,"ON")) logger3("1. http",$_SESSION['http']);



##  ### GEOBYTES (NEW)
##  if( ($_SESSION['geo']) || ($_SERVER['REMOTE_ADDR']) || ($_GET['clear_geo']) ) {
##  	unset($_GET['clear_geo']);
##  	$_SESSION['geo'] = geobytes($_SERVER['REMOTE_ADDR']);
##  	$_SESSION['geo']['ip'] = $_SERVER['REMOTE_ADDR'];
##  	echo "_SESSION['geo'] reset";
##  }



if(stristr($master_config_session_logging,"ON")) logger3("_SESSION['geo']",$_SESSION['geo']);


//logger3("903 _SESSION['session']['geo']",$_SESSION['session']['geo']);
# GEOBYTES

if(stristr($master_config_session_logging,"ON")) logger3("0. session['geo']",$_SESSION['session']['geo']);


if(isset($_SESSION['session']['geo']['country'])) {
	
	if(stristr($master_config_session_logging,"ON")) logger3("session['geo']['country']",$_SESSION['session']['geo']['country']);
	
	$tmp_sql = "SELECT iso3 FROM `geo_data` WHERE name = '" . strtoupper($_SESSION['session']['geo']['country']) . "';";
	if(stristr($master_config_session_logging,"ON")) logger3("tmp_sql",$tmp_sql);
	$tmp_iso3 = getTHECASHIER($tmp_sql);
	if(stristr($master_config_session_logging,"ON")) logger3("tmp_iso3",$tmp_iso3);
	
	if(!stristr($tmp_iso3,$_SESSION['session']['geo']['iso3'])) $data_does_not_match = true;
}

//if(!empty($_SESSION['session']['geo'])) logger3("1 _SESSION['session']['geo']",$_SESSION['session']['geo']);

//if(!empty($_SESSION['session']['geo'])) {
	
	// if( 
	// ( 
	// ($_SESSION['session']['geo']['known'] != "1") && 
	// ($_SESSION['session']['geo']['known'] != 1) && 
	// ($_SESSION['session']['geo']['known'] != true) && 
	// ($_SESSION['session']['geo']['known'] != "true") 


//logger3("000 _SESSION['session']['geo']",$_SESSION['session']['geo']);



# if( 
# (!stristr($_SESSION['session']['geo']['known'],"true")) 
# ) {
#     
#     if(stristr($master_config_session_logging,"ON")) logger3("_SERVER['REMOTE_ADDR']",$_SERVER['REMOTE_ADDR']);
#     
#     
#     ### START:  GEOBYTES / GEO EVERYTHING!!!
#     $_SESSION['session']['geo'] = "";
#     $_SESSION['session']['geobytes'] = "";
#     $_SESSION['session']['geo_data'] = "";
#     $_SESSION['session']['geodata'] = "";
# 	$tmp_geobytes_array = array();
# 	$tmp_geobytes_array = geobytes($_SERVER['REMOTE_ADDR']);
#     $_SESSION['session']['geo'] = $tmp_geobytes_array;
#     $_SESSION['session']['geobytes'] = $tmp_geobytes_array;
#     $_SESSION['session']['geo_data'] = $tmp_geobytes_array;
#     $_SESSION['session']['geodata'] = $tmp_geobytes_array;
# 	//logger3("001 _SESSION['session']['geo']",$_SESSION['session']['geo']);
#     ### END:  GEOBYTES / GEO EVERYTHING!!!
#     
#     
#     /// if not data, set best guess:
#     
#     if(
#     (!stristr($_SESSION['session']['geo']['known'],"TRUE")) 
#     ) {
# 	    
# 	    
# 	    //logger3("003 _SESSION['session']['geo']",$_SESSION['session']['geo']);
# 
# 	    
# 
#     	$_SESSION['session']['geo'] = geobytes($IP_ADDRESS = $_SERVER['REMOTE_ADDR']);
# 
#     }
#     
#     
#     
#     /// if STILL no data, set default:
#     if(
#     (!stristr($_SESSION['session']['geo']['known'],"TRUE"))
#     ) {
# 	    
# 	    //logger3("004 _SESSION['session']['geo']",$_SESSION['session']['geo']);
# 
# 
#     	include($_SESSION['template']['company']['file_path'] . "shared/set_default_geodata.inc");
# 
#     } 
#     
#     
#     
#     
#  
#     
#     
#     
#     
#     
#     
#     if(stristr($master_config_session_logging,"ON")) logger3("2. session['geo']",$_SESSION['session']['geo']);
# 
#     /*
#     RETURNS:
#     
#     known] => true
#     [locationcode] => AUNSSYDN
#     [fips104] => AS
#     [iso2] => AU
#     [iso3] => AUS
#     [ison] => 36
#     [internet] => AU
#     [countryid] => 14
#     [country] => Australia
#     [regionid] => 4
#     [region] => New South Wales
#     [regioncode] => NS
#     [adm1code] => AS02
#     [cityid] => 1311
#     [city] => Sydney
#     [latitude] => -33.8830
#     [longitude] => 151.2170
#     [timezone] => +10:00
#     [certainty] => 83 
#     */
# 
# }

	
//}
  

 //logger3("010 _SESSION['session']['geo']",$_SESSION['session']['geo']);







if(
($_GET['secured_server'] == "NO") ||
($session_is_cron_or_system_service == "YES")
) {
	$secured_server = strtoupper($_GET['secured_server']);
	$_SESSION['session']['access_status'] = "Granted"; // grants access to development servers athat are not opublic.
	setcookie("cookie_access_status", "GRANTED", 0, "/", $jumble_domain, 0, 0);
}



if(!is_array($tmp_domain)) $tmp_domain = array();
if(!isset($tmp_domain[0])) $tmp_domain[0] = "";


if(
($secured_server != "NO") &&
($session_is_cron_or_system_service != "YES")
) {
	//don't do these things if it's a system service.

	

	## HOST_WWW
	if(stristr($master_config_session_logging,"ON")) logger3("_SERVER['HTTP_HOST']",$_SERVER['HTTP_HOST']);
	if( (strtoupper($tmp_domain[0]) == "WWW") && ($_SESSION['template']['company']['host_www'] != $_SERVER['HTTP_HOST']) 
) {
		
		
		$tmp_goto_url = "https://" . $_SESSION['template']['company']['host_www'] . $_SERVER['REQUEST_URI'];
		if(stristr($master_config_session_logging,"ON")) logger3("0. tmp_goto_url",$tmp_goto_url);
		
		jump("javascript",$tmp_goto_url);
		exit;
	}
	
	
	
	# HTTPS
	if(stristr($master_config_session_logging,"ON")) logger3("_SERVER[SERVER_PORT]",$_SERVER["SERVER_PORT"]);
	
	if(
	(!$master_config_domain == "biometric-blacklist.org") &&
	(!stristr($_SESSION['template']['company']['text_name'],"vocaDEMO")) &&
	(!stristr($_SESSION['template']['company']['text_name'],"Chestnut Financial Services")) &&
	($_SERVER["SERVER_PORT"] != "443")
	&& ($secured_server != "NO")
	) {
		$tmp_goto_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		if(stristr($master_config_session_logging,"ON")) logger3("1. tmp_goto_url",$tmp_goto_url);
		jump("javascript",$tmp_goto_url);
		exit;
	}
	
	
	
	### SET SESSION TIMEOUT VARS:
	$tmp_time = time();
	if(!isset($_SESSION['session']['datetime_start'])) {
		$_SESSION['session']['new_timestamp'] = $tmp_time;
		$_SESSION['session']['old_timestamp'] = $_SESSION['session']['new_timestamp'];
		$_SESSION['session']['datetime_start'] = datetime($_SESSION['session']['new_timestamp']);
		if(stristr($master_config_session_logging,"ON")) logger3("session['datetime_start']",$_SESSION['session']['datetime_start']);
	}
	
	$_SESSION['session']['old_timestamp'] = $_SESSION['session']['new_timestamp']; # makes the switch (for active users)
	$_SESSION['session']['new_timestamp'] = $tmp_time; # sets the new timestamp
	
	
	### SET DEFAULT EXCEPTIONS: // basically, this security session stuff only applies to accounts - not gateway. nor support. etc.
	//logger3("_SERVER['HTTP_HOST']",$_SERVER['HTTP_HOST']);
	//logger3("_SESSION['template']['company']['host_www']",$_SESSION['template']['company']['host_www']);
	if( strtolower($_SERVER['HTTP_HOST']) != strtolower($_SESSION['template']['company']['host_www']) ) {
		$active_user_session_timeout = "OFF";
	}
	
	//logger3("active_user_session_timeout",$active_user_session_timeout);
	/// override default (option)
	
	if(!isset($active_user_session_timeout)) $active_user_session_timeout = "OFF";
	
	if( 
		($active_user_session_timeout != "OFF")
		
	) {
		if(!isset($active_user_session_timeout))  $active_user_session_timeout = $master_config_active_user_session_timeout;
		
		
		### test
		//$tmp_adjusted_old = $_SESSION['session']['old_timestamp'] + ($active_user_session_timeout * 60);
		//logger3("kill the session when","new: " . $_SESSION['session']['new_timestamp'] . " > "  . $tmp_adjusted_old . " :old");
		
		if( $_SESSION['session']['new_timestamp'] > ($_SESSION['session']['old_timestamp'] + ($active_user_session_timeout * 60)) ) { // convert $active_user_session_timeout to "minutes" -- displayed to user
		
		
			### PROCESSING
			$full_html_headers = "yes";
			$spinner_placement = "inline";
			$generic_processing_message = "<br>
			<br>
			<span style='color:#220000; font-family:verdana,arial; font-size:20px;'>" . $active_user_session_timeout . "-Minute Security Timeout Reached.</span>";
			include($_SESSION['template']['company']['file_path'] . "shared/generic_processing_visual.shared");
			$processing_vertical_align = "bottom";
			echo $generic_processing_visual_api;
			
			### 
			# $clear_cookies = "YES";
			# include($_SESSION['template']['company']['file_path'] . "shared/session_clear.shared");
			
			/// if gateway/shoppingcart, send back to business.
			if(isset($_SESSION['gateway']['incoming']['customer_return_url'])) {
				jump("javascript_top","https://" . $_SESSION['template']['company']['host_www'] . "/returning_customer_to_business.b!",3000);
				exit;
				
			/// default - logout
			} else {
				jump("javascript_top","https://" . $_SESSION['template']['company']['host_www'] . "/logoff.b!",3000);
				exit;
			}
			
	
		
		}
	}

}

//test("_SESSION['template']['company']",$_SESSION['template']['company']);










### ### SYSTEM_STATUS = "OFFLINE"
### 
// DATABASE:
# $tmp_system_status = getTHECASHIER("SELECT system_status 
# 									FROM templates_companies 
# 									WHERE templateid = '" . $_SESSION['template']['company']['templateid'] . "'
# 									;"
# 									);
# if($tmp_system_status) $_SESSION['template']['company']['system_status'] = $tmp_system_status;
### 
### // MASTERCONFIG
### if($master_config_system_status) $_SESSION['template']['company']['system_status'] = $master_config_system_status;
### //logger3("_SESSION['template']['company']['system_status']",$_SESSION['template']['company']['system_status']);
### 	
### 
### 


/// this allows a user to bypass "underconstruction" by submitting:
/// example: https://login.worldkyc.info?enterprise_access_password=Password123!



if(!$incoming_vars) {
	$incoming_vars = "";
	$incoming_vars = array();
	if($_POST) $incoming_vars = $_POST;
	if(empty($incoming_vars)) $incoming_vars = $_GET;
}

//test("incoming_vars",$incoming_vars);

if(!isset($incoming_vars['enterprise_access_password'])) $incoming_vars['enterprise_access_password'] = "";

if($incoming_vars['enterprise_access_password']) {
	
	
	$tmp_sql = "SELECT hash
				FROM administators
				WHERE template_company_hash = '". $_SESSION['template']['company']['hash'] ."'
				AND password = '". $incoming_vars['enterprise_access_password'] ."'
				;";
	//test("tmp_sql",$tmp_sql);
	$_SESSION['allow_this_user_to_pass'] = getTHECASHIER($tmp_sql,"intelitruth");
	//test("_SESSION['intelitruth']['allow_this_user_to_pass']",$_SESSION['intelitruth']['allow_this_user_to_pass']);

}



if(empty($_SESSION['template']['company']['system_status']))
{
	$_SESSION['template']['company']['system_status'] = "";
}

if(
	(stristr($_SESSION['template']['company']['system_status'],"OFFLINE"))
	&& ($_SERVER['REMOTE_ADDR'] != "74.81.189.7")
) {	
	//$scheduled_or_not = "an un-scheduled";
	//$datetime_back_online = "2014-05-21 20:00:00";
	//$system_offline_mesage_update = "Payment processing has been suspended while we upgrade our gateway servers.<br>
	// We sincerely apologize for the inconvenience, and thank you kindly for your patience, as we work to improve our service.";
	
	//include($_SESSION['template']['company']['file_path'] . "shared/announce_system_offline.shared");
	
	if(!$_SESSION['allow_this_user_to_pass']) {
		include($_SESSION['template']['company']['file_path'] . "shared/announce_system_offline_intelitruth.shared");
		exit;
	}
}



//test("2-_SESSION['template']['company']['file_path']",$_SESSION['template']['company']['file_path']);


//logger3("3 _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);

####################################################################################
### START THIS SESSION  (???)
//test("jumble_domain",$jumble_domain);
if(stristr($master_config_session_logging,"ON")) logger3("0. cookie_this_session",$cookie_this_session);
if(!$cookie_this_session) {
	if(stristr($master_config_session_logging,"ON")) logger("Set 'this session' cookie... ");
	$tmp_time = time();
	//setcookie("cookie_this_session", $tmp_time, 0, "/", "." . $_SESSION['template']['company']['domain'], 0);
	//test("2jumble_domain",$jumble_domain);
	setcookie("cookie_this_session", $tmp_time, 0, "/", $jumble_domain, 0);
}

///test("...",1);

//test("3-_SESSION['template']['company']['file_path']",$_SESSION['template']['company']['file_path']);


### SESSION CANCELED 

if(stristr($master_config_session_logging,"ON")) logger3("0. _SESSION['payme']['cancel']",$_SESSION['payme']['cancel']);
if(stristr($master_config_session_logging,"ON")) logger3("cookie_this_session",$cookie_this_session);

if(!isset($_SESSION['payme'])) $_SESSION['payme'] = array();
if(!isset($_SESSION['payme']['cancel'])) $_SESSION['payme']['cancel'] = "";

if($cookie_this_session == "canceled") {
	
	///test("...",2);
	if(stristr($master_config_session_logging,"ON"))  logger3("1. cookie_this_session",$cookie_this_session);
	setcookie("cookie_this_session", $tmp_time, 0, "/", "." . $_SESSION['template']['company']['domain'], 0);
	if(!$uri_business_account_string[1]) {
		jump("javascript","https://" . $_SESSION['template']['company']['host_www']);
		exit;
	}
} else if(strtoupper($_SESSION['payme']['cancel']) == "YES") {
	
	///test("...",3);
	
	if(stristr($master_config_session_logging,"ON")) logger3("1. _SESSION['payme']['cancel']",$_SESSION['payme']['cancel']);
	$_SESSION['payme']['cancel'] = "";
	include($_SESSION['template']['company']['file_path'] . "www/cancel.bi");
	exit;
} 


///test("...",4);
### TEXT/ALL SESSIONS CLEAR
if($clear == "yes") {
	
	$_SESSION['payme'] = NULL;
	$_SESSION['account'] = NULL;
	$_SESSION['member'] = NULL;
	$_SESSION['authorization'] = NULL;
	$_SESSION['transaction'] = NULL;
	$_SESSION['SYSMSG'] = NULL;
	$_SESSION['session'] = NULL;
	
	//logger3("payme",$payme . "(cleared)");
}
####################################################################################

///test("...",5);

### TRACKING:
//logger3("OWA_tracking",$OWA_tracking);

if(stristr($master_config_OWA_tracking,"ON")) {
	
	//logger3("owa",$owa);
	
	require_once('/BANGK!/admin/stats/OWA/owa_php.php');		
	$owa = new owa_php();
	//logger3("owa",$owa);
	if(stristr($_SESSION['template']['company']['text_name'],"vocaONE")) {
		
	        // Set the site id you want to track
	        $owa->setSiteId('a07613f0c1de25678908ec09fb095872');
	        
	        // Uncomment the next line to set your page title
	        //$owa->setPageTitle('somepagetitle');
	        // Set other page properties
	        //$owa->setProperty('foo', 'bar');   
	        $owa->trackPageView();
	}
	if(stristr($_SESSION['template']['company']['text_name'],"vocaPASS")) {	
		$owa->setSiteId('73c4488e8ee0cfa9217397fbd3b14017');
	        $owa->trackPageView();
	}
	if(stristr($_SESSION['template']['company']['text_name'],"vocaSIGN")) {	
		$owa->setSiteId('20060ec3ac9cafc93f86ada6899ae9b2');
	        $owa->trackPageView();
	}
	
	
	if(stristr($_SESSION['template']['company']['text_name'],"vocaMATCH")) {	
		$owa->setSiteId('a131f1d7aa2643ff1718a9129bac5926');
	        $owa->trackPageView();
	}
	
	
	if(
	(stristr($_SERVER['HTTP_HOST'],"2-factor-authentication.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"2-factor-verification.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"2-step-authentication.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"2-step-verification.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"3-factor-authentication.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"3-factor-verification.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometric-id.org")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometric-signatures.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"multi-factor-authentication.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"multi-factor.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"multi-factor-verification.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"pin-pass.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"robustvoicebiometric.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"the-biometric-blacklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"thebiometricblacklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"three-factor-authentication.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"three-factor-verification.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"two-factor-authentication.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"two-factor-verification.com"))
	) {	
		$owa->setSiteId('528cd845a776bf05f9f2b5dded63f9c8');
	        $owa->trackPageView();
	}



	if(
	(stristr($_SERVER['HTTP_HOST'],"voice-authentication.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"voice-authorisation-as-a-service.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"voice-authorisation.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"voice-authorization-as-a-service.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"voice-authorization.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"voicematch.org")) ||
	(stristr($_SERVER['HTTP_HOST'],"voice-signatures-as-a-service.com"))
	) {	
		$owa->setSiteId('379b3864259617ecbc9abed7068d6152');
	        $owa->trackPageView();
	}


	if(
	(stristr($_SERVER['HTTP_HOST'],"biometric-blacklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometricblacklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometric-blacklist.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometricblacklist.net")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometric-blacklist.org")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometricblacklist.org")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometricblocklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"biometricblocklist.org")) ||
	
	(stristr($_SERVER['HTTP_HOST'],"the-biometric-blacklist.com")) ||
	(stristr($_SERVER['HTTP_HOST'],"thebiometricblacklist.com"))

	) {	
		
		$owa->setSiteId('1d0aba29e5ff4c60f1b7b14a5cb5d6a6');
	    $owa->trackPageView();
	}
	
	
	

}
### TRACKING END:

///test("...",6);



######################################################
######################################################
######################################################
### START:  RE-SET TEMPLATE COMPANY
if(empty($_SESSION['template']['company']['hash'])) {
	$_SESSION['template']['company'] = IEW_template();
}
#END# START:  RE-SET TEMPLATE COMPANY	
######################################################
######################################################
######################################################

	
//$master_config_session_logging = "ON";
if(stristr($master_config_session_logging,"ON")) {
	logger3("


##################################################################################
### END OF SESSION.SHARED
##################################################################################


",$_SESSION['template']['company']);
}
 
/*
if(!stristr($_COOKIE['AJAX_COMPATIBILITY'],"TRUE")) {
	logger3("i",$i++);
    echo "
    <script>
    	commonAJAX('action=test_ajax_compatibility','goAJAX.b!');
    </script>
    ";
    
    sleep(1);
    if(!stristr($_COOKIE['AJAX_COMPATIBILITY'],"TRUE")) {
		
    	$_SESSION['SYSMSG'] = "<span style='color:#CC0000; font-size:18px;'><b>ALERT!</b><br>
    	Your browser is not AJAX Compatible.  Please upgrade your browser.
    	</span>";
    	jump("javascript",$_SESSION['template']['company']['domain']);
    	exit;
	}
}
*/
//logger3("4 _SERVER['REQUEST_URI']",$_SERVER['REQUEST_URI']);

	//exit;
	



//test("3_SESSION['template']['company']",$_SESSION['template']['company']);	


/*
if(!stristr($_SESSION['template']['company']['system_status'],"PUBLIC")) {
	
	echo '<link href="https://fonts.googleapis.com/css?family=Roboto:300&display=swap" rel="stylesheet">';
	echo "<table style='width:100%; margin-top:15%; font-family:roboto; font-size:30;'>";
	echo "<tr>";
	echo "<td>";
	echo "<center>";
	echo "<p><b>". $_SESSION['template']['company']['name'] . "</b> is temporarily OFFLINE for unscheduled maintenance.</p>";
	echo "<p>We apologize for any inconvenience.</p>";
	echo "<p>Thank you for your patience.</p>";
	echo "<p>&nbsp;</p>";
	echo "<p>". $_SESSION['template']['company']['emailaddress_support'] ."</p>";
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	exit;
	
}
*/	
	

if(!isset($_SESSION['user_selected_language_iso2'])) $_SESSION['user_selected_language_iso2'] = "";

if(!$_SESSION['user_selected_language_iso2']) {
	
	$user_ip_address_details_array = ip2location_v10($ipaddress=$_SERVER['REMOTE_ADDR']);
	
	//test("user_ip_address_details_array",$user_ip_address_details_array);
	
	if(isset($user_ip_address_details_array))
	{
		$_SESSION['user_ip_address_details_array'] = $user_ip_address_details_array;
	}
	
	
	if(isset($user_ip_address_details_array['language_iso2']))
	{
		$_SESSION['user_selected_language_iso2'] = $user_ip_address_details_array['language_iso2'];
	}
	
	
	if(isset($user_ip_address_details_array['language_iso2']))
	{
		$user_selected_language_iso2 = $user_ip_address_details_array['language_iso2'];
	}
	
	
	if(isset($user_ip_address_details_array['language_iso2']))
	{
		$incoming_vars_user_selected_language_iso2 = $user_ip_address_details_array['language_iso2'];
	}
	
	
}

//test("_SESSION['user_selected_language_iso2']",$_SESSION['user_selected_language_iso2']);

//test("user_selected_language_iso2",$user_selected_language_iso2);
//exit;
//test("_SESSION['user_ip_address_details_array']",$_SESSION['user_ip_address_details_array']);


if(!isset($_GET['language_iso2'])) $_GET['language_iso2'] = "";
if(!isset($incoming_vars_user_selected_language_iso2)) $incoming_vars_user_selected_language_iso2 = "";

if(
	($_GET['language_iso2'])
	|| ($incoming_vars_user_selected_language_iso2)
) {
	
	//test(1,0);
	//exit;
	include($_SESSION['template']['company']['file_path'] . "gateway/plateform_language_updater.gate");
}	
	
	
	
?>