From d916632d1b9e48fc50890e9a05c2890e2cd5c39a Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 2 Mar 2026 11:49:41 +0100 Subject: [PATCH] new table service --- WEBROOT/config.php | 7 +++ WEBROOT/controller/DatabaseConnect.php | 2 +- WEBROOT/controller/DatabaseController.php | 67 +++++++++++++++++++++++ WEBROOT/services/tabellen.php | 57 +++++++++++++++++++ WEBROOT/style.css | 48 ++++++++++++++++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 WEBROOT/services/tabellen.php diff --git a/WEBROOT/config.php b/WEBROOT/config.php index 0fb8792..e18c38d 100644 --- a/WEBROOT/config.php +++ b/WEBROOT/config.php @@ -54,6 +54,7 @@ $serviceGroups = array ( array ( 0 => 'api_tester', 1 => 'weather_chart', + 2 => 'tabellen', ), ), ); @@ -149,6 +150,12 @@ $services = array ( 'active' => true, 'adminOnly' => true, ), + 'tabellen' => + array ( + 'name' => 'Tabellen', + 'active' => true, + 'adminOnly' => false, + ), ); $linkGroups = array ( diff --git a/WEBROOT/controller/DatabaseConnect.php b/WEBROOT/controller/DatabaseConnect.php index a0f4742..fb46b21 100644 --- a/WEBROOT/controller/DatabaseConnect.php +++ b/WEBROOT/controller/DatabaseConnect.php @@ -28,7 +28,7 @@ function db_connect() { ] ]; - $enviroment = 'live'; + $enviroment = 'vpn'; $conn = new mysqli( $servers[$enviroment]['hostaddr'], diff --git a/WEBROOT/controller/DatabaseController.php b/WEBROOT/controller/DatabaseController.php index 1095905..79fae4b 100644 --- a/WEBROOT/controller/DatabaseController.php +++ b/WEBROOT/controller/DatabaseController.php @@ -1,5 +1,72 @@ prepare($sql); + + if (!$stmt) { + die("Fehler beim Prepare: " . $conn->error); + } + + if (!$stmt->execute()) { + die("Fehler beim Execute: " . $stmt->error); + } + + return true; +} + +function DatabaseShowTables() { + include_once 'DatabaseConnect.php'; + $conn = db_connect(); + + $tablesResult = $conn->query("SHOW TABLES"); + if (!$tablesResult) { + die("Fehler beim Laden der Tabellen: " . $conn->error); + } + + $tables = []; + + while ($tableRow = $tablesResult->fetch_array()) { + $tables[] = $tableRow[0]; + } + + return $tables; +} + +function DatabaseShowTableStructure($table) { + include_once 'DatabaseConnect.php'; + $conn = db_connect(); + + $stmt = $conn->prepare("SHOW COLUMNS FROM `$table`"); + if (!$stmt) { + die("Fehler beim Prepare: " . $conn->error); + } + + if (!$stmt->execute()) { + die("Fehler beim Execute: " . $stmt->error); + } + + $result = $stmt->get_result(); + + $columns = []; + + while ($column = $result->fetch_assoc()) { + $columns[] = [ + "Field" => $column["Field"], + "Type" => $column["Type"], + "Null" => $column["Null"], + "Key" => $column["Key"], + "Default" => $column["Default"], + "Extra" => $column["Extra"] + ]; + } + + return $columns; +} + function DatabaseShow($table, $columns = "*", $where = "", ...$values) { include_once 'DatabaseConnect.php'; $conn = db_connect(); diff --git a/WEBROOT/services/tabellen.php b/WEBROOT/services/tabellen.php new file mode 100644 index 0000000..0021a57 --- /dev/null +++ b/WEBROOT/services/tabellen.php @@ -0,0 +1,57 @@ + + +

Datenbank Struktur

+ +
+ + + + +
+ +Struktur von: " . htmlspecialchars($selectedTable) . ""; + + echo "
"; + echo ""; + echo " + + + + + + + "; + + foreach ($structure as $column) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + + echo "
FieldTypeNullKeyDefaultExtra
" . htmlspecialchars($column['Field']) . "" . htmlspecialchars($column['Type']) . "" . htmlspecialchars($column['Null']) . "" . htmlspecialchars($column['Key']) . "" . htmlspecialchars($column['Default']) . "" . htmlspecialchars($column['Extra']) . "
"; + echo "
"; +} +?> \ No newline at end of file diff --git a/WEBROOT/style.css b/WEBROOT/style.css index ee0fa30..ec04fab 100644 --- a/WEBROOT/style.css +++ b/WEBROOT/style.css @@ -954,4 +954,52 @@ body.dark-mode .info-key { body.dark-mode .info-value { color: #ccc; +} + +/* ===== Datenbank Struktur Tabelle ===== */ + +.db-table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; + table-layout: fixed; /* sorgt für feste Spaltenbreite */ +} + +.db-table thead { + background-color: var(--btn-bg); + color: var(--btn-text); +} + +.db-table th, +.db-table td { + padding: 12px 15px; + text-align: left; + border-bottom: 1px solid var(--card-border); + + /* Wichtig für gleiche Größe */ + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.db-table tr:hover { + background-color: rgba(0, 123, 255, 0.08); +} + +/* Alternierende Zeilen */ +.db-table tr:nth-child(even) { + background-color: var(--card-bg); +} + +/* Dark Mode */ +body.dark-mode .db-table thead { + background-color: #0056b3; +} + +body.dark-mode .db-table tr:hover { + background-color: rgba(0, 123, 255, 0.15); +} + +body.dark-mode .db-table tr:nth-child(even) { + background-color: #1e1e1e; } \ No newline at end of file