Added initial functionality for pagination
This commit is contained in:
parent
3a3855e939
commit
d61caad090
106
api/domains.php
106
api/domains.php
|
@ -29,38 +29,16 @@ if(!isset($input->csrfToken) || $input->csrfToken !== $_SESSION['csrfToken']) {
|
||||||
|
|
||||||
if(isset($input->action) && $input->action == "getDomains") {
|
if(isset($input->action) && $input->action == "getDomains") {
|
||||||
|
|
||||||
|
// Here we get the number of matching records
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT D.id,D.name,D.type,count(R.domain_id) AS records
|
SELECT COUNT(*) AS anzahl
|
||||||
FROM domains D
|
FROM domains D
|
||||||
LEFT OUTER JOIN records R ON D.id = R.domain_id
|
|
||||||
LEFT OUTER JOIN permissions P ON D.id = P.domain
|
LEFT OUTER JOIN permissions P ON D.id = P.domain
|
||||||
WHERE (P.user=? OR ?)
|
WHERE (P.user=? OR ?) AND
|
||||||
GROUP BY D.id
|
|
||||||
HAVING
|
|
||||||
(D.name LIKE ? OR ?) AND
|
(D.name LIKE ? OR ?) AND
|
||||||
(D.type=? OR ?)
|
(D.type=? OR ?)
|
||||||
";
|
";
|
||||||
|
|
||||||
if(isset($input->sort->field) && $input->sort->field != "") {
|
|
||||||
if($input->sort->field == "id") {
|
|
||||||
$sql .= "ORDER BY id";
|
|
||||||
} else if($input->sort->field == "name") {
|
|
||||||
$sql .= "ORDER BY name";
|
|
||||||
} else if($input->sort->field == "type") {
|
|
||||||
$sql .= "ORDER BY type";
|
|
||||||
} else if($input->sort->field == "records") {
|
|
||||||
$sql .= "ORDER BY records";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($input->sort->order)) {
|
|
||||||
if($input->sort->order == 0) {
|
|
||||||
$sql .= " DESC";
|
|
||||||
} else if($input->sort->order == 1) {
|
|
||||||
$sql .= " ASC";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt = $db->prepare($sql);
|
$stmt = $db->prepare($sql);
|
||||||
|
|
||||||
if(isset($input->name)) {
|
if(isset($input->name)) {
|
||||||
|
@ -91,10 +69,86 @@ if(isset($input->action) && $input->action == "getDomains") {
|
||||||
|
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
// This is the object containing the number of rows
|
||||||
|
$obj = $result->fetch_object();
|
||||||
|
|
||||||
|
// Initialize the return value
|
||||||
$retval = Array();
|
$retval = Array();
|
||||||
|
|
||||||
|
$retval['pages']['current'] = 1;
|
||||||
|
$retval['pages']['total'] = $obj->anzahl / $config['domain_rows'];
|
||||||
|
|
||||||
|
|
||||||
|
// Now the real search is done on the database
|
||||||
|
$sql = "
|
||||||
|
SELECT D.id,D.name,D.type,count(R.domain_id) AS records
|
||||||
|
FROM domains D
|
||||||
|
LEFT OUTER JOIN records R ON D.id = R.domain_id
|
||||||
|
LEFT OUTER JOIN permissions P ON D.id = P.domain
|
||||||
|
WHERE (P.user=? OR ?)
|
||||||
|
GROUP BY D.id
|
||||||
|
HAVING
|
||||||
|
(D.name LIKE ? OR ?) AND
|
||||||
|
(D.type=? OR ?)
|
||||||
|
";
|
||||||
|
|
||||||
|
if(isset($input->sort->field) && $input->sort->field != "") {
|
||||||
|
if($input->sort->field == "id") {
|
||||||
|
$sql .= "ORDER BY id";
|
||||||
|
} else if($input->sort->field == "name") {
|
||||||
|
$sql .= "ORDER BY name";
|
||||||
|
} else if($input->sort->field == "type") {
|
||||||
|
$sql .= "ORDER BY type";
|
||||||
|
} else if($input->sort->field == "records") {
|
||||||
|
$sql .= "ORDER BY records";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($input->sort->order)) {
|
||||||
|
if($input->sort->order == 0) {
|
||||||
|
$sql .= " DESC";
|
||||||
|
} else if($input->sort->order == 1) {
|
||||||
|
$sql .= " ASC";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now the number of entries gets limited to the domainRows config value
|
||||||
|
*/
|
||||||
|
$sql .= " LIMIT " . $config['domain_rows'];
|
||||||
|
|
||||||
|
$stmt = $db->prepare($sql);
|
||||||
|
|
||||||
|
if(isset($input->name)) {
|
||||||
|
$name_filter = "%" . $input->name . "%";
|
||||||
|
$name_filter_used = 0;
|
||||||
|
} else {
|
||||||
|
$name_filter = "";
|
||||||
|
$name_filter_used = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id_filter = $_SESSION['id'];
|
||||||
|
$id_filter_used = (int)($_SESSION['type'] == "admin" ? 1 : 0);
|
||||||
|
|
||||||
|
if(isset($input->type)) {
|
||||||
|
$type_filter = $input->type;
|
||||||
|
$type_filter_used = 0;
|
||||||
|
} else {
|
||||||
|
$type_filter = "";
|
||||||
|
$type_filter_used = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->bind_param("sisiii",
|
||||||
|
$id_filter, $id_filter_used,
|
||||||
|
$name_filter, $name_filter_used,
|
||||||
|
$type_filter, $type_filter_used
|
||||||
|
);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
while($obj = $result->fetch_object()) {
|
while($obj = $result->fetch_object()) {
|
||||||
$retval[] = $obj;
|
$retval['data'][] = $obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,4 +26,7 @@ $config['db_name'] = "pdnsmanager";
|
||||||
//Remote update
|
//Remote update
|
||||||
$config['nonce_lifetime'] = 15;
|
$config['nonce_lifetime'] = 15;
|
||||||
|
|
||||||
include 'config-user.php';
|
//Number of rows in domain overview
|
||||||
|
$config['domain_rows'] = 100;
|
||||||
|
|
||||||
|
include 'config-user.php';
|
||||||
|
|
29
domains.php
29
domains.php
|
@ -50,7 +50,7 @@ limitations under the License.
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<table class="table table-hover" id="table-domains">
|
<table class="table table-hover" id="table-domains">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -82,12 +82,31 @@ limitations under the License.
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="cursor-pointer">
|
<tbody class="cursor-pointer">
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div id="pagination" class="text-center">
|
||||||
|
<ul class="pagination">
|
||||||
|
<li>
|
||||||
|
<a href="#" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">«</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li><a href="#">1</a></li>
|
||||||
|
<li><a href="#">2</a></li>
|
||||||
|
<li><a href="#">3</a></li>
|
||||||
|
<li><a href="#">4</a></li>
|
||||||
|
<li><a href="#">5</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="#" aria-label="Next">
|
||||||
|
<span aria-hidden="true">»</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if($_SESSION['type'] == "admin") {
|
if($_SESSION['type'] == "admin") {
|
||||||
echo '<div class="row">';
|
echo '<div class="row text-center">';
|
||||||
echo '<a class="btn btn-success" href="add-domain.php#MASTER">Add MASTER</a>';
|
echo '<a class="btn btn-success" href="add-domain.php#MASTER">Add MASTER</a>';
|
||||||
echo '<a class="btn btn-primary margin-left-20" href="add-domain.php#NATIVE">Add NATIVE</a>';
|
echo '<a class="btn btn-primary margin-left-20" href="add-domain.php#NATIVE">Add NATIVE</a>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
@ -108,6 +127,8 @@ limitations under the License.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo '<span class="hidden" id="csrfToken">' . $_SESSION['csrfToken'] . '</span>'; ?>
|
|
||||||
|
<?php echo '<span class="hidden" id="csrfToken">' . $_SESSION['csrfToken'] . '</span>'; ?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -39,15 +39,15 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
requestData();
|
requestData();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#searchName').bind("paste keyup", function() {
|
$('#searchName').bind("paste keyup", function() {
|
||||||
requestData();
|
requestData();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#searchType').change(function() {
|
$('#searchType').change(function() {
|
||||||
requestData();
|
requestData();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#searchType').select2({
|
$('#searchType').select2({
|
||||||
minimumResultsForSearch: Infinity
|
minimumResultsForSearch: Infinity
|
||||||
});
|
});
|
||||||
|
@ -55,23 +55,23 @@ $(document).ready(function() {
|
||||||
|
|
||||||
function requestData() {
|
function requestData() {
|
||||||
var restrictions = {
|
var restrictions = {
|
||||||
csrfToken: $('#csrfToken').text()
|
csrfToken: $('#csrfToken').text(),
|
||||||
};
|
};
|
||||||
|
|
||||||
restrictions.sort = sort;
|
restrictions.sort = sort;
|
||||||
|
|
||||||
var searchName = $('#searchName').val();
|
var searchName = $('#searchName').val();
|
||||||
if(searchName.length > 0) {
|
if(searchName.length > 0) {
|
||||||
restrictions.name = searchName;
|
restrictions.name = searchName;
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchType = $('#searchType').val();
|
var searchType = $('#searchType').val();
|
||||||
if(searchType != "none") {
|
if(searchType != "none") {
|
||||||
restrictions.type = searchType;
|
restrictions.type = searchType;
|
||||||
}
|
}
|
||||||
|
|
||||||
restrictions.action = "getDomains";
|
restrictions.action = "getDomains";
|
||||||
|
|
||||||
$.post(
|
$.post(
|
||||||
"api/domains.php",
|
"api/domains.php",
|
||||||
JSON.stringify(restrictions),
|
JSON.stringify(restrictions),
|
||||||
|
@ -84,6 +84,7 @@ function requestData() {
|
||||||
|
|
||||||
function recreateTable(data) {
|
function recreateTable(data) {
|
||||||
$('#table-domains>tbody').empty();
|
$('#table-domains>tbody').empty();
|
||||||
|
$('#pagination').empty();
|
||||||
|
|
||||||
$.each(data, function(index,item) {
|
$.each(data, function(index,item) {
|
||||||
$('<tr></tr>').appendTo('#table-domains>tbody')
|
$('<tr></tr>').appendTo('#table-domains>tbody')
|
||||||
|
@ -144,4 +145,4 @@ function deleteDomainWithId(id, callback) {
|
||||||
},
|
},
|
||||||
"json"
|
"json"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue