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'],
'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++;

View File

@@ -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,12 +32,15 @@ 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);
@@ -49,17 +50,13 @@ if ($page == 'log'
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);
@@ -70,53 +67,51 @@ if ($page == 'log'
$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 ($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 ($_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') . "\";");
}
}

View File

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