Teilnahme Eintragung hinzugefügt
This commit is contained in:
157
admin/participant.php
Executable file
157
admin/participant.php
Executable file
@@ -0,0 +1,157 @@
|
|||||||
|
<?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']);
|
||||||
|
|
||||||
|
// Daten speichern, wenn das Formular abgeschickt wurde
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$table_name = "meeting_teilnehmer"; // <<< Korrekter Tabellenname
|
||||||
|
|
||||||
|
// Vorhandene Daten für dieses Meeting löschen, um Duplikate zu vermeiden
|
||||||
|
$stmt = mysqli_prepare($conn, "DELETE FROM " . $table_name . " 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 " . $table_name . " (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);
|
||||||
|
|
||||||
|
$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)
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Meeting-Details abrufen
|
||||||
|
$stmt = mysqli_prepare($conn, "SELECT m.meeting_date, c.name AS color_name FROM meetings m 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
$table_name = "meeting_teilnehmer"; // <<< Korrekter Tabellenname
|
||||||
|
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid FROM " . $table_name . " 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>
|
||||||
|
<p class="text-muted">für das Treffen am **<?= date('d.m.Y', strtotime($meeting['meeting_date'])) ?>** in der Farbe **<?= htmlspecialchars($meeting['color_name']) ?>**.</p>
|
||||||
|
|
||||||
|
<?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 ?>" method="post">
|
||||||
|
<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="../index.php" class="btn btn-outline-secondary">Abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include('../inc/footer.php'); ?>
|
||||||
50
index.php
50
index.php
@@ -1,22 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
include('inc/check_login.php');
|
include('inc/check_login.php');
|
||||||
include('inc/db.php');
|
include('inc/db.php');
|
||||||
|
include('inc/helpers.php');
|
||||||
|
|
||||||
// Aktuelle Kalenderwoche berechnen
|
// Funktion, um den nächsten Termin zu holen
|
||||||
$current_week = date('W');
|
function get_next_meeting($conn)
|
||||||
|
{
|
||||||
// SQL-Abfrage mit JOIN zwischen meetings und colors
|
$sql = "SELECT id, meeting_date, color_id, reason
|
||||||
$sql = "SELECT * FROM meetings
|
FROM meetings
|
||||||
JOIN colors ON meetings.color_id = colors.id
|
WHERE meeting_date > NOW()
|
||||||
WHERE WEEK(meeting_date, 1) = $current_week
|
ORDER BY meeting_date ASC
|
||||||
ORDER BY meeting_date DESC LIMIT 1";
|
LIMIT 1";
|
||||||
|
|
||||||
$result = mysqli_query($conn, $sql);
|
$result = mysqli_query($conn, $sql);
|
||||||
if (!$result) {
|
|
||||||
die("Fehler in der SQL-Abfrage: " . mysqli_error($conn));
|
if ($result && mysqli_num_rows($result) > 0) {
|
||||||
|
return mysqli_fetch_assoc($result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc($result);
|
// Den nächsten Termin holen
|
||||||
|
$row = get_next_meeting($conn);
|
||||||
|
|
||||||
// Funktion, die basierend auf der Hintergrundfarbe die optimale Textfarbe zurückgibt
|
// Funktion, die basierend auf der Hintergrundfarbe die optimale Textfarbe zurückgibt
|
||||||
function get_readable_text_color($hex_code)
|
function get_readable_text_color($hex_code)
|
||||||
@@ -59,34 +64,45 @@ $german_weekdays = [
|
|||||||
<div class="container py-5">
|
<div class="container py-5">
|
||||||
<div class="text-center mb-5">
|
<div class="text-center mb-5">
|
||||||
<h1 class="display-4 fw-bold">DoMiLi</h1>
|
<h1 class="display-4 fw-bold">DoMiLi</h1>
|
||||||
<p class="lead">Farbe für Kalenderwoche <strong><?= $current_week ?></strong></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($row): ?>
|
<?php if ($row): ?>
|
||||||
<?php
|
<?php
|
||||||
$english_weekday = date('D', strtotime($row['meeting_date']));
|
$english_weekday = date('D', strtotime($row['meeting_date']));
|
||||||
$german_weekday = $german_weekdays[$english_weekday] ?? '';
|
$german_weekday = $german_weekdays[$english_weekday] ?? '';
|
||||||
|
|
||||||
|
// Hole die Farbdetails, da sie nicht mehr im ursprünglichen JOIN sind
|
||||||
|
$color_sql = "SELECT * FROM colors WHERE id = ?";
|
||||||
|
$color_stmt = mysqli_prepare($conn, $color_sql);
|
||||||
|
mysqli_stmt_bind_param($color_stmt, "i", $row['color_id']);
|
||||||
|
mysqli_stmt_execute($color_stmt);
|
||||||
|
$color_result = mysqli_stmt_get_result($color_stmt);
|
||||||
|
$color_row = mysqli_fetch_assoc($color_result);
|
||||||
?>
|
?>
|
||||||
<div class="card mx-auto bg-light shadow" style="max-width: 400px;">
|
<div class="card mx-auto bg-light shadow" style="max-width: 400px;">
|
||||||
<div class="card-body text-center">
|
<div class="card-body text-center">
|
||||||
<h5 class="card-title mb-3">Farbe der Woche</h5>
|
<h5 class="card-title mb-3">Farbe des nächsten Treffens</h5>
|
||||||
<div class="rounded mb-3 mx-auto d-flex justify-content-center align-items-center" style="height: min(100px, 25vw); background-color: <?= htmlspecialchars($row['hex_code']) ?>; text-shadow: 1px 1px 2px rgba(0,0,0,0.5);">
|
<div class="rounded-4 mb-3 mx-auto d-flex flex-column justify-content-center align-items-center color-box" style="background-image: linear-gradient(135deg, <?= htmlspecialchars($color_row['hex_code']) ?>, <?= darken_color($color_row['hex_code']) ?>);">
|
||||||
<p class="fs-5 fw-semibold m-0" style="color: <?= get_readable_text_color($row['hex_code']) ?>;"><?= htmlspecialchars($row['name']) ?></p>
|
<p class="fs-5 fw-semibold m-0" style="color: <?= get_readable_text_color($color_row['hex_code']) ?>;"><?= htmlspecialchars($color_row['name']) ?></p>
|
||||||
|
<p class="fs-6 fw-normal m-0" style="color: <?= get_readable_text_color($color_row['hex_code']) ?>;"><?= htmlspecialchars($row['reason']) ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="text-muted">nächster Termin:</p>
|
<p class="text-muted">nächster Termin:</p>
|
||||||
<p class="text-muted fw-bold"><?= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) ?></p>
|
<p class="text-muted fw-bold"><?= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-center my-3" style="max-width: 400px; margin-left: auto; margin-right: auto;">
|
<div class="d-flex justify-content-center my-3" style="max-width: 400px; margin-left: auto; margin-right: auto;">
|
||||||
<a href="#" class="btn btn-sm btn-outline-danger me-4">Absagen</a>
|
<a href="#" class="btn btn-sm btn-outline-danger me-2">Absagen</a>
|
||||||
<a href="#" class="btn btn-sm btn-outline-secondary">Verschiebung beantragen</a>
|
<a href="#" class="btn btn-sm btn-outline-secondary">Verschiebung beantragen</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="d-flex justify-content-center my-3" style="max-width: 400px; margin-left: auto; margin-right: auto;">
|
||||||
|
<a href="admin/participant.php?id=<?= htmlspecialchars($row['id']) ?>" class="btn btn-sm btn-outline-primary">Teilnahme eintragen</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div class="alert alert-warning text-center">
|
<div class="alert alert-warning text-center">
|
||||||
Keine Farbe für diese Woche festgelegt.
|
Keine anstehenden Termine gefunden.
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user