Pagination is now functional and loads the requested sites

This commit is contained in:
Maurice Meyer 2016-06-05 20:00:45 +02:00
parent b644d5ed66
commit 788f9eafcd
2 changed files with 20 additions and 8 deletions

View file

@ -28,7 +28,12 @@ if(!isset($input->csrfToken) || $input->csrfToken !== $_SESSION['csrfToken']) {
}
if(isset($input->action) && $input->action == "getDomains") {
// Check if the requested page is a number
if(!(is_int($input->page) && $input->page > 0)) {
echo "Requested page must be a positive number!";
exit();
}
// Here we get the number of matching records
$sql = "
SELECT COUNT(*) AS anzahl
@ -75,7 +80,7 @@ if(isset($input->action) && $input->action == "getDomains") {
// Initialize the return value
$retval = Array();
$retval['pages']['current'] = 4000;
$retval['pages']['current'] = $input->page;
$retval['pages']['total'] = ceil($obj->anzahl / $config['domain_rows']);
@ -113,10 +118,15 @@ if(isset($input->action) && $input->action == "getDomains") {
}
/*
* Now the number of entries gets limited to the domainRows config value
* Now the number of entries gets limited to the domainRows config value.
* SQL LIMIT is used for that:
* LIMIT lower, upper
* Note that LIMIT 0,4 returns the first five rows!
*/
$sql .= " LIMIT " . $config['domain_rows'];
$lower_limit = ($config['domain_rows'] * ($input->page - 1));
$sql .= " LIMIT " . $lower_limit . ", " . $config['domain_rows'];
$stmt = $db->prepare($sql);
if(isset($input->name)) {

View file

@ -20,7 +20,8 @@ var sort = {
}
$(document).ready(function() {
requestData();
// When the site is loaded, always show the first page
requestData(1);
$('#table-domains>thead>tr>td span').click(function() {
var field = $(this).siblings('strong').text().toLowerCase();
@ -53,7 +54,7 @@ $(document).ready(function() {
});
});
function requestData() {
function requestData(page) {
var restrictions = {
csrfToken: $('#csrfToken').text(),
};
@ -71,6 +72,7 @@ function requestData() {
}
restrictions.action = "getDomains";
restrictions.page = page;
$.post(
"api/domains.php",
@ -189,5 +191,5 @@ function deleteDomainWithId(id, callback) {
}
function paginationClicked() {
alert($(this).data("page"));
requestData($(this).data("page"));
}