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,7 +16,6 @@
* @package Panel * @package Panel
* *
*/ */
define('AREA', 'customer'); define('AREA', 'customer');
require './lib/init.php'; require './lib/init.php';
@@ -25,8 +24,7 @@ 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,12 +32,15 @@ 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);
@@ -49,17 +50,13 @@ if ($page == 'log'
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);
@@ -70,9 +67,8 @@ if ($page == 'log'
$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']);
@@ -110,13 +106,12 @@ 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 ++;
} }
eval("echo \"" . getTemplate('logger/logger') . "\";"); eval("echo \"" . getTemplate('logger/logger') . "\";");
} }
} }

View File

@@ -89,6 +89,8 @@ class paging {
*/ */
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
*/ */