<?



####################################################################################
####################################################################################
####################################################################################
/// START: SET WHITELABEL SESSION:

//str_ireplace(, , )
//start fresh
//$_SESSION['intelitruth'] = "";

//if(!$_SESSION['intelitruth']['whitelabel_business_account_details']) {


$tmp_HTTP_HOST = $_SERVER['HTTP_HOST'];
$_SESSION['intelitruth']['whitelabel_business_account_details'] = "";
//$tmp_HTTP_HOST = $_SESSION['template']['company']['host_www']
//if($tmp_HTTP_HOST == "demo-admin.intelitruth.com") $tmp_HTTP_HOST = "intelitruth-admin.intelitruth.com";
//if($tmp_HTTP_HOST == "whitelabel-admin.intelitruth.com") $tmp_HTTP_HOST = "intelitruth-admin.intelitruth.com";
//if($tmp_HTTP_HOST == "onboarding-admin.intelitruth.com") $tmp_HTTP_HOST = "intelitruth-admin.intelitruth.com";
//if($tmp_HTTP_HOST == "onboarding-demo-admin.intelitruth.com") $tmp_HTTP_HOST = "intelitruth-admin.intelitruth.com";


/// NEW database driven whitelabel
$third_level_hostname = explode(".", $tmp_HTTP_HOST);
//test("third_level_hostname",$third_level_hostname);
$tmp_sql = "SELECT * 
			FROM accounts 
			WHERE 
				(
				whitelabel_admin = '". $third_level_hostname[0] ."'
				OR whitelabel_agent = '". $third_level_hostname[0] ."'
				)
			AND template_company_hash = '". $_SESSION['template']['company']['hash'] ."'
			;";
logger3("tmp_sql",$tmp_sql);
$_SESSION['intelitruth']['whitelabel_business_account_details'] = object_to_array_v2(readTHECASHIER($tmp_sql));
logger("_SESSION['intelitruth']['whitelabel_business_account_details']",$_SESSION['intelitruth']['whitelabel_business_account_details']);




//test("1-_SESSION['intelitruth']['whitelabel_business_account_details']",$_SESSION['intelitruth']['whitelabel_business_account_details']);
//test("incoming_vars",$incoming_vars);

if(
	(empty($_SESSION['intelitruth']['whitelabel_business_account_details']['hash'])) 
	&& (!empty($incoming_vars['login_emailaddress']))
	&& (!empty($incoming_vars['login_password']))
) {
	
	
	
	$tmp_sql = "SELECT * 
				FROM administators 
				WHERE emailaddress = '". addslashes($incoming_vars['login_emailaddress']) ."'
				AND password = '". addslashes($incoming_vars['login_password']) ."'
				;";
	logger3("tmp_sql",$tmp_sql);
	
	$administrators_details = object_to_array_v2(readTHECASHIER($tmp_sql,"intelitruth"));
	
	logger3("administrators_details",$administrators_details);
	
	//exit;
	
	if(!$administrators_details['hash']) {
		
		
		$tmp_sql = "SELECT * 
				FROM members 
				WHERE emailaddress = '". addslashes($incoming_vars['login_emailaddress']) ."'
				AND password = '". addslashes($incoming_vars['login_password']) ."'
				;";
		logger3("tmp_sql",$tmp_sql);
	
		$member_details = object_to_array_v2(readTHECASHIER($tmp_sql,""));
	
		logger3("member_details",$member_details);
		
		if($member_details['hash']) {
			
			
			$tmp_sql = "SELECT * 
				FROM accounts
				
				WHERE creator_member_hash = '". addslashes($member_details['hash']) ."'
				AND accounttype = 'BUSINESS'
				;";
			logger3("tmp_sql",$tmp_sql);
	
			$account_details = object_to_array_v2(readTHECASHIER($tmp_sql,""));
			logger3("account_details",$account_details);
			
			
			if($account_details['whitelabel_business_account_hash']) {
				
				$_SESSION['intelitruth']['whitelabel_business_account_details'] = account($account_details['whitelabel_business_account_hash']);
				
			}
		}
	} else {
		
		$_SESSION['intelitruth']['whitelabel_business_account_details'] = account($administrators_details['whitelabel_business_account_hash']);
		
	}
}


if(empty($_SESSION['intelitruth']['whitelabel_business_account_details'])) {
	

	$_SESSION['ADMIN_SYSMSG'] = "<span style='line-height:25px;'>
	(1) ALERT!
	<br>
	We were unable to locate your account with the credentials you provided.
	<br>
	Please confirm your credentials - try again...
	</span>
	";
	jump("javascript","//". $_SESSION['template']['company']['host_login'],0);
	exit;
}

logger3("9-_SESSION['intelitruth']['whitelabel_business_account_details']",$_SESSION['intelitruth']['whitelabel_business_account_details']);
//exit;



/// GET WHITELABEL PREFERENCES:
if($whitelabel_preferences_profile) {
	$insert_preferences_profile = "AND form_name = '". $whitelabel_preferences_profile . "'";
} else {
	$insert_preferences_profile = "AND form_name = 'DEFAULT'";
}

$tmp_sql = "SELECT * 
			FROM onboarding_preferences 
			WHERE whitelabel_business_account_hash = '". $_SESSION['intelitruth']['whitelabel_business_account_details']['hash'] ."'
			$insert_preferences_profile
			;";
logger3("tmp_sql",$tmp_sql);
$_SESSION['intelitruth']['whitelabel_onboarding_preferences'] = "";
$_SESSION['intelitruth']['whitelabel_onboarding_preferences'] = object_to_array_v2(readTHECASHIER($tmp_sql,"intelitruth"));

logger3("_SESSION['intelitruth']['whitelabel_onboarding_preferences']",$_SESSION['intelitruth']['whitelabel_onboarding_preferences']);


$tmp_sql = "SELECT * 
			FROM onboarding_preferences 
			WHERE whitelabel_business_account_hash = '". $_SESSION['intelitruth']['whitelabel_business_account_details']['hash'] ."'
			;";
logger3("tmp_sql",$tmp_sql);
$_SESSION['intelitruth']['whitelabel_onboarding_preferences_array'] = "";
$_SESSION['intelitruth']['whitelabel_onboarding_preferences_array'] = object_to_array_v2(readarrayTHECASHIER($tmp_sql,"intelitruth"));


logger3("_SESSION['intelitruth']['whitelabel_onboarding_preferences_array']",$_SESSION['intelitruth']['whitelabel_onboarding_preferences_array']);

	
	
	
	
	
	
	
	
		
//}
/// END: SET WHITELABEL SESSION...!
####################################################################################
####################################################################################
####################################################################################




//exit;









?>