Add Button angepasst

This commit is contained in:
Borgal
2025-08-20 17:56:36 +02:00
parent 7978eba678
commit 220a0bb99d
3 changed files with 185 additions and 142 deletions

View File

@@ -77,7 +77,6 @@ require_once '../inc/header.php';
?>
<div class="container mt-5">
<h2 class="mb-4">Farbverwaltung</h2>
<?php if ($message) : ?>
<div class="alert alert-<?= $message_type ?> alert-dismissible fade show" role="alert">
@@ -86,6 +85,14 @@ require_once '../inc/header.php';
</div>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Farbverwaltung</h2>
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#colorFormCollapse" role="button" aria-expanded="false" aria-controls="colorFormCollapse">
<span class="material-symbols-outlined">add</span>
</a>
</div>
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="colorFormCollapse">
<div class="card shadow mb-4">
<div class="card-header bg-primary-subtle text-secondary">
<h4 class="mb-0"><?= $edit_mode ? 'Farbe bearbeiten' : 'Neue Farbe hinzufügen'; ?></h4>
@@ -118,10 +125,14 @@ require_once '../inc/header.php';
</form>
</div>
</div>
<hr class="mt-4 mb-4">
</div>
<div class="card shadow">
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
<h4 class="mb-0">Aktuelle Farben</h4>
</div>
<div class="card-body">
<?php if (empty($colors)): ?>

View File

@@ -75,7 +75,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
// 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, reason FROM meetings WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason FROM meetings WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
@@ -93,15 +93,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$meeting_date_only = $_POST['meeting_date'];
$meeting_time_only = $_POST['meeting_time'] ?? '12:00'; // Standardwert 12:00 Uhr
$meeting_time_only = $_POST['meeting_time'] ?? '12:00';
$meeting_date = $meeting_date_only . ' ' . $meeting_time_only;
$color_id = $_POST['color_id'];
$reason = $_POST['reason'] ?? 'Zufallsfarbe'; // <<< NEU: Grund aus dem Formular holen, Standardwert bei leerem Feld
$reason = $_POST['reason'] ?? 'Zufallsfarbe';
$id = $_POST['id'] ?? null;
if ($id) { // Update-Logik
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id); // <<< NEU: 's' für den String-Parameter
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id);
if (mysqli_stmt_execute($stmt)) {
$message = "Termin erfolgreich aktualisiert!";
$message_type = 'success';
@@ -111,8 +111,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
}
mysqli_stmt_close($stmt);
} else { // Insert-Logik
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason); // <<< NEU: 's' für den String-Parameter
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason);
if (mysqli_stmt_execute($stmt)) {
$message = "Neuer Termin erfolgreich hinzugefügt!";
$message_type = 'success';
@@ -139,9 +139,9 @@ for ($i = 0; $i < 2; $i++) {
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, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
$default_reason = "Zufallsfarbe"; // <<< NEU: Grund für automatisch erstellte Termine
mysqli_stmt_bind_param($stmt_insert, "sis", $next_thursday, $color_id, $default_reason); // <<< NEU: 's' für den String-Parameter
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
$default_reason = "Zufallsfarbe";
mysqli_stmt_bind_param($stmt_insert, "sis", $next_thursday, $color_id, $default_reason);
mysqli_stmt_execute($stmt_insert);
mysqli_stmt_close($stmt_insert);
}
@@ -159,7 +159,7 @@ while ($row = mysqli_fetch_assoc($result)) {
}
$meetings = [];
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, m.reason, 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"); // <<< NEU: 'reason' in der Abfrage
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, m.reason, c.name AS color_name, c.hex_code FROM meetings m JOIN colors c ON m.color_id = c.id WHERE m.meeting_date >= CURDATE() ORDER BY m.meeting_date");
while ($row = mysqli_fetch_assoc($result)) {
$meetings[] = $row;
}
@@ -168,7 +168,6 @@ 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">
@@ -177,32 +176,40 @@ require_once '../inc/header.php';
</div>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Terminverwaltung</h2>
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#planningFormCollapse" role="button" aria-expanded="false" aria-controls="planningFormCollapse">
<span class="material-symbols-outlined">add</span>
</a>
</div>
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="planningFormCollapse">
<div class="card shadow mb-4">
<div class="card-header bg-primary-subtle text-secondary">
<h4 class="mb-0"><?php echo $edit_mode ? 'Termin bearbeiten' : 'Neuen Termin hinzufügen'; ?></h4>
<h4 class="mb-0"><?= $edit_mode ? 'Termin bearbeiten' : 'Neuen Termin hinzufügen'; ?></h4>
</div>
<div class="card-body">
<form action="planning.php" method="post">
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_meeting['id']); ?>">
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_meeting['id']); ?>">
<?php endif; ?>
<div class="row g-1 align-items-end">
<div class="col-md-4">
<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_only'] ?? ''); ?>" required>
<input type="date" class="form-control" id="meeting_date" name="meeting_date" value="<?= htmlspecialchars($edit_meeting['meeting_date_only'] ?? ''); ?>" required>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-4">
<label for="meeting_time" class="form-label">Uhrzeit</label>
<input type="time" class="form-control" id="meeting_time" name="meeting_time" value="<?php echo htmlspecialchars($edit_meeting['meeting_time_only'] ?? '12:00'); ?>" required>
<input type="time" class="form-control" id="meeting_time" name="meeting_time" value="<?= htmlspecialchars($edit_meeting['meeting_time_only'] ?? '12:00'); ?>" required>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-4">
<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 value="<?= htmlspecialchars($color['id']); ?>" <?= (($edit_meeting['color_id'] ?? '') == $color['id']) ? 'selected' : ''; ?>>
<?= htmlspecialchars($color['name']); ?>
</option>
<?php endforeach; ?>
</select>
@@ -210,13 +217,13 @@ require_once '../inc/header.php';
</div>
<div class="col-md-6">
<label for="reason" class="form-label">Grund für die Farbe (optional)</label>
<input type="text" class="form-control" id="reason" name="reason" value="<?php echo htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
<input type="text" class="form-control" id="reason" name="reason" value="<?= htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
<div class="form-text">wenn leer, wird automatisch "Zufallsfarbe" eingetragen</div>
</div>
<div class="col-12 d-flex justify-content-start">
<div class="d-flex w-100">
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="planning.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
@@ -227,6 +234,8 @@ require_once '../inc/header.php';
</form>
</div>
</div>
<hr class="mt-4 mb-4">
</div>
<div class="card shadow">
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
@@ -248,21 +257,21 @@ require_once '../inc/header.php';
<tbody>
<?php foreach ($meetings as $meeting): ?>
<tr>
<td><?php echo date('d.m.Y H:i', strtotime($meeting['meeting_date'])); ?></td>
<td><?= date('d.m.Y H:i', 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>
<div class="color-preview rounded me-2" style="background-color: <?= htmlspecialchars($meeting['hex_code']); ?>;"></div>
<div>
<span><?php echo htmlspecialchars($meeting['color_name']); ?></span>
<div class="small text-muted mt-1">Grund: <?php echo htmlspecialchars($meeting['reason']); ?></div>
<span><?= htmlspecialchars($meeting['color_name']); ?></span>
<div class="small text-muted mt-1">Grund: <?= htmlspecialchars($meeting['reason']); ?></div>
</div>
</div>
</td>
<td>
<a href="planning.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">
<a href="planning.php?action=edit&id=<?= 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="planning.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">
<a href="planning.php?action=delete&id=<?= 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>

View File

@@ -28,7 +28,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
// 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 = ?");
// E-Mail-Feld zur Abfrage hinzugefügt, da es für das Bearbeiten benötigt wird
$stmt = mysqli_prepare($conn, "SELECT id, username, email, role FROM users WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
@@ -42,6 +43,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
// E-Mail-Feld aus dem Formular auslesen
$email = $_POST['email'] ?? null;
$role = $_POST['role'] === 'admin' ? 'admin' : 'member';
$id = $_POST['id'] ?? null;
@@ -49,11 +52,15 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Ü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);
// E-Mail-Feld zum UPDATE-Statement hinzugefügt
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, password = ?, email = ?, role = ? WHERE id = ?");
// `email` zur Parameter-Bindung hinzugefügt
mysqli_stmt_bind_param($stmt, "ssssi", $username, $password_hashed, $email, $role, $id);
} else {
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, role = ? WHERE id = ?");
mysqli_stmt_bind_param($stmt, "ssi", $username, $role, $id);
// E-Mail-Feld zum UPDATE-Statement hinzugefügt
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, email = ?, role = ? WHERE id = ?");
// `email` zur Parameter-Bindung hinzugefügt
mysqli_stmt_bind_param($stmt, "sssi", $username, $email, $role, $id);
}
if (mysqli_stmt_execute($stmt)) {
@@ -66,8 +73,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
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);
// E-Mail-Feld zum INSERT-Statement hinzugefügt
$stmt = mysqli_prepare($conn, "INSERT INTO users (username, password, email, role) VALUES (?, ?, ?, ?)");
// `email` zur Parameter-Bindung hinzugefügt
mysqli_stmt_bind_param($stmt, "ssss", $username, $password_hashed, $email, $role);
if (mysqli_stmt_execute($stmt)) {
$message = "Benutzer erfolgreich hinzugefügt.";
$message_type = 'success';
@@ -79,7 +88,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
}
}
// Benutzerübersicht abrufen
// Benutzerübersicht abrufen (E-Mail-Feld entfernt)
$users = [];
$result = mysqli_query($conn, "SELECT id, username, role FROM users ORDER BY id ASC");
if ($result) {
@@ -92,7 +101,6 @@ require_once('../inc/header.php');
?>
<div class="container mt-5">
<h2 class="mb-4">Benutzerverwaltung</h2>
<?php if ($message) : ?>
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
@@ -101,39 +109,52 @@ require_once('../inc/header.php');
</div>
<?php endif; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Benutzerverwaltung</h2>
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#userFormCollapse" role="button" aria-expanded="false" aria-controls="userFormCollapse">
<span class="material-symbols-outlined">add</span>
</a>
</div>
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="userFormCollapse">
<div class="card shadow mb-4">
<div class="card-header bg-primary-subtle text-secondary">
<h4 class="mb-0"><?php echo $edit_mode ? 'Benutzer bearbeiten' : 'Neuen Benutzer hinzufügen'; ?></h4>
<h4 class="mb-0"><?= $edit_mode ? 'Benutzer bearbeiten' : 'Neuen Benutzer hinzufügen'; ?></h4>
</div>
<div class="card-body">
<form action="users.php" method="post">
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_user['id']); ?>">
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_user['id']); ?>">
<?php endif; ?>
<div class="row g-1 align-items-end">
<div class="col-md-4">
<div class="col-md-3">
<label for="username" class="form-label">Benutzername</label>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($edit_user['username'] ?? ''); ?>" required>
<input type="text" class="form-control" id="username" name="username" value="<?= htmlspecialchars($edit_user['username'] ?? ''); ?>" required>
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-4">
<div class="col-md-3">
<label for="email" class="form-label">E-Mail (optional)</label>
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($edit_user['email'] ?? ''); ?>">
<div class="form-text" style="visibility: hidden;">&nbsp;</div>
</div>
<div class="col-md-3">
<label for="password" class="form-label">Passwort</label>
<input type="password" class="form-control" id="password" name="password" <?php echo $edit_mode ? '' : 'required'; ?>>
<input type="password" class="form-control" id="password" name="password" <?= $edit_mode ? '' : 'required'; ?>>
<div class="form-text">
<?php echo $edit_mode ? 'Feld leer lassen, um das Passwort nicht zu ändern.' : '&nbsp;'; ?>
<?= $edit_mode ? 'Feld leer lassen, um das Passwort nicht zu ändern.' : '&nbsp;'; ?>
</div>
</div>
<div class="col-md-4">
<div class="col-md-3">
<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>
<option value="member" <?= (($edit_user['role'] ?? '') === 'member') ? 'selected' : ''; ?>>Mitglied</option>
<option value="admin" <?= (($edit_user['role'] ?? '') === 'admin') ? 'selected' : ''; ?>>Admin</option>
</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-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="users.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
@@ -143,6 +164,8 @@ require_once('../inc/header.php');
</form>
</div>
</div>
<hr class="mt-4 mb-4">
</div>
<div class="card shadow">
<div class="card-header bg-secondary bg-opacity-50 text-secondary">