//we may need a way to credit users who have gotten coins at an old address...
        //we now check both columns... so this is done
    }
    echo $strError;
    die;
    $intUserID = 0;
}
//############ LOGIC HERE #############################
//$value_in_satoshi = urldecode($value_in_satoshi);
$value_in_satoshi = abs($value_in_satoshi);
// SECURITY prevent negative attacks
//$value_in_satoshi = (float) $value_in_satoshi; //why do we float this value here? no decimal..
$crypto_amt = $value_in_satoshi / 100000000;
//echo "satoshi= ".$value_in_satoshi." <br> ";
//we need to make sure this function works. a backup may be needed! Gox, blockchain, coinbase, bitpay ?
$intRate = funct_Billing_UpdateRate("btc", RATE_HUD_EXCHANGE);
//bitstamp.. lower the rate the bigger the spread
//get value of BTC to convert to fiat
$intBTC_Convert2Fiat = $crypto_amt * (1 / $intFiatConversionPercent);
//calculate final BTC to add to BTC balance
$intBTC_Add2Balance = $crypto_amt - $intBTC_Convert2Fiat;
//calculate final FIAT to add to balance
$intTotalUSD = $intRate * $intBTC_Convert2Fiat;
//echo "userid: $intUserID";
//IF THEY have specified a different currency then we need to convert BTC to that currency
if ($intCurrencyID != 144) {
    //if fiat currency is NOT USD then we need to get the exchange rate and adjust the amount of fiat they earned
    //get fiat rate, fiat code and
    $intFiatRate = funct_Billing_UpdateRate_Fiat($strCurrencyCode);
    //convert to value of btc.. we store all this into the orders table  //ex. 0.7 for usd-eur
    $intTotalFiat = $intFiatRate * $intTotalUSD;
function funct_Billing_GetRate($strCrypto, $strExchange)
{
    global $DB_LINK;
    //needed for all db calls
    if (!$strCrypto) {
        $strCrypto = "btc";
    }
    if (!$strExchange) {
        $strExchange = RATE_HUD_EXCHANGE;
    }
    $intTime_FreshSeconds = RATE_REFRESH_SECONDS;
    $query = "SELECT * FROM " . TBL_RATES . " WHERE crypto= '" . $strCrypto . "' AND exchange='" . $strExchange . "'";
    //echo "Rate Select SQL = " . $query .  "<br>";
    $rs = mysqli_query($DB_LINK, $query) or die(mysqli_error());
    if (mysqli_num_rows($rs) > 0) {
        $row = mysqli_fetch_array($rs);
        $intRate = $row["rate"];
        $intTimeLast = $row["date"];
    }
    $intTimeDiffRate = time() - $intTimeLast;
    if ($intTimeDiffRate > $intTime_FreshSeconds) {
        $intRate = funct_Billing_UpdateRate($strCrypto, $strExchange);
    }
    //custom modifers
    if (RATE_MINIMUM_SELL and $intRate < RATE_MINIMUM_SELL) {
        $intRate = RATE_MINIMUM_SELL;
    }
    $intRate = $intRate + rand(0, RATE_RANDOMIZER_MAX);
    return $intRate;
}