Semi-stable version with old variable names
This commit is contained in:
@@ -21,12 +21,12 @@ check_user_permission('wk_leitung');
|
||||
verify_csrf();
|
||||
|
||||
// Validate input
|
||||
if (!isset($_POST['abt']) || !ctype_digit($_POST['abt'])) {
|
||||
if (!isset($_POST['abtId']) || !ctype_digit($_POST['abtId'])) {
|
||||
http_response_code(406);
|
||||
exit;
|
||||
}
|
||||
|
||||
$abtInput = (int) $_POST['abt'];
|
||||
$abtInputId = (int) $_POST['abtId'];
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
@@ -40,34 +40,27 @@ if ($dbconnection['success'] !== true){
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
// Fetch existing Abteilungen ordered by name
|
||||
$abts = db_select($mysqli, $tableAbt, '*', '', [], 'name ASC');
|
||||
// Fetch existing Abteilungen ordered by order_index
|
||||
$abts = db_select($mysqli, $tableAbt, '*', '', [], 'order_index ASC');
|
||||
|
||||
$deleteId = null;
|
||||
$deleteIndex = null;
|
||||
$indexed_abts = array_column($abts, null, 'id');
|
||||
|
||||
foreach ($abts as $ind => $abt) {
|
||||
if ((int)$abt['name'] === (int)$abtInput) {
|
||||
$deleteId = (int)$abt['id'];
|
||||
$deleteIndex = $ind;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$deleteIndex = $indexed_abts[$abtInputId]['order_index'] ?? null;
|
||||
|
||||
if ($deleteId === null) {
|
||||
if ($deleteIndex === null) {
|
||||
http_response_code(406);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete selected row
|
||||
db_delete($mysqli, $tableAbt, ['id' => $deleteId]);
|
||||
db_delete($mysqli, $tableAbt, ['id' => $abtInputId]);
|
||||
|
||||
// Reindex subsequent rows
|
||||
for ($i = $deleteIndex + 1; $i < count($abts); $i++) {
|
||||
db_update(
|
||||
$mysqli,
|
||||
$tableAbt,
|
||||
['name' => (int)$abts[$i]['name'] - 1],
|
||||
['order_index' => (int)$abts[$i]['order_index'] - 1],
|
||||
['id' => (int)$abts[$i]['id']]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user