Merge pull request #505 from TheSerapher/issue-404

Adding new admin transaction view
This commit is contained in:
Sebastian Grewe 2013-07-23 03:39:04 -07:00
commit a4b7ea4974
3 changed files with 157 additions and 109 deletions

View File

@ -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);

View File

@ -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');
?>

View File

@ -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"}
<table cellpadding="1" cellspacing="1" width="100%">
<tbody>
<tr>
<td class="left">
{if $COUNTTRANSACTIONS / $LIMIT > 1}
{if $smarty.request.start|default:"0" > 0}
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page}&action={$smarty.request.action}&start={$smarty.request.start|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><img src="{$PATH}/images/prev.png" /></a>
{else}
<img src="{$PATH}/images/prev.png" />
{/if}
{/if}
</td>
<td class="right">
{if $COUNTTRANSACTIONS / $LIMIT > 1}
{if $COUNTTRANSACTIONS - $smarty.request.start|default:"0" - $LIMIT > 0}
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page}&action={$smarty.request.action}&start={$smarty.request.start|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><img src="{$PATH}/images/next.png" /></a>
{else}
<img src="{$PATH}/images/next.png" />
{/if}
{/if}
</td>
</tr>
<form action="{$smarty.server.PHP_SELF}">
<input type="hidden" name="page" value="{$smarty.request.page}" />
<input type="hidden" name="action" value="{$smarty.request.action}" />
<tr>
<td class="left">TX Type</td>
<td class="right">{html_options name="filter[type]" options=$TRANSACTIONTYPES selected=$smarty.request.filter.type|default:""}</td>
</tr>
<tr>
<td class="left">TX Status</td>
<td class="right">{html_options name="filter[status]" options=$TXSTATUS selected=$smarty.request.filter.status|default:""}</td>
</tr>
<tr>
<td class="left">Account</td>
<td class="right"><input size="20" type="text" name="filter[account]" value="{$smarty.request.filter.account|default:""}" /></td>
</tr>
<tr>
<td class="left">Address</td>
<td class="right"><input size="20" type="text" name="filter[address]" value="{$smarty.request.filter.address|default:""}" /></td>
</tr>
<tr>
<td class="center" colspan="2"><input type="submit" class="submit small" value="Filter"></td>
</tr>
</form>
</tbody>
</table>
{include file="global/block_footer.tpl"}
{include file="global/block_header.tpl" ALIGN="right" BLOCK_STYLE="width: 75%" BLOCK_HEADER="Transaction History"}
<div class="block_content" style="clear:;">
<center>
<a href="{$smarty.server.PHP_SELF}?page=admin&action=transactions&start={$smarty.request.start|default:"0" - 30}"><img src="{$PATH}/images/prev.png" /></a>
<a href="{$smarty.server.PHP_SELF}?page=admin&action=transactions&start={$smarty.request.start|default:"0" + 30}"><img src="{$PATH}/images/next.png" /></a>
</center>
<div class="block_content tab_content" id="Confirmed" style="clear:;">
<center>
<table cellpadding="1" cellspacing="1" width="98%" class="pagesort">
<table cellpadding="1" cellspacing="1" width="100%">
<thead style="font-size:13px;">
<tr>
<th class="header" style="cursor: pointer;">TX #</th>
<th class="header" style="cursor: pointer;">Account</th>
<th class="header" style="cursor: pointer;">Date</th>
<th class="header" style="cursor: pointer;">TX Type</th>
<th class="header" style="cursor: pointer;">Status</th>
<th class="header" style="cursor: pointer;">Payment Address</th>
<th class="header" style="cursor: pointer;">Block #</th>
<th class="header" style="cursor: pointer;">Amount</th>
</tr>
</thead>
<tbody style="font-size:12px;">
{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}
<tr class="{cycle values="odd,even"}">
<td>{$TRANSACTIONS[transaction].id}</td>
<td>{$TRANSACTIONS[transaction].username}</td>
<td>{$TRANSACTIONS[transaction].timestamp}</td>
<td>{$TRANSACTIONS[transaction].type}</td>
<td>
{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
}<font color="green">Confirmed</font>
{else if $TRANSACTIONS[transaction].confirmations == -1}<font color="red">Orphaned</font>
{else}<font color="orange">Unconfirmed</font>{/if}
<font size="1px">({$TRANSACTIONS[transaction].confirmations|default:"n/a"})</font>
</td>
<td>{$TRANSACTIONS[transaction].coin_address}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{if $GLOBAL.blockexplorer}<a href="{$GLOBAL.blockexplorer}{$TRANSACTIONS[transaction].blockhash}">{$TRANSACTIONS[transaction].height}</a>{else}{$TRANSACTIONS[transaction].height}{/if}{/if}</td>
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Credit_PPS' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
</tr>
{/if}
{/section}
{if $confirmed != 1}
<tr>
<td class="center" colspan="7">No confirmed transactions</td>
</tr>
{/if}
</tbody>
</table>
<p>
@ -51,84 +98,4 @@
</p>
</center>
</div>
<div class="block_content tab_content" id="Unconfirmed" style="">
<center>
<table cellpadding="1" cellspacing="1" width="98%" class="pagesort2">
<thead style="font-size:13px;">
<tr>
<th class="header" style="cursor: pointer;">TX #</th>
<th class="header" style="cursor: pointer;">Account</th>
<th class="header" style="cursor: pointer;">Date</th>
<th class="header" style="cursor: pointer;">TX Type</th>
<th class="header" style="cursor: pointer;">Payment Address</th>
<th class="header" style="cursor: pointer;">Block #</th>
<th class="header" style="cursor: pointer;">Amount</th>
</tr>
</thead>
<tbody style="font-size:12px;">
{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}
<tr class="{cycle values="odd,even"}">
<td>{$TRANSACTIONS[transaction].id}</td>
<td>{$TRANSACTIONS[transaction].username}</td>
<td>{$TRANSACTIONS[transaction].timestamp}</td>
<td>{$TRANSACTIONS[transaction].type}</td>
<td>{$TRANSACTIONS[transaction].coin_address}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
</tr>
{/if}
{/section}
{if $unconfirmed != 1}
<tr>
<td colspan="7">No unconfirmed transactions</td>
</tr>
{/if}
</tbody>
</table>
<p><font color="" sizeze="1">Listed are your estimated rewards and donations/fees for all blocks awaiting {$GLOBAL.confirmations} confirmations.</font></p>
</center>
</div>
<div class="block_content tab_content" id="Orphan" style="">
<center>
<table cellpadding="1" cellspacing="1" width="98%" class="pagesort3">
<thead style="font-size:13px;">
<tr>
<th class="header" style="cursor: pointer;">TX #</th>
<th class="header" style="cursor: pointer;">Account</th>
<th class="header" style="cursor: pointer;">Date</th>
<th class="header" style="cursor: pointer;">TX Type</th>
<th class="header" style="cursor: pointer;">Payment Address</th>
<th class="header" style="cursor: pointer;">Block #</th>
<th class="header" style="cursor: pointer;">Amount</th>
</tr>
</thead>
<tbody style="font-size:12px;">
{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}
<tr class="{cycle values="odd,even"}">
<td>{$TRANSACTIONS[transaction].id}</td>
<td>{$TRANSACTIONS[transaction].username}</td>
<td>{$TRANSACTIONS[transaction].timestamp}</td>
<td>{$TRANSACTIONS[transaction].type}</td>
<td>{$TRANSACTIONS[transaction].coin_address}</td>
<td>{if $TRANSACTIONS[transaction].height == 0}n/a{else}{$TRANSACTIONS[transaction].height}{/if}</td>
<td><font color="{if $TRANSACTIONS[transaction].type == 'Credit' or $TRANSACTIONS[transaction].type == 'Bonus'}green{else}red{/if}">{$TRANSACTIONS[transaction].amount|number_format:"8"}</td>
</tr>
{/if}
{/section}
{if $orphaned != 1}
<tr>
<td class="center" colspan="7">No orphan transactions</td>
</tr>
{/if}
</tbody>
</table>
<p><font color="" sizeze="1">Listed are your orphaned transactions for blocks not part of the main blockchain.</font></p>
</center>
</div>
{include file="global/block_footer.tpl"}