Adding working user admin panel to query user DB
* Users are all fetched from the DB * Each user is assigned special stats * Hashrate * Shares * Balance * Est. Payout * Est. Donation * Display in sortable and paginated table This is not well optimized. Each user stats are grabbed individually via the stats and transaction classes. It would probably make sense to expand the statistics class to list a full user list with all statistics available instead to cover this in a single SQL query.
This commit is contained in:
parent
ed0853202b
commit
065f5e6d16
@ -58,6 +58,18 @@ class User {
|
||||
return $this->updateSingle($id, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all users for administrative tasks
|
||||
* @param none
|
||||
* @return data array All users with db columns as array fields
|
||||
**/
|
||||
public function getUsers($filter='%') {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM " . $this->getTableName() . " WHERE username LIKE ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user login
|
||||
* @param username string Username
|
||||
|
||||
@ -10,10 +10,30 @@ if (!$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
||||
die();
|
||||
}
|
||||
|
||||
$aRoundShares = $statistics->getRoundShares();
|
||||
|
||||
if ($_POST['query']) {
|
||||
// Fetch all users from DB cross referencing all stats
|
||||
// Fetch requested users
|
||||
$aUsers = $user->getUsers($_POST['query']);
|
||||
|
||||
// Add additional stats to each user
|
||||
// This is not optimized yet, best is a proper SQL
|
||||
// Query against the stats table? Currently cached though.
|
||||
foreach ($aUsers as $iKey => $aUser) {
|
||||
$aUser['balance'] = $transaction->getBalance($aUser['id']);
|
||||
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
||||
$aUser['shares'] = $statistics->getUserShares($aUser['id']);
|
||||
$aUser['payout']['est_block'] = round(( (int)$aUser['shares']['valid'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
|
||||
$aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
|
||||
$aUser['payout']['est_donation'] = round((( $aUser['donate_percent'] / 100) * ($aUser['payout']['est_block'] - $aUser['payout']['est_fee'])), 3);
|
||||
$aUser['payout']['est_payout'] = round($aUser['payout']['est_block'] - $aUser['payout']['est_donation'] - $aUser['payout']['est_fee'], 3);
|
||||
$aUsers[$iKey] = $aUser;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign our variables
|
||||
$smarty->assign("USERS", $aUsers);
|
||||
|
||||
// Tempalte specifics
|
||||
$smarty->assign("CONTENT", "default.tpl");
|
||||
?>
|
||||
|
||||
@ -465,6 +465,12 @@ a:hover {
|
||||
.block table tr th.right{
|
||||
text-align: right;
|
||||
}
|
||||
.block table tr td.center{
|
||||
text-align: center;
|
||||
}
|
||||
.block table tr th.center{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.block table tr td.delete a { color: #666; }
|
||||
|
||||
BIN
public/site_assets/mmcFE/images/first.png
Normal file
BIN
public/site_assets/mmcFE/images/first.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 720 B |
BIN
public/site_assets/mmcFE/images/last.png
Normal file
BIN
public/site_assets/mmcFE/images/last.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 737 B |
BIN
public/site_assets/mmcFE/images/next.png
Normal file
BIN
public/site_assets/mmcFE/images/next.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 736 B |
BIN
public/site_assets/mmcFE/images/prev.png
Normal file
BIN
public/site_assets/mmcFE/images/prev.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 745 B |
@ -66,6 +66,10 @@ $(function () {
|
||||
widgets: ['zebra']
|
||||
});
|
||||
|
||||
$("table.pagesort")
|
||||
.tablesorter({ widgets: ['zebra'] })
|
||||
.tablesorterPager({ positionFixed: false, container: $("#pager") });
|
||||
|
||||
$('.block table tr th.header').css('cursor', 'pointer');
|
||||
|
||||
// Check / uncheck all checkboxes
|
||||
|
||||
@ -2,7 +2,82 @@
|
||||
<form action="{$smarty.server.PHP_SELF}" method="POST">
|
||||
<input type="hidden" name="page" value="{$smarty.request.page}">
|
||||
<input type="hidden" name="action" value="{$smarty.request.action}">
|
||||
<input type="text" name="query" value="{$smarty.request.query|default:"%"}">
|
||||
<input type="submit" value="Query">
|
||||
<input type="text" class="pin" name="query" value="{$smarty.request.query|default:"%"}">
|
||||
<input type="submit" class="submit small" value="Query">
|
||||
</form>
|
||||
{include file="global/block_footer.tpl"}
|
||||
|
||||
{include file="global/block_header.tpl" BLOCK_HEADER="User Information"}
|
||||
<center>
|
||||
<div id="pager">
|
||||
<form>
|
||||
<img src="{$PATH}/images/first.png" class="first"/>
|
||||
<img src="{$PATH}/images/prev.png" class="prev"/>
|
||||
<input type="text" class="pagedisplay"/>
|
||||
<img src="{$PATH}/images/next.png" class="next"/>
|
||||
<img src="{$PATH}/images/last.png" class="last"/>
|
||||
<select class="pagesize">
|
||||
<option selected="selected" value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="40">40</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</center>
|
||||
<table width="100%" class="pagesort">
|
||||
<colgroup>
|
||||
<col style="width: 120px">
|
||||
<col style="width: 120px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
<col style="width: 60px">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>E-Mail</th>
|
||||
<th class="right">Hashrate</th>
|
||||
<th class="right">Valid</th>
|
||||
<th class="right">Invalid</th>
|
||||
<th class="right">Balance</th>
|
||||
<th class="right">Est. Donation</th>
|
||||
<th class="right">Est. Payout</th>
|
||||
<th class="center">Admin</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{section name=user loop=$USERS|default}
|
||||
<tr>
|
||||
<td>{$USERS[user].username}</td>
|
||||
<td>{$USERS[user].email}</td>
|
||||
<td class="right">{$USERS[user].hashrate}</td>
|
||||
<td class="right">{$USERS[user].shares.valid}</td>
|
||||
<td class="right">{$USERS[user].shares.invalid}</td>
|
||||
<td class="right">{$USERS[user].balance}</td>
|
||||
<td class="right">{$USERS[user].payout.est_donation}</td>
|
||||
<td class="right">{$USERS[user].payout.est_payout}</td>
|
||||
<td class="center">
|
||||
<img src="{$PATH}/images/{if $USERS[user].admin}success{else}error{/if}.gif" />
|
||||
</td>
|
||||
</tr>
|
||||
{/section}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>E-Mail</th>
|
||||
<th class="right">Hashrate</th>
|
||||
<th colspan="2" class="center">Shares</th>
|
||||
<th class="right">Balance</th>
|
||||
<th class="right">Est. Donation</th>
|
||||
<th class="right">Est. Payout</th>
|
||||
<th class="center">Admin</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
{include file="global/block_footer.tpl"}
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
{/if}
|
||||
{if $smarty.session.AUTHENTICATED|default:"0" == 1 && $GLOBAL.userdata.admin == 1}<li><a href="#">Admin Panel</a></li>{/if}
|
||||
{if $smarty.session.AUTHENTICATED|default:"0" == 1 && $GLOBAL.userdata.admin == 1}
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=admin">Admin Panel</a>
|
||||
<ul>
|
||||
<li><a href="{$smarty.server.PHP_SELF}?page=admin&action=user">User Info</a></li>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user