Menü und Anzahl angepasst
This commit is contained in:
119
colors.php
119
colors.php
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start(); // Sicherstellen, dass Session läuft
|
session_start();
|
||||||
if (!isset($_SESSION['user_id'])) {
|
if (!isset($_SESSION['user_id'])) {
|
||||||
header("Location: login.php");
|
header("Location: login.php");
|
||||||
exit();
|
exit();
|
||||||
@@ -7,7 +7,6 @@ if (!isset($_SESSION['user_id'])) {
|
|||||||
|
|
||||||
require_once 'inc/db.php';
|
require_once 'inc/db.php';
|
||||||
|
|
||||||
// Prüfen, ob der aktuelle Benutzer Admin ist
|
|
||||||
$is_admin = ($_SESSION['role'] === 'admin');
|
$is_admin = ($_SESSION['role'] === 'admin');
|
||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
@@ -28,15 +27,14 @@ if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'delete' && isset(
|
|||||||
$message_type = 'danger';
|
$message_type = 'danger';
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
// Weiterleitung verhindert doppeltes Löschen beim Reload
|
|
||||||
header("Location: colors.php");
|
header("Location: colors.php");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Nur Admins: Bearbeiten (Vorbereitung) ---
|
// --- Nur Admins: Bearbeiten ---
|
||||||
if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
||||||
$id = (int)$_GET['id'];
|
$id = (int)$_GET['id'];
|
||||||
$stmt = mysqli_prepare($conn, "SELECT id, name, hex_code FROM colors WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "SELECT id, name, hex_code, is_special FROM colors WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
@@ -50,10 +48,11 @@ if ($is_admin && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Nur Admins: Hinzufügen / Aktualisieren ---
|
// --- Nur Admins: Speichern ---
|
||||||
if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
$hex_code = trim($_POST['hex_code'] ?? '');
|
$hex_code = trim($_POST['hex_code'] ?? '');
|
||||||
|
$is_special = !empty($_POST['is_special']) ? 1 : 0;
|
||||||
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
|
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
|
||||||
|
|
||||||
if (empty($name) || empty($hex_code)) {
|
if (empty($name) || empty($hex_code)) {
|
||||||
@@ -61,37 +60,40 @@ if ($is_admin && $_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
$message_type = 'danger';
|
$message_type = 'danger';
|
||||||
} else {
|
} else {
|
||||||
if ($id) {
|
if ($id) {
|
||||||
$stmt = mysqli_prepare($conn, "UPDATE colors SET name = ?, hex_code = ? WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "UPDATE colors SET name = ?, hex_code = ?, is_special = ? WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "ssi", $name, $hex_code, $id);
|
mysqli_stmt_bind_param($stmt, "ssii", $name, $hex_code, $is_special, $id);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
|
||||||
$message = "Farbe erfolgreich aktualisiert!";
|
|
||||||
$message_type = 'success';
|
|
||||||
} else {
|
|
||||||
$message = "Fehler beim Aktualisieren der Farbe.";
|
|
||||||
$message_type = 'danger';
|
|
||||||
}
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
} else {
|
} else {
|
||||||
$stmt = mysqli_prepare($conn, "INSERT INTO colors (name, hex_code) VALUES (?, ?)");
|
$stmt = mysqli_prepare($conn, "INSERT INTO colors (name, hex_code, is_special) VALUES (?, ?, ?)");
|
||||||
mysqli_stmt_bind_param($stmt, "ss", $name, $hex_code);
|
mysqli_stmt_bind_param($stmt, "ssi", $name, $hex_code, $is_special);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
|
||||||
$message = "Neue Farbe erfolgreich hinzugefügt!";
|
|
||||||
$message_type = 'success';
|
|
||||||
} else {
|
|
||||||
$message = "Fehler beim Hinzufügen der Farbe.";
|
|
||||||
$message_type = 'danger';
|
|
||||||
}
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
}
|
}
|
||||||
// Nach POST: Weiterleitung zur Anzeige (Post-Redirect-Get)
|
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
$message = $id ? "Farbe erfolgreich aktualisiert!" : "Neue Farbe erfolgreich hinzugefügt!";
|
||||||
|
$message_type = 'success';
|
||||||
|
} else {
|
||||||
|
$message = "Fehler beim Speichern der Farbe.";
|
||||||
|
$message_type = 'danger';
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
header("Location: colors.php");
|
header("Location: colors.php");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Farben für alle anzeigen ---
|
// --- Farben mit Nutzungszähler laden ---
|
||||||
$colors = [];
|
$colors = [];
|
||||||
$result = mysqli_query($conn, "SELECT id, name, hex_code FROM colors ORDER BY name");
|
$result = mysqli_query($conn, "
|
||||||
|
SELECT
|
||||||
|
c.id,
|
||||||
|
c.name,
|
||||||
|
c.hex_code,
|
||||||
|
c.is_special,
|
||||||
|
COUNT(m.id) AS usage_count
|
||||||
|
FROM colors c
|
||||||
|
LEFT JOIN meetings m ON c.id = m.color_id
|
||||||
|
GROUP BY c.id, c.name, c.hex_code, c.is_special
|
||||||
|
ORDER BY c.name
|
||||||
|
");
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
$colors[] = $row;
|
$colors[] = $row;
|
||||||
}
|
}
|
||||||
@@ -110,11 +112,6 @@ require_once 'inc/header.php';
|
|||||||
|
|
||||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<h2 class="mb-0">Farbverwaltung</h2>
|
<h2 class="mb-0">Farbverwaltung</h2>
|
||||||
<?php if ($is_admin): ?>
|
|
||||||
<a class="btn btn-sm btn-outline-primary d-flex align-items-center" data-bs-toggle="collapse" href="#colorFormCollapse" role="button">
|
|
||||||
<span class="material-symbols-outlined me-1">add</span> Farbe hinzufügen
|
|
||||||
</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($is_admin): ?>
|
<?php if ($is_admin): ?>
|
||||||
@@ -139,6 +136,14 @@ require_once 'inc/header.php';
|
|||||||
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code"
|
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code"
|
||||||
value="<?= htmlspecialchars($edit_color['hex_code'] ?? '#000000'); ?>">
|
value="<?= htmlspecialchars($edit_color['hex_code'] ?? '#000000'); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="is_special" name="is_special" <?= (!empty($edit_color['is_special']) ? 'checked' : ''); ?>>
|
||||||
|
<label class="form-check-label" for="is_special">
|
||||||
|
Sonderfarbe (wird nicht im Zufallsmodus verwendet)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="col-12 d-flex justify-content-start mt-2">
|
<div class="col-12 d-flex justify-content-start mt-2">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> me-2">
|
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> me-2">
|
||||||
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
||||||
@@ -149,13 +154,17 @@ require_once 'inc/header.php';
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="mt-4 mb-4">
|
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow">
|
<div class="card shadow">
|
||||||
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
<div class="card-header bg-secondary bg-opacity-50 text-secondary d-flex justify-content-between align-items-center">
|
||||||
<h4 class="mb-0">Aktuelle Farben</h4>
|
<h4 class="mb-0">Aktuelle Farben</h4>
|
||||||
|
<?php if ($is_admin): ?>
|
||||||
|
<a class="btn btn-sm d-flex align-items-center justify-content-center" data-bs-toggle="collapse" href="#colorFormCollapse" role="button" aria-expanded="false" aria-controls="colorFormCollapse">Add
|
||||||
|
<span class="material-symbols-outlined">add</span>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<?php if (empty($colors)): ?>
|
<?php if (empty($colors)): ?>
|
||||||
@@ -166,8 +175,8 @@ require_once 'inc/header.php';
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Hex-Code</th>
|
|
||||||
<th>Farbe</th>
|
<th>Farbe</th>
|
||||||
|
<th>Anz</th>
|
||||||
<?php if ($is_admin): ?>
|
<?php if ($is_admin): ?>
|
||||||
<th>Aktionen</th>
|
<th>Aktionen</th>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -176,19 +185,37 @@ require_once 'inc/header.php';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($colors as $color): ?>
|
<?php foreach ($colors as $color): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= htmlspecialchars($color['name']); ?></td>
|
<td>
|
||||||
<td><?= htmlspecialchars($color['hex_code']); ?></td>
|
<?= htmlspecialchars($color['name']); ?>
|
||||||
|
<?php if ($color['is_special']): ?>
|
||||||
|
<span class="badge bg-info ms-1" title="Sonderfarbe – nicht im Zufallsmodus">★</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div style="background-color: <?= htmlspecialchars($color['hex_code']); ?>; width: 40px; height: 20px; border: 1px solid #ccc;"></div>
|
<div style="background-color: <?= htmlspecialchars($color['hex_code']); ?>; width: 40px; height: 20px; border: 1px solid #ccc;"></div>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<?= (int)$color['usage_count']; ?>
|
||||||
|
</td>
|
||||||
<?php if ($is_admin): ?>
|
<?php if ($is_admin): ?>
|
||||||
<td>
|
<td class="text-end align-middle">
|
||||||
<a href="colors.php?action=edit&id=<?= htmlspecialchars($color['id']); ?>" class="text-dark me-1 text-decoration-none">
|
<div class="dropdown">
|
||||||
<span class="material-icons">mode_edit_outline</span>
|
<a href="#" class="text-secondary" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
</a>
|
<span class="material-icons">more_vert</span>
|
||||||
<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?');">
|
</a>
|
||||||
<span class="material-icons">delete_outline</span>
|
<ul class="dropdown-menu dropdown-menu-end">
|
||||||
</a>
|
<li>
|
||||||
|
<a class="dropdown-item d-flex align-items-center" href="colors.php?action=edit&id=<?= htmlspecialchars($color['id']); ?>">
|
||||||
|
<span class="material-icons me-2">mode_edit_outline</span> Bearbeiten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item d-flex align-items-center text-danger" href="colors.php?action=delete&id=<?= htmlspecialchars($color['id']); ?>" onclick="return confirm('Sind Sie sicher, dass Sie diese Farbe löschen möchten?');">
|
||||||
|
<span class="material-icons me-2">delete_outline</span> Löschen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user