From 9969e37105e87a946546e78f917fc1b730073898 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 9 Jan 2012 10:20:13 +1100 Subject: [PATCH] paginate modlog --- mod.php | 69 +++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/mod.php b/mod.php index 02208713..df3cf528 100644 --- a/mod.php +++ b/mod.php @@ -268,40 +268,67 @@ 'mod'=>true ) ); - } elseif(preg_match('/^\/log$/', $query)) { + } elseif(preg_match('/^\/log(\/(\d+))?$/', $query, $match)) { if(!hasPermission($config['mod']['modlog'])) error($config['error']['noaccess']); + $page = isset($match[2]) ? $match[2] : 1; + $boards = Array(); $_boards = listBoards(); foreach($_boards as &$_b) { $boards[$_b['id']] = $_b['uri']; } - $body = ''; - - $query = prepare("SELECT `mods`.`id`,`username`,`ip`,`board`,`time`,`text` FROM `modlogs` INNER JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :limit"); + $query = prepare("SELECT `mods`.`id`,`username`,`ip`,`board`,`time`,`text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :offset, :limit"); $query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT); + $query->bindValue(':offset', ($page - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); - while($log = $query->fetch()) { - $log['text'] = utf8tohtml($log['text']); - $log['text'] = preg_replace('/(\d+\.\d+\.\d+\.\d+)/', '$1', $log['text']); + if(!$query->rowCount()) { + $body = '

(Nothing to display.)

'; + } else { + $body = '
' . _('User') . '' . _('IP address') . '' . _('Ago') . '' . _('Board') . '' . _('Action') . '
' . + '' . + '' . + '' . + '' . + '' . + '' . + ''; + while($log = $query->fetch()) { + $log['text'] = utf8tohtml($log['text']); + $log['text'] = preg_replace('/(\d+\.\d+\.\d+\.\d+)/', '$1', $log['text']); - $body .= '' . - '' . - '' . - '' . - '' - : 'deleted?') - : '-') . - '' . - ''; - } + $body .= '' . + '' . + '' . + '' . + '' + : 'deleted?') + : '-') . + '' . + ''; + } - $body .= '
' . _('User') . '' . _('IP address') . '' . _('Ago') . '' . _('Board') . '' . _('Action') . '
' . $log['username'] . '' . $log['ip'] . '' . ago($log['time']) . '' . - ($log['board'] ? - (isset($boards[$log['board']]) ? - '' . sprintf($config['board_abbreviation'], $boards[$log['board']]) . '' . $log['text'] . '
' . + ($log['username'] ? + '' . $log['username'] . '' + : 'deleted?') . + '' . $log['ip'] . '' . ago($log['time']) . '' . + ($log['board'] ? + (isset($boards[$log['board']]) ? + '' . sprintf($config['board_abbreviation'], $boards[$log['board']]) . '' . $log['text'] . '
'; + $body .= ''; + + $query = prepare("SELECT COUNT(*) AS `count` FROM `modlogs`"); + $query->execute() or error(db_error($query)); + $count = $query->fetch(); + + $body .= '

'; + for($x = 0; $x < $count['count'] / $config['mod']['modlog_page']; $x ++) { + $body .= '[' . ($x + 1) . '] '; + } + $body .= '

'; + } echo Element('page.html', Array( 'config'=>$config,