Exemplo n.º 1
0
function handle_uploaded_identity_docs()
{
    global $is_logged_in, $is_admin;
    ?>
    <div class='content_box'>
    <h3>Upload Results</h3>
<?php 
    if ($is_admin && isset($_POST['uid'])) {
        $uid = post('uid');
        if ($uid == '') {
            $uid = $is_logged_in;
        } else {
            get_openid_for_user($uid);
        }
        // will throw exception if user doesn't exist
    } else {
        $uid = $is_logged_in;
    }
    $uploaded = 0;
    for ($i = 0; $i < ID_FILE_UPLOAD_SLOTS; $i++) {
        $uploaded += upload_identity_doc($i, $uid);
    }
    echo "<p>" . _("Documents uploaded") . ": {$uploaded}</p>\n";
    echo "</div>\n";
    if ($uploaded && !$is_admin) {
        email_tech(_("User Uploaded New Identity Documents"), sprintf("%s\n\n%s", sprintf(_("User %s uploaded %s new file(s)."), $is_logged_in, $uploaded), sprintf("%s?page=docs&uid=%s", SITE_URL, $is_logged_in)));
    }
}
Exemplo n.º 2
0
<?php

require_once '../util.php';
$is_logged_in = 'sync_to_bitcoin';
foreach (bitcoin_list_accounts(CONFIRMATIONS_FOR_DEPOSIT) as $account => $balance) {
    if ($balance) {
        try {
            get_openid_for_user($account);
            // check they have an account
        } catch (Exception $e) {
            continue;
        }
        get_user_lock($account);
        addlog(LOG_CRONJOB, sprintf("add %s BTC for user %s", internal_to_numstr($balance), $account));
        sync_to_bitcoin((string) $account);
        release_lock($account);
    }
}
Exemplo n.º 3
0
function show_statement($userid, $interval = 'forever', $from_zero, $deposit_btc, $withdraw_btc, $deposit_fiat, $withdraw_fiat, $buy, $sell)
{
    global $is_logged_in, $is_admin;
    if ($userid) {
        $specified_user = true;
    } else {
        $specified_user = false;
        $userid = $is_logged_in;
    }
    $show_increments = false;
    $show_prices = true;
    echo "<div class='content_box'>\n";
    $all_users = $userid == 'all';
    $deposit_address = $create_timestamp = false;
    if ($all_users) {
        echo "<h3>" . _("Statement for All Users") . "</h3>\n";
        $check_stuff = "";
    } else {
        $openid = get_openid_for_user($userid);
        echo "<h3>" . sprintf(_("Statement for UID %s"), $userid) . "</h3>\n";
        $check_stuff = "uid='{$userid}' AND ";
        if ($is_admin) {
            $create_timestamp = get_account_creation_timest_for_user($userid);
            try {
                $deposit_address = bitcoin_get_account_address($userid);
            } catch (Exception $e) {
            }
        }
    }
    echo "<form method='get'>\n" . "<p>\n" . _("Show entries from ") . "\n" . "<input type='hidden' name='page' value='statement' />\n";
    echo "<select onChange='this.form.submit()' name='interval'>\n";
    foreach (array('4 hour' => _('the last 4 hours'), '12 hour' => _('the last 12 hours'), '1 day' => _('the last 24 hours'), '3 day' => _('the last 3 days'), '1 week' => _('the last 7 days'), '1 month' => _('the last month'), '2 month' => _('the last 2 months'), '3 month' => _('the last 3 months'), '6 month' => _('the last 6 months'), '1 year' => _('the last year'), 'forever' => _('forever'), 'pending' => _('still pending')) as $key => $text) {
        printf("<option %s value='%s'>%s</option>\n", $interval == $key ? "selected='selected'" : "", $key, $text);
    }
    echo "</select>\n";
    if ($is_admin) {
        echo " for <select onChange='this.form.submit()' name='user'>\n";
        if ($all_users) {
            printf("<option value='{$is_logged_in}'>%s</option>\n", _("my account"));
            printf("<option value='all' selected='selected'>all users</option>\n");
        } else {
            if ($userid != $is_logged_in) {
                printf("<option value='{$is_logged_in}'>%s</option>\n", _("my account"));
            }
            printf("<option value='{$userid}' selected='selected'>%s</option>\n", $userid == $is_logged_in ? _("my account") : "UID {$userid}");
            echo "<option value='all'>all users</option>\n";
        }
        echo "</select>\n";
        echo " or UID or OpenID: ";
        echo "<input class='nline' type='text' name='uid'>\n";
    }
    $pending = $interval == 'pending';
    $use_interval = $interval != 'forever' && !$pending;
    $args = $specified_user ? "user={$userid}&" : "";
    $args .= "interval={$interval}";
    if ($from_zero) {
        $args .= "&fromz=1";
    }
    echo "<input type='hidden' name='form' value='1' /><br />\n";
    echo statement_checkbox('dbtc', $deposit_btc, _("Deposit") . " " . "BTC", $args);
    echo statement_checkbox('wbtc', $withdraw_btc, _("Withdraw") . " " . "BTC", $args);
    echo statement_checkbox('dfiat', $deposit_fiat, _("Deposit") . " " . CURRENCY, $args);
    echo statement_checkbox('wfiat', $withdraw_fiat, _("Withdraw") . " " . CURRENCY, $args);
    echo statement_checkbox('bbtc', $buy, _("Buy") . " " . "BTC", $args);
    echo statement_checkbox('sbtc', $sell, _("Sell") . " " . "BTC", $args);
    if ($interval != 'forever') {
        echo statement_checkbox('fromz', $from_zero, _("Start at Zero"));
    } else {
        if ($from_zero) {
            echo "<input type='hidden' name='fromz' value='1' />\n";
        }
    }
    echo "</p>\n";
    echo "</form>\n";
    if (!$all_users) {
        echo "<p>" . _("OpenID") . ": <a href=\"{$openid}\">{$openid}</a></p>\n";
        if ($deposit_address) {
            echo "<p>" . _("Deposit Address") . ": {$deposit_address}</p>\n";
        }
    }
    $query = "\n        SELECT\n            uid,\n            txid, a_orderid AS orderid,\n            a_amount AS gave_amount, '" . CURRENCY . "' AS gave_curr,\n            (b_amount-b_commission) AS got_amount,  'BTC' AS got_curr,\n            NULL as reqid,  NULL as req_type,\n            NULL as amount, NULL as curr_type, NULL as addy, NULL as voucher, NULL as final, NULL as bank, NULL as acc_num,\n            " . sql_format_date('transactions.timest') . " AS date,\n            transactions.timest as timest, " . ($use_interval ? "transactions.timest > NOW() - INTERVAL {$interval}" : ($pending ? "0" : "1")) . " AS new\n        FROM\n            transactions\n        JOIN\n            orderbook\n        ON\n            orderbook.orderid = transactions.a_orderid\n        WHERE\n            {$check_stuff}\n            b_amount != -1\n\n    UNION\n\n        SELECT\n            uid,\n            txid, b_orderid AS orderid,\n            b_amount AS gave_amount, 'BTC' AS gave_curr,\n            (a_amount-a_commission) AS got_amount,  '" . CURRENCY . "' AS got_curr,\n            NULL, NULL,\n            NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n            " . sql_format_date('transactions.timest') . " AS date,\n            transactions.timest as timest, " . ($use_interval ? "transactions.timest > NOW() - INTERVAL {$interval}" : ($pending ? "0" : "1")) . " AS new\n        FROM\n            transactions\n        JOIN\n            orderbook\n        ON\n            orderbook.orderid=transactions.b_orderid\n        WHERE\n            {$check_stuff}\n            b_amount != -1\n\n    UNION\n\n        SELECT\n            uid,\n            NULL, NULL,\n            NULL, NULL,\n            NULL, NULL,\n            requests.reqid,  req_type,\n            amount, curr_type, addy, CONCAT(prefix, '-...') as voucher, status = 'FINAL', bank, acc_num,\n            " . sql_format_date('timest') . " AS date,\n            timest, " . ($use_interval ? "timest > NOW() - INTERVAL {$interval}" : ($pending ? "status != 'FINAL'" : "1")) . " AS new\n        FROM\n            requests\n        LEFT JOIN\n            bitcoin_requests\n        ON\n            requests.reqid = bitcoin_requests.reqid\n        LEFT JOIN\n            voucher_requests\n        ON\n            (requests.reqid = voucher_requests.reqid OR\n             requests.reqid = voucher_requests.redeem_reqid)\n        LEFT JOIN\n            uk_requests\n        ON\n            requests.reqid = uk_requests.reqid\n        WHERE\n            {$check_stuff}\n            status != 'CANCEL'\n\n    ORDER BY\n        timest, txid, got_curr\n    ";
    $first = true;
    $result = do_query($query);
    $fiat = $btc = numstr_to_internal(0);
    $total_fiat_deposit = $total_fiat_withdrawal = $total_btc_deposit = $total_btc_withdrawal = numstr_to_internal(0);
    $total_fiat_got = $total_fiat_given = $total_btc_got = $total_btc_given = numstr_to_internal(0);
    $period_fiat_deposit = $period_fiat_withdrawal = $period_btc_deposit = $period_btc_withdrawal = numstr_to_internal(0);
    $period_fiat_got = $period_fiat_given = $period_btc_got = $period_btc_given = numstr_to_internal(0);
    echo "<table class='display_data'>\n";
    echo "<tr>";
    echo "<th>" . _("Date") . "</th>";
    if ($all_users) {
        echo "<th>" . _("User") . "</th>";
    }
    echo "<th>" . _("Description") . "</th>";
    if (!$pending) {
        if ($show_prices) {
            echo "<th class='right'>" . _("Price") . "</th>";
        }
        if ($show_increments) {
            echo "<th class='right'>+/-</th>";
        }
        echo "<th class='right'>BTC</th>";
        if ($show_increments) {
            echo "<th class='right'>+/-</th>";
        }
        echo "<th class='right'>" . CURRENCY . "</th>";
    }
    echo "</tr>\n";
    if ($create_timestamp && !$pending) {
        printf("<tr><td>%s</td><td>%s</td></tr>\n", $create_timestamp, _("Create Account"));
    }
    $all_final = true;
    while ($row = mysql_fetch_array($result)) {
        $new = $row['new'];
        $uid = $row['uid'];
        $date = $row['date'];
        if ($first && $new) {
            if ($from_zero) {
                $btc = $fiat = numstr_to_internal(0);
            }
            show_balances_in_statement(_("Opening Balances"), $btc, $fiat, $all_users, $show_prices, $show_increments, $pending);
            $first = false;
        }
        if (isset($row['txid'])) {
            /* buying or selling */
            $txid = $row['txid'];
            $orderid = $row['orderid'];
            $gave_amount = $row['gave_amount'];
            $gave_curr = $row['gave_curr'];
            $got_amount = $row['got_amount'];
            $got_curr = $row['got_curr'];
            if ($got_curr == 'BTC') {
                /* buying BTC */
                if ($buy) {
                    $fiat = gmp_sub($fiat, $gave_amount);
                    $btc = gmp_add($btc, $got_amount);
                }
                $total_btc_got = gmp_add($total_btc_got, $got_amount);
                $total_fiat_given = gmp_add($total_fiat_given, $gave_amount);
                $got_str = internal_to_numstr($got_amount, BTC_PRECISION);
                $gave_str = internal_to_numstr($gave_amount, FIAT_PRECISION);
                if ($new && $buy) {
                    $period_btc_got = gmp_add($period_btc_got, $got_amount);
                    $period_fiat_given = gmp_add($period_fiat_given, $gave_amount);
                    if (string_is_zero($got_str) && string_is_zero($gave_str)) {
                        continue;
                    }
                    echo "<tr><td>{$date}</td>";
                    if ($all_users) {
                        echo active_table_cell_link_to_user_statement($uid, $interval);
                    }
                    active_table_cell_for_order(sprintf(_("Buy %s %s for %s %s"), $got_str, $got_curr, $gave_str, $gave_curr), $orderid);
                    if ($show_prices) {
                        printf("<td>%s</td>", trade_price($got_amount, $gave_amount));
                    }
                    if ($show_increments) {
                        printf("<td class='right'>+ %s</td>", $got_str);
                    }
                    printf("<td class='right'> %s</td>", internal_to_numstr($btc, BTC_PRECISION));
                    if ($show_increments) {
                        printf("<td class='right'>- %s</td>", $gave_str);
                    }
                    printf("<td class='right'> %s</td>", internal_to_numstr($fiat, FIAT_PRECISION));
                    echo "</tr>\n";
                }
            } else {
                /* selling BTC */
                if ($sell) {
                    $fiat = gmp_add($fiat, $got_amount);
                    $btc = gmp_sub($btc, $gave_amount);
                }
                $total_fiat_got = gmp_add($total_fiat_got, $got_amount);
                $total_btc_given = gmp_add($total_btc_given, $gave_amount);
                $gave_str = internal_to_numstr($gave_amount, BTC_PRECISION);
                $got_str = internal_to_numstr($got_amount, FIAT_PRECISION);
                if ($new && $sell) {
                    $period_fiat_got = gmp_add($period_fiat_got, $got_amount);
                    $period_btc_given = gmp_add($period_btc_given, $gave_amount);
                    if (string_is_zero($got_str) && string_is_zero($gave_str)) {
                        continue;
                    }
                    echo "<tr><td>{$date}</td>";
                    if ($all_users) {
                        echo active_table_cell_link_to_user_statement($uid, $interval);
                    }
                    active_table_cell_for_order(sprintf(_("Sell %s %s for %s %s"), $gave_str, $gave_curr, $got_str, $got_curr), $orderid);
                    if ($show_prices) {
                        printf("<td>%s</td>", trade_price($gave_amount, $got_amount));
                    }
                    if ($show_increments) {
                        printf("<td class='right'>-%s</td>", $gave_str);
                    }
                    // don't show balances between pairs of buy and sell rows if we're showing buy as well as sell
                    printf("<td class='right'>%s</td>", $all_users && $buy ? "" : internal_to_numstr($btc, BTC_PRECISION));
                    if ($show_increments) {
                        printf("<td class='right'>+%s</td>", $got_str);
                    }
                    printf("<td class='right'>%s</td>", $all_users && $buy ? "" : internal_to_numstr($fiat, FIAT_PRECISION));
                    echo "</tr>\n";
                }
            }
        } else {
            /* withdrawal or deposit */
            $reqid = $row['reqid'];
            $req_type = $row['req_type'];
            $amount = $row['amount'];
            $curr_type = $row['curr_type'];
            $voucher = $row['voucher'];
            $final = $row['final'];
            // echo "final is $final<br/>\n";
            $show = $req_type == 'DEPOS' && ($curr_type == 'BTC' && $deposit_btc || $curr_type != 'BTC' && $deposit_fiat) || $req_type != 'DEPOS' && ($curr_type == 'BTC' && $withdraw_btc || $curr_type != 'BTC' && $withdraw_fiat);
            if ($new && $show) {
                echo "<tr><td>{$date}</td>";
                if ($all_users) {
                    echo active_table_cell_link_to_user_statement($uid, $interval);
                }
            }
            if (!$final) {
                $all_final = false;
            }
            if ($req_type == 'DEPOS') {
                /* deposit */
                $title = '';
                if ($voucher) {
                    $title = sprintf(_("from voucher") . " &quot;%s&quot;", $voucher);
                }
                if ($curr_type == 'BTC') {
                    /* deposit BTC */
                    if ($show) {
                        $btc = gmp_add($btc, $amount);
                    }
                    $total_btc_deposit = gmp_add($total_btc_deposit, $amount);
                    if ($new && $show) {
                        $period_btc_deposit = gmp_add($period_btc_deposit, $amount);
                        active_table_cell_for_request(sprintf("<strong title='%s'>%s%s %s BTC%s</strong>", $title, $final ? "" : "* ", $voucher ? _("Redeem voucher") . ":" : _("Deposit"), internal_to_numstr($amount, BTC_PRECISION), $final ? "" : " *"), $reqid);
                        if (!$pending) {
                            if ($show_prices) {
                                printf("<td></td>");
                            }
                            if ($show_increments) {
                                printf("<td class='right'>+%s</td>", internal_to_numstr($amount, BTC_PRECISION));
                            }
                            printf("<td class='right'>%s</td>", internal_to_numstr($btc, BTC_PRECISION));
                            if ($show_increments) {
                                printf("<td></td>");
                            }
                            printf("<td></td>");
                        }
                    }
                } else {
                    /* deposit FIAT */
                    if ($show) {
                        $fiat = gmp_add($fiat, $amount);
                    }
                    $total_fiat_deposit = gmp_add($total_fiat_deposit, $amount);
                    if ($new && $show) {
                        $period_fiat_deposit = gmp_add($period_fiat_deposit, $amount);
                        active_table_cell_for_request(sprintf("<strong title='%s'>%s%s %s %s%s</strong>", $title, $final ? "" : "* ", $voucher ? _("Redeem voucher") . ":" : _("Deposit"), internal_to_numstr($amount, FIAT_PRECISION), CURRENCY, $final ? "" : " *"), $reqid);
                        if (!$pending) {
                            if ($show_prices) {
                                printf("<td></td>");
                            }
                            if ($show_increments) {
                                printf("<td></td>");
                            }
                            printf("<td></td>");
                            if ($show_increments) {
                                printf("<td class='right'>+%s</td>", internal_to_numstr($amount, FIAT_PRECISION));
                            }
                            printf("<td class='right'>%s</td>", internal_to_numstr($fiat, FIAT_PRECISION));
                        }
                    }
                }
            } else {
                /* withdrawal */
                if ($curr_type == 'BTC') {
                    /* withdraw BTC */
                    if ($show) {
                        $btc = gmp_sub($btc, $amount);
                    }
                    $total_btc_withdrawal = gmp_add($total_btc_withdrawal, $amount);
                    if ($new && $show) {
                        $period_btc_withdrawal = gmp_add($period_btc_withdrawal, $amount);
                        $addy = $row['addy'];
                        if ($addy) {
                            $title = sprintf(_("to Bitcoin address") . " &quot;%s&quot;", $addy);
                        } else {
                            if ($voucher) {
                                $title = sprintf(_("to %svoucher") . " &quot;%s&quot;", $final ? "" : _("unredeemed") . " ", $voucher);
                            }
                        }
                        active_table_cell_for_request(sprintf("<strong title='%s'>%s%s %s BTC%s</strong>", $title, $final ? "" : "* ", $voucher ? _("Create voucher") . ":" : _("Withdraw"), internal_to_numstr($amount, BTC_PRECISION), $final ? "" : " *"), $reqid);
                        if (!$pending) {
                            if ($show_prices) {
                                printf("<td></td>");
                            }
                            if ($show_increments) {
                                printf("<td class='right'>-%s</td>", internal_to_numstr($amount, BTC_PRECISION));
                            }
                            printf("<td class='right'>%s</td>", internal_to_numstr($btc, BTC_PRECISION));
                            if ($show_increments) {
                                printf("<td></td>");
                            }
                            printf("<td></td>");
                        }
                    }
                } else {
                    /* withdraw FIAT */
                    if ($show) {
                        $fiat = gmp_sub($fiat, $amount);
                    }
                    $total_fiat_withdrawal = gmp_add($total_fiat_withdrawal, $amount);
                    if ($new && $show) {
                        $period_fiat_withdrawal = gmp_add($period_fiat_withdrawal, $amount);
                        $title = '';
                        if ($voucher) {
                            $title = sprintf(_("to %svoucher") . " &quot;%s&quot;", $final ? "" : _("unredeemed") . " ", $voucher);
                        } else {
                            $title = sprintf(_("to account %s at %s"), $row['acc_num'], $row['bank']);
                        }
                        active_table_cell_for_request(sprintf("<strong title='%s'>%s%s %s %s%s</strong>", $title, $final ? "" : "* ", $voucher ? _("Create voucher") . ":" : _("Withdraw"), internal_to_numstr($amount, FIAT_PRECISION), CURRENCY, $final ? "" : " *"), $reqid);
                        if (!$pending) {
                            if ($show_prices) {
                                printf("<td></td>");
                            }
                            if ($show_increments) {
                                printf("<td></td>");
                            }
                            printf("<td></td>");
                            if ($show_increments) {
                                printf("<td class='right'>-%s</td>", internal_to_numstr($amount, FIAT_PRECISION));
                            }
                            printf("<td class='right'>%s</td>", internal_to_numstr($fiat, FIAT_PRECISION));
                        }
                    }
                }
            }
            if ($new) {
                echo "</tr>\n";
            }
        }
    }
    if ($first && $from_zero) {
        $fiat = $btc = numstr_to_internal(0);
    }
    show_balances_in_statement($first ? _("There are no entries for this period") : _("Closing Balances"), $btc, $fiat, $all_users, $show_prices, $show_increments, $pending);
    echo "</table>\n";
    if (!$all_final) {
        echo "<p>" . _("Items marked with '*' are not yet final.") . "</p>\n";
        echo "<p>" . _("Any such withdrawals and vouchers can be cancelled.") . "</p>\n";
        echo "<p>" . _("Any such deposits are pending, and should be finalised within a minute or two.") . "</p>\n";
    }
    echo "</div>";
    if (gmp_cmp($total_fiat_deposit, $period_fiat_deposit) != 0 || gmp_cmp($total_fiat_withdrawal, $period_fiat_withdrawal) != 0 || gmp_cmp($total_btc_deposit, $period_btc_deposit) != 0 || gmp_cmp($total_btc_withdrawal, $period_btc_withdrawal) != 0 || gmp_cmp($total_fiat_got, $period_fiat_got) != 0 || gmp_cmp($total_fiat_given, $period_fiat_given) != 0 || gmp_cmp($total_btc_got, $period_btc_got) != 0 || gmp_cmp($total_btc_given, $period_btc_given) != 0) {
        show_statement_summary(_("Summary of displayed entries"), $period_fiat_deposit, $period_fiat_withdrawal, $period_btc_deposit, $period_btc_withdrawal, $period_fiat_got, $period_fiat_given, $period_btc_got, $period_btc_given);
    }
    show_statement_summary(_("Account Summary"), $total_fiat_deposit, $total_fiat_withdrawal, $total_btc_deposit, $total_btc_withdrawal, $total_fiat_got, $total_fiat_given, $total_btc_got, $total_btc_given);
}