paginated logs

This commit is contained in:
Shish 2010-02-12 17:22:19 +00:00
parent 5d0c9d3fa3
commit 6c85ed3ba0
2 changed files with 33 additions and 3 deletions

View file

@ -46,6 +46,8 @@ class LogDatabase extends SimpleExtension {
if($user->is_admin()) { if($user->is_admin()) {
$wheres = array(); $wheres = array();
$args = array(); $args = array();
$page_num = int_escape($event->get_arg(0));
if($page_num <= 0) $page_num = 1;
if(!empty($_GET["time"])) { if(!empty($_GET["time"])) {
$wheres[] = "date_sent LIKE ?"; $wheres[] = "date_sent LIKE ?";
$args[] = $_GET["time"]."%"; $args[] = $_GET["time"]."%";
@ -76,13 +78,32 @@ class LogDatabase extends SimpleExtension {
$wheres[] = "priority >= ?"; $wheres[] = "priority >= ?";
$args[] = int_escape($_GET["priority"]); $args[] = int_escape($_GET["priority"]);
} }
else {
$wheres[] = "priority >= ?";
$args[] = 20;
}
$where = ""; $where = "";
if(count($wheres) > 0) { if(count($wheres) > 0) {
$where = "WHERE "; $where = "WHERE ";
$where .= join(" AND ", $wheres); $where .= join(" AND ", $wheres);
} }
$events = $database->get_all("SELECT * FROM score_log $where ORDER BY id DESC LIMIT 50", $args);
$this->theme->display_events($events); $limit = 50;
$offset = ($page_num-1) * $limit;
$page_total = $database->cache->get("event_log_length");
if(!$page_total) {
$page_total = $database->db->GetOne("SELECT count(*) FROM score_log $where", $args);
// don't cache a length of zero when the extension is first installed
if($page_total > 10) {
$database->cache->set("event_log_length", 600);
}
}
$args[] = $offset;
$args[] = $limit;
$events = $database->get_all("SELECT * FROM score_log $where ORDER BY id DESC LIMIT ?,?", $args);
$this->theme->display_events($events, $page_num, 100);
} }
} }
} }

View file

@ -5,7 +5,13 @@ class LogDatabaseTheme extends Themelet {
if(isset($_GET[$var])) return html_escape($_GET[$var]); if(isset($_GET[$var])) return html_escape($_GET[$var]);
else return ""; else return "";
} }
public function display_events($events) {
protected function ueie($var) {
if(isset($_GET[$var])) return $var."=".url_escape($_GET[$var]);
else return "";
}
public function display_events($events, $page_num, $page_total) {
$table = " $table = "
<style> <style>
.sizedinputs TD INPUT { .sizedinputs TD INPUT {
@ -59,6 +65,9 @@ class LogDatabaseTheme extends Themelet {
$page->set_heading("Event Log"); $page->set_heading("Event Log");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Events", $table)); $page->add_block(new Block("Events", $table));
$args = $this->ueie("time")."&".$this->ueie("module")."&".$this->ueie("user")."&".$this->ueie("priority");
$this->display_paginator($page, "log/view", $args, $page_num, $page_total);
} }
protected function pri_to_col($pri) { protected function pri_to_col($pri) {