query("SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence'"); $tables = []; while ($row = $tablesResult->fetchArray(SQLITE3_ASSOC)) { $tables[] = $row['name']; } if ($selectedTable && in_array($selectedTable, $tables)) { $_SESSION['selectedTable'] = $selectedTable; $columnsResult = $db->query("PRAGMA table_info($selectedTable)"); while ($row = $columnsResult->fetchArray(SQLITE3_ASSOC)) { $columns[] = $row['name']; } if ($selectedTable == 'content' && in_array('date', $columns)) { $orderBy = "ORDER BY date DESC"; // das hier machen default sorting nach datum und ziiht de neuschti row zerscht will susch isch das unmanagebar } else { $orderBy = in_array('date', $columns) ? "ORDER BY date $sortOrder" : "ORDER BY id ASC"; } $rowsResult = $db->query("SELECT * FROM $selectedTable $orderBy"); while ($row = $rowsResult->fetchArray(SQLITE3_ASSOC)) { $rows[] = $row; } } else { $selectedTable = ''; $_SESSION['selectedTable'] = ''; } if (isset($_POST['edit_row'])) { header("Location: edit_row.php?table=$selectedTable&id=" . $_POST['id']); exit(); } if (isset($_POST['delete_row'])) { $idsToDelete = $_POST['ids'] ?? []; foreach ($idsToDelete as $id) { $stmt = $db->prepare("DELETE FROM $selectedTable WHERE id = :id"); $stmt->bindValue(':id', $id, SQLITE3_INTEGER); $stmt->execute(); } $message = "Selected rows deleted successfully (most likely)."; } if (isset($_POST['insert_row'])) { $values = $_POST['values']; $highestIdResult = $db->querySingle("SELECT MAX(id) as max_id FROM $selectedTable"); $highestId = $highestIdResult ? $highestIdResult : 0; $values['id'] = $highestId + 1; if ($selectedTable == 'content') { if (empty($values['date'])) { $values['date'] = date('Y-m-d H:i:s'); } } $columnsString = implode(", ", array_keys($values)); $placeholders = implode(", ", array_fill(0, count($values), "?")); $stmt = $db->prepare("INSERT INTO $selectedTable ($columnsString) VALUES ($placeholders)"); $index = 1; foreach ($values as $value) { $stmt->bindValue($index, $value ?: null, SQLITE3_TEXT); $index++; } $stmt->execute(); $message = "Row inserted successfully. (maybe)"; } if (isset($_POST['swap_row'])) { $id = $_POST['id']; $targetId = $_POST['target_id']; $db->exec("BEGIN TRANSACTION"); $db->exec("UPDATE $selectedTable SET id = -1 WHERE id = $id"); $db->exec("UPDATE $selectedTable SET id = $id WHERE id = $targetId"); $db->exec("UPDATE $selectedTable SET id = $targetId WHERE id = -1"); $db->exec("COMMIT"); $message = "Row swapped successfully for sure."; } if (isset($_POST['push_row'])) { $id = $_POST['id']; $targetId = $_POST['target_id']; $tempTable = $selectedTable . '_temp'; $db->exec("BEGIN TRANSACTION"); $db->exec("CREATE TEMPORARY TABLE $tempTable AS SELECT * FROM $selectedTable"); $db->exec("UPDATE $tempTable SET id = -1 WHERE id = $id"); if ($id < $targetId) { $db->exec("UPDATE $tempTable SET id = id - 1 WHERE id > $id AND id <= $targetId"); } else { $db->exec("UPDATE $tempTable SET id = id + 1 WHERE id < $id AND id >= $targetId"); } $db->exec("UPDATE $tempTable SET id = $targetId WHERE id = -1"); $db->exec("DELETE FROM $selectedTable"); $db->exec("INSERT INTO $selectedTable SELECT * FROM $tempTable"); $db->exec("DROP TABLE $tempTable"); $db->exec("COMMIT"); $message = "Row pushed successfully (perhaps)."; } if (isset($_POST['reassign_ids'])) { $tempBackup = $backupDir . '/' . $timestamp . '_temp.db'; copy($source, $tempBackup); try { $db->exec("BEGIN TRANSACTION"); $tempTable = $selectedTable . '_temp'; $db->exec("CREATE TEMPORARY TABLE $tempTable AS SELECT * FROM $selectedTable"); $db->exec("DELETE FROM $selectedTable"); if (in_array('date', $columns)) { $orderBy = "ORDER BY date ASC"; } else { $orderBy = "ORDER BY id ASC"; } $rowsResult = $db->query("SELECT * FROM $tempTable $orderBy"); $newId = 1; while ($row = $rowsResult->fetchArray(SQLITE3_ASSOC)) { $row['id'] = $newId++; $columnsString = implode(", ", array_keys($row)); $placeholders = implode(", ", array_fill(0, count($row), "?")); $stmt = $db->prepare("INSERT INTO $selectedTable ($columnsString) VALUES ($placeholders)"); $index = 1; foreach ($row as $value) { $stmt->bindValue($index, $value ?: null, SQLITE3_TEXT); $index++; } $stmt->execute(); } $db->exec("DROP TABLE $tempTable"); $db->exec("COMMIT"); $message = "IDs reassigned successfully."; } catch (Exception $e) { copy($tempBackup, $source); $message = "Failed to reassign IDs. Database restored from backup. (probably)"; } finally { unlink($tempBackup); } } ?> Edit Database

Edit Database

Editing Table:

Select Sort by Date Actions
Select Sort by Datum Actions

No das table selected. Please select das table to editieren.