Geburtstagslogik implementiert

This commit is contained in:
Borgal
2025-10-31 15:03:43 +01:00
parent 9cd9afaad4
commit bbce9776e1
2 changed files with 69 additions and 40 deletions

View File

@@ -1,13 +1,8 @@
<?php
// Fehleranzeige für Entwicklung (optional)
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
include('inc/check_login.php');
include('inc/db.php');
require_once 'inc/helpers.php';
// Meeting-ID prüfen
if (!isset($_GET['id'])) {
$_SESSION['error_message'] = "Keine Meeting-ID angegeben.";
header("Location: index.php");
@@ -15,12 +10,9 @@ if (!isset($_GET['id'])) {
}
$meeting_id = intval($_GET['id']);
// Quelle merken (für Weiterleitung)
$source_page = isset($_GET['source']) && $_GET['source'] === 'history' ? 'history' : 'index';
$cancel_link = $source_page === 'history' ? 'history.php' : 'index.php';
// Meeting-Daten laden
$stmt = mysqli_prepare($conn, "SELECT meeting_date, color_id, reason FROM meetings WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
mysqli_stmt_execute($stmt);
@@ -33,7 +25,6 @@ if (!$meeting) {
exit;
}
// Farben und Benutzer laden
$colors = [];
$colors_result = mysqli_query($conn, "SELECT id, name FROM colors ORDER BY name");
while ($row = mysqli_fetch_assoc($colors_result)) {
@@ -46,7 +37,6 @@ while ($row = mysqli_fetch_assoc($users_result)) {
$users[] = $row;
}
// Bestehende Teilnehmerdaten laden
$existing_feedback = [];
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid FROM meeting_teilnehmer WHERE meeting_id = ?");
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
@@ -60,9 +50,7 @@ mysqli_stmt_close($stmt);
$message = '';
$message_type = '';
// POST-Verarbeitung
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// Meeting-Daten aktualisieren (nur im History-Modus)
if ($source_page === 'history') {
$meeting_date = $_POST['meeting_date'] ?? '';
$color_id = intval($_POST['color_id'] ?? 0);
@@ -97,7 +85,24 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
}
mysqli_stmt_close($stmt_insert);
// Meeting als abgeschlossen markieren (nur im Index-Modus)
// 🔹 GEBURTSTAGS-REGEL: last_birthday_year setzen
foreach ($_POST['user_id'] as $user_id) {
$user_id = (int)$user_id;
$paid = isset($_POST['paid'][$user_id]) ? 1 : 0;
if ($paid) {
$stmt_bday = mysqli_prepare($conn, "
UPDATE users
SET last_birthday_year = YEAR(CURDATE())
WHERE id = ? AND birthday IS NOT NULL
");
mysqli_stmt_bind_param($stmt_bday, "i", $user_id);
mysqli_stmt_execute($stmt_bday);
mysqli_stmt_close($stmt_bday);
}
}
// Meeting abschließen (nur im Index-Modus)
if ($source_page === 'index') {
$stmt_complete = mysqli_prepare($conn, "UPDATE meetings SET is_completed = 1 WHERE id = ?");
mysqli_stmt_bind_param($stmt_complete, "i", $meeting_id);
@@ -112,7 +117,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$message_type = 'warning';
}
// 🔁 Zurück zur ursprünglichen Quelle
header("Location: " . $cancel_link);
exit;
}