From 0559cf9de64e24792de6f6f89e9f7f257c80fc03 Mon Sep 17 00:00:00 2001 From: Chaoyi Zha Date: Sun, 31 May 2015 23:07:57 +0000 Subject: [PATCH 1/2] Add pagination fix #58 --- admin/index.php | 161 ++++++++++++++++++++++++++++++++++++++++++------ css/main.css | 10 +++ lib-core.php | 13 ++-- 3 files changed, 157 insertions(+), 27 deletions(-) diff --git a/admin/index.php b/admin/index.php index a95bb3f..7b2dfea 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,20 +1,82 @@ isadminli(); + +@$users_page = $_GET['upage']; +@$links_page = $_GET['lpage']; +@$admin_links_page = $_GET['alpage']; + +function table_length($table_name) { + global $mysqli; + if ($table_name == "redirinfo") { + $colname = "rurl"; + } + else if ($table_name == "auth") { + $colname = "username"; + } + $result = $mysqli->query("SELECT COUNT(`{$colname}`) FROM `{$table_name}`;") or showerror(); + $count = ($result->fetch_assoc()); + $count = (double) $count["COUNT(`{$colname}`)"]; + + $pages = $count / 30; + + return ceil($pages); +} +function paginate_table($current_page = 0, $total_pages = 0, $pag_name, $sel_name) { + $markup = ''; + return $markup; +} + +function user_link_table_length($current_user) { + global $mysqli; + $current_user = $mysqli->real_escape_string($current_user); + $result = $mysqli->query("SELECT COUNT(`rurl`) FROM `redirinfo` WHERE `user` = '{$current_user}';") or showerror(); + + $count = ($result->fetch_assoc()); + $count = (double) $count["COUNT(`rurl`)"]; + $pages = $count / 30; + return ceil($pages); +} + if (!is_array($auth->islogged())) { - echo "

You must login to access this page.


Home"; + echo "

You must login to access this page.


Home"; require_once '../layout-footerlg.php'; die(); } else { $userinfo = $auth->islogged(); - function fetchurls($lstart = 0) { + function fetchurls($lstart = 0, $limit = 30) { global $userinfo; global $mysqli; - $sqr = "SELECT `baseval`,`rurl`,`date`,`lkey` FROM `redirinfo` WHERE user = '{$mysqli->real_escape_string($userinfo['username'])}' LIMIT {$lstart} , 720;"; + $sqr = "SELECT `baseval`,`rurl`,`date`,`lkey` FROM `redirinfo` WHERE user = '{$mysqli->real_escape_string($userinfo['username'])}' LIMIT {$lstart} , {$limit};"; $res = $mysqli->query($sqr); $links = mysqli_fetch_all($res, MYSQLI_ASSOC); @@ -25,7 +87,7 @@ if (!is_array($auth->islogged())) { $is_secret = "True"; } $linkshtml = $linkshtml . "" . $link['baseval'] . '' - . "" . substr($link['rurl'], 0, 170) . '' + . "" . substr($link['rurl'], 0, 255) . '' . "" . $link['date'] . '' . "" . $is_secret . ""; } @@ -33,7 +95,24 @@ if (!is_array($auth->islogged())) { return $linkshtml; } - $linkshtml = fetchurls(); + $links_total_pages = user_link_table_length($userinfo['username']); + $linkshtml = false; + if ($links_page && is_numeric($links_page)) { + // If valid links page + $links_page = intval($links_page); + if ($links_page < $links_total_pages && $links_page > 0) { + $ls = (30 * $links_page); + $limit = ($lstart + 30); + $linkshtml = fetchurls($ls, $limit); + } + } + if ($linkshtml == false) { + $linkshtml = fetchurls(); + $links_page = 0; + } + $linkshtml .= paginate_table($links_page, $links_total_pages, "lpage", "links"); + + echo "

Polr Dashboard


"; echo '