From 9556488db5febdb74863491a75fb72c30085f7f9 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 10 Sep 2020 11:11:54 +0200 Subject: [PATCH] * Admin: fix some status filter gave empty rows for more then 50 accounts --- admin/inc/class.admin_ui.inc.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/admin/inc/class.admin_ui.inc.php b/admin/inc/class.admin_ui.inc.php index 512abc4271..8eceef8fa2 100644 --- a/admin/inc/class.admin_ui.inc.php +++ b/admin/inc/class.admin_ui.inc.php @@ -333,19 +333,26 @@ class admin_ui 'order' => $query['order'], 'sort' => $query['sort'], 'active' => !empty($query['active']) ? $query['active'] : false, - 'status' => $query['filter2'] ); // Make sure active filter give status what it needs switch($query['filter2']) { - case '': case 'disabled': case 'expired': case 'not_enabled': + case 'expires': + // this filters are not implemented by backend --> need to do unlimited query, then apply status filter and finally limit the query + $need_status_filter = $query['filter2']; + $params['start'] = false; + unset($params['offset']); + $params['active'] = $query['filter2'] === 'expires'; + break; + + case '': // all $params['active'] = false; break; + case 'enabled': - default: $params['active'] = true; break; } @@ -363,14 +370,15 @@ class admin_ui $rows = array_values(self::$accounts->search($params)); //error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total); + $total = self::$accounts->total; foreach($rows as $key => &$row) { // Filter by status - if($params['status'] && !static::filter_status($params['status'], $row)) + if ($need_status_filter && !static::filter_status($need_status_filter, $row)) { unset($rows[$key]); - self::$accounts->total--; + $total--; continue; } $row['status'] = self::$accounts->is_expired($row) ? @@ -381,8 +389,12 @@ class admin_ui if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; } - - return self::$accounts->total; + // finally limit query, if status filter was used + if ($need_status_filter) + { + $rows = array_values(array_slice($rows, (int)$query['start'], $query['num_rows'] ?: count($rows))); + } + return $total; }