Example #1
0
/////////Pay users who have reached their threshold payout
$bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost);
$resultQ = mysql_query("select userId, cast(balance as decimal(16,8)) as balance, IFNULL(paid, 0) as paid, IFNULL(sendAddress, '') as sendAddress FROM accountBalance WHERE CAST(threshold AS decimal(16,8)) >= 0.1 AND CAST(balance AS decimal(16,8)) >= CAST(threshold AS decimal(16,8))");
while ($resultR = mysql_fetch_object($resultQ)) {
    $currentBalance = $resultR->balance;
    $paid = $resultR->paid;
    $paymentAddress = $resultR->sendAddress;
    $userId = $resultR->userId;
    //echo "Payment: $paid , User: $userId , Current Balance: $currentBalance<br>";
    if ($paymentAddress != '') {
        $isValidAddress = $bitcoinController->validateaddress($paymentAddress);
        if ($isValidAddress) {
            //Subtract TX feee
            //$currentBalance = $currentBalance - 0.01;
            //Send money//
            if ($bitcoinController->sendtoaddress($paymentAddress, $currentBalance)) {
                //Reduce balance amount to zero
                mysql_query("UPDATE `accountBalance` SET balance = '0', paid = '" . $paid . "' WHERE `userId` = '" . $userId . "'");
                $userInfoQ = mysql_query("SELECT id,username, email, sendemail, emailAuthPin, recivemail FROM webUsers WHERE id = '" . $resultR->userId . "'");
                $userInfo = mysql_fetch_object($userInfoQ);
                if ($userInfo->sendemail == 'yes' && $userInfo->recivemail == 'yes') {
                    $id = $userInfo->id;
                    $to = "{$userInfo->email}";
                    $pin = "{$userInfo->emailAuthPin}";
                    $subject = "OzCoin Payout";
                    $msg = "\n<html>\n<head>\n<title>Ozcoin's Payout</title>\n</head>\n<body>\nHello, {$userInfo->username}<br />\n<br />\nA block payout has just finished and you have been paid<br />\nPaid: {$currentBalance} LTC<br />\nLitecoin Address: {$paymentAddress}<br />\n<br />\nThanks for using Ozcoin<br />\n<img src=\"https://ozco.in/images/ozcoin.png\" alt=\"ozcoin site\"/><br>\nTo Unsubscribe from getting emails please <a href=https://ozco.in/unsub.php?id={$id}&pin={$pin}>click here</a>\n</body></html>";
                    $from_email = "*****@*****.**";
                    //site email
                    $headers = "From: {$from_email}\n";
                    $headers .= 'MIME-Version: 1.0' . "\n";
                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";