function show_mini_orderbook_table_row($id, $curr, $price, $have, $want, $this_fiat, $this_btc, $sum_fiat, $sum_btc, $mine) { global $minimum_btc_amount, $minimum_fiat_amount; $this_btc_str = internal_to_numstr($this_btc, BTC_PRECISION); $this_fiat_str = internal_to_numstr($this_fiat, FIAT_PRECISION); if (string_is_zero($this_btc_str) || string_is_zero($this_fiat_str) || gmp_cmp($this_btc, $minimum_btc_amount) < 0 || gmp_cmp($this_fiat, $minimum_fiat_amount) < 0) { return; } if ($mine) { $sum_btc_str = internal_to_numstr($sum_btc, BTC_PRECISION); $sum_fiat_str = internal_to_numstr($sum_fiat, FIAT_PRECISION); active_table_row("me", "?page=view_order&orderid={$mine}"); echo "<td class='right'>{$price}</td>\n"; echo "<td class='right'>{$this_btc_str}</td>\n"; echo "<td class='right'>{$this_fiat_str}</td>\n"; echo "<td class='right'>{$sum_btc_str}</td>\n"; echo "<td class='right'>{$sum_fiat_str}</td>\n"; echo "</tr>\n"; } else { echo "<tr>\n"; echo "<td class='right'>{$price}</td>\n"; show_mini_orderbook_table_cell($id . 't', $curr, $price, $have, $want, $this_fiat, $this_btc); show_mini_orderbook_table_cell($id . 'c', $curr, $price, $have, $want, $sum_fiat, $sum_btc); } echo "</tr>\n"; }
function show_withdrawals() { echo "<div class='content_box'>\n"; echo "<h3>" . _("Withdraw requests") . "</h3>\n"; $result = do_query("\n SELECT requests.reqid as reqid, uid, amount, " . sql_format_date("timest") . " as timest, name, bank, acc_num, sort_code\n FROM requests\n JOIN uk_requests\n ON uk_requests.reqid = requests.reqid\n WHERE req_type = 'WITHDR'\n AND curr_type = '" . CURRENCY . "'\n AND status = 'VERIFY'"); $first = true; while ($row = mysql_fetch_assoc($result)) { if ($first) { $first = false; echo "<table class='display_data'>\n"; echo "<tr>"; // echo "<th>User</th>"; echo "<th>" . CURRENCY . "</th>"; echo "<th>Time</th>"; echo "<th>Name</th>"; echo "<th>Bank</th>"; echo "<th>Account#</th>"; echo "<th>BSB</th>"; echo "</tr>\n"; } $reqid = $row['reqid']; // $uid = $row['uid']; $amount = internal_to_numstr($row['amount']); $timest = $row['timest']; $name = $row['name']; $bank = $row['bank']; $acc_num = $row['acc_num']; $sort_code = $row['sort_code']; echo "<tr>"; echo active_table_row("me", "?page=view_request&reqid={$reqid}&show_finish"); // echo "<td>$uid</td>"; echo "<td>{$amount}</td>"; echo "<td>{$timest}</td>"; echo "<td>{$name}</td>"; echo "<td>{$bank}</td>"; echo "<td>{$acc_num}</td>"; echo "<td>{$sort_code}</td>"; echo "</tr>\n"; } if ($first) { echo "<p>No pending withdrawals.</p>\n"; } else { echo "</table>\n"; } echo "</div>\n"; }
function display_double_entry($curr_a, $curr_b, $base_curr, $uid, $is_admin) { if (isset($_GET['show_all']) && get('show_all') == 'true') { $show_all = true; } else { $show_all = false; } echo "<div class='content_box'>\n"; if ($curr_a == 'BTC') { echo "<h3>" . sprintf(_("People selling %s for %s"), $curr_a, $curr_b) . "</h3>\n"; } else { echo "<h3>" . sprintf(_("People buying %s for %s"), $curr_b, $curr_a) . "</h3>\n"; } $exchange_fields = calc_exchange_rate($curr_a, $curr_b, $base_curr); if (!$exchange_fields) { if ($curr_a == 'BTC') { echo "<p>" . sprintf(_("Nobody is selling %s for %s."), $curr_a, $curr_b) . "</p>"; } else { echo "<p>" . sprintf(_("Nobody is buying %s for %s."), $curr_b, $curr_a) . "</p>"; } echo "</div>"; return; } list($total_amount, $total_want_amount, $rate) = $exchange_fields; echo "<p>" . _("Best exchange rate is") . " "; if ($base_curr == BASE_CURRENCY::A) { echo "<b>{$rate} {$curr_b}/{$curr_a}</b>"; } else { echo "<b>{$rate} {$curr_a}/{$curr_b}</b>"; } echo ".</p>"; if (!$show_all) { echo "<p>" . sprintf(_("Showing top %d entries"), DEFAULT_ORDERBOOK_DEPTH) . ":</p>"; } ?> <table class='display_data'> <tr> <th><?php echo _("Cost / BTC"); ?> </th> <th><?php echo _("Giving"); ?> </th> <th><?php echo _("Wanted"); ?> </th> <?php if ($is_admin) { ?> <th><?php echo _("User"); ?> </th> <?php } if (SHOW_CUMULATIVE_DEPTH) { ?> <th><?php echo _("Cumulative Give"); ?> </th> <th><?php echo _("Cumulative Want"); ?> </th> <?php } ?> </tr><?php $show_query = 'LIMIT ' . DEFAULT_ORDERBOOK_DEPTH; if ($show_all) { $show_query = ''; } $query = "\n SELECT\n orderid,\n amount,\n want_amount,\n uid={$uid} as me,\n uid,\n IF(\n type='BTC',\n initial_want_amount/initial_amount,\n initial_amount/initial_want_amount\n ) AS rate\n FROM orderbook\n WHERE type='{$curr_a}' AND want_type='{$curr_b}' AND status='OPEN'\n ORDER BY\n IF(type='BTC', rate, -rate) ASC, timest ASC\n {$show_query}\n "; $result = do_query($query); $cumulative_curr_a = 0; $cumulative_curr_b = 0; if ($curr_a == 'BTC') { $precision_a = BTC_PRECISION; $precision_b = FIAT_PRECISION; } else { $precision_a = FIAT_PRECISION; $precision_b = BTC_PRECISION; } while ($row = mysql_fetch_array($result)) { $amount_i = $row['amount']; $amount = internal_to_numstr($amount_i, $precision_a); $cumulative_curr_a = gmp_add($cumulative_curr_a, $amount_i); $want_amount_i = $row['want_amount']; $want_amount = internal_to_numstr($want_amount_i, $precision_b); $cumulative_curr_b = gmp_add($cumulative_curr_b, $want_amount_i); // MySQL kindly computes this for us. // we trim the excessive 0 $rate = clean_sql_numstr($row['rate']); $me = $row['me']; $uid = $row['uid']; if ($me) { echo " ", active_table_row("me", "?page=view_order&orderid={$row['orderid']}"); } else { echo " ", active_table_row("them", "?page=trade&in={$curr_b}&have={$want_amount_i}&want={$amount_i}&rate={$rate}"); } echo " <td>{$rate}</td>\n"; echo " <td>{$amount} {$curr_a}</td>\n"; echo " <td>{$want_amount} {$curr_b}</td>\n"; if ($is_admin) { echo " <td>{$uid}</td>\n"; } if (SHOW_CUMULATIVE_DEPTH) { echo " <td>" . internal_to_numstr($cumulative_curr_a, $precision_a) . " {$curr_a}</td>\n"; echo " <td>" . internal_to_numstr($cumulative_curr_b, $precision_b) . " {$curr_b}</td>\n"; } echo " </tr>\n"; } echo " <tr>\n"; echo " <td>" . _("Total") . ":</td>\n"; // strstr's 3rd argument only works in PHP 5.3.0 and newer // http://php.net/manual/en/function.strstr.php // use explode instead $total_amount = explode('.', $total_amount, 2); $total_amount = $total_amount[0]; echo " <td>{$total_amount} {$curr_a}</td>\n"; echo " <td></td>\n"; echo " </tr>\n"; echo "</table>\n"; if ($show_all) { echo "<p><a href='?page=orderbook&show_all=false'>>> " . _("hide") . "</a></p>\n"; } else { echo "<p><a href='?page=orderbook&show_all=true'>>> " . _("show all") . "</a></p>\n"; } echo "</div>\n"; }
function show_users() { $omit_zero_balances = true; $omit_very_low_balances = true; echo "<div class='content_box'>\n"; echo "<h3>" . _("Users") . "</h3>\n"; $query = "\n SELECT\n u.uid, oidlogin, is_admin, timest, a.amount as fiat, b.amount as btc\n FROM\n users as u\n JOIN\n purses as a\n ON\n a.uid = u.uid AND a.type = '" . CURRENCY . "'\n JOIN\n purses as b\n ON\n b.uid = u.uid AND b.type = 'BTC'\n ORDER BY\n is_admin DESC, u.uid;\n "; $result = do_query($query); $fiat_total = $c_fiat_total = $t_fiat_total = '0'; $btc_total = $c_btc_total = $t_btc_total = '0'; $first = true; $count_users = $count_funded_users = $count_low_balance_users = $count_shown_users = 0; // omit users who don't have more than just least-significant-digit amounts of anything $tiny_fiat = pow(10, 8 - FIAT_PRECISION) * 10; $tiny_btc = pow(10, 8 - BTC_PRECISION) * 10; while ($row = mysql_fetch_assoc($result)) { $uid = $row['uid']; $oidlogin = $row['oidlogin']; $is_admin = $row['is_admin']; $timest = $row['timest']; $fiat = $row['fiat']; $btc = $row['btc']; $committed = fetch_committed_balances($uid); $c_fiat = $committed[CURRENCY]; $c_btc = $committed['BTC']; $t_fiat = gmp_add($fiat, $c_fiat); $t_btc = gmp_add($btc, $c_btc); if ($uid == '1') { $uid = "fees"; } else { $count_users++; } if ($omit_zero_balances && $fiat == 0 && $c_fiat == 0 && $btc == 0 && $c_btc == 0) { continue; } if ($first) { $first = false; echo "<table class='display_data'>\n"; show_users_header(); } $fiat_total = gmp_add($fiat_total, $fiat); $c_fiat_total = gmp_add($c_fiat_total, $c_fiat); $t_fiat_total = gmp_add($t_fiat_total, $t_fiat); $btc_total = gmp_add($btc_total, $btc); $c_btc_total = gmp_add($c_btc_total, $c_btc); $t_btc_total = gmp_add($t_btc_total, $t_btc); if ($uid != 'fees') { $count_funded_users++; if ($fiat < $tiny_fiat && $c_fiat < $tiny_fiat && $btc < $tiny_btc && $c_btc < $tiny_btc) { $count_low_balance_users++; if ($omit_very_low_balances) { continue; } } $count_shown_users++; } if ($uid == 'fees') { $url = "?page=commission"; } else { $url = "?page=statement&user={$uid}"; } if ($is_admin) { active_table_row('me', $url); } else { active_table_row('active', $url); } echo "<td>{$uid}</td>"; // echo "<td>$oidlogin</td>"; echo "<td class='right'>", internal_to_numstr($fiat, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($c_fiat, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($t_fiat, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($btc, BTC_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($c_btc, BTC_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($t_btc, BTC_PRECISION), "</td>"; // echo "<td>$timest</td>"; echo "</tr>\n"; if (!($count_shown_users % RESHOW_COLUMN_HEADINGS_AFTER_ROWS)) { show_users_header(); } } if (!$first) { echo "<tr><td></td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td></tr>\n"; active_table_row('me', "?page=statement&user=all"); echo "<td></td>"; echo "<td class='right'>", internal_to_numstr($fiat_total, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($c_fiat_total, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($t_fiat_total, FIAT_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($btc_total, BTC_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($c_btc_total, BTC_PRECISION), "</td>"; echo "<td class='right'>", internal_to_numstr($t_btc_total, BTC_PRECISION), "</td>"; echo "</tr>\n"; echo "</table>\n"; echo "<p>" . _("Admins are shown in bold type, and at the top of the table.") . "</p>\n"; } echo "<p>" . sprintf(_("There are %s users with funds, and %s in total."), $count_funded_users, $count_users) . "</p>\n"; if ($omit_very_low_balances && $count_low_balance_users) { echo "<p>" . sprintf(_("%d user(s) have very low balances, and aren't shown above."), $count_low_balance_users) . "</p>\n"; } $balance0 = bitcoin_get_balance('*', 0); $balance1 = bitcoin_get_balance('*', 1); $balance = bitcoin_get_balance('', 0); $unconfirmed = gmp_sub($balance0, $balance1); echo "<p>" . sprintf(_("The Bitcoin wallet has %s BTC"), internal_to_numstr($balance0, BTC_PRECISION)); if (gmp_cmp($unconfirmed, 0) != 0) { printf(_(", %s BTC of which currently has 0 confirmations"), internal_to_numstr($unconfirmed, BTC_PRECISION)); } echo ".<br/></p>\n"; if ($balance0 == $balance) { $balance = $balance0; } else { $pending = gmp_sub($balance0, $balance); echo "<p>" . sprintf(_("The main wallet account has %s BTC; other accounts have %s BTC awaiting confirmations."), internal_to_numstr($balance, BTC_PRECISION), internal_to_numstr($pending, BTC_PRECISION)) . "</p>"; } // take off the amount that's waiting to be withdrawn. it's in the wallet, but not in user accounts $pending_withdrawal = btc_pending_withdrawal(); $balance = gmp_sub($balance, $pending_withdrawal); if ($pending_withdrawal) { echo "<p>" . sprintf(_("There are pending BTC withdrawals worth %s BTC, which will reduce the wallet balance to %s BTC."), internal_to_numstr($pending_withdrawal, BTC_PRECISION), internal_to_numstr($balance, BTC_PRECISION)) . "</p>"; } $diff = gmp_sub($t_btc_total, $balance); $cmp = gmp_cmp($diff, 0); if ($cmp == 0) { echo "<p>" . _("That's the exact right amount.") . "</p>\n"; } else { if ($cmp > 0) { echo "<p>" . sprintf(_("That's %s BTC less than is on deposit."), internal_to_numstr($diff, BTC_PRECISION)) . "</p>\n"; } else { echo "<p>" . sprintf(_("That's %s BTC more than is on deposit"), internal_to_numstr(gmp_mul("-1", $diff), BTC_PRECISION)) . "</p>\n"; } } echo "</div>\n"; }
echo "<th class='right'>" . CURRENCY . "</th>"; if ($is_admin) { echo "<th>" . _("User") . "</th>"; } echo "<th class='right'>" . _("BTC") . "</th>"; echo "<th class='right'>" . _("Price") . "</th>"; echo "<th>" . _("Date") . "</th>"; echo "</tr>"; } $a_is_me = $a_uid == $is_logged_in; $b_is_me = $b_uid == $is_logged_in; if ($a_is_me) { echo active_table_row("active", "?page=view_order&orderid={$a_orderid}"); } else { if ($b_is_me) { echo active_table_row("active", "?page=view_order&orderid={$b_orderid}"); } else { echo "<tr>"; } } echo "<td class='right'>{$txid}</td>"; if ($is_admin) { if ($a_is_me || $b_is_me) { echo "<td>{$a_uid}</td>"; } else { active_table_cell_link_to_user_statement($a_uid); } } if ($a_is_me) { $mine++; echo "<td class='right' style='font-weight:bold;'>{$a_amount_str}</td>";
$orderid = $row['orderid']; $amount = $row['amount']; $initial_amount = $row['initial_amount']; $type = $row['type']; $initial_want_amount = $row['initial_want_amount']; $want_type = $row['want_type']; $timest = $row['timest']; // $timest = str_replace(" ", "<br/>", $timest); $status_code = $row['status']; $status = translate_order_code($status_code); $price = $type == 'BTC' ? fiat_and_btc_to_price($initial_want_amount, $initial_amount) : fiat_and_btc_to_price($initial_amount, $initial_want_amount); $percent_complete = sprintf("%.0f", bcdiv(gmp_strval(gmp_mul(gmp_sub($initial_amount, $amount), 100)), $initial_amount, 1)); $trade_count = count_transactions($orderid); $give_precision = $type == 'BTC' ? BTC_PRECISION : FIAT_PRECISION; $want_precision = $type == 'BTC' ? FIAT_PRECISION : BTC_PRECISION; echo " ", active_table_row("active", "?page=view_order&orderid={$orderid}"), "\n"; echo " <td class='right'>" . internal_to_numstr($initial_amount, $give_precision) . " {$type}</td>\n"; echo " <td class='right'>" . internal_to_numstr($initial_want_amount, $want_precision) . " {$want_type}</td>\n"; echo " <td class='right'>{$price}</td>\n"; echo " <td>{$timest}</td>\n"; echo " <td>{$status} ({$percent_complete}%)</td>\n"; echo " <td>{$trade_count}</td>\n"; echo " </tr>\n"; } while ($row = mysql_fetch_assoc($result)); echo "</table></div>"; } // also used when you view an order display_transactions($uid, 0); $query = "\n SELECT\n reqid,\n req_type,\n amount,\n curr_type,\n " . sql_format_date("timest") . " AS timest,\n status\n FROM requests\n WHERE\n uid='{$uid}' \n AND (req_type='WITHDR' OR req_type='DEPOS') \n AND status!='IGNORE'\n ORDER BY requests.timest DESC;\n"; $result = do_query($query); $row = mysql_fetch_assoc($result);
function display_transactions($uid, $orderid) { global $is_logged_in, $is_admin; $ordselq = ''; if (!$orderid) { $sort = "DESC"; } else { $sort = "ASC"; $ordselq = " AND orderbook.orderid='{$orderid}' "; } $query = "\n SELECT\n orderbook.orderid AS orderid,\n IF(transactions.a_orderid=orderbook.orderid, 'A', 'B') AS who,\n transactions.a_amount AS a_amount,\n transactions.b_amount AS b_amount,\n transactions.a_commission AS a_commission,\n transactions.b_commission AS b_commission,\n orderbook.type AS type,\n orderbook.want_type AS want_type,\n " . sql_format_date("transactions.timest") . " AS timest\n FROM transactions\n JOIN orderbook\n ON\n transactions.a_orderid=orderbook.orderid\n OR transactions.b_orderid=orderbook.orderid\n WHERE orderbook.uid='{$uid}' {$ordselq}\n ORDER BY transactions.txid {$sort};\n "; $result = do_query($query); $first = true; $a_total = 0; $b_total = 0; $commission_total = 0; $count = 0; while ($row = mysql_fetch_assoc($result)) { $count++; $who = $row['who']; $a_amount = $row['a_amount']; $b_amount = $row['b_amount']; $a_commission = $row['a_commission']; $b_commission = $row['b_commission']; if ($who == 'B') { list($a_amount, $b_amount) = array($b_amount, $a_amount); $b_commission = $a_commission; } // skip cancelled orders since we already show those if ((int) $b_amount == -1) { continue; } if ($first) { $first = false; ?> <div class='content_box'> <h3> <?php if ($is_logged_in == $uid) { echo _("Your trades") . " "; } else { echo _("Trades") . " "; } if ($orderid) { echo _('for this order'); } ?> </h3> <table class='display_data'> <tr> <?php if (!$orderid) { ?> <th class='right'><?php echo _("Order"); ?> </th> <?php } ?> <th class='right'><?php echo _("You gave"); ?> </th> <th class='right'><?php echo _("You got"); ?> </th> <th class='right'><?php echo _("Commission"); ?> </th> <th class='right'><?php echo _("Price"); ?> </th> <th class='center'><?php echo _("Time"); ?> </th> </tr><?php } $a_total = gmp_add($a_total, $a_amount); $b_total = gmp_add($b_total, $b_amount); $commission_total = gmp_add($commission_total, $b_commission); if ($b_amount) { $commission_percent = bcdiv(bcmul($b_commission, 100), $b_amount, 3); } else { $commission_percent = 0; } $b_amount = gmp_sub($b_amount, $b_commission); $type = $row['type']; $want_type = $row['want_type']; $price = 0; if ($type == 'BTC') { if ($a_amount) { $price = fiat_and_btc_to_price($b_amount, $a_amount); } } else { if ($b_amount) { $price = fiat_and_btc_to_price($a_amount, $b_amount); } } $this_orderid = $row['orderid']; $timest = $row['timest']; $give_precision = $type == 'BTC' ? BTC_PRECISION : FIAT_PRECISION; $want_precision = $type == 'BTC' ? FIAT_PRECISION : BTC_PRECISION; if (!$orderid) { echo " ", active_table_row("active", "?page=view_order&orderid={$this_orderid}"), "\n"; } else { echo " <tr>\n"; } echo " "; if (!$orderid) { echo "<td class='right'>{$this_orderid}</td>"; } echo "<td class='right'>" . internal_to_numstr($a_amount, $give_precision) . " {$type}</td>"; echo "<td class='right'>" . internal_to_numstr($b_amount, $want_precision) . " {$want_type}</td>"; echo "<td class='right'>" . internal_to_numstr($b_commission, $want_precision) . " {$want_type} (", sprintf("%.2f", $commission_percent), "%)</td>"; echo "<td class='right'>{$price}</td>"; echo "<td class='right'>{$timest}</td>\n"; echo " </tr>\n"; } // if we showed any table at all if (!$first) { // if we need to show a summary line if ($orderid && $count > 1) { $commission_percent = bcdiv(bcmul(gmp_strval($commission_total), 100), gmp_strval($b_total), 3); $b_total = gmp_sub($b_total, $commission_total); $price = 0; if ($type == 'BTC') { if ($a_total) { $price = fiat_and_btc_to_price($b_total, $a_total); } } else { if ($b_total) { $price = fiat_and_btc_to_price($a_total, $b_total); } } $a_total = internal_to_numstr($a_total, $give_precision); $b_total = internal_to_numstr($b_total, $want_precision); $commission_total = internal_to_numstr($commission_total, $want_precision); echo " <tr>\n"; echo " <td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td>\n"; echo " <td></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td class='right'>{$a_total} {$type}</td><td class='right'>{$b_total} {$want_type}</td><td class='right'>{$commission_total} {$want_type} (", sprintf("%.2f", $commission_percent), "%)</td><td class='right'>{$price}</td>\n"; echo " <td></td>\n"; echo " </tr>\n"; } echo "</table>\n"; echo "<p>" . _("The 'you got' column is the amount you received after commission was taken off.") . "</p>"; echo "<p>" . _("The 'price' column shows the effective price of the trade, after commission.") . "</p>"; echo "</div>\n"; } }