From 918d6b561be6a648cb5494ba77f66b625e4aabeb Mon Sep 17 00:00:00 2001 From: mad Date: Mon, 13 Aug 2018 16:49:49 +0200 Subject: [PATCH] delete vm from db --- web/header.php | 19 ++++++++++++++++++- web/index.php | 18 ++++++++++++++++-- web/nlvmi.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/web/header.php b/web/header.php index 8a61474..8f3a065 100644 --- a/web/header.php +++ b/web/header.php @@ -6,8 +6,25 @@ - + nlvmi + +
diff --git a/web/index.php b/web/index.php index 02aa333..ce75943 100644 --- a/web/index.php +++ b/web/index.php @@ -44,6 +44,20 @@ if ($config['DATABASETYPE']=="sqlite"){ 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'); $mode=""; if (isset($_REQUEST['start'])){ @@ -195,7 +209,7 @@ if(isset($_REQUEST['mode'])){ } if($mode!="newvm"){ - echo "Create a new VM
"; + echo "Create a new VM
"; } //getting vms from DB $sql="SELECT * FROM vms"; @@ -207,7 +221,7 @@ while ($row = $res->fetchArray(SQLITE3_ASSOC)){ } else { $button = "stop"; } - echo "
$row[vmname]
edit $button
"; + echo "
$row[vmname]
edit $button
"; } echo "
"; ?> diff --git a/web/nlvmi.js b/web/nlvmi.js index aa2a808..ecf1b6d 100644 --- a/web/nlvmi.js +++ b/web/nlvmi.js @@ -2,3 +2,37 @@ function dropdown(i,e) { document.getElementById(i).innerHTML = 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}); +});