<?



##### GET THE INCOMING VALUES:
if($_GET['coupon']) {
	$tmp_sponsor_type = "COUPON";
	$set_sponsor_accountid = trim($_GET['coupon']);
}

if($_GET['invite']) {
	$tmp_sponsor_type = "INVITE";
	$set_sponsor_accountid = trim($_GET['invite']);
}

if($_GET['affiliate']) {
	$tmp_sponsor_type = "AFFILIATE";
	$set_sponsor_accountid = trim($_GET['affiliate']);
}

if($_GET['sponsor']) {
	$tmp_sponsor_type = "SPONSOR";
	$set_sponsor_accountid = trim($_GET['sponsor']);
}

if($_GET['key']) {
	$tmp_sponsor_type = "KEY";
	$set_sponsor_accountid = trim($_GET['key']);
}

if($_GET['campaign']) {
	$tmp_sponsor_type = "CAMPAIGN";
	$tmp_campaign_name = trim($_GET['campaign']);
}

//$confirmed_sponsor_account = account($set_sponsor_accountid);


# if(
# ($confirmed_sponsor_account['accountid']) ||
# ($_GET['invite'] == "14e7b661ce98813417442f2ed57caac7") // flowers 
# ) {



### LOG THE INCOMING USER:
//$_SESSION['tracking'] = "";
if(empty($_SESSION['tracking'])) {

	$_SESSION['tracking'] = "LOGGED";

	$tmp_trackingid = "";
	$tmp_tracking_hash = hash_me();
	$tmp_spondor_accountid = $set_sponsor_accountid;
	//$tmp_campaign_name = "";
	$tmp_ip = $_SERVER['REMOTE_ADDR'];
	$tmp_ip_country_iso3 = $_SESSION['session']['geo']['iso3'];
	$tmp_HTTP_REFERER = $_SERVER['HTTP_REFERER'];
	$tmp_status = NULL;
	$tmp_datetime_created = datetime();

	$tmp_sql = "INSERT INTO `tracking`
				(`trackingid`
				, `hash`
				, `sponsor_type`
				, `sponsor_accountid`
				, `campaign_name`
				, `ip`
				, `ip_country_iso3`
				, `HTTP_REFERER`
				, `status`
				, `datetime_created`
			) VALUES (
				'". $tmp_trackingid ."'
				,'". $tmp_tracking_hash ."'
				,'". $tmp_sponsor_type ."'
				,'". $tmp_spondor_accountid ."'
				,'". $tmp_campaign_name ."'
				,'". $tmp_ip ."'
				,'". $tmp_ip_country_iso3 ."'
				,'". $tmp_HTTP_REFERER ."'
				,'". $tmp_status ."'
				,'". $tmp_datetime_created ."'
			)";
	//test("tmp_sql",$tmp_sql);
	$trackingid = insertTHECASHIER($tmp_sql,"ad_campaigns");
	//test("trackingid",$trackingid);
	setcookie("campaign_and_sponsor_tracking",$tmp_tracking_hash,time()+(60*60*24*30),"/",".".strtolower($_SESSION['template']['company']['domain']));
	setcookie("sponsor_accountid",$set_sponsor_accountid,time()+(60*60*24*30),"/",".".strtolower($_SESSION['template']['company']['domain']));
	//if(!empty($set_sponsor_accountid)) setcookie("sponsor_accountid", $set_sponsor_accountid, time()+2592000, "/", ".".$_SESSION['template']['company']['domain'], 0); // expires after 30 days

	### CLEANUP URL
	jump("javascript",$_SERVER['SCRIPT_URI']);
	exit;
}




?>
