delete vm from db

This commit is contained in:
mad 2018-08-13 16:49:49 +02:00
parent ce8f08776d
commit 918d6b561b
3 changed files with 68 additions and 3 deletions

View File

@ -6,8 +6,25 @@
<script src="jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script> <script src="popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> <script src="bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="nlvmi.js"></script>
<title>nlvmi</title> <title>nlvmi</title>
</head> </head>
<body> <body>
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" id="modaltext1">
Are you sure?
</div>
<div class="modal-body" id="modaltext2">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-danger btn-ok">Delete</a>
</div>
</div>
</div>
</div>
<script src="nlvmi.js"></script>
<div class=container-fluid><div class="row" style="background-color:lightgreen;"><div class="col"><h1><a href="?" style=color:white;>nlvmi</a></h1></div></div> <div class=container-fluid><div class="row" style="background-color:lightgreen;"><div class="col"><h1><a href="?" style=color:white;>nlvmi</a></h1></div></div>

View File

@ -44,6 +44,20 @@ if ($config['DATABASETYPE']=="sqlite"){
exit; exit;
} }
} }
if ((isset($_POST['deletevm']))&&(isset($_POST['deletename']))){
$vmname = clean($_POST['deletename']);
$vmid = clean($_POST['deletevm']);
$sql="SELECT id FROM vms WHERE vmname='$vmname' AND id='$vmid'";
$res = $db_handle->query($sql);
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
$sqld="DELETE FROM vms WHERE id='$vmid'";
if ($db_handle->query($sqld)){
echo "VM $vmname deleted!";
}
}
}
include('header.php'); include('header.php');
$mode=""; $mode="";
if (isset($_REQUEST['start'])){ if (isset($_REQUEST['start'])){
@ -195,7 +209,7 @@ if(isset($_REQUEST['mode'])){
} }
if($mode!="newvm"){ if($mode!="newvm"){
echo "<a href=?newvm>Create a new VM</a></br>"; echo "<a class=\"btn btn-primary\" href=?newvm>Create a new VM</a></br>";
} }
//getting vms from DB //getting vms from DB
$sql="SELECT * FROM vms"; $sql="SELECT * FROM vms";
@ -207,7 +221,7 @@ while ($row = $res->fetchArray(SQLITE3_ASSOC)){
} else { } else {
$button = "stop"; $button = "stop";
} }
echo "<div class=col style=\"border:solid 1px;\">$row[vmname]</br><a class=\"btn btn-primary\" href=?edit=$row[id]>edit</a> <a href=?$button=$row[vmname] class=\"btn btn-primary\">$button</a></div>"; echo "<div class=col style=\"border:solid 1px;\">$row[vmname]</br><a class=\"btn btn-primary\" href=?edit=$row[id]>edit</a> <a href=?$button=$row[vmname] class=\"btn btn-primary\">$button</a> <button class=\"btn btn-default\" data-delete-text=\"Delete VM $row[vmname]!\" data-delete-vm=\"$row[id]\" data-delete-name=\"$row[vmname]\" data-toggle=\"modal\" data-target=\"#confirm-delete\">Delete VM</button></div>";
} }
echo "</div></div></body></html>"; echo "</div></div></body></html>";
?> ?>

View File

@ -2,3 +2,37 @@ function dropdown(i,e) {
document.getElementById(i).innerHTML = e; document.getElementById(i).innerHTML = e;
document.getElementById(i +'h').value = e; document.getElementById(i +'h').value = e;
} }
function post(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
$('#confirm-delete').on('click', '.btn-ok', function(e) {
var $modalDiv = $('#confirm-detele'.delegateTarget);
var vmname = $(this).data('deleteName');
var vmid = $(this).data('deleteVm');
post('?', {deletevm: vmid,deletename: vmname});
});
$('#confirm-delete').on('show.bs.modal', function(e) {
var data = $(e.relatedTarget).data();
$('.title', this).text(data.deleteVm);
document.getElementById('modaltext2').innerHTML = data.deleteText;
$('.btn-ok', this).data({'deleteName': data.deleteName,'deleteVm': data.deleteVm});
});