222 lines
10 KiB
PHP
Executable File
222 lines
10 KiB
PHP
Executable File
<?php
|
|
include('../inc/check_login.php');
|
|
include('../inc/db.php');
|
|
require_once '../inc/helpers.php';
|
|
|
|
$message = '';
|
|
$message_type = '';
|
|
|
|
// Prüfen, ob eine Meeting-ID übergeben wurde
|
|
if (!isset($_GET['id'])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$meeting_id = htmlspecialchars($_GET['id']);
|
|
|
|
// Neu: Quelle des Aufrufs festlegen für bedingte Logik und Weiterleitung
|
|
$source_page = isset($_GET['source']) && $_GET['source'] == 'history' ? 'history' : 'index';
|
|
$cancel_link = $source_page === 'history' ? '../history.php' : '../index.php';
|
|
|
|
// Daten speichern, wenn das Formular abgeschickt wurde
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
// Neu: Daten des Meetings selbst aktualisieren, falls aus der History aufgerufen
|
|
if ($source_page === 'history') {
|
|
$meeting_date = $_POST['meeting_date'];
|
|
$color_id = $_POST['color_id'];
|
|
$reason = $_POST['reason'] ?? null;
|
|
|
|
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?");
|
|
if ($stmt) {
|
|
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $meeting_id);
|
|
mysqli_stmt_execute($stmt);
|
|
mysqli_stmt_close($stmt);
|
|
} else {
|
|
die("Fehler beim Vorbereiten der Meeting-Update-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
}
|
|
|
|
// Vorhandene Daten für dieses Meeting löschen
|
|
$stmt = mysqli_prepare($conn, "DELETE FROM meeting_teilnehmer WHERE meeting_id = ?");
|
|
if ($stmt === false) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
|
mysqli_stmt_execute($stmt);
|
|
mysqli_stmt_close($stmt);
|
|
|
|
// Gesendete Daten verarbeiten und speichern
|
|
if (isset($_POST['user_id'])) {
|
|
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meeting_teilnehmer (meeting_id, user_id, attended, wore_color, paid) VALUES (?, ?, ?, ?, ?)");
|
|
if ($stmt_insert === false) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
|
|
foreach ($_POST['user_id'] as $user_id) {
|
|
$attended = isset($_POST['attended'][$user_id]) ? 1 : 0;
|
|
$wore_color = isset($_POST['wore_color'][$user_id]) ? 1 : 0;
|
|
$paid = isset($_POST['paid'][$user_id]) ? 1 : 0;
|
|
|
|
mysqli_stmt_bind_param($stmt_insert, "iiiii", $meeting_id, $user_id, $attended, $wore_color, $paid);
|
|
mysqli_stmt_execute($stmt_insert);
|
|
}
|
|
mysqli_stmt_close($stmt_insert);
|
|
|
|
// NEU: Termin als abgeschlossen markieren
|
|
$stmt_complete = mysqli_prepare($conn, "UPDATE meetings SET is_completed = 1 WHERE id = ?");
|
|
if ($stmt_complete) {
|
|
mysqli_stmt_bind_param($stmt_complete, "i", $meeting_id);
|
|
mysqli_stmt_execute($stmt_complete);
|
|
mysqli_stmt_close($stmt_complete);
|
|
}
|
|
|
|
$message = "Meeting-Daten erfolgreich gespeichert!";
|
|
$message_type = 'success';
|
|
} else {
|
|
$message = "Keine Benutzerdaten zum Speichern vorhanden.";
|
|
$message_type = 'warning';
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------
|
|
// Daten für das Formular abrufen (Meetings und Benutzer)
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Neu: Zusätzliche Meeting-Details für den Edit-Modus abrufen
|
|
$stmt = mysqli_prepare($conn, "SELECT m.meeting_date, m.reason, m.color_id, c.name AS color_name FROM meetings m LEFT JOIN colors c ON m.color_id = c.id WHERE m.id = ?");
|
|
if ($stmt === false) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
|
mysqli_stmt_execute($stmt);
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
$meeting = mysqli_fetch_assoc($result);
|
|
mysqli_stmt_close($stmt);
|
|
|
|
if (!$meeting) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Neu: Alle Farben für das Dropdown im Edit-Modus abrufen
|
|
$colors = [];
|
|
$colors_result = mysqli_query($conn, "SELECT id, name FROM colors ORDER BY name");
|
|
if ($colors_result) {
|
|
while ($row = mysqli_fetch_assoc($colors_result)) {
|
|
$colors[] = $row;
|
|
}
|
|
}
|
|
|
|
// Alle Benutzer abrufen
|
|
$users = [];
|
|
$users_result = mysqli_query($conn, "SELECT id, username AS name FROM users ORDER BY username");
|
|
if ($users_result === false) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
while ($row = mysqli_fetch_assoc($users_result)) {
|
|
$users[] = $row;
|
|
}
|
|
|
|
// Bestehende Feedback-Daten für dieses Meeting abrufen, falls vorhanden
|
|
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid FROM meeting_teilnehmer WHERE meeting_id = ?");
|
|
if ($stmt === false) {
|
|
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
|
}
|
|
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
|
mysqli_stmt_execute($stmt);
|
|
$result = mysqli_stmt_get_result($stmt);
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$existing_feedback[$row['user_id']] = $row;
|
|
}
|
|
mysqli_stmt_close($stmt);
|
|
|
|
require_once '../inc/header.php';
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<h2 class="mb-4">Teilnahme eintragen</h2>
|
|
|
|
<?php if ($source_page === 'index'): ?>
|
|
<p class="text-muted">für das Treffen am <strong><?= date('d.m.Y', strtotime($meeting['meeting_date'])) ?></strong> in der Farbe <strong><?= htmlspecialchars($meeting['color_name']) ?></strong>.</p>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-<?= $message_type ?> alert-dismissible fade show" role="alert">
|
|
<?= $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-body">
|
|
<form action="participant.php?id=<?= $meeting_id ?>&source=<?= $source_page ?>" method="post">
|
|
<?php if ($source_page === 'history'): ?>
|
|
<h5 class="mb-3">Treffen-Details bearbeiten</h5>
|
|
<div class="row">
|
|
<div class="col-md-4 mb-3">
|
|
<label for="meeting_date" class="form-label">Datum des Treffens</label>
|
|
<input type="datetime-local" class="form-control" id="meeting_date" name="meeting_date" value="<?= date('Y-m-d\TH:i', strtotime($meeting['meeting_date'])) ?>" required>
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label for="color_id" class="form-label">Farbvorgabe</label>
|
|
<select class="form-select" id="color_id" name="color_id" required>
|
|
<?php foreach ($colors as $color): ?>
|
|
<option value="<?= $color['id'] ?>" <?= $meeting['color_id'] == $color['id'] ? 'selected' : '' ?>>
|
|
<?= htmlspecialchars($color['name']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4 mb-3">
|
|
<label for="reason" class="form-label">Grund (optional)</label>
|
|
<input type="text" class="form-control" id="reason" name="reason" value="<?= htmlspecialchars($meeting['reason']) ?>">
|
|
</div>
|
|
</div>
|
|
<hr>
|
|
<h5 class="mb-3">Teilnehmer-Details bearbeiten</h5>
|
|
<?php endif; ?>
|
|
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Benutzer</th>
|
|
<th class="text-center">Dabei?</th>
|
|
<th class="text-center">Farbe getragen?</th>
|
|
<th class="text-center">Gezahlt?</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($users as $user): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($user['name']) ?></td>
|
|
<td class="text-center">
|
|
<div class="form-check d-inline-block">
|
|
<input class="form-check-input" type="checkbox" name="attended[<?= $user['id'] ?>]" id="attended_<?= $user['id'] ?>" value="1" <?= isset($existing_feedback[$user['id']]) && $existing_feedback[$user['id']]['attended'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</td>
|
|
<td class="text-center">
|
|
<div class="form-check d-inline-block">
|
|
<input class="form-check-input" type="checkbox" name="wore_color[<?= $user['id'] ?>]" id="wore_color_<?= $user['id'] ?>" value="1" <?= isset($existing_feedback[$user['id']]) && $existing_feedback[$user['id']]['wore_color'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</td>
|
|
<td class="text-center">
|
|
<div class="form-check d-inline-block">
|
|
<input class="form-check-input" type="checkbox" name="paid[<?= $user['id'] ?>]" id="paid_<?= $user['id'] ?>" value="1" <?= isset($existing_feedback[$user['id']]) && $existing_feedback[$user['id']]['paid'] ? 'checked' : '' ?>>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<input type="hidden" name="user_id[]" value="<?= $user['id'] ?>">
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<div class="d-flex justify-content-between mt-3">
|
|
<button type="submit" class="btn btn-primary">Speichern</button>
|
|
<a href="<?= htmlspecialchars($cancel_link) ?>" class="btn btn-outline-secondary">Abbrechen</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include('../inc/footer.php'); ?>
|