diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 4aa7fbd7..e4bb9d1f 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -33,42 +33,13 @@ class Transaction extends Base { /** * Get all transactions from start for account_id - * @param account_id int Account ID * @param start int Starting point, id of transaction + * @param filter array Filter to limit transactions + * @param limit int Only display this many transactions + * @param account_id int Account ID * @return data array Database fields as defined in SELECT **/ - public function getTransactions($account_id, $start=0) { - $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare(" - SELECT - t.id AS id, - t.type AS type, - t.amount AS amount, - t.coin_address AS coin_address, - t.timestamp AS timestamp, - b.height AS height, - b.confirmations AS confirmations - FROM transactions AS t - LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - WHERE t.account_id = ? - ORDER BY id DESC"); - if ($this->checkStmt($stmt)) { - if(!$stmt->bind_param('i', $account_id)) return false; - $stmt->execute(); - $result = $stmt->get_result(); - return $result->fetch_all(MYSQLI_ASSOC); - } - $this->debug->append('Unable to fetch transactions'); - return false; - } - - /** - * Fetch all transactions for all users - * Optionally apply a filter - * @param none - * @return mixed array or false - **/ - public function getAllTransactions($start=0,$filter=NULL,$limit=30) { + public function getTransactions($start=0, $filter=NULL, $limit=30, $account_id=NULL) { $this->debug->append("STA " . __METHOD__, 4); $sql = " SELECT @@ -124,6 +95,13 @@ class Transaction extends Base { $sql .= " WHERE " . implode(' AND ', $aFilter); } } + if (is_int($account_id) && empty($aFilter)) { + $sql .= " WHERE a.id = ?"; + $this->addParam('i', $account_id); + } else if (is_int($account_id)) { + $sql .= " AND a.id = ?"; + $this->addParam('i', $account_id); + } $sql .= " ORDER BY id DESC LIMIT ?,? @@ -132,15 +110,14 @@ class Transaction extends Base { $this->addParam('i', $start); $this->addParam('i', $limit); $stmt = $this->mysqli->prepare($sql); - if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $start, $limit) && $stmt->execute() && $result = $stmt->get_result()) { + if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute() && $result = $stmt->get_result()) { // Fetch matching row count $num_rows = $this->mysqli->prepare("SELECT FOUND_ROWS() AS num_rows"); if ($num_rows->execute() && $row_count = $num_rows->get_result()->fetch_object()->num_rows) $this->num_rows = $row_count; - if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); } - $this->debug->append('Unable to fetch transactions'); + $this->debug->append('Failed to fetch transactions: ' . $this->mysqli->error); return false; } diff --git a/public/include/pages/account/transactions.inc.php b/public/include/pages/account/transactions.inc.php index 7bcfb4f2..bd8f2aa4 100644 --- a/public/include/pages/account/transactions.inc.php +++ b/public/include/pages/account/transactions.inc.php @@ -3,9 +3,17 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); if ($user->isAuthenticated()) { - $aTransactions = $transaction->getTransactions($_SESSION['USERDATA']['id']); + $iLimit = 30; + empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start']; + $aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit, $_SESSION['USERDATA']['id']); + $iCountTransactions = $transaction->num_rows; + $aTransactionTypes = $transaction->getTypes(); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); + $smarty->assign('LIMIT', $iLimit); $smarty->assign('TRANSACTIONS', $aTransactions); + $smarty->assign('TRANSACTIONTYPES', $aTransactionTypes); + $smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan')); + $smarty->assign('COUNTTRANSACTIONS', $iCountTransactions); } $smarty->assign('CONTENT', 'default.tpl'); ?> diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index e068d293..505f25ab 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -12,9 +12,9 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $iLimit = 30; $debug->append('No cached version available, fetching from backend', 3); - $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start'], @$_REQUEST['filter'], $iLimit); - $iCountTransactions = $transaction->num_rows; empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start']; + $aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit); + $iCountTransactions = $transaction->num_rows; $aTransactionTypes = $transaction->getTypes(); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); $smarty->assign('LIMIT', $iLimit); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index a7337bd6..5563aee4 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -1,40 +1,86 @@ -{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Log" BUTTONS=array(Confirmed,Unconfirmed,Orphan)} -
| TX # | +Account | Date | TX Type | +Status | Payment Address | Block # | Amount | |
|---|---|---|---|---|---|---|---|---|
| {$TRANSACTIONS[transaction].id} | +{$TRANSACTIONS[transaction].username} | {$TRANSACTIONS[transaction].timestamp} | {$TRANSACTIONS[transaction].type} | ++ {if $TRANSACTIONS[transaction].type == 'Credit_PPS' OR + $TRANSACTIONS[transaction].type == 'Fee_PPS' OR + $TRANSACTIONS[transaction].type == 'Donation_PPS' OR + $TRANSACTIONS[transaction].type == 'Debit_MP' OR + $TRANSACTIONS[transaction].type == 'Debit_AP' OR + $TRANSACTIONS[transaction].type == 'TXFee' OR + $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations + }Confirmed + {else if $TRANSACTIONS[transaction].confirmations == -1}Orphaned + {else}Unconfirmed{/if} + ({$TRANSACTIONS[transaction].confirmations|default:"n/a"}) + | {$TRANSACTIONS[transaction].coin_address} | -{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} | +{if $TRANSACTIONS[transaction].height == 0}n/a{else}{if $GLOBAL.blockexplorer}{$TRANSACTIONS[transaction].height}{else}{$TRANSACTIONS[transaction].height}{/if}{/if} | {$TRANSACTIONS[transaction].amount|number_format:"8"} |
| No data | ||||||||
@@ -44,97 +90,4 @@
-| TX # | -Date | -TX Type | -Payment Address | -Block # | -Amount | -
|---|---|---|---|---|---|
| {$TRANSACTIONS[transaction].id} | -{$TRANSACTIONS[transaction].timestamp} | -{$TRANSACTIONS[transaction].type} | -{$TRANSACTIONS[transaction].coin_address} | -{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} | -{$TRANSACTIONS[transaction].amount|number_format:"8"} | -
| No data | |||||
| Unconfirmed Totals: | -{($credits|default - $debits|default)|number_format:"8"} | -||||
Listed are your estimated rewards and donations/fees for all blocks awaiting {$GLOBAL.confirmations} confirmations.
-| TX # | -Date | -TX Type | -Payment Address | -Block # | -Amount | -
|---|---|---|---|---|---|
| {$TRANSACTIONS[transaction].id} | -{$TRANSACTIONS[transaction].timestamp} | -{$TRANSACTIONS[transaction].type} | -{$TRANSACTIONS[transaction].coin_address} | -{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if} | -{$TRANSACTIONS[transaction].amount|number_format:"8"} | -
| No data | |||||
| Orphaned Totals: | -{($orphan_credits|default - $orphan_debits|default)|number_format:"8"} | -||||
Listed are your orphaned transactions for blocks not part of the main blockchain.
-