document.getElementById('optin').submit();
";
$auto_optin="$optin_form";
echo $auto_optin;
}
}
function setPayee($product, $itemnumber, $pct1, $pct2)
{
global $sys_paypal, $tier;
global $sys_eq1_pct, $sys_eq1_paypal;
global $sys_eq2_pct, $sys_eq2_paypal;
$email = $sys_paypal; #sale defaults to merchant
$tier=0;
if(isset($_COOKIE['aff']) && strtolower($email)<>strtolower($_COOKIE['aff']))
{
$affiliate=strtolower($_COOKIE['aff']);
$sql="SELECT * FROM nicknames
WHERE email='".$affiliate."'";
$nres=@mysql_query($sql);
if(@mysql_num_rows($nres)>0) {
$nrec=@mysql_fetch_assoc($nres);
$sponsor=$nrec['sponsor'];
}
# See if affiliate should get this sale.
$affpct = 0;
$t1sales = 0;
$t2sales = 0;
$affreferrals = 0;
$sql="SELECT * FROM sales
WHERE productID=".$product."
AND refunded=0
AND item_number='".$itemnumber."'
AND affiliate='".$affiliate."'";
$sres=@mysql_query($sql);
while($sales=@mysql_fetch_array($sres))
{
# Affiliate referral
$affreferrals++;
if($sales['tier'] == 1)
$t1sales++;
if($sales['tier'] == 2)
$t2sales++;
}
if($affreferrals > 0)
{
$t1pct = ($t1sales / $affreferrals)*100;
$t2pct = ($t2sales / $affreferrals)*100;
if($pct1 > 0 && $t1pct<$pct1) {
$email = urldecode($affiliate);
$tier = 1;
} else {
if($sys_two_tier && $sponsor != "" && $pct2 > 0 && $t2pct<$pct2) {
$email = urldecode($sponsor);
$tier = 2;
}
}
}
}
/*__________ Calculate Equity Partner Share ____________*/
if($email == $sys_paypal) #sale to merchant
{
if($sys_eq1_paypal <> "")
{
$totsales=0;
$p1sales=0;
$p2sales=0;
$sql="SELECT * FROM sales
WHERE productID=".$product."
AND refunded=0
AND item_number='".$itemnumber."'
AND tier=0";
$sres=@mysql_query($sql);
while($sales=@mysql_fetch_array($sres))
{
$totsales+=$sales['payment_amount'];
if($sales['receiver_email']==$sys_eq1_paypal)
$p1sales+=$sales['payment_amount'];
if($sales['receiver_email']==$sys_eq2_paypal)
$p2sales+=$sales['payment_amount'];
}
$p1_pct=($p1sales / $totsales)*100;
$p2_pct=($p2sales / $totsales)*100;
if($p1_pct < $sys_eq1_pct) {
$email=$sys_eq1_paypal;
} elseif($p2_pct < $sys_eq2_pct) {
$email=$sys_eq2_paypal;
}
}
}
return $email;
}
# Set privacy policy to insure current IE browsers will accept the cookie.
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
$action="none";
if(isset($_REQUEST['action'])) $action = $_REQUEST['action'];
switch ($action)
{
case "squeeze" :
if($sys_giveaway)
{
$url = $_SERVER[PHP_SELF]."?action=squeeze&dld=1";
break;
}
case "otodownload" :
if(!isset($_GET["dld"]) && !isset($_GET["e"]))
{
# Check for sale to this IP address
$oto = false;
if($action=="otodownload") $oto = true;
$ip = $_SERVER["REMOTE_ADDR"];
$sql="SELECT * FROM sales
WHERE productID=".$productID."
AND ip_address='".$ip."'
ORDER BY expires DESC";
$sres=@mysql_query($sql);
if(@mysql_num_rows($sres)==0)
$nosale=true;
$sales=@mysql_fetch_array($sres);
if($oto && $sales['item_number']!=$sys_oto_number)
$nosale=true;
# Make sure sale isn't expired
if(time()>strtotime($sales['expires']))
$nosale=true;
if(!$nosale){
$firstname=$sales['firstname'];
$lastname=$sales['lastname'];
$fullname=$sales['firstname']." ".$sales['lastname'];
$email=$sales['payer_email'];
$txn_id=$sales['txn_id'];
$affiliate=#sales['affiliate'];
setcookie("custfirst", $firstname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custlast", $lastname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custfull", $fullname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custemail", $email, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("txn_id", $txn_id, time()+(60*60*24*365), "/", "." . $sys_domain);
# Sales record found.
switch ($action)
{
case "squeeze" :
$url = $_SERVER[PHP_SELF]."?action=squeeze&id=".$sales['txn_id']."&dld=1";
break;
case "otodownload" :
$url = $_SERVER[PHP_SELF]."?action=download&id=".$sales['txn_id']."&dld=1";
break;
default :
$url = $_SERVER[PHP_SELF];
break;
}
header("Location: $url");
}
elseif($_GET["retry"]<11)
{
# Allow 60 seconds for PayPal to post IPN record
$retry = 0;
if(isset($_GET["retry"]))
$retry = $_GET["retry"] + 1;
$seconds = 60 - ($retry * 5);
$refresh = "";
$header = $sys_tmpl_folder."header.html";
$footer = $sys_tmpl_folder."footer.html";
$filename = $sys_tmpl_folder."from_paypal.html";
@include($header);
include($filename);
@include($footer);
} else {
# IP not found in sales records. Show error message.
$header = $sys_tmpl_folder."header.html";
$footer = $sys_tmpl_folder."footer.html";
$filename = $sys_tmpl_folder."payment_timeout.html";
@include($header);
include($filename);
@include($footer);
}
exit;
}
break;
}
if(isset($_GET['dc']))
{
$dc=$_GET['dc'];
$rightnow = date('Y-m-d H:i:s');
$sql="SELECT * FROM coupons
WHERE productID=".$productID."
AND code ='".$dc."'
AND expires > '".$rightnow."'";
$resource=@mysql_query($sql);
while($result=@mysql_fetch_assoc($resource)) {
$discount=$result['id'];
$item_price=$result['price'];
}
}
if(isset($_GET["e"]))
{
switch ($action) {
case "presale" :
case "jvsignup" :
case "affsignup" :
$target="?action=".$action;
break;
}
if(isset($_GET['dc'])) {
if(!isset($target)) {
$target = "?dc=".$_GET['dc'];
} else {
$target .= "&dc=".$_GET['dc'];
}
}
if($_GET["e"] == "")
{
# Clear affiliate cookie.
setcookie("aff", FALSE, time()+(60*60*24*365), $sys_affcookiepath, "." . $sys_domain);
header("Location: $_SERVER[PHP_SELF]$target");
exit;
} else {
if (!eregi("@", $_GET["e"])) {
$e = trim($_GET['e']);
$sql="SELECT * FROM nicknames
WHERE nickname = '".$e."'";
$eres=@mysql_query($sql);
$erec=@mysql_fetch_array($eres);
// Replace the affiliate nickname with their Paypal email address
if($erec['nickname']==$e) {
$_GET["e"] = $erec['email'];
} else {
unset($_GET["e"]);
}
}
# Make sure this affiliate hasn't been banned
$sql="SELECT * FROM banned
WHERE email='".strtolower($_GET['e'])."'";
$res=@mysql_query($sql);
if(@mysql_num_rows($res)==0)
{
# Set cookie and redirect visitor if it's through an affiliate link.
if(!$sys_cust_only)
{
$validaff = true;
} else {
$validaff = false;
$where="";
if(!$sys_glbaff)
$where=" AND productID=".$productID;
$sql="SELECT * FROM nicknames
WHERE email='".strtolower($_GET['e'])."'".$where;
$res=@mysql_query($sql);
if(@mysql_num_rows($res)>0)
{
# Affiliate is valid
$validaff = true;
} else {
# See if this affiliate bought the product
$sql="SELECT * FROM sales
WHERE payer_email = '".strtolower($_GET['e'])."'
AND refunded <> 1".$where;
$salesres = @mysql_query($sql);
while($salesrec = @mysql_fetch_array($salesres))
{
$validaff = true;
break;
}
}
}
if($validaff)
{
setcookie("aff", strtolower($_GET['e']), time()+(60*60*24*365), $sys_affcookiepath, "." . $sys_domain);
if($_GET['taf'])
{
header("Location: $_SERVER[PHP_SELF]?taf=1");
} else {
header("Location: $_SERVER[PHP_SELF]$target");
}
} else {
# Clear affiliate cookie and request sales page
setcookie("aff", $sys_paypal, time()+(60*60*24*365), $sys_affcookiepath, "." . $sys_domain);
header("Location: $_SERVER[PHP_SELF]$target");
}
exit;
}
else
{
# Clear affiliate cookie of banned affiliate
setcookie("aff", $sys_paypal, time()+(60*60*24*365), $sys_affcookiepath, "." . $sys_domain);
header("Location: $_SERVER[PHP_SELF]$target");
exit;
}
}
}
if(isset($_COOKIE['aff']) && $_COOKIE['aff']!="")
{
$email = $_COOKIE['aff'];
$affiliate = $_COOKIE['aff'];
} else {
$email = $sys_paypal;
}
if($sys_disabled) {
$header = $sys_tmpl_folder."header.html";
$footer = $sys_tmpl_folder."footer.html";
$filename = $sys_tmpl_folder."offline.html";
@include($header);
include($filename);
@include($footer);
exit;
}
switch ($action) {
# CHECK FOR ADDON ACTION
#_______________________
case "a" :
if ($_GET['fn'])
{
$numdotdots = count(explode("/",$sys_install_folder))-2;
$dots="";
for ($i=0; $i<$numdotdots; $i++) {
$dots = $dots."../";
}
$filename = $dots."rap_admin/addons/".$_GET['fn'].".php";
break;
}
break;
# HANDLE PRE-SALES PAGE
# _______________________
case "presale" :
$filename = $sys_tmpl_folder."presale.html";
break;
# HANDLE ORDER VIA PAYPAL
# _______________________
case "order" :
if($sys_giveaway && !isset($_GET["oto"]))
{
# Send visitor straight to the squeeze page
$filename = $sys_tmpl_folder . "squeeze.html";
break;
}
if($sys_get_zips && !isset($_GET["gotzip"]) && !isset($_GET["oto"]))
{
# Show location info form.
$filename = $sys_tmpl_folder . "zips.html";
break;
} else {
$country = "";
$state = "";
$zipcode = "";
if($sys_get_zips)
{
# retrieve location info from cookies.
$zips = explode("|", $_COOKIE["zips"]);
$country = $zips[0];
$state = $zips[1];
$zipcode = $zips[2];
}
# Which salesletter template?
if(isset($_COOKIE['slsltr']))
{
$salesletter = $_COOKIE['slsltr'];
} else {
# Get salesletter template
$sql = "SELECT * from salesletters
WHERE productID = '".$instrow['id']."'
AND disabled <> 1
ORDER BY hits LIMIT 1";
$slres = @mysql_query($sql);
$slrow = @mysql_fetch_array($slres);
$salesletter = $slrow['template'];
}
# Send them through the order process.
if(isset($_COOKIE['aff']))
{
$where="";
if(!$sys_glbaff)
$where=" AND productID=".$productID;
$sql="SELECT * FROM nicknames
WHERE type='jv'
AND email='".$_COOKIE['aff']."'".$where;
$pres=@mysql_query($sql);
if(@mysql_num_rows($pres) > 0) {
if($sys_jv_item_pct>0)
$sys_item_pct=$sys_jv_item_pct;
if($sys_jv_oto_pct>0)
$sys_oto_pct=$sys_jv_oto_pct;
if($sys_jv_item_pct2>0)
$sys_item_pct2=$sys_jv_item_pct2;
if($sys_jv_oto_pct2>0)
$sys_oto_pct2=$sys_jv_oto_pct2;
}
}
if(isset($_GET["oto"]))
{
# Buying OTO.
$email = $sys_paypal;
if(isset($_COOKIE['aff']))
{
$checkotosale = true;
if($sys_otocust_only)
{
$checkotosale = false;
# Restrict OTO commissions to OTO customers only.
$sale = verifyOTO(urldecode($_COOKIE['aff']));
if(is_array($sale))
{
$checkotosale = true;
}
}
if($checkotosale)
$email = setPayee($productID, $sys_oto_number, $sys_oto_pct, $sys_oto_pct2);
}
$item_name = $sys_oto_name;
$item_number = $sys_oto_number;
$item_price = $sys_oto_price;
$item_download_url = "http://$sys_domain" . $sys_install_folder . "?action=otodownload";
$item_cancel_url = "http://$sys_domain" . $sys_install_folder . "?action=download";
$item_ipn_url = "http://$sys_domain" . "/rap_admin/ipn.php";
$_SESSION['orderbutton']=$sys_oto_orderbutton;
} else {
# Regular purchase.
if($sys_item_pct < 100) {
$email = setPayee($productID, $sys_item_number, $sys_item_pct, $sys_item_pct2);
} elseif(isset($_COOKIE['aff']) && $_COOKIE['aff']<>$sys_paypal) {
$tier = 1;
$email = $_COOKIE['aff'];
} else {
$tier = 0;
$email = $sys_paypal;
}
$item_name = $sys_item_name;
$item_number = $sys_item_number;
$item_price = $sys_item_price;
$item_download_url = "http://$sys_domain" . $sys_install_folder . "?action=squeeze";
$item_cancel_url = $sys_cancel_url;
$item_ipn_url = "http://$sys_domain" . "/rap_admin/ipn.php";
$_SESSION['orderbutton']=$sys_item_orderbutton;
}
# Get customer IP address.
$ip = $_SERVER["REMOTE_ADDR"];
if(isset($_GET['dc'])) {
$dc=$_GET['dc'];
$rightnow = date('Y-m-d H:i:s');
$sql="SELECT * FROM coupons
WHERE productID=".$productID."
AND code ='".$dc."'
AND expires > '".$rightnow."'";
$resource=@mysql_query($sql);
while($result=@mysql_fetch_assoc($resource)) {
$discount=$result['id'];
$item_price=$result['price'];
}
}
if($email == "") $email = $sys_paypal;
if($_COOKIE['aff'] == $sys_paypal) {
$affiliate = $sys_paypal;
} else {
$affiliate = $_COOKIE['aff'];
}
# Submit to PayPal.
$header = $sys_tmpl_folder."header.html";
$footer = $sys_tmpl_folder."footer.html";
$filename = $sys_tmpl_folder."goto_paypal.html";
@include($header);
include($filename);
## include("http://".$sys_domain."/rap_admin/".$_SESSION['orderbutton']);
$numdotdots = count(explode("/",$sys_install_folder))-2;
$dots="";
for ($i=0; $i<$numdotdots; $i++) {
$dots = $dots."../";
}
$p = $dots."rap_admin/".$_SESSION['orderbutton'];
include($p);
echo <<< END
END;
@include($footer);
exit;
}
break;
# GATHERED COUNTRY / STATE / ZIP INFO
# ___________________________________
case "zips" :
unset($_SESSION['errmsg']);
# Check for required fields
if($_REQUEST["country"] == "" | $_REQUEST["state"] == "" | $_REQUEST["zipcode"] == "")
{
$_SESSION['errmsg'] = "All fields are Required! RETRY";
$filename = $sys_tmpl_folder."zips.html";
} else {
setcookie("zips", "$_GET[country]|$_GET[state]|$_GET[zipcode]", time()+(60*60*24*365), $sys_install_folder, "." . $sys_domain);
header("Location: $_SERVER[PHP_SELF]?action=order&gotzip=1");
exit;
}
break;
# HANDLE SQUEEZE/DOWNLOAD PAGE
# ____________________________
case "squeeze" :
case "download" :
If(isset($_REQUEST['id'])){
# Check that Transaction ID is valid
$id = $_REQUEST['id'];
$sql="SELECT * FROM sales
WHERE txn_id='".$id."'";
$sres=@mysql_query($sql);
$sales=@mysql_fetch_array($sres);
if($sales['txn_id']==$id){
# Check that download link has not expired
if(time()<=strtotime($sales['expires'])){
if($sales['item_number']==$sys_oto_number){
# Download One-time offer
if($sys_taf)
{
$filename = $sys_tmpl_folder . "ototaf.html";
} else {
$filename = $sys_tmpl_folder . "otodownload.html";
}
} elseif(isset($_REQUEST['rx'])) {
# Download front-end offer
$filename = $sys_tmpl_folder . "download.html";
} else {
if($action=="squeeze")
{
$firstname=$sales['firstname'];
$lastname=$sales['lastname'];
$fullname=$sales['firstname']." ".$sales['lastname'];
$email=$sales['payer_email'];
$txn_id=$sales['txn_id'];
$affiliate=#sales['affiliate'];
$fullurl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$root_path=substr($fullurl,0,strrpos($fullurl, "/"));
$awreturnurl=$root_path.$install_folder."/?action=download target='iframe'";
setcookie("custfirst", $firstname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custlast", $lastname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custfull", $fullname, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("custemail", $email, time()+(60*60*24*365), "/", "." . $sys_domain);
setcookie("txn_id", $txn_id, time()+(60*60*24*365), "/", "." . $sys_domain);
if(!$sys_bypass_squeeze && !$sys_aw_flag)
{
$filename = $sys_tmpl_folder . "squeeze.html";
} else {
# Show appropriate page.
if ($sys_oto_flag) {
$filename = $sys_tmpl_folder . "oto.html";
} elseif($sys_taf) {
$filename = $sys_tmpl_folder . "taf.html";
} else {
$filename = $sys_tmpl_folder . "download.html";
}
}
} else {
if($sys_oto_flag) {
$filename = $sys_tmpl_folder . "oto.html";
} elseif($sys_taf) {
$filename = $sys_tmpl_folder . "taf.html";
} else {
$filename = $sys_tmpl_folder . "download.html";
}
}
}
} else {
# Download link is expired
$filename = $sys_tmpl_folder . "expired.html";
}
} else {
# Invalid ID.
$filename = $sys_tmpl_folder . "invalid.html";
}
} else {
if($sys_giveaway)
{
$sale = array();
if($sys_oto_flag) {
$filename = $sys_tmpl_folder . "oto.html";
} elseif($sys_taf) {
$filename = $sys_tmpl_folder . "taf.html";
} else {
$filename = $sys_tmpl_folder . "download.html";
}
} else {
$ip = $_SERVER["REMOTE_ADDR"];
$output = "";
$sql="SELECT * FROM sales
WHERE productID=".$productID."
AND ip_address='".$ip."'
ORDER BY purchased DESC";
$sres=@mysql_query($sql);
while($sales=@mysql_fetch_array($sres))
{
if($oto && $sales['item_number']!=$sys_oto_number){
$output = "";
} else {
# Make sure download hasn't expired
if(time()
You will no longer receive email at:
$email from $sys_item_name.
You will no longer receive Affiliate emails at:
$email from $sys_item_name.