0) ? mysqli_fetch_assoc($result) : null; } $row = get_current_meeting($conn); // --- TEILNAHME-LOGIK & TERMINVERSCHIEBUNG --- if ($row) { $meeting_id = $row['id']; // Aktionen verarbeiten (Zusagen / Absagen / Vielleicht) if (isset($_GET['action']) && isset($_GET['meeting_id']) && $_GET['meeting_id'] == $meeting_id) { $action = $_GET['action']; $rsvp_status_value = null; $attended_value = 0; if ($action === 'accept') { $rsvp_status_value = 'accepted'; $attended_value = 1; } elseif ($action === 'decline') { $rsvp_status_value = 'declined'; $attended_value = 0; } elseif ($action === 'maybe') { $rsvp_status_value = 'maybe'; $attended_value = 0; } if ($rsvp_status_value !== null) { $check_sql = "SELECT rsvp_status FROM meeting_teilnehmer WHERE meeting_id = ? AND user_id = ?"; $check_stmt = mysqli_prepare($conn, $check_sql); $existing = null; if ($check_stmt) { mysqli_stmt_bind_param($check_stmt, "ii", $meeting_id, $logged_in_user_id); mysqli_stmt_execute($check_stmt); $existing = mysqli_fetch_assoc(mysqli_stmt_get_result($check_stmt)); mysqli_stmt_close($check_stmt); } if ($existing) { $update_sql = "UPDATE meeting_teilnehmer SET rsvp_status = ?, attended = ? WHERE meeting_id = ? AND user_id = ?"; $update_stmt = mysqli_prepare($conn, $update_sql); if ($update_stmt) { mysqli_stmt_bind_param($update_stmt, "siii", $rsvp_status_value, $attended_value, $meeting_id, $logged_in_user_id); mysqli_stmt_execute($update_stmt); mysqli_stmt_close($update_stmt); } } else { $insert_sql = "INSERT INTO meeting_teilnehmer (meeting_id, user_id, attended, rsvp_status) VALUES (?, ?, ?, ?)"; $insert_stmt = mysqli_prepare($conn, $insert_sql); if ($insert_stmt) { mysqli_stmt_bind_param($insert_stmt, "iiis", $meeting_id, $logged_in_user_id, $attended_value, $rsvp_status_value); mysqli_stmt_execute($insert_stmt); mysqli_stmt_close($insert_stmt); } } header("Location: index.php"); exit; } } // 🔥 Automatisch ablehnen, wenn im Abwesenheitsmodus $auto_declined = auto_decline_if_on_vacation($conn, $meeting_id, $logged_in_user_id, $row['meeting_date']); // Status abrufen $user_attendance_status = null; $user_status_sql = "SELECT rsvp_status FROM meeting_teilnehmer WHERE meeting_id = ? AND user_id = ?"; $user_status_stmt = mysqli_prepare($conn, $user_status_sql); if ($user_status_stmt) { mysqli_stmt_bind_param($user_status_stmt, "ii", $meeting_id, $logged_in_user_id); mysqli_stmt_execute($user_status_stmt); $user_status_result = mysqli_stmt_get_result($user_status_stmt); $user_status_row = mysqli_fetch_assoc($user_status_result); if ($user_status_row) { $user_attendance_status = $user_status_row['rsvp_status']; } mysqli_stmt_close($user_status_stmt); } // Teilnehmerlisten laden $attendees_sql = "SELECT t.rsvp_status, u.username FROM meeting_teilnehmer AS t LEFT JOIN users AS u ON t.user_id = u.id WHERE t.meeting_id = ?"; $attendees_stmt = mysqli_prepare($conn, $attendees_sql); $accepted_users = []; $declined_users = []; $maybe_users = []; $total_accepted = 0; $total_declined = 0; $total_maybe = 0; if ($attendees_stmt) { mysqli_stmt_bind_param($attendees_stmt, "i", $meeting_id); mysqli_stmt_execute($attendees_stmt); $attendees_result = mysqli_stmt_get_result($attendees_stmt); while ($row_user = mysqli_fetch_assoc($attendees_result)) { switch ($row_user['rsvp_status']) { case 'accepted': $accepted_users[] = htmlspecialchars($row_user['username']); $total_accepted++; break; case 'declined': $declined_users[] = htmlspecialchars($row_user['username']); $total_declined++; break; case 'maybe': $maybe_users[] = htmlspecialchars($row_user['username']); $total_maybe++; break; } } mysqli_stmt_close($attendees_stmt); } // --- ZAHLENDE PERSON BESTIMMEN (MIT GEBURTSTAGS-REGEL) --- $next_payer_username = null; if ($total_accepted > 0) { $current_year = date('Y'); $meeting_date = $row['meeting_date']; // Kandidaten holen $sql_candidates = " SELECT u.id, u.username, u.birthday, u.last_birthday_year, (SELECT COUNT(*) FROM meeting_teilnehmer WHERE user_id = u.id AND paid = 1) AS paid_count FROM meeting_teilnehmer mt JOIN users u ON mt.user_id = u.id WHERE mt.meeting_id = ? AND mt.rsvp_status = 'accepted' ORDER BY u.username "; $stmt_candidates = mysqli_prepare($conn, $sql_candidates); mysqli_stmt_bind_param($stmt_candidates, "i", $meeting_id); mysqli_stmt_execute($stmt_candidates); $candidates = mysqli_fetch_all(mysqli_stmt_get_result($stmt_candidates), MYSQLI_ASSOC); mysqli_stmt_close($stmt_candidates); $birthday_payers = []; $regular_payers = []; foreach ($candidates as $c) { if (empty($c['birthday'])) { $regular_payers[] = $c; continue; } $birth_month = (int)date('m', strtotime($c['birthday'])); $birth_day = (int)date('d', strtotime($c['birthday'])); $birthday_this_year = "$current_year-$birth_month-$birth_day"; $already_paid_this_year = ($c['last_birthday_year'] == $current_year); $birthday_passed = (strtotime($birthday_this_year) <= strtotime($meeting_date)); if (!$already_paid_this_year && $birthday_passed) { $birthday_payers[] = $c; } else { $regular_payers[] = $c; } } // Priorität: Geburtstagskinder zuerst if (!empty($birthday_payers)) { usort($birthday_payers, function ($a, $b) { return $a['paid_count'] <=> $b['paid_count']; }); $next_payer_username = $birthday_payers[0]['username']; } elseif (!empty($regular_payers)) { usort($regular_payers, function ($a, $b) { return $a['paid_count'] <=> $b['paid_count']; }); $next_payer_username = $regular_payers[0]['username']; } } // --- TERMINVERSCHIEBUNG: Logik einbinden UND ausführen --- include('verschiebung.php'); handle_reschedule_actions($conn, $meeting_id, $logged_in_user_id); $reschedule_data = load_reschedule_data($conn, $meeting_id, $logged_in_user_id); $active_proposals = $reschedule_data['active_proposals']; $user_votes = $reschedule_data['user_votes']; $yes_voters = $reschedule_data['yes_voters']; $no_voters = $reschedule_data['no_voters']; } include('inc/header.php'); $german_weekdays = [ 'Mon' => 'Mo.', 'Tue' => 'Di.', 'Wed' => 'Mi.', 'Thu' => 'Do.', 'Fri' => 'Fr.', 'Sat' => 'Sa.', 'Sun' => 'So.' ]; ?>
= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) . " Uhr" ?>
Farbe des Treffens:
= htmlspecialchars($color_row['name']) ?>
= htmlspecialchars($row['reason']) ?>
Du hast zugesagt!
Du hast abgesagt!
Vielleicht dabei!
Bist du dabei?
Rechnung wird bezahlt von:
= htmlspecialchars($p['reason'] ?: 'Kein Grund angegeben') ?>