From c0fddbce8117b55ec6807dd511d47b20be9510d2 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Wed, 8 Mar 2017 14:04:40 +0100 Subject: [PATCH] use correct pagination in admin-log/customer-log, fixes #1726 Signed-off-by: Michael Kaufmann (d00p) --- admin_logger.php | 15 ++-- customer_logger.php | 119 +++++++++++++--------------- lib/classes/output/class.paging.php | 11 ++- 3 files changed, 75 insertions(+), 70 deletions(-) diff --git a/admin_logger.php b/admin_logger.php index a409c021..8aba34c8 100644 --- a/admin_logger.php +++ b/admin_logger.php @@ -30,11 +30,12 @@ if ($page == 'log' 'user' => $lng['logger']['user'], 'text' => $lng['logger']['action'] ); - $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); - $result_stmt = Database::query(' - SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() - ); - $logs_count = Database::num_rows(); + $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc', 30); + $query = 'SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy(); + $result_stmt = Database::query($query . ' ' . $paging->getSqlLimit()); + $result_cnt_stmt = Database::query($query); + $res_cnt = $result_cnt_stmt->fetch(PDO::FETCH_ASSOC); + $logs_count = $res_cnt['resultrows']; $paging->setEntries($logs_count); $sortcode = $paging->getHtmlSortCode($lng); $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); @@ -67,7 +68,7 @@ if ($page == 'log' foreach ($clog as $action => $logrows) { $_action = 0; foreach ($logrows as $row) { - if ($paging->checkDisplay($i)) { + // if ($paging->checkDisplay($i)) { $row = htmlentities_array($row); $row['date'] = date("d.m.y H:i:s", $row['date']); @@ -105,7 +106,7 @@ if ($page == 'log' eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";"); $count++; $_action = $action; - } + // } $i++; } $i++; diff --git a/customer_logger.php b/customer_logger.php index 07e3f8e2..e3290296 100644 --- a/customer_logger.php +++ b/customer_logger.php @@ -16,17 +16,15 @@ * @package Panel * */ - define('AREA', 'customer'); require './lib/init.php'; // redirect if this customer page is hidden via settings -if (Settings::IsInList('panel.customer_hide_options','extras.logger')) { +if (Settings::IsInList('panel.customer_hide_options', 'extras.logger')) { redirectTo('customer_index.php'); } -if ($page == 'log' -) { +if ($page == 'log') { if ($action == '') { $fields = array( 'date' => $lng['logger']['date'], @@ -34,89 +32,86 @@ if ($page == 'log' 'user' => $lng['logger']['user'], 'text' => $lng['logger']['action'] ); - $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); - $result_stmt = Database::prepare(' - SELECT * FROM `' . TABLE_PANEL_LOG . '` WHERE `user` = :loginname ' . $paging->getSqlWhere(true) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() - ); - Database::pexecute($result_stmt, array("loginname" => $userinfo['loginname'])); - $logs_count = Database::num_rows(); + $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc', 30); + $query = 'SELECT * FROM `' . TABLE_PANEL_LOG . '` WHERE `user` = :loginname ' . $paging->getSqlWhere(true) . ' ' . $paging->getSqlOrderBy(); + $result_stmt = Database::prepare($query . ' ' . $paging->getSqlLimit()); + Database::pexecute($result_stmt, array( + "loginname" => $userinfo['loginname'] + )); + $result_cnt_stmt = Database::query($query); + $res_cnt = $result_cnt_stmt->fetch(PDO::FETCH_ASSOC); + $logs_count = $res_cnt['resultrows']; $paging->setEntries($logs_count); $sortcode = $paging->getHtmlSortCode($lng); $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); $searchcode = $paging->getHtmlSearchCode($lng); $pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s); $clog = array(); - + while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - - if (!isset($clog[$row['action']]) - || !is_array($clog[$row['action']]) - ) { + + if (! isset($clog[$row['action']]) || ! is_array($clog[$row['action']])) { $clog[$row['action']] = array(); } $clog[$row['action']][$row['logid']] = $row; } - - if ($paging->sortfield == 'date' - && $paging->sortorder == 'desc' - ) { + + if ($paging->sortfield == 'date' && $paging->sortorder == 'desc') { krsort($clog); } else { ksort($clog); } - + $i = 0; $count = 0; $log_count = 0; $log = ''; foreach ($clog as $action => $logrows) { - $_action = 0; foreach ($logrows as $row) { - if ($paging->checkDisplay($i)) { - $row = htmlentities_array($row); - $row['date'] = date("d.m.y H:i:s", $row['date']); - - if ($_action != $action) { - switch ($action) { - case USR_ACTION: - $_action = $lng['admin']['customer']; - break; - case RES_ACTION: - $_action = $lng['logger']['reseller']; - break; - case ADM_ACTION: - $_action = $lng['logger']['admin']; - break; - case CRON_ACTION: - $_action = $lng['logger']['cron']; - break; - case LOGIN_ACTION: - $_action = $lng['logger']['login']; - break; - case LOG_ERROR: - $_action = $lng['logger']['intern']; - break; - default: - $_action = $lng['logger']['unknown']; - break; - } - - $row['action'] = $_action; - eval("\$log.=\"" . getTemplate('logger/logger_action') . "\";"); + // if ($paging->checkDisplay($i)) { + $row = htmlentities_array($row); + $row['date'] = date("d.m.y H:i:s", $row['date']); + + if ($_action != $action) { + switch ($action) { + case USR_ACTION: + $_action = $lng['admin']['customer']; + break; + case RES_ACTION: + $_action = $lng['logger']['reseller']; + break; + case ADM_ACTION: + $_action = $lng['logger']['admin']; + break; + case CRON_ACTION: + $_action = $lng['logger']['cron']; + break; + case LOGIN_ACTION: + $_action = $lng['logger']['login']; + break; + case LOG_ERROR: + $_action = $lng['logger']['intern']; + break; + default: + $_action = $lng['logger']['unknown']; + break; } - - $log_count++; - $row['type'] = getLogLevelDesc($row['type']); - eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";"); - $count++; - $_action = $action; + + $row['action'] = $_action; + eval("\$log.=\"" . getTemplate('logger/logger_action') . "\";"); } - $i++; + + $log_count ++; + $row['type'] = getLogLevelDesc($row['type']); + eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";"); + $count ++; + $_action = $action; + // } + $i ++; } - $i++; + $i ++; } - + eval("echo \"" . getTemplate('logger/logger') . "\";"); - } } diff --git a/lib/classes/output/class.paging.php b/lib/classes/output/class.paging.php index 62384248..8ee2bc25 100644 --- a/lib/classes/output/class.paging.php +++ b/lib/classes/output/class.paging.php @@ -88,6 +88,8 @@ class paging { * @var bool */ private $natSorting = false; + + private $_limit = 0; /** * Class constructor. Loads settings from request or from userdata and saves them to session. @@ -101,7 +103,7 @@ class paging { * @param string $default_order default sorting order 'asc' or 'desc' * */ - public function __construct($userinfo, $table, $fields, $entriesperpage = 0, $natSorting = false, $default_field = 0, $default_order = 'asc') { + public function __construct($userinfo, $table, $fields, $entriesperpage = 0, $natSorting = false, $default_field = 0, $default_order = 'asc', $limit = 0) { // entries per page and natsorting-flag are not // passed as parameter anymore, because these are @@ -230,6 +232,8 @@ class paging { 'adminsession' => $userinfo['adminsession'] ); Database::pexecute($upd_stmt, $upd_data); + + $this->_limit = $limit; } /** @@ -378,6 +382,11 @@ class paging { * @return string always empty */ public function getSqlLimit() { + + if ($this->_limit > 0) { + $_offset = ($this->pageno - 1) * $this->_limit; + return ' LIMIT '.$_offset.','.$this->_limit; + } /** * currently not in use */