From a3ebd21541628914bebd51d6919390f8df6c3a9b Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Sat, 16 Jan 2016 15:46:43 +0100 Subject: [PATCH] Implemented domain overview, permissions are still ignored --- api/domains.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++ domains.php | 34 +++++++++++++++++- include/custom.css | 4 ++- js/domains.js | 80 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 api/domains.php diff --git a/api/domains.php b/api/domains.php new file mode 100644 index 0000000..e9d0b0a --- /dev/null +++ b/api/domains.php @@ -0,0 +1,86 @@ +. + * + * 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); diff --git a/domains.php b/domains.php index 35f26b6..ecbfc7e 100644 --- a/domains.php +++ b/domains.php @@ -46,7 +46,39 @@ limitations under the License.
- + + + + + + + + + + + + +
ID +
+
+ Name + + +
+
+
+
+
+ Type + + +
+
+
Records
+ diff --git a/include/custom.css b/include/custom.css index 9f5cb16..18a856b 100644 --- a/include/custom.css +++ b/include/custom.css @@ -9,4 +9,6 @@ .vspacer-100 { height: 100px; } .vspacer-150 { height: 150px; } -.defaulthidden { display: none; } \ No newline at end of file +.defaulthidden { display: none !important; } + +.cursor-pointer {cursor: pointer; } \ No newline at end of file diff --git a/js/domains.js b/js/domains.js index b87cd6d..3ea9a28 100644 --- a/js/domains.js +++ b/js/domains.js @@ -14,6 +14,84 @@ * limitations under the License. */ +var sort = { + field: "", + order: 1 +} + $(document).ready(function() { + requestData(); -}); \ No newline at end of file + $('#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) { + $('').appendTo('#table-domains>tbody') + .append('' + item.id + '') + .append('' + item.name + '') + .append('' + item.type + '') + .append('' + item.records + ''); + + }); + + $('#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); + } + }); +} \ No newline at end of file