diff --git a/bans.php b/bans.php
index 8260d22..21b3c0f 100644
--- a/bans.php
+++ b/bans.php
@@ -37,6 +37,7 @@ $page = new Page();
+ print_pager("bans.php"); ?>
print_footer(); ?>
diff --git a/includes/page.php b/includes/page.php
index 8618bf7..f97ca34 100644
--- a/includes/page.php
+++ b/includes/page.php
@@ -10,25 +10,41 @@ class Page {
$this->settings = $settings;
$this->uuid_name_cache = array();
$this->time = microtime(true);
- }
+ $this->page = 0;
- function get_query($table) {
- $active_query = $this->settings->active_query;
- $limit = $this->settings->limit_per_page;
- return "SELECT * FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT $limit";
+ if (isset($_GET['page'])) {
+ $page = $_GET['page']; // user input
+ if (filter_var($page, FILTER_VALIDATE_INT)) {
+ $this->page = (int)$page;
+ }
+ }
}
function run_query($table) {
try {
- $result = $this->conn->query($this->get_query($table));
+ $active_query = $this->settings->active_query;
+ $limit = $this->settings->limit_per_page;
+
+ $offset = 0;
+ if ($this->settings->show_pager) {
+ $offset = ($limit * $this->page);
+ }
+ $query = "SELECT * FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT :limit OFFSET :offset";
+ $st = $this->conn->prepare($query);
+
+ $st->bindParam(':offset', $offset, PDO::PARAM_INT);
+ $st->bindParam(':limit', $limit, PDO::PARAM_INT);
+
+ $st->execute();
+
+ return $st;
} catch (PDOException $ex) {
die($ex->getMessage());
}
- return $result;
}
function get_avatar($name) {
- return "$name";
+ return "
$name";
}
function get_name($uuid) {
@@ -107,6 +123,19 @@ class Page {
');
}
+ function print_pager($page) {
+ if (!$this->settings->show_pager) return;
+ $prev = $this->page - 1;
+ $next = $this->page + 1;
+
+ $pager_prev = "