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