Added function to delete a complete domain

This commit is contained in:
Lukas Metzger 2016-01-23 20:38:01 +01:00
parent 91a201c783
commit 3f8156939e
3 changed files with 146 additions and 62 deletions

View file

@ -22,6 +22,8 @@ require_once '../lib/session.php';
$input = json_decode(file_get_contents('php://input'));
if(isset($input->action) && $input->action == "getDomains") {
$sql = "
SELECT D.id,D.name,D.type,count(R.domain_id) AS records
FROM domains D
@ -89,5 +91,33 @@ $retval = Array();
while($obj = $result->fetch_object()) {
$retval[] = $obj;
}
}
if(isset($input->action) && $input->action == "deleteDomain") {
$domainId = $input->id;
$db->autocommit(false);
$stmt = $db->prepare("DELETE FROM permissions WHERE domain=?");
$stmt->bind_param("i", $domainId);
$stmt->execute();
$stmt->close();
$stmt = $db->prepare("DELETE FROM records WHERE domain_id=?");
$stmt->bind_param("i", $domainId);
$stmt->execute();
$stmt->close();
$stmt = $db->prepare("DELETE FROM domains WHERE id=?");
$stmt->bind_param("i", $domainId);
$stmt->execute();
$stmt->close();
$db->commit();
}
if(isset($retval)) {
echo json_encode($retval);
} else {
echo "{}";
}

View file

@ -83,5 +83,18 @@ limitations under the License.
</table>
</div>
<div class="modal fade" id="deleteConfirm" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
Are you shure to <strong>delete</strong> the zone <strong><span id="zoneToDelete"></span></strong>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button id="buttonDelete" type="button" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</div>
</body>
</html>

View file

@ -68,6 +68,8 @@ function requestData() {
restrictions.type = searchType;
}
restrictions.action = "getDomains";
$.post(
"api/domains.php",
JSON.stringify(restrictions),
@ -86,7 +88,8 @@ function recreateTable(data) {
.append('<td>' + item.id + '</td>')
.append('<td>' + item.name + '</td>')
.append('<td>' + item.type + '</td>')
.append('<td>' + item.records + '</td>');
.append('<td>' + item.records + '</td>')
.append('<td><span class="glyphicon glyphicon-trash cursor-pointer"></span></td>');
});
@ -98,4 +101,42 @@ function recreateTable(data) {
location.assign('edit-master.php#' + id);
}
});
$('#table-domains>tbody>tr>td>span.glyphicon-trash').click(function() {
$(this).parent().parent().unbind();
deleteDomain.call(this);
});
}
function deleteDomain() {
var deleteId = $(this).parent().parent().children('td').eq(0).text();
var deleteZone = $(this).parent().parent().children('td').eq(1).text();
var rowToRemove = $(this).parent().parent();
$('#zoneToDelete').text(deleteZone);
$('#deleteConfirm #buttonDelete').click(function() {
deleteDomainWithId(deleteId, function() {
$('#deleteConfirm').modal("hide");
$(rowToRemove).remove();
});
});
$('#deleteConfirm').modal();
}
function deleteDomainWithId(id, callback) {
var data = {
action: "deleteDomain",
id: id
};
$.post(
"api/domains.php",
JSON.stringify(data),
function() {
callback();
},
"json"
);
}