diff --git a/web/index.php b/web/index.php index 4b79e23..5934639 100644 --- a/web/index.php +++ b/web/index.php @@ -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 ""; - //echo "