From 065d10d2e039d772124e26d2c98e333b84042c83 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 23 Dec 2013 22:37:57 +0100 Subject: [PATCH 1/3] [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. --- public/include/classes/statistics.class.php | 56 ++++++++++++++--- public/include/pages/admin/user.inc.php | 64 +++++++++++++------- public/templates/mpos/admin/user/default.tpl | 61 ++++++++++++++++--- 3 files changed, 143 insertions(+), 38 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index d3d754cd..ffe69db1 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -406,9 +406,9 @@ class Statistics extends Base { * Admin panel specific query * @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); - $stmt = $this->mysqli->prepare(" + $sql = " SELECT a.id AS id, a.is_admin as is_admin, @@ -417,18 +417,56 @@ class Statistics extends Base { a.username AS username, a.donate_percent AS donate_percent, a.email AS email - FROM " . $this->user->getTableName() . " AS a - WHERE - a.username LIKE ? - GROUP BY username - ORDER BY username"); - if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) { + FROM " . $this->user->getTableName() . " AS a"; + if (is_array($filter)) { + $aFilter = array(); + foreach ($filter as $key => $value) { + if (isset($value) && $value != "" ) { + 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 + $aUsers = array(); while ($row = $result->fetch_assoc()) { $row['shares'] = $this->getUserShares($row['id']); $aUsers[] = $row; } - return $aUsers; + if (count($aUsers) > 0) { + return $aUsers; + } } return $this->sqlError(); } diff --git a/public/include/pages/admin/user.inc.php b/public/include/pages/admin/user.inc.php index e6fcacaa..f3d28dbb 100644 --- a/public/include/pages/admin/user.inc.php +++ b/public/include/pages/admin/user.inc.php @@ -9,9 +9,16 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { 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': $supress_master = 1; // Reset user account @@ -31,27 +38,42 @@ case 'admin': break; } -if (@$_POST['query']) { - // Fetch requested users - $aUsers = $statistics->getAllUserStats($_POST['query']); +// Gernerate the GET URL for filters +if (isset($_REQUEST['filter'])) { + // Fetch round shares for estimates + $aRoundShares = $statistics->getRoundShares(); - // Add additional stats to each user - foreach ($aUsers as $iKey => $aUser) { - $aBalance = $transaction->getBalance($aUser['id']); - $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; + // Create filter URL for pagination arrows + $strFilters = ''; + foreach (@$_REQUEST['filter'] as $filter => $value) { + $filter = "filter[$filter]"; + $strFilters .= "&$filter=$value"; + } + $smarty->assign('FILTERS', $strFilters); + + // Fetch requested users + if ($aUsers = $statistics->getAllUserStats($_REQUEST['filter'], $iLimit, $start)) { + // Add additional stats to each user + foreach ($aUsers as $iKey => $aUser) { + $aBalance = $transaction->getBalance($aUser['id']); + $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); } diff --git a/public/templates/mpos/admin/user/default.tpl b/public/templates/mpos/admin/user/default.tpl index 7a8f2b0f..060c7885 100644 --- a/public/templates/mpos/admin/user/default.tpl +++ b/public/templates/mpos/admin/user/default.tpl @@ -22,6 +22,59 @@ } +
+

User Search

+
+
+ + + + + + + + + +
+{if $smarty.request.start|default:"0" > 0} + +{else} + +{/if} + + +
+
+ + +
+
+ + +
+
+ + {html_options name="filter[is_admin]" options=$ADMIN selected=$smarty.request.filter.is_admin|default:""} +
+
+ + {html_options name="filter[is_locked]" options=$LOCKED selected=$smarty.request.filter.is_locked|default:""} +
+
+ + {html_options name="filter[no_fees]" options=$NOFEE selected=$smarty.request.filter.no_fees|default:""} +
+
    +
  • Note: Text search fields support '%' as wildcard.
  • +
+
+
+ +
+ +
@@ -108,13 +161,5 @@
-
From 003b8c79b6b6dc9f8c8ad6c4a352b542087e9e45 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 23 Dec 2013 22:51:26 +0100 Subject: [PATCH 2/3] [FIX] Removed old paginator --- public/templates/mpos/admin/user/default.tpl | 24 +------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/public/templates/mpos/admin/user/default.tpl b/public/templates/mpos/admin/user/default.tpl index 060c7885..522fd447 100644 --- a/public/templates/mpos/admin/user/default.tpl +++ b/public/templates/mpos/admin/user/default.tpl @@ -79,9 +79,8 @@

User Information

-
- +
@@ -140,26 +139,5 @@ {/section} {/nocache} - - - - - - - -{if $GLOBAL.config.payout_system != 'pps'} - - -{else} - -{/if} - - - - - -
ID
IDUsernameE-MailShares  Hashrate  Est. Donation  Est. Payout   Est. 24 Hours   Balance   AdminLockedNo Fees
-
-
From 2a24f90ed00aa1862a35b0b8f83997f108258a78 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 23 Dec 2013 23:04:13 +0100 Subject: [PATCH 3/3] [ADDED] Pagination support on pool workers page Adds pagination support for the admin panel pool workers page. Will greatly increase loading times of this page if working as intended. Fixes another part of #1043. --- public/include/classes/worker.class.php | 6 ++-- .../include/pages/admin/poolworkers.inc.php | 11 +++++-- .../mpos/admin/poolworkers/default.tpl | 29 +++++++++++++++---- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index 66a14365..2d0e606f 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -153,7 +153,7 @@ class Worker extends Base { * @param limit int * @return mixed array Workers and their settings or false **/ - public function getAllWorkers($iLimit=0, $interval=600) { + public function getAllWorkers($iLimit=0, $interval=600, $start=0) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, @@ -191,8 +191,8 @@ class Worker extends Base { WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND) )) AS avg_difficulty FROM $this->table AS w - ORDER BY hashrate DESC LIMIT ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $iLimit) && $stmt->execute() && $result = $stmt->get_result()) + ORDER BY hashrate DESC LIMIT ?,?"); + if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $start, $iLimit) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); return $this->sqlError('E0057'); } diff --git a/public/include/pages/admin/poolworkers.inc.php b/public/include/pages/admin/poolworkers.inc.php index 54ea4e3c..814d6c07 100644 --- a/public/include/pages/admin/poolworkers.inc.php +++ b/public/include/pages/admin/poolworkers.inc.php @@ -8,11 +8,16 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { die("404 Page not found"); } - $iActiveWorkers = $worker->getCountAllActiveWorkers(); - $aWorkers = $worker->getAllWorkers($iActiveWorkers); +// Some defaults +$interval = 600; +$iActiveWorkers = $worker->getCountAllActiveWorkers(); +$iActiveWorkers > 30 ? $iLimit = 30 : $iLimit = $iActiveWorkers; +empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start']; - $smarty->assign('WORKERS', $aWorkers); +$aWorkers = $worker->getAllWorkers($iLimit, $interval, $start); +$smarty->assign('LIMIT', $iLimit); +$smarty->assign('WORKERS', $aWorkers); $smarty->assign('CONTENT', 'default.tpl'); ?> diff --git a/public/templates/mpos/admin/poolworkers/default.tpl b/public/templates/mpos/admin/poolworkers/default.tpl index b9b7cc8a..3af8fece 100644 --- a/public/templates/mpos/admin/poolworkers/default.tpl +++ b/public/templates/mpos/admin/poolworkers/default.tpl @@ -1,6 +1,25 @@
-

{count($WORKERS)} Current Active Pool Workers

- +

{$GLOBAL.workers} Current Active Pool Workers

+ + + +
+ + + + + + +
+{if $smarty.request.start|default:"0" > 0} + +{else} + +{/if} + + +
+ @@ -14,7 +33,7 @@ {nocache} {section worker $WORKERS} - + @@ -28,6 +47,6 @@ {/section} {/nocache} - -
Worker Name
{$WORKERS[worker].username|escape} {$WORKERS[worker].password|escape}
+ +