Layout angepasst

This commit is contained in:
Borgal
2025-08-12 00:27:34 +02:00
parent e2f4a1f521
commit 1fc70bf275
3 changed files with 361 additions and 37 deletions

View File

@@ -96,7 +96,7 @@ require_once '../inc/header.php';
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_color['id']); ?>">
<?php endif; ?>
<div class="row g-3 align-items-end">
<div class="row g-1 align-items-end">
<div class="col-md-5">
<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>
@@ -105,18 +105,17 @@ require_once '../inc/header.php';
<div class="col-md-5">
<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'] ?? '#'); ?>">
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-2 d-flex flex-column justify-content-end">
<div class="d-flex w-100">
<button type="submit" class="btn btn-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-100 me-2">
<div class="col-12 d-flex justify-content-start">
<button type="submit" class="btn btn-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="colors.php" class="btn btn-secondary w-100">Abbrechen</a>
<a href="colors.php" class="btn btn-secondary w-auto">Abbrechen</a>
<?php endif; ?>
</div>
</div>
</div>
</form>
</div>
</div>

259
admin/meetings.php Executable file
View File

@@ -0,0 +1,259 @@
<?php
include('../inc/check_login.php');
require_once('../inc/db.php');
$message = '';
$message_type = '';
$edit_mode = false;
$edit_meeting = null;
// Nur Admins haben Zugriff
if ($_SESSION['role'] !== 'admin') {
die("Zugriff nur für Admins");
}
// --- Funktion zur gewichteten zufälligen Farbauswahl ---
function get_weighted_random_color($conn)
{
// 1. Alle Farben abrufen
$all_colors = [];
$result_all = mysqli_query($conn, "SELECT id FROM colors");
while ($row = mysqli_fetch_assoc($result_all)) {
$all_colors[] = $row['id'];
}
if (empty($all_colors)) {
return null; // Keine Farben vorhanden
}
// 2. Anzahl der Farben als "Sperrzeit"
$color_count = count($all_colors);
// 3. Kürzlich verwendete Farben abrufen
$used_colors_id = [];
$stmt = mysqli_prepare($conn, "SELECT color_id FROM meetings ORDER BY meeting_date DESC LIMIT ?");
mysqli_stmt_bind_param($stmt, "i", $color_count);
mysqli_stmt_execute($stmt);
$result_used = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result_used)) {
$used_colors_id[] = $row['color_id'];
}
mysqli_stmt_close($stmt);
// 4. Farben-Pool erstellen
$color_pool = [];
foreach ($all_colors as $color_id) {
if (in_array($color_id, $used_colors_id)) {
// Kürzlich verwendete Farben haben 1x Chance
$color_pool[] = $color_id;
} else {
// Andere Farben haben 3x Chance
$color_pool[] = $color_id;
$color_pool[] = $color_id;
$color_pool[] = $color_id;
}
}
// 5. Zufällige Farbe aus dem Pool auswählen
shuffle($color_pool);
return $color_pool[0];
}
// --- Logik zum Löschen und Bearbeiten von Terminen ---
// Aktion Löschen
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = mysqli_prepare($conn, "DELETE FROM meetings WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
if (mysqli_stmt_execute($stmt)) {
$message = "Termin erfolgreich gelöscht!";
$message_type = 'success';
} else {
$message = "Fehler beim Löschen des Termins.";
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
}
// Aktion Bearbeiten (Formular laden)
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id FROM meetings WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$edit_meeting = mysqli_fetch_assoc($result);
mysqli_stmt_close($stmt);
$edit_mode = true;
}
// --- Logik zum Hinzufügen oder Speichern von Terminen (POST) ---
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$meeting_date = $_POST['meeting_date'];
$color_id = $_POST['color_id'];
$id = $_POST['id'] ?? null;
if ($id) { // Update-Logik
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sii", $meeting_date, $color_id, $id);
if (mysqli_stmt_execute($stmt)) {
$message = "Termin erfolgreich aktualisiert!";
$message_type = 'success';
} else {
$message = "Fehler beim Aktualisieren des Termins.";
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
} else { // Insert-Logik
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id) VALUES (?, ?)");
mysqli_stmt_bind_param($stmt, "si", $meeting_date, $color_id);
if (mysqli_stmt_execute($stmt)) {
$message = "Neuer Termin erfolgreich hinzugefügt!";
$message_type = 'success';
} else {
$message = "Fehler beim Hinzufügen des Termins.";
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
}
}
// --- Nächste 2 Donnerstage automatisch hinzufügen ---
$date = new DateTime('now');
$date->modify('next thursday');
for ($i = 0; $i < 2; $i++) {
$next_thursday = $date->format('Y-m-d');
$stmt = mysqli_prepare($conn, "SELECT id FROM meetings WHERE meeting_date = ?");
mysqli_stmt_bind_param($stmt, "s", $next_thursday);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) == 0) {
$color_id = get_weighted_random_color($conn);
if ($color_id) {
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id) VALUES (?, ?)");
mysqli_stmt_bind_param($stmt_insert, "si", $next_thursday, $color_id);
mysqli_stmt_execute($stmt_insert);
mysqli_stmt_close($stmt_insert);
}
}
mysqli_stmt_close($stmt);
$date->modify('+1 week');
}
// --- Termine und alle Farben abrufen (für Übersicht und Formular) ---
$all_colors = [];
$result = mysqli_query($conn, "SELECT id, name, hex_code FROM colors ORDER BY name");
while ($row = mysqli_fetch_assoc($result)) {
$all_colors[] = $row;
}
$meetings = [];
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, c.name AS color_name, c.hex_code FROM meetings m JOIN colors c ON m.color_id = c.id ORDER BY m.meeting_date");
while ($row = mysqli_fetch_assoc($result)) {
$meetings[] = $row;
}
require_once '../inc/header.php';
?>
<div class="container mt-5">
<h2 class="mb-4">Terminverwaltung</h2>
<?php if ($message) : ?>
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
<?php echo htmlspecialchars($message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<div class="card shadow mb-4">
<div class="card-header bg-primary text-white">
<h4 class="mb-0"><?php echo $edit_mode ? 'Termin bearbeiten' : 'Neuen Termin hinzufügen'; ?></h4>
</div>
<div class="card-body">
<form action="meetings.php" method="post">
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_meeting['id']); ?>">
<?php endif; ?>
<div class="row g-1 align-items-end">
<div class="col-md-6">
<label for="meeting_date" class="form-label">Datum</label>
<input type="date" class="form-control" id="meeting_date" name="meeting_date" value="<?php echo htmlspecialchars($edit_meeting['meeting_date'] ?? ''); ?>" required>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-6">
<label for="color_id" class="form-label">Farbe</label>
<select class="form-select" id="color_id" name="color_id" required>
<?php foreach ($all_colors as $color): ?>
<option value="<?php echo htmlspecialchars($color['id']); ?>" <?php echo (($edit_meeting['color_id'] ?? '') == $color['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($color['name']); ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-12 d-flex justify-content-start">
<button type="submit" class="btn btn-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="meetings.php" class="btn btn-secondary w-auto">Abbrechen</a>
<?php endif; ?>
</div>
</div>
</form>
</div>
</div>
<div class="card shadow">
<div class="card-header bg-secondary text-white">
<h4 class="mb-0">Übersicht der Termine</h4>
</div>
<div class="card-body">
<?php if (empty($meetings)): ?>
<p class="text-muted text-center">Es sind noch keine Termine vorhanden.</p>
<?php else: ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Datum</th>
<th>Farbe</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($meetings as $meeting): ?>
<tr>
<td><?php echo date('d.m.Y', strtotime($meeting['meeting_date'])); ?></td>
<td>
<div class="d-flex align-items-center">
<div class="color-preview rounded me-2" style="background-color: <?php echo htmlspecialchars($meeting['hex_code']); ?>;"></div>
<span><?php echo htmlspecialchars($meeting['color_name']); ?></span>
</div>
</td>
<td>
<a href="meetings.php?action=edit&id=<?php echo htmlspecialchars($meeting['id']); ?>" class="text-dark me-1 text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Bearbeiten">
<span class="material-icons">mode_edit_outline</span>
</a>
<a href="meetings.php?action=delete&id=<?php echo htmlspecialchars($meeting['id']); ?>" class="text-danger text-decoration-none" onclick="return confirm('Sind Sie sicher, dass Sie diesen Termin löschen möchten?');" data-bs-toggle="tooltip" data-bs-placement="top" title="Löschen">
<span class="material-icons">delete_outline</span>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php include('../inc/footer.php'); ?>

View File

@@ -2,7 +2,7 @@
include('../inc/check_login.php');
require_once('../inc/db.php');
// Zugriff nur für eingeloggte Admins
// Nur Admins haben Zugriff
if ($_SESSION['role'] !== 'admin') {
die("Zugriff nur für Admins");
}
@@ -12,20 +12,75 @@ $message_type = '';
$edit_mode = false;
$edit_user = null;
// Benutzer hinzufügen
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['username'], $_POST['password'], $_POST['role'])) {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$role = $_POST['role'] === 'admin' ? 'admin' : 'member';
// --- Logik zum Löschen und Bearbeiten von Benutzern ---
$sql = "INSERT INTO users (username, password, role) VALUES ('$username', '$password', '$role')";
if (mysqli_query($conn, $sql)) {
// Aktion Löschen
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = mysqli_prepare($conn, "DELETE FROM users WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
if (mysqli_stmt_execute($stmt)) {
$message = "Benutzer erfolgreich gelöscht!";
$message_type = 'success';
} else {
$message = "Fehler beim Löschen des Benutzers.";
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
}
// Aktion Bearbeiten (Formular laden)
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = mysqli_prepare($conn, "SELECT id, username, role FROM users WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$edit_user = mysqli_fetch_assoc($result);
mysqli_stmt_close($stmt);
$edit_mode = true;
}
// --- Logik zum Hinzufügen oder Speichern von Benutzern ---
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$role = $_POST['role'] === 'admin' ? 'admin' : 'member';
$id = $_POST['id'] ?? null;
if ($id) { // Update-Logik
// Überprüfen, ob ein neues Passwort gesetzt wurde
if (!empty($password)) {
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, password = ?, role = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sssi", $username, $password_hashed, $role, $id);
} else {
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, role = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "ssi", $username, $role, $id);
}
if (mysqli_stmt_execute($stmt)) {
$message = "Benutzer erfolgreich aktualisiert!";
$message_type = 'success';
} else {
$message = "Fehler beim Aktualisieren des Benutzers.";
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
} else { // Insert-Logik
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
$stmt = mysqli_prepare($conn, "INSERT INTO users (username, password, role) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sss", $username, $password_hashed, $role);
if (mysqli_stmt_execute($stmt)) {
$message = "Benutzer erfolgreich hinzugefügt.";
$message_type = 'success';
} else {
$message = "Fehler beim Hinzufügen: " . mysqli_error($conn);
$message_type = 'danger';
}
mysqli_stmt_close($stmt);
}
}
// Benutzerübersicht abrufen
@@ -52,31 +107,42 @@ require_once('../inc/header.php');
<div class="card shadow mb-4">
<div class="card-header bg-primary text-white">
<h4 class="mb-0">Neuen Benutzer hinzufügen</h4>
<h4 class="mb-0"><?php echo $edit_mode ? 'Benutzer bearbeiten' : 'Neuen Benutzer hinzufügen'; ?></h4>
</div>
<div class="card-body">
<form method="post">
<div class="row g-3 align-items-end">
<form action="users.php" method="post">
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_user['id']); ?>">
<?php endif; ?>
<div class="row g-1 align-items-end">
<div class="col-md-4">
<label for="username" class="form-label">Benutzername</label>
<input type="text" class="form-control" id="username" name="username" required>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($edit_user['username'] ?? ''); ?>" required>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-4">
<label for="password" class="form-label">Passwort</label>
<input type="password" class="form-control" id="password" name="password" required>
<input type="password" class="form-control" id="password" name="password" <?php echo $edit_mode ? '' : 'required'; ?>>
<div class="form-text">
<?php echo $edit_mode ? 'Feld leer lassen, um das Passwort nicht zu ändern.' : '&nbsp;'; ?>
</div>
</div>
<div class="col-md-4">
<label for="role" class="form-label">Rolle</label>
<select class="form-select" id="role" name="role">
<option value="member" <?php echo ($edit_user['role'] ?? '') === 'member' ? 'selected' : ''; ?>>Mitglied</option>
<option value="admin" <?php echo ($edit_user['role'] ?? '') === 'admin' ? 'selected' : ''; ?>>Admin</option>
</select>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-4 d-flex flex-column justify-content-end">
<label for="role" class="form-label">Rolle</label>
<div class="d-flex w-100">
<select class="form-select w-100" id="role" name="role">
<option value="member">Mitglied</option>
<option value="admin">Admin</option>
</select>
<div class="col-12 d-flex justify-content-start">
<button type="submit" class="btn btn-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="users.php" class="btn btn-secondary w-auto">Abbrechen</a>
<?php endif; ?>
</div>
</div><button type="submit" class="btn btn-primary ms-2">Hinzufügen</button>
</div>
</form>
</div>
@@ -108,10 +174,10 @@ require_once('../inc/header.php');
</span>
</td>
<td>
<a href="#" class="text-dark me-1 text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Bearbeiten">
<a href="users.php?action=edit&id=<?= htmlspecialchars($user['id']) ?>" class="text-dark me-1 text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Bearbeiten">
<span class="material-icons">mode_edit_outline</span>
</a>
<a href="#" class="text-danger text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Löschen">
<a href="users.php?action=delete&id=<?= htmlspecialchars($user['id']) ?>" class="text-danger text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Löschen" onclick="return confirm('Sind Sie sicher, dass Sie diesen Benutzer löschen möchten?');">
<span class="material-icons">delete_outline</span>
</a>
</td>