mirror of
https://github.com/loewexy/pdnsmanager.git
synced 2025-01-16 03:02:22 +01:00
Implemented domain overview, permissions are still ignored
This commit is contained in:
parent
801fe2c06c
commit
a3ebd21541
4 changed files with 201 additions and 3 deletions
86
api/domains.php
Normal file
86
api/domains.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once '../config/config-default.php';
|
||||
require_once '../lib/database.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'));
|
||||
|
||||
$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
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
if(isset($input->name)) {
|
||||
$name_filter = "%" . $input->name . "%";
|
||||
$name_filter_used = 0;
|
||||
} else {
|
||||
$name_filter = "";
|
||||
$name_filter_used = 1;
|
||||
}
|
||||
|
||||
if(isset($input->type)) {
|
||||
$type_filter = $input->type;
|
||||
$type_filter_used = 0;
|
||||
} else {
|
||||
$type_filter = "";
|
||||
$type_filter_used = 1;
|
||||
}
|
||||
|
||||
$stmt->bind_param("sisi",
|
||||
$name_filter, $name_filter_used,
|
||||
$type_filter, $type_filter_used
|
||||
);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$retval = Array();
|
||||
|
||||
while($obj = $result->fetch_object()) {
|
||||
$retval[] = $obj;
|
||||
}
|
||||
|
||||
echo json_encode($retval);
|
34
domains.php
34
domains.php
|
@ -46,7 +46,39 @@ limitations under the License.
|
|||
</nav>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<table class="table table-hover" id="table-domains">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><strong>ID</strong> <span class="glyphicon glyphicon-sort cursor-pointer"></span></td>
|
||||
<td>
|
||||
<form class="form-inline">
|
||||
<div class="form-group">
|
||||
<strong>Name</strong>
|
||||
<span class="glyphicon glyphicon-sort cursor-pointer cursor-pointer"></span>
|
||||
<input type="text" class="form-control" id="searchName" placeholder="Search" autocomplete="off">
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form class="form-inline">
|
||||
<div class="form-group">
|
||||
<strong>Type</strong>
|
||||
<span class="glyphicon glyphicon-sort cursor-pointer cursor-pointer"></span>
|
||||
<select class="form-control" id="searchType">
|
||||
<option value="none">No filter...</option>
|
||||
<option value="MASTER">MASTER</option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
<td><strong>Records</strong> <span class="glyphicon glyphicon-sort cursor-pointer"></span></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -9,4 +9,6 @@
|
|||
.vspacer-100 { height: 100px; }
|
||||
.vspacer-150 { height: 150px; }
|
||||
|
||||
.defaulthidden { display: none; }
|
||||
.defaulthidden { display: none !important; }
|
||||
|
||||
.cursor-pointer {cursor: pointer; }
|
|
@ -14,6 +14,84 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var sort = {
|
||||
field: "",
|
||||
order: 1
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
requestData();
|
||||
|
||||
});
|
||||
$('#table-domains>thead>tr>td span').click(function() {
|
||||
var field = $(this).siblings('strong').text().toLowerCase();
|
||||
if(sort.field == field) {
|
||||
if(sort.order == 1) sort.order = 0;
|
||||
else sort.field = "";
|
||||
} else {
|
||||
sort.field = field;
|
||||
sort.order = 1;
|
||||
}
|
||||
$('#table-domains>thead>tr>td span').removeClass("glyphicon-sort-by-attributes glyphicon-sort-by-attributes-alt");
|
||||
|
||||
if(sort.field == field) {
|
||||
if(sort.order == 1) $(this).addClass("glyphicon-sort-by-attributes");
|
||||
else $(this).addClass("glyphicon-sort-by-attributes-alt");
|
||||
}
|
||||
requestData();
|
||||
});
|
||||
|
||||
$('#searchName').bind("paste keyup", function() {
|
||||
requestData();
|
||||
});
|
||||
|
||||
$('#searchType').change(function() {
|
||||
requestData();
|
||||
});
|
||||
});
|
||||
|
||||
function requestData() {
|
||||
var restrictions = {};
|
||||
|
||||
restrictions.sort = sort;
|
||||
|
||||
var searchName = $('#searchName').val();
|
||||
if(searchName.length > 0) {
|
||||
restrictions.name = searchName;
|
||||
}
|
||||
|
||||
var searchType = $('#searchType').val();
|
||||
if(searchType != "none") {
|
||||
restrictions.type = searchType;
|
||||
}
|
||||
|
||||
$.post(
|
||||
"api/domains.php",
|
||||
JSON.stringify(restrictions),
|
||||
function(data) {
|
||||
recreateTable(data);
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
||||
function recreateTable(data) {
|
||||
$('#table-domains>tbody').empty();
|
||||
|
||||
$.each(data, function(index,item) {
|
||||
$('<tr></tr>').appendTo('#table-domains>tbody')
|
||||
.append('<td>' + item.id + '</td>')
|
||||
.append('<td>' + item.name + '</td>')
|
||||
.append('<td>' + item.type + '</td>')
|
||||
.append('<td>' + item.records + '</td>');
|
||||
|
||||
});
|
||||
|
||||
$('#table-domains>tbody>tr').click(function() {
|
||||
var id = $(this).children('td').first().text();
|
||||
var type = $(this).children('td').eq(2).text();
|
||||
|
||||
if(type == 'MASTER') {
|
||||
location.assign('edit-master.php?id=' + id);
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue