<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/includes.inc.php");
require_once($_SERVER['DOCUMENT_ROOT']."/includes/postback.functions.inc.php");
require_once($_SERVER['DOCUMENT_ROOT']."/includes/postback.logging.inc.php");
//Setting initial variables
$secret_key = 'mysecretapkey'; //Enter secret key here
$user_id = $_REQUEST['uid'];
$user_name = ScrapeDB('username', $user_id, 0);
$external_hash = $_REQUEST['sig'];
$transaction_id = $_REQUEST['id'];
$points_earned = $_REQUEST['new'];
//Security check to verify real postback
$local_hash_calc = md5($transaction_id . ':' . $points_earned . ':' . $user_id . ':' . $secret_key);
if(($local_hash_calc == $external_hash) && (CheckForUniqueSID($user_id, $transaction_id) == 0)) {
$user_id = ScrapeDB('id', $user_name, 0);
$referral_id = ScrapeDB('referral_ID', $user_name, 0);
$referral_name = ScrapeDB('username', $referral_id, 1);
$referral_points_earned = CalcReferralPoints($points_earned, $referral_id);
//Update User Points
UpdateUserPoints($points_earned, $user_name, 0);
UpdateReferralPoints($referral_points_earned, $referral_id, $user_id);
$total_user_points = ScrapeDB('points', $user_name);
$total_referral_points = ScrapeDB('points', $referral_id, '1');
WriteLogsToDB($user_name,
$user_id,
$points_earned,
$total_user_points,
$referral_name,
$referral_id,
$referral_points_earned,
$total_referral_points,
's-rewards',
$transaction_id);
echo "1";// if user is credited successfully else echo 0
} else if (CheckForUniqueSID($user_id, $transaction_id) >= 1){
echo "1";
}else{
echo "0";
}
?>