diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 2cbe4312..ab9314b9 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -81,12 +81,13 @@ class Transaction { /** * Fetch all transactions for all users + * Optionally apply a filter * @param none * @return mixed array or false **/ - public function getAllTransactions($start=0) { + public function getAllTransactions($start=0,$filter=NULL,$limit=30) { $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare(" + $sql = " SELECT t.id AS id, a.username as username, @@ -95,18 +96,81 @@ class Transaction { t.coin_address AS coin_address, t.timestamp AS timestamp, b.height AS height, + b.blockhash AS blockhash, b.confirmations AS confirmations - FROM transactions AS t + FROM $this->table AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id + LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id"; + if (is_array($filter)) { + $aFilter = array(); + foreach ($filter as $key => $value) { + if (!empty($value)) { + switch ($key) { + case 'type': + $aFilter[] = "t.type = '$value'"; + break; + case 'status': + switch ($value) { + case 'Confirmed': + if (empty($filter['type']) || ($filter['type'] != 'Debit_AP' && $filter['type'] != 'Debit_MP' && $filter['type'] != 'TXFee' && $filter['type'] != 'Credit_PPS' && $filter['type'] != 'Fee_PPS' && $filter['type'] != 'Donation_PPS')) { + $aFilter[] = "b.confirmations >= " . $this->config['confirmations']; + } + break; + case 'Unconfirmed': + $aFilter[] = "b.confirmations < " . $this->config['confirmations'] . " AND b.confirmations >= 0"; + break; + case 'Orphan': + $aFilter[] = "b.confirmations = -1"; + break; + } + break; + case 'account': + $aFilter[] = "LOWER(a.username) = LOWER('$value')"; + break; + case 'address': + $aFilter[] = "t.coin_address = '$value'"; + break; + } + } + } + if (!empty($aFilter)) { + $sql .= " WHERE " . implode(' AND ', $aFilter); + } + } + $sql .= " ORDER BY id DESC - LIMIT ?,30"); - if ($this->checkStmt($stmt) && $stmt->bind_param('i', $start) && $stmt->execute() && $result = $stmt->get_result()) + LIMIT ?,? + "; + $stmt = $this->mysqli->prepare($sql); + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $start, $limit) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); $this->debug->append('Unable to fetch transactions'); return false; } + /** + * Count the amount of transactions in the table + **/ + public function getCountAllTransactions($filter=NULL) { + $stmt = $this->mysqli->prepare("SELECT COUNT(id) AS total FROM $this->table"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->total; + $this->debug->append('Failed to fetch transaction count: ' . $this->mysqli->error); + return false; + } + public function getTypes() { + $stmt = $this->mysqli->prepare("SELECT DISTINCT type FROM $this->table"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) { + $aData = array('' => ''); + while ($row = $result->fetch_assoc()) { + $aData[$row['type']] = $row['type']; + } + return $aData; + } + $this->debug->append('Failed to fetch transaction types: ' . $this->mysqli->error); + return false; + } + private function checkStmt($bState) { if ($bState ===! true) { $this->debug->append("Failed to prepare statement: " . $this->mysqli->error); diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index fe991ba5..f106de26 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -10,12 +10,29 @@ 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']); + $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start'], @$_REQUEST['filter'], $iLimit); + $iCountTransactions = $transaction->getCountAllTransactions(); + $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); } else { $debug->append('Using cached page', 3); } -$smarty->assign('TRANSACTIONS', $aTransactions); + +// Gernerate the GET URL for filters +if (isset($_REQUEST['filter'])) { + $strFilters = ''; + foreach (@$_REQUEST['filter'] as $filter => $value) { + $filter = "filter[$filter]"; + $strFilters .= "&$filter=$value"; + } + $smarty->assign('FILTERS', $strFilters); +} $smarty->assign('CONTENT', 'default.tpl'); ?> diff --git a/public/templates/mmcFE/admin/transactions/default.tpl b/public/templates/mmcFE/admin/transactions/default.tpl index c493de8b..f23b265a 100644 --- a/public/templates/mmcFE/admin/transactions/default.tpl +++ b/public/templates/mmcFE/admin/transactions/default.tpl @@ -1,47 +1,94 @@ -{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Log" BUTTONS=array(Confirmed,Unconfirmed,Orphan)} +{include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 23%" BLOCK_HEADER="Transaction Filter"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+{if $COUNTTRANSACTIONS / $LIMIT > 1} + {if $smarty.request.start|default:"0" > 0} + + {else} + + {/if} +{/if} + +{if $COUNTTRANSACTIONS / $LIMIT > 1} + {if $COUNTTRANSACTIONS - $smarty.request.start|default:"0" - $LIMIT > 0} + + {else} + + {/if} +{/if} +
TX Type{html_options name="filter[type]" options=$TRANSACTIONTYPES selected=$smarty.request.filter.type|default:""}
TX Status{html_options name="filter[status]" options=$TXSTATUS selected=$smarty.request.filter.status|default:""}
Account
Address
+{include file="global/block_footer.tpl"} + +{include file="global/block_header.tpl" ALIGN="right" BLOCK_STYLE="width: 75%" BLOCK_HEADER="Transaction History"} +
- - -
-
-
- +
+ - {assign var=confirmed value=0} {section transaction $TRANSACTIONS} - {if ( - ( ( $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee' ) and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations ) - or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Fee_PPS' or $TRANSACTIONS[transaction].type == 'Donation_PPS' - or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' or $TRANSACTIONS[transaction].type == 'TXFee' - )} - {assign var=confirmed value=1} + - + - {/if} {/section} - {if $confirmed != 1} - - - - {/if}
TX # Account Date TX TypeStatus 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 confirmed transactions

@@ -51,84 +98,4 @@

-
-
- - - - - - - - - - - - - - {assign var=unconfirmed value=0} -{section transaction $TRANSACTIONS} - {if ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Fee') and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations and $TRANSACTIONS[transaction].confirmations >= 0} - {assign var=unconfirmed value=1} - - - - - - - - - - {/if} -{/section} - {if $unconfirmed != 1} - - - - {/if} - -
TX #AccountDateTX TypePayment AddressBlock #Amount
{$TRANSACTIONS[transaction].id}{$TRANSACTIONS[transaction].username}{$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 unconfirmed transactions
-

Listed are your estimated rewards and donations/fees for all blocks awaiting {$GLOBAL.confirmations} confirmations.

-
-
-
-
- - - - - - - - - - - - - - {assign var=orphaned value=0} -{section transaction $TRANSACTIONS} - {if ($TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Fee' or $TRANSACTIONS[transaction].type == 'Donation' or $TRANSACTIONS[transaction].type == 'Bonus') and $TRANSACTIONS[transaction].confirmations == -1} - {assign var=orphaned value=1} - - - - - - - - - - {/if} -{/section} - {if $orphaned != 1} - - - - {/if} - -
TX #AccountDateTX TypePayment AddressBlock #Amount
{$TRANSACTIONS[transaction].id}{$TRANSACTIONS[transaction].username}{$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 orphan transactions
-

Listed are your orphaned transactions for blocks not part of the main blockchain.

-
-
{include file="global/block_footer.tpl"}