0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
affiliates_8mor
/
[
Home
]
File: sale.php
<?php ##################################################################################### ## JROX.COM Affiliate Manager - sale.php file ## Version 1.6.2 ## ## Author: Ryan Roxas(ryan@jrox.com) ## Homepage: http://jam.jrox.com ## Bug Reports: http://jam.jrox.com/bugzilla/ ## Release Notes: docs/READ_ME.txt ####################################################################################### ####################################################################################### ## COPYRIGHT NOTICE ## Copyright 2007 JROX Technologies, Inc. All Rights Reserved. ## ## This script may be only used and modified in accordance to the license ## agreement attached (license.txt) except where expressly noted within ## commented areas of the code body. This copyright notice and the ## comments above and below must remain intact at all times. By using this ## code you agree to indemnify JROX Technologies, Inc, its corporate agents ## and affiliates from any liability that might arise from its use. ## ## Selling the code for this program without prior written consent is ## expressly forbidden and in violation of Domestic and International ## copyright laws. ####################################################################################### ####################################################################################### ## This file is used for recording commissions for affiliates ####################################################################################### header("P3P: CP=\"NOI DSP COR NID CUR OUR NOR\""); set_time_limit(0); $jam_ext_sessions = 1; require_once 'includes/common.php'; require_once 'includes/sessions.php'; require_once 'includes/setlang.php'; if (DEBUG_ADVANCED_ERROR == true) { error_reporting(E_ALL); } else { error_reporting(0); } ################### ## SET VARIABLES ## ################### $processed = false; $check_amount = false; $process_commission = false; ################################## ## CUSTOM VALUES OVERWRITES ALL ## ################################## if (!empty($_GET['custom_mid'])) { $custom_mid = $_GET['custom_mid']; } if (!empty($_GET['custom_commission_amount']) AND is_numeric($_GET['custom_commission_amount'])) { $custom_commission_amount = $_GET['custom_commission_amount']; } elseif (!empty($_POST['custom_commission_amount']) AND is_numeric($_POST['custom_commission_amount'])) { $custom_commission_amount = $_POST['custom_commission_amount']; } //CHECK IF $custom_mid VARIABLE WILL BE USED if (empty($custom_mid)) { ########################## ## GET COOKIE VARIABLES ## ########################## if (!empty($_COOKIE['jrox'])) { $custom_mid_array = explode('###', urldecode($_COOKIE['jrox'])); } } else { //SET CUSTOM MID $custom_mid_array = explode('###', urldecode($custom_mid)); } if (!empty($custom_mid_array) AND count($custom_mid_array) > 0) { if (!empty($custom_mid_array[0])) { $mid = $custom_mid_array[0]; } if (!empty($custom_mid_array[1])) { $cookie_pid = $custom_mid_array[1]; } if (!empty($custom_mid_array[2])) { $tool = $custom_mid_array[2]; } if (!empty($custom_mid_array[3])) { $tool_id = $custom_mid_array[3]; } if (!empty($custom_mid_array[5])) { $tracker = $custom_mid_array[4]; $referrer = $custom_mid_array[5]; } elseif (!empty($custom_mid_array[4])) { $referrer = $custom_mid_array[4]; } } if (!empty($_REQUEST['mid'])) $mid = $_REQUEST['mid']; ########################################################################################### ## CHECK IF THERE IS A PRODUCT ID MANUALLY SET FIRST, ELSE USE THE COOKIE PRODUCT VARIABLE ########################################################################################### if (!empty($_GET['program_id']) AND is_numeric($_GET['program_id'])) { $program_id = $_GET['program_id']; } elseif (!empty($_POST['program_id']) AND is_numeric($_POST['program_id'])) { $program_id = $_GET['program_id']; } if (!empty($program_id)) { $pid = $program_id; } elseif (!empty($cookie_pid)) { if (is_numeric($cookie_pid)) { $pid = $cookie_pid; } else { $pid = 1; } } else { $pid = 1; } ######################################### ## GET PRODUCT ID VALUES ######################################### $pid = mysql_real_escape_string($pid); $pquery = @mysql_query("SELECT * FROM jx_products WHERE pid = '$pid'"); if ($pquery) { $program_row= mysql_fetch_assoc($pquery); extract($program_row); $redirect_url = $url_after_sale; $new_comm_setting = $new_commission_setting; if ($product_type == 'lead') { $amount = '1.00'; $trans_id = ROW_PPL."-".JAM_LEAD_TRANS_ID; } } ################################################################## ## CHECK IF IP ADDRESS OR COOKIE WILL BE USED TO TRACK THE SALE ## ################################################################## $enable_ip_tracking = $JAMSettings['enable_ip_tracking']; $enable_session_tracking = $JAMSettings['enable_session_tracking']; $default_affiliate_id = $JAMSettings['default_affiliate_id']; $security_ips = $JAMSettings['security_ips']; //CHECK IF SECURITY IPs ARE REQUIRED if (!empty($security_ips)) { $ip_array = explode(",", $security_ips); foreach ($ip_array as $ip) { if (trim($ip) == $_SERVER['REMOTE_ADDR']) { $ip_set = true; continue; } } if (empty($ip_set)) { return; } } if ($enable_ip_tracking == 1) { //GET VALUES FROM TRAFFIC TABLE $remote_ip = $_SERVER['REMOTE_ADDR']; $get_ip = @mysql_query("SELECT * FROM jx_traffic WHERE ip_address = '$remote_ip' ORDER BY id DESC LIMIT 1"); if ($get_ip) { if (mysql_num_rows($get_ip) > 0) { $get_ip_row = mysql_fetch_assoc($get_ip); $cookie_pid = $get_ip_row['pid']; extract($get_ip_row); } } } ################################# ## CHECK FOR SESSION VARIABLES ## ################################# if ($enable_session_tracking == 1) { if (!empty($_SESSION['jrox_jam'])) { $sess1 = explode('###', urldecode($_SESSION['jrox_jam'])); if (count($sess1) > 0) { $mid = $sess1[0]; $cookie_pid = $sess1[1]; if (!empty($sess1[2])) { $tool = $sess1[2]; } if (!empty($sess1[3])) { $tool_id = $sess1[3]; } if (!empty($sess1[5])) { $tracker = $sess1[4]; $referrer = $sess1[5]; } elseif (!empty($sess1[4])) { $referrer = $sess1[4]; } } } } ####################################### ## CHECK IF MEMBER ID IS STILL VALID ## ####################################### if (!empty($mid) AND is_numeric($mid)) { $checkmid = @mysql_query("SELECT mid, program_group FROM jx_members WHERE mid = '$mid' AND status = 'active'"); if ($checkmid) { if (mysql_num_rows($checkmid) > 0) { $process_commission = true; $member_array = mysql_fetch_row($checkmid); } elseif (!empty($default_affiliate_id)) { $mid = $default_affiliate_id; $process_commission = true; $member_array[1] = 1; } else { return; } } } elseif (!empty($default_affiliate_id)) { $mid = $default_affiliate_id; $member_array[1] = 1; $process_commission = true; } else { return; } ################################ ## CHECK PROGRAM MATCH VALUES ## ################################ if (JAM_MATCH_MEMBER_PROGRAM_ID == true) { if ($member_array[1] != $pid) { return; } } ################################################################################ ## CHECK IF THIS IS A PAYPAL SUBSCRIPTION OR A CUSTOM SET RECURRING FREQUENCY ## ################################################################################ if (!empty($_GET['custom_frequency'])) { $custom_frequency = $_GET['custom_frequency']; } elseif (!empty($_POST['custom_frequency'])) { $custom_frequency = $_POST['custom_frequency']; } if (!empty($custom_frequency)) { switch ($custom_frequency) { case "one_time": $commission_frequency = 'one_time'; break; case "1D": $commission_frequency = 'daily'; break; case "1W": $commission_frequency = 'weekly'; break; case "1M": $commission_frequency = 'monthly'; break; case "3M": $commission_frequency = 'quarterly'; break; case "6M": $commission_frequency = 'semi-annually'; break; case "1Y": $commission_frequency = 'annually'; break; } } if (!empty($jam_subscription)) { $commission_frequency = "one_time"; } ################################################ ## CHECK IF WE NEED TO PROCESS THE COMMISSION ## ################################################ if ($process_commission == true) { //GET SALE CONFIG FROM DB $query = @mysql_query("SELECT * FROM jx_integration"); if ($query) { $row = mysql_fetch_assoc($query); extract($row); } else { return; } ######################################### ## SETUP UP VARIABLES FIRST ######################################### //CHECK TRANSACTION ID VARIABLE if (!empty($_GET['trans_id'])) { $trans_id = $_GET['trans_id']; } elseif (!empty($trans_id)) { $trans_id = $trans_id; } else { $trans_id = ''; } //CHECK AMOUNT VARIABLE if (!empty($paypal_amount)) { $sale_amount = $paypal_amount; $check_amount = true; if (!empty($txn_id)) { $trans_id = $txn_id; } if (!empty($payer_email)) { $sale_var_1_value = $payer_email; } if (!empty($item_name)) { $sale_var_2_value = $item_name; } if (!empty($payment_status)) { $sale_var_3_value = $payment_status; } if (!empty($item_number)) { $sale_var_4_value = $item_number; } } if (!empty($amount) AND is_numeric($amount)) { $sale_amount = $amount; $check_amount = true; } if (!empty($_GET['amount'])) { if (is_numeric($_GET['amount'])) { $sale_amount = $_GET['amount']; if (strstr($sale_amount, '$')) { $sale_amount = preg_replace('/\$/', '', $_GET['amount']); } $check_amount = true; } } //CHECK CURRENCY CONVERTER if (!empty($_REQUEST['currency'])) { $currency_code = $_REQUEST['currency']; if (file_exists(HOME_BASE_DIRECTORY.'/includes/currencies.php')) { require (HOME_BASE_DIRECTORY.'/includes/currencies.php'); foreach ($currency_array as $code => $conversion) { if ($currency_code == $code) { $rate = $conversion['rate']; $symbol = $conversion['symbol']; eval("\$sale_amount = \$sale_amount $rate;"); } } $sale_amount = number_format($sale_amount, DECIMAL_PLACES, DECIMAL_SEPARATOR, THOUSANDS_SEPARATOR); } } //CHECK EXTRA COMMISSION VARIABLES if (empty($referrer)) { $referrer = ROW_UNKNOWN; } if (!empty($jrox_svalue_1)) { $sale_var_1_value = $jrox_svalue_1; } if (!empty($jrox_svalue_2)) { $sale_var_2_value = $jrox_svalue_2; } if (!empty($jrox_svalue_3)) { $sale_var_3_value = $jrox_svalue_3; } if (!empty($jrox_svalue_4)) { $sale_var_4_value = $jrox_svalue_4; } if (!empty($jrox_svalue_5)) { $sale_var_5_value = $jrox_svalue_5; } if (!empty($_GET['jrox_svalue_1'])) { $sale_var_1_value = $_GET['jrox_svalue_1']; } elseif (!empty($_POST['jrox_svalue_1'])) { $sale_var_1_value = $_POST['jrox_svalue_1']; } if (!empty($_GET['jrox_svalue_2'])) { $sale_var_2_value = $_GET['jrox_svalue_2']; } elseif (!empty($_POST['jrox_svalue_2'])) { $sale_var_2_value = $_POST['jrox_svalue_2']; } if (!empty($_GET['jrox_svalue_3'])) { $sale_var_3_value = $_GET['jrox_svalue_3']; } elseif (!empty($_POST['jrox_svalue_3'])) { $sale_var_3_value = $_POST['jrox_svalue_3']; } if (!empty($_GET['jrox_svalue_4'])) { $sale_var_4_value = $_GET['jrox_svalue_4']; } elseif (!empty($_POST['jrox_svalue_4'])) { $sale_var_4_value = $_POST['jrox_svalue_4']; } if (!empty($_GET['jrox_svalue_5'])) { $sale_var_5_value = $_GET['jrox_svalue_5']; } elseif (!empty($_POST['jrox_svalue_5'])) { $sale_var_5_value = $_POST['jrox_svalue_5']; } ######################################### ## CHECK FOR DUPLICATE COMMISSION ######################################### if ($check_amount == true) { //GET DUPLICATE TRANSACTION MONITOR SETTINGS FIRST $enable_transaction_monitor = $JAMSettings['enable_transaction_monitor']; $transaction_monitor_time = $JAMSettings['transaction_monitor_time']; $alert_commission_generated = $JAMSettings['alert_commission_generated']; $enable_performance_bonus = $JAMSettings['enable_performance_bonus']; $performance_criteria = $JAMSettings['performance_criteria']; $performance_amount_required = $JAMSettings['performance_amount_required']; $performance_bonus_amount = $JAMSettings['performance_bonus_amount']; if ($enable_transaction_monitor == 1 || $enable_transaction_monitor == 2) { $remote_ip = $_SERVER['REMOTE_ADDR']; $current_time = time(); $check_comm2 = @mysql_query("SELECT commission_timer FROM jx_timer WHERE ip_address = '$remote_ip' ORDER BY id DESC"); if ($check_comm2) { if (mysql_num_rows($check_comm2) > 0) { $check_comm2_row = mysql_fetch_row($check_comm2); $commission_timer = $check_comm2_row[0]; if ($commission_timer >= $current_time) { //CHECK IF THERE IS A DUPLICATE TRANSACTION ID FROM THE SAME IP ADDRESS if ($enable_transaction_monitor == 2) { if (!empty($trans_id)) { $check_comm3 = @mysql_query("SELECT cid FROM jx_commissions WHERE ip_address = '$remote_ip' AND trans_id = '$trans_id' ORDER BY cid DESC LIMIT 10"); if ($check_comm3) { if (mysql_num_rows($check_comm3) > 0) { //TIMER NOT EXPIRED //LOG ERROR EVENTS Log_Events(COMMISSION, "2", DUPLICATE_TRANSACTION_TRIED.", ".TIME.": ".CURRENT_TIME.", ".IP_ADDRESS.": ".$_SERVER['REMOTE_ADDR'].""); return; } } } } else { //LOG ERROR EVENTS Log_Events(COMMISSION, "2", DUPLICATE_TRANSACTION_TRIED.", ".TIME.": ".CURRENT_TIME.", ".IP_ADDRESS.": ".$_SERVER['REMOTE_ADDR'].""); return; } } } } } ################################################################ ## GET ALL UPLINE SPONSORS, CREATE COMMISSION AND SEND ALERTS ## ################################################################ if ($commission_levels > 1) { //GET CURRENT AFFILIATE LEVEL $current_level = $commission_levels; //CREATE COMMISSION FOR CURRENT AFFILIATE if (Create_Commission("1", $mid) == true) { //LOG SUCCESSFUL COMMISSION Log_Events(COMMISSION, "1", COMMISSION_GENERATED.", ".TRANSACTION_ID.": ".$trans_id.", Level: 1, ".SALE_AMOUNT.": ".$sale_amount.", ".COMMISSION_AMOUNT.": ".$commission_amount.", ".AFFILIATE_ID.": ".$mid.", ".TIME.": ".CURRENT_TIME.", ".IP_ADDRESS.": ".$_SERVER['REMOTE_ADDR'].""); //create email data array for sending out $array = array ( 'sale_amount' => $sale_amount, 'commission_amount' => $commission_amount, 'trans_id' => $trans_id, 'username' => $username, 'primary_email' => $primary_email, 'F_Custom_Value_1' => $sale_var_1_value, 'F_Custom_Value_2' => $sale_var_2_value, 'F_Custom_Value_3' => $sale_var_3_value, 'F_Custom_Value_4' => $sale_var_4_value, 'F_Custom_Value_5' => $sale_var_5_value, ); //SEND AFFILIATE COMMISSION ALERTS if ($alert_commission_generated == 1 AND $new_comm_setting == "unpaid") { Send_System_Email('9', $primary_email, $array); } //CHECK FOR ADMIN COMMISSION ALERTS Send_System_Email('2', '', $array); } if ($current_level > 1) { $upline = Get_Member_Upline($mid, $commission_levels, $current_level); //CALCULATE COMMISSION AND RECURRING STATUS FOR ALL SPONSORS foreach ($upline as $value) { $key = array(); $comm_array = array(); if ($value[1] > 0) { if (Create_Commission($value[0], $value[1]) == true) //INSERT COMMISSION FOR ALL MEMBERS { //LOG SUCCESSFUL COMMISSION Log_Events(COMMISSION, "1", COMMISSION_GENERATED.", ".TRANSACTION_ID.": ".$trans_id.", Level: ".$value[0].", ".SALE_AMOUNT.": ".$sale_amount.", ".COMMISSION_AMOUNT.": ".$commission_amount.", ".AFFILIATE_ID.": ".$value[1].", ".TIME.": ".CURRENT_TIME.", ".IP_ADDRESS.": ".$_SERVER['REMOTE_ADDR'].""); $array = array ( 'sale_amount' => $sale_amount, 'commission_amount' => $commission_amount, 'trans_id' => $trans_id, 'username' => $username, 'primary_email' => $primary_email, 'F_Custom_Value_1' => $sale_var_1_value, 'F_Custom_Value_2' => $sale_var_2_value, 'F_Custom_Value_3' => $sale_var_3_value, 'F_Custom_Value_4' => $sale_var_4_value, 'F_Custom_Value_5' => $sale_var_5_value, ); //SEND AFFILIATE COMMISSION ALERTS if ($alert_commission_generated == 1 AND $new_comm_setting == "unpaid") { Send_System_Email('9', $primary_email, $array); } //CHECK FOR ADMIN COMMISSION ALERTS Send_System_Email('2', '', $array); } } } } } else { //CREATE COMMISSION FOR CURRENT AFFILIATE if (Create_Commission(1, $mid) == true) { //LOG SUCCESSFUL COMMISSION Log_Events(COMMISSION, "1", COMMISSION_GENERATED.", ".TRANSACTION_ID.": ".$trans_id.", ".SALE_AMOUNT.": ".$sale_amount.", ".COMMISSION_AMOUNT.": ".$commission_amount.", ".AFFILIATE_ID.": ".$mid.", ".TIME.": ".CURRENT_TIME.", ".IP_ADDRESS.": ".$_SERVER['REMOTE_ADDR'].""); //SEND AFFILIATE COMMISSION ALERTS $array = array ( 'sale_amount' => $sale_amount, 'commission_amount' => $commission_amount, 'trans_id' => $trans_id, 'username' => $username, 'primary_email' => $primary_email, 'F_Custom_Value_1' => $sale_var_1_value, 'F_Custom_Value_2' => $sale_var_2_value, 'F_Custom_Value_3' => $sale_var_3_value, 'F_Custom_Value_4' => $sale_var_4_value, 'F_Custom_Value_5' => $sale_var_5_value, ); if ($alert_commission_generated == 1 AND $new_comm_setting == "unpaid") { Send_System_Email('9', $primary_email, $array); } //CHECK FOR ADMIN COMMISSION ALERTS Send_System_Email('2', '', $array); } } //LOG COMMISSION TIMER $ip = $_SERVER['REMOTE_ADDR']; Insert_Commission_Timer($ip, $transaction_monitor_time); } $processed = true; } ?>