Änderung zurückgenommen
This commit is contained in:
@@ -3,15 +3,12 @@ include('../inc/check_login.php');
|
|||||||
include('../inc/check_admin.php');
|
include('../inc/check_admin.php');
|
||||||
require_once '../inc/db.php';
|
require_once '../inc/db.php';
|
||||||
|
|
||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
$message_type = '';
|
$message_type = '';
|
||||||
$edit_mode = false;
|
$edit_mode = false;
|
||||||
$edit_color = null;
|
$edit_color = null;
|
||||||
|
|
||||||
// --- Logik zum Hinzufügen, Bearbeiten und Löschen von Farben ---
|
// --- Löschen ---
|
||||||
|
|
||||||
// Aktion Löschen
|
|
||||||
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
|
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$stmt = mysqli_prepare($conn, "DELETE FROM colors WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "DELETE FROM colors WHERE id = ?");
|
||||||
@@ -26,7 +23,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
|
|||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktion Bearbeiten (Formular laden)
|
// --- Bearbeiten ---
|
||||||
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$stmt = mysqli_prepare($conn, "SELECT id, name, hex_code FROM colors WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "SELECT id, name, hex_code FROM colors WHERE id = ?");
|
||||||
@@ -38,13 +35,13 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
|||||||
$edit_mode = true;
|
$edit_mode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktion Hinzufügen oder Speichern (POST)
|
// --- Hinzufügen / Aktualisieren ---
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$name = $_POST['name'];
|
$name = $_POST['name'];
|
||||||
$hex_code = $_POST['hex_code'];
|
$hex_code = $_POST['hex_code'];
|
||||||
$id = $_POST['id'] ?? null;
|
$id = $_POST['id'] ?? null;
|
||||||
|
|
||||||
if ($id) { // Update-Logik
|
if ($id) {
|
||||||
$stmt = mysqli_prepare($conn, "UPDATE colors SET name = ?, hex_code = ? WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "UPDATE colors SET name = ?, hex_code = ? WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "ssi", $name, $hex_code, $id);
|
mysqli_stmt_bind_param($stmt, "ssi", $name, $hex_code, $id);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
@@ -55,7 +52,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
$message_type = 'danger';
|
$message_type = 'danger';
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
} else { // Insert-Logik
|
} else {
|
||||||
$stmt = mysqli_prepare($conn, "INSERT INTO colors (name, hex_code) VALUES (?, ?)");
|
$stmt = mysqli_prepare($conn, "INSERT INTO colors (name, hex_code) VALUES (?, ?)");
|
||||||
mysqli_stmt_bind_param($stmt, "ss", $name, $hex_code);
|
mysqli_stmt_bind_param($stmt, "ss", $name, $hex_code);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
@@ -69,7 +66,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Logik zum Auslesen aller Farben ---
|
// --- Farben auslesen ---
|
||||||
$colors = [];
|
$colors = [];
|
||||||
$result = mysqli_query($conn, "SELECT id, name, hex_code FROM colors ORDER BY name");
|
$result = mysqli_query($conn, "SELECT id, name, hex_code FROM colors ORDER BY name");
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
@@ -83,38 +80,38 @@ require_once '../inc/header.php';
|
|||||||
<h2 class="mb-4">Farbverwaltung</h2>
|
<h2 class="mb-4">Farbverwaltung</h2>
|
||||||
|
|
||||||
<?php if ($message) : ?>
|
<?php if ($message) : ?>
|
||||||
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
|
<div class="alert alert-<?= $message_type ?> alert-dismissible fade show" role="alert">
|
||||||
<?php echo htmlspecialchars($message); ?>
|
<?= htmlspecialchars($message) ?>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header bg-primary-subtle text-secondary">
|
<div class="card-header bg-primary-subtle text-secondary">
|
||||||
<h4 class="mb-0"><?php echo $edit_mode ? 'Farbe bearbeiten' : 'Neue Farbe hinzufügen'; ?></h4>
|
<h4 class="mb-0"><?= $edit_mode ? 'Farbe bearbeiten' : 'Neue Farbe hinzufügen'; ?></h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form action="colors.php" method="post">
|
<form action="colors.php" method="post">
|
||||||
<?php if ($edit_mode): ?>
|
<?php if ($edit_mode): ?>
|
||||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_color['id']); ?>">
|
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_color['id']); ?>">
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="row g-1 align-items-end">
|
<div class="row g-3">
|
||||||
<div class="col-md-5">
|
<div class="col-md-6">
|
||||||
<label for="name" class="form-label">Name der Farbe</label>
|
<label for="name" class="form-label">Name der Farbe</label>
|
||||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($edit_color['name'] ?? ''); ?>" required>
|
<input type="text" class="form-control" id="name" name="name"
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
value="<?= htmlspecialchars($edit_color['name'] ?? ''); ?>" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-5">
|
<div class="col-md-6">
|
||||||
<label for="hex_code" class="form-label">Hex-Code</label>
|
<label for="hex_code" class="form-label">Hex-Code</label>
|
||||||
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code" value="<?php echo htmlspecialchars($edit_color['hex_code'] ?? '#'); ?>">
|
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code"
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
value="<?= htmlspecialchars($edit_color['hex_code'] ?? '#'); ?>">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 d-flex justify-content-start">
|
<div class="col-12 d-flex justify-content-start mt-2">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2 d-flex align-items-center">
|
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> me-2">
|
||||||
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
||||||
</button>
|
</button>
|
||||||
<?php if ($edit_mode): ?>
|
<?php if ($edit_mode): ?>
|
||||||
<a href="colors.php" class="btn btn-sm btn-outline-secondary w-auto d-flex align-items-center">Abbrechen</a>
|
<a href="colors.php" class="btn btn-sm btn-outline-secondary">Abbrechen</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -143,16 +140,16 @@ require_once '../inc/header.php';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($colors as $color): ?>
|
<?php foreach ($colors as $color): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars($color['name']); ?></td>
|
<td><?= htmlspecialchars($color['name']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($color['hex_code']); ?></td>
|
<td><?= htmlspecialchars($color['hex_code']); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="color-preview" style="background-color: <?php echo htmlspecialchars($color['hex_code']); ?>"></div>
|
<div style="background-color: <?= htmlspecialchars($color['hex_code']); ?>; width: 40px; height: 20px; border: 1px solid #ccc;"></div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="colors.php?action=edit&id=<?php echo htmlspecialchars($color['id']); ?>" class="text-dark me-1 text-decoration-none">
|
<a href="colors.php?action=edit&id=<?= htmlspecialchars($color['id']); ?>" class="text-dark me-1 text-decoration-none">
|
||||||
<span class="material-icons">mode_edit_outline</span>
|
<span class="material-icons">mode_edit_outline</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="colors.php?action=delete&id=<?php echo htmlspecialchars($color['id']); ?>" class="text-danger text-decoration-none" onclick="return confirm('Sind Sie sicher, dass Sie diese Farbe löschen möchten?');">
|
<a href="colors.php?action=delete&id=<?= htmlspecialchars($color['id']); ?>" class="text-danger text-decoration-none" onclick="return confirm('Sind Sie sicher, dass Sie diese Farbe löschen möchten?');">
|
||||||
<span class="material-icons">delete_outline</span>
|
<span class="material-icons">delete_outline</span>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -164,7 +161,6 @@ require_once '../inc/header.php';
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php include('../inc/footer.php'); ?>
|
<?php include('../inc/footer.php'); ?>
|
||||||
Reference in New Issue
Block a user