move prio upon delete

This commit is contained in:
nativemad 2018-10-24 12:20:36 +02:00
parent 3581d8ec80
commit daabc3d8a0
1 changed files with 23 additions and 13 deletions

View File

@ -144,6 +144,25 @@ if (isset($_SESSION['username'])){
$sql="SELECT id,prio FROM vms WHERE vmname='$vmname' AND id='$vmid'";
$res = $db_handle->query($sql);
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
$prio = $row['prio'];
$nextprio = $prio + 1;
$lastprio = "no";
while ($lastprio == "no"){
$sqln="SELECT id FROM vms WHERE prio='$nextprio'";
$nid = $db_handle->query($sqln)->fetchArray(SQLITE3_ASSOC)['id'];
if($nid == ""){
$lastprio = "yes";
} else {
$sqlu="UPDATE vms SET prio='$prio' WHERE id='$nid'";
if (!$db_handle->query($sqlu)){
echo "SQL $sqlu failed!";
exit;
} else {
$nextprio = $nextprio + 1;
$prio = $prio + 1;
}
}
}
$sqld="DELETE FROM vms WHERE id='$vmid'";
if ($db_handle->query($sqld)){
echo "VM $vmname deleted!";
@ -313,12 +332,9 @@ if (isset($_SESSION['username'])){
$sqlv .= "'$rvalue',";
}
}
// $sqlc = rtrim($sqlc, ',');
$sqlc.=" 'prio')";
// $sqlv = rtrim($sqlv, ',');
$sqlv.=" '$prio')";
$sql = "$sqls$sqlc$sqlv";
//echo $sql;
$res = $db_handle->exec($sql);
echo "success";
exit;
@ -416,8 +432,7 @@ if (isset($_SESSION['username'])){
if (($_SESSION['username']=="inituser")||($_SESSION['isadmin']=="1")){
$sql="SELECT * FROM users";
$res = $db_handle->query($sql);
echo "</br>";
//echo "<div class=row><div class=col>Username</div><div class=col>Is Admin</div><div class=col>New Password</div></div>";
echo "</br>";
if ($_SESSION['username']!="inituser"){
echo "<h2>Existing users</h2>";
}
@ -452,7 +467,6 @@ if (isset($_SESSION['username'])){
$sql="SELECT * FROM servers";
$res = $db_handle->query($sql);
echo "</br>";
//echo "<div class=row><div class=col>Username</div><div class=col>Is Admin</div><div class=col>New Password</div></div>";
echo "<h2>Existing servers</h2>";
echo "<div class=row><div class=col>hostname</div><div class=col>connectstring</div><div class=col>VM directory</div><div class=col>ISO directory</div><div class=col></div></div>";
while ($row = $res->fetchArray(SQLITE3_ASSOC)){
@ -550,7 +564,7 @@ if (isset($_SESSION['username'])){
}
$server = $e['server'];
for ($col=0; $col <count($arrColnames); $col++){
if ($arrColnames[$col]!="id"){
if (($arrColnames[$col]!="id")&&($arrColnames[$col]!="prio")){
if (isset($e[$arrColnames[$col]])){
$val = $e[$arrColnames[$col]];
} else {
@ -583,7 +597,6 @@ if (isset($_SESSION['username'])){
echo "<div class=dropdown-menu aria-labelledby=archbutton>";
echo "<a class=dropdown-item href=\"javascript:dropdown('archbutton','x86_64')\">x86_64</a>";
echo "</div></div></div></div><input type=hidden id=archbuttonh name=arch value=x86_64>";
// echo "$arrColnames[$col] <select name=arch><option value=qemu-system-x86_64>x86_64</option></select></br>";
} elseif (preg_match('/format/', $arrColnames[$col])){
formatbuttons($arrColnames[$col], $val);
} elseif ($arrColnames[$col] == "autostart"){
@ -593,7 +606,6 @@ if (isset($_SESSION['username'])){
}
echo "<div class=row><div class=col-md-1 style=text-align:right>autostart</div><div class=col-md-2><input data-onstyle=\"success\" data-offstyle=danger name=autostart id=\"autostart\" type=\"checkbox\" data-toggle=\"toggle\" data-on=\"boot with host\" data-off=\"no autostart\" $checked></div></div>";
} elseif ($arrColnames[$col] == "cdrom"){
//echo "<div id=cdromdiv>";
serverdepropdown($server, $val, "cdrom");
echo "</div>";
} elseif (preg_match('/tapdev/', $arrColnames[$col])) {
@ -630,7 +642,7 @@ if (isset($_SESSION['username'])){
if(($mode!="newvm")&&($mode!="editvm")&&($mode!='usermgmt')){
if ($_SESSION['isadmin']=="1"){
if ($_SESSION['isadmin']=="1"){
$sqllimit="";
echo "</br><a class=\"btn btn-primary\" href=# onclick=\"post('?', {newvm: 'newvm'});\">Create a new VM</a></br></br>";
} else {
@ -651,9 +663,7 @@ if (isset($_SESSION['username'])){
$buttonc = "btn-warning";
}
$vncport = sprintf("%02d", $row['vncport']);
echo "<div >";
//style=\"margin:5px;padding:5px;border:solid 1px;max-width:295px;\">
echo "<button type=button onclick=\"arrow('up', '$row[id]');\" class=\"btn btn-default\" aria-label=\"Left Align\"><span><img src=arrowup.png width=6px ></span></button><br/>";
echo "<div><button type=button onclick=\"arrow('up', '$row[id]');\" class=\"btn btn-default\" aria-label=\"Left Align\"><span><img src=arrowup.png width=6px ></span></button><br/>";
echo "<button type=button onclick=\"arrow('down', '$row[id]');\" class=\"btn btn-default\" aria-label=\"Left Align\"><span><img src=arrowdown.png width=6px></span></button></div>";
echo "<div class=col-sm><b>$row[vmname]</b></div><div class=col-sm>$row[server]</div><div class=col-sm>$row[cpus] CPUs, $row[memory] MB RAM</div><div class=col-sm>$row[drive1]</div>";
echo "<div class=col-sm>VNC port: 59$vncport</div><div class-col-sm><a class=\"btn btn-primary\" href=# onclick=\"post('?', {edit: '$row[id]'});\">edit</a> ";