[IMPROVED] User info pagination and filters
This will add pagination and user filters to the Admin Panel User Information page. * Added various filter methods (combined with AND in SQL) * Added pagination and limits to fetch only matching users This will greatly increase efficiency on larger pools Fixes #1043 once merged.
This commit is contained in:
parent
01a740d5ed
commit
065d10d2e0
@ -406,9 +406,9 @@ class Statistics extends Base {
|
|||||||
* Admin panel specific query
|
* Admin panel specific query
|
||||||
* @return data array User settings and shares
|
* @return data array User settings and shares
|
||||||
**/
|
**/
|
||||||
public function getAllUserStats($filter='%') {
|
public function getAllUserStats($filter='%',$limit=1,$start=0) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
$stmt = $this->mysqli->prepare("
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
a.id AS id,
|
a.id AS id,
|
||||||
a.is_admin as is_admin,
|
a.is_admin as is_admin,
|
||||||
@ -417,18 +417,56 @@ class Statistics extends Base {
|
|||||||
a.username AS username,
|
a.username AS username,
|
||||||
a.donate_percent AS donate_percent,
|
a.donate_percent AS donate_percent,
|
||||||
a.email AS email
|
a.email AS email
|
||||||
FROM " . $this->user->getTableName() . " AS a
|
FROM " . $this->user->getTableName() . " AS a";
|
||||||
WHERE
|
if (is_array($filter)) {
|
||||||
a.username LIKE ?
|
$aFilter = array();
|
||||||
GROUP BY username
|
foreach ($filter as $key => $value) {
|
||||||
ORDER BY username");
|
if (isset($value) && $value != "" ) {
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
switch ($key) {
|
||||||
|
case 'account':
|
||||||
|
$aFilter[] = "a.username LIKE ?";
|
||||||
|
$this->addParam('s', $value);
|
||||||
|
break;
|
||||||
|
case 'email':
|
||||||
|
$aFilter[] = "a.email LIKE ?";
|
||||||
|
$this->addParam('s', $value);
|
||||||
|
break;
|
||||||
|
case 'is_admin':
|
||||||
|
$aFilter[] = "a.is_admin = ?";
|
||||||
|
$this->addParam('i', $value);
|
||||||
|
break;
|
||||||
|
case 'is_locked':
|
||||||
|
$aFilter[] = "a.is_locked = ?";
|
||||||
|
$this->addParam('i', $value);
|
||||||
|
break;
|
||||||
|
case 'no_fees':
|
||||||
|
$aFilter[] = "a.no_fees = ?";
|
||||||
|
$this->addParam('i', $value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($aFilter)) {
|
||||||
|
$sql .= " WHERE ";
|
||||||
|
$sql .= implode(' AND ', $aFilter);
|
||||||
|
}
|
||||||
|
$sql .= "
|
||||||
|
ORDER BY username
|
||||||
|
LIMIT ?,?";
|
||||||
|
$this->addParam('i', $start);
|
||||||
|
$this->addParam('i', $limit);
|
||||||
|
$stmt = $this->mysqli->prepare($sql);
|
||||||
|
if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||||
// Add our cached shares to the users
|
// Add our cached shares to the users
|
||||||
|
$aUsers = array();
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$row['shares'] = $this->getUserShares($row['id']);
|
$row['shares'] = $this->getUserShares($row['id']);
|
||||||
$aUsers[] = $row;
|
$aUsers[] = $row;
|
||||||
}
|
}
|
||||||
return $aUsers;
|
if (count($aUsers) > 0) {
|
||||||
|
return $aUsers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,16 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
|||||||
die("404 Page not found");
|
die("404 Page not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
$aRoundShares = $statistics->getRoundShares();
|
// Some defaults
|
||||||
|
$iLimit = 30;
|
||||||
|
$smarty->assign('LIMIT', $iLimit);
|
||||||
|
empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start'];
|
||||||
|
$smarty->assign('ADMIN', array('' => '', '0' => 'No', '1' => 'Yes'));
|
||||||
|
$smarty->assign('LOCKED', array('' => '', '0' => 'No', '1' => 'Yes'));
|
||||||
|
$smarty->assign('NOFEE', array('' => '', '0' => 'No', '1' => 'Yes'));
|
||||||
|
|
||||||
switch (@$_POST['do']) {
|
// Catch our JS queries to update some settings
|
||||||
|
switch (@$_REQUEST['do']) {
|
||||||
case 'lock':
|
case 'lock':
|
||||||
$supress_master = 1;
|
$supress_master = 1;
|
||||||
// Reset user account
|
// Reset user account
|
||||||
@ -31,27 +38,42 @@ case 'admin':
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@$_POST['query']) {
|
// Gernerate the GET URL for filters
|
||||||
// Fetch requested users
|
if (isset($_REQUEST['filter'])) {
|
||||||
$aUsers = $statistics->getAllUserStats($_POST['query']);
|
// Fetch round shares for estimates
|
||||||
|
$aRoundShares = $statistics->getRoundShares();
|
||||||
|
|
||||||
// Add additional stats to each user
|
// Create filter URL for pagination arrows
|
||||||
foreach ($aUsers as $iKey => $aUser) {
|
$strFilters = '';
|
||||||
$aBalance = $transaction->getBalance($aUser['id']);
|
foreach (@$_REQUEST['filter'] as $filter => $value) {
|
||||||
$aUser['balance'] = $aBalance['confirmed'];
|
$filter = "filter[$filter]";
|
||||||
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
$strFilters .= "&$filter=$value";
|
||||||
|
}
|
||||||
if ($config['payout_system'] == 'pps') {
|
$smarty->assign('FILTERS', $strFilters);
|
||||||
$aUser['sharerate'] = $statistics->getUserSharerate($aUser['id']);
|
|
||||||
$aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['id']);
|
// Fetch requested users
|
||||||
$aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue());
|
if ($aUsers = $statistics->getAllUserStats($_REQUEST['filter'], $iLimit, $start)) {
|
||||||
} else {
|
// Add additional stats to each user
|
||||||
$aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']);
|
foreach ($aUsers as $iKey => $aUser) {
|
||||||
}
|
$aBalance = $transaction->getBalance($aUser['id']);
|
||||||
$aUsers[$iKey] = $aUser;
|
$aUser['balance'] = $aBalance['confirmed'];
|
||||||
|
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
|
||||||
|
|
||||||
|
if ($config['payout_system'] == 'pps') {
|
||||||
|
$aUser['sharerate'] = $statistics->getUserSharerate($aUser['id']);
|
||||||
|
$aUser['difficulty'] = $statistics->getUserShareDifficulty($aUser['id']);
|
||||||
|
$aUser['estimates'] = $statistics->getUserEstimates($aUser['sharerate'], $aUser['difficulty'], $user->getUserDonatePercent($aUser['id']), $user->getUserNoFee($aUser['id']), $statistics->getPPSValue());
|
||||||
|
} else {
|
||||||
|
$aUser['estimates'] = $statistics->getUserEstimates($aRoundShares, $aUser['shares'], $aUser['donate_percent'], $aUser['no_fees']);
|
||||||
|
}
|
||||||
|
$aUsers[$iKey] = $aUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign our variables
|
||||||
|
$smarty->assign("USERS", $aUsers);
|
||||||
|
} else {
|
||||||
|
$_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any users', 'TYPE' => 'errormsg');
|
||||||
}
|
}
|
||||||
// Assign our variables
|
|
||||||
$smarty->assign("USERS", $aUsers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,59 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<article class="module width_full">
|
||||||
|
<header><h3>User Search</h3></header>
|
||||||
|
<div class="module_content">
|
||||||
|
<form action="{$smarty.server.PHP_SELF}">
|
||||||
|
<input type="hidden" name="page" value="{$smarty.request.page|escape}" />
|
||||||
|
<input type="hidden" name="action" value="{$smarty.request.action|escape}" />
|
||||||
|
<input type="hidden" name="do" value="query" />
|
||||||
|
<table cellspacing="0" class="tablesorter">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
{if $smarty.request.start|default:"0" > 0}
|
||||||
|
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" - $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-left-open"></i></a>
|
||||||
|
{else}
|
||||||
|
<i class="icon-left-open"></i>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td align="right">
|
||||||
|
<a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&start={$smarty.request.start|escape|default:"0" + $LIMIT}{if $FILTERS|default:""}{$FILTERS}{/if}"><i class="icon-right-open"></i></a>
|
||||||
|
</td>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<fieldset>
|
||||||
|
<label>Account</label>
|
||||||
|
<input size="20" type="text" name="filter[account]" value="{$smarty.request.filter.account|default:""}" />
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label>E-Mail</label>
|
||||||
|
<input size="20" type="text" name="filter[email]" value="{$smarty.request.filter.email|default:""}" />
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label>Is Admin</label>
|
||||||
|
{html_options name="filter[is_admin]" options=$ADMIN selected=$smarty.request.filter.is_admin|default:""}
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label>Is Locked</label>
|
||||||
|
{html_options name="filter[is_locked]" options=$LOCKED selected=$smarty.request.filter.is_locked|default:""}
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label>No Fees</label>
|
||||||
|
{html_options name="filter[no_fees]" options=$NOFEE selected=$smarty.request.filter.no_fees|default:""}
|
||||||
|
</fieldset>
|
||||||
|
<ul>
|
||||||
|
<li>Note: Text search fields support '%' as wildcard.</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<div class="submit_link">
|
||||||
|
<input type="submit" value="Search" class="alt_btn">
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
|
||||||
<article class="module width_full">
|
<article class="module width_full">
|
||||||
<header>
|
<header>
|
||||||
@ -108,13 +161,5 @@
|
|||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
<footer>
|
<footer>
|
||||||
<div class="submit_link">
|
|
||||||
<form action="{$smarty.server.PHP_SELF}" method="POST" id='query'>
|
|
||||||
<input type="hidden" name="page" value="{$smarty.request.page|escape}">
|
|
||||||
<input type="hidden" name="action" value="{$smarty.request.action|escape}">
|
|
||||||
<input type="text" class="pin" name="query" value="{$smarty.request.query|default:"%"|escape}">
|
|
||||||
<input type="submit" value="Query" class="alt_btn">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user