use correct pagination in admin-log/customer-log, fixes #1726

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2017-03-08 14:04:40 +01:00
parent 2284706e0c
commit c0fddbce81
3 changed files with 75 additions and 70 deletions

View File

@@ -30,11 +30,12 @@ if ($page == 'log'
'user' => $lng['logger']['user'], 'user' => $lng['logger']['user'],
'text' => $lng['logger']['action'] 'text' => $lng['logger']['action']
); );
$paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc', 30);
$result_stmt = Database::query(' $query = 'SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy();
SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() $result_stmt = Database::query($query . ' ' . $paging->getSqlLimit());
); $result_cnt_stmt = Database::query($query);
$logs_count = Database::num_rows(); $res_cnt = $result_cnt_stmt->fetch(PDO::FETCH_ASSOC);
$logs_count = $res_cnt['resultrows'];
$paging->setEntries($logs_count); $paging->setEntries($logs_count);
$sortcode = $paging->getHtmlSortCode($lng); $sortcode = $paging->getHtmlSortCode($lng);
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
@@ -67,7 +68,7 @@ if ($page == 'log'
foreach ($clog as $action => $logrows) { foreach ($clog as $action => $logrows) {
$_action = 0; $_action = 0;
foreach ($logrows as $row) { foreach ($logrows as $row) {
if ($paging->checkDisplay($i)) { // if ($paging->checkDisplay($i)) {
$row = htmlentities_array($row); $row = htmlentities_array($row);
$row['date'] = date("d.m.y H:i:s", $row['date']); $row['date'] = date("d.m.y H:i:s", $row['date']);
@@ -105,7 +106,7 @@ if ($page == 'log'
eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";"); eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";");
$count++; $count++;
$_action = $action; $_action = $action;
} // }
$i++; $i++;
} }
$i++; $i++;

View File

@@ -16,17 +16,15 @@
* @package Panel * @package Panel
* *
*/ */
define('AREA', 'customer'); define('AREA', 'customer');
require './lib/init.php'; require './lib/init.php';
// redirect if this customer page is hidden via settings // 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'); redirectTo('customer_index.php');
} }
if ($page == 'log' if ($page == 'log') {
) {
if ($action == '') { if ($action == '') {
$fields = array( $fields = array(
'date' => $lng['logger']['date'], 'date' => $lng['logger']['date'],
@@ -34,89 +32,86 @@ if ($page == 'log'
'user' => $lng['logger']['user'], 'user' => $lng['logger']['user'],
'text' => $lng['logger']['action'] 'text' => $lng['logger']['action']
); );
$paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc', 30);
$result_stmt = Database::prepare(' $query = 'SELECT * FROM `' . TABLE_PANEL_LOG . '` WHERE `user` = :loginname ' . $paging->getSqlWhere(true) . ' ' . $paging->getSqlOrderBy();
SELECT * FROM `' . TABLE_PANEL_LOG . '` WHERE `user` = :loginname ' . $paging->getSqlWhere(true) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() $result_stmt = Database::prepare($query . ' ' . $paging->getSqlLimit());
); Database::pexecute($result_stmt, array(
Database::pexecute($result_stmt, array("loginname" => $userinfo['loginname'])); "loginname" => $userinfo['loginname']
$logs_count = Database::num_rows(); ));
$result_cnt_stmt = Database::query($query);
$res_cnt = $result_cnt_stmt->fetch(PDO::FETCH_ASSOC);
$logs_count = $res_cnt['resultrows'];
$paging->setEntries($logs_count); $paging->setEntries($logs_count);
$sortcode = $paging->getHtmlSortCode($lng); $sortcode = $paging->getHtmlSortCode($lng);
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
$searchcode = $paging->getHtmlSearchCode($lng); $searchcode = $paging->getHtmlSearchCode($lng);
$pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s); $pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s);
$clog = array(); $clog = array();
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (!isset($clog[$row['action']]) if (! isset($clog[$row['action']]) || ! is_array($clog[$row['action']])) {
|| !is_array($clog[$row['action']])
) {
$clog[$row['action']] = array(); $clog[$row['action']] = array();
} }
$clog[$row['action']][$row['logid']] = $row; $clog[$row['action']][$row['logid']] = $row;
} }
if ($paging->sortfield == 'date' if ($paging->sortfield == 'date' && $paging->sortorder == 'desc') {
&& $paging->sortorder == 'desc'
) {
krsort($clog); krsort($clog);
} else { } else {
ksort($clog); ksort($clog);
} }
$i = 0; $i = 0;
$count = 0; $count = 0;
$log_count = 0; $log_count = 0;
$log = ''; $log = '';
foreach ($clog as $action => $logrows) { foreach ($clog as $action => $logrows) {
$_action = 0;
foreach ($logrows as $row) { foreach ($logrows as $row) {
if ($paging->checkDisplay($i)) { // if ($paging->checkDisplay($i)) {
$row = htmlentities_array($row); $row = htmlentities_array($row);
$row['date'] = date("d.m.y H:i:s", $row['date']); $row['date'] = date("d.m.y H:i:s", $row['date']);
if ($_action != $action) { if ($_action != $action) {
switch ($action) { switch ($action) {
case USR_ACTION: case USR_ACTION:
$_action = $lng['admin']['customer']; $_action = $lng['admin']['customer'];
break; break;
case RES_ACTION: case RES_ACTION:
$_action = $lng['logger']['reseller']; $_action = $lng['logger']['reseller'];
break; break;
case ADM_ACTION: case ADM_ACTION:
$_action = $lng['logger']['admin']; $_action = $lng['logger']['admin'];
break; break;
case CRON_ACTION: case CRON_ACTION:
$_action = $lng['logger']['cron']; $_action = $lng['logger']['cron'];
break; break;
case LOGIN_ACTION: case LOGIN_ACTION:
$_action = $lng['logger']['login']; $_action = $lng['logger']['login'];
break; break;
case LOG_ERROR: case LOG_ERROR:
$_action = $lng['logger']['intern']; $_action = $lng['logger']['intern'];
break; break;
default: default:
$_action = $lng['logger']['unknown']; $_action = $lng['logger']['unknown'];
break; break;
}
$row['action'] = $_action;
eval("\$log.=\"" . getTemplate('logger/logger_action') . "\";");
} }
$log_count++; $row['action'] = $_action;
$row['type'] = getLogLevelDesc($row['type']); eval("\$log.=\"" . getTemplate('logger/logger_action') . "\";");
eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";");
$count++;
$_action = $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') . "\";"); eval("echo \"" . getTemplate('logger/logger') . "\";");
} }
} }

View File

@@ -88,6 +88,8 @@ class paging {
* @var bool * @var bool
*/ */
private $natSorting = false; private $natSorting = false;
private $_limit = 0;
/** /**
* Class constructor. Loads settings from request or from userdata and saves them to session. * 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' * @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 // entries per page and natsorting-flag are not
// passed as parameter anymore, because these are // passed as parameter anymore, because these are
@@ -230,6 +232,8 @@ class paging {
'adminsession' => $userinfo['adminsession'] 'adminsession' => $userinfo['adminsession']
); );
Database::pexecute($upd_stmt, $upd_data); Database::pexecute($upd_stmt, $upd_data);
$this->_limit = $limit;
} }
/** /**
@@ -378,6 +382,11 @@ class paging {
* @return string always empty * @return string always empty
*/ */
public function getSqlLimit() { public function getSqlLimit() {
if ($this->_limit > 0) {
$_offset = ($this->pageno - 1) * $this->_limit;
return ' LIMIT '.$_offset.','.$this->_limit;
}
/** /**
* currently not in use * currently not in use
*/ */