Geburtstagslogik implementiert
This commit is contained in:
77
index.php
77
index.php
@@ -23,7 +23,7 @@ function is_user_on_vacation($conn, $user_id, $meeting_date)
|
|||||||
return $found !== null;
|
return $found !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔹 Funktion: Automatisch ablehnen, wenn im Urlaub (außer bei expliziter Zusage)
|
// 🔹 Funktion: Automatisch ablehnen, wenn im Urlaub
|
||||||
function auto_decline_if_on_vacation($conn, $meeting_id, $user_id, $meeting_date)
|
function auto_decline_if_on_vacation($conn, $meeting_id, $user_id, $meeting_date)
|
||||||
{
|
{
|
||||||
if (!is_user_on_vacation($conn, $user_id, $meeting_date)) {
|
if (!is_user_on_vacation($conn, $user_id, $meeting_date)) {
|
||||||
@@ -39,12 +39,10 @@ function auto_decline_if_on_vacation($conn, $meeting_id, $user_id, $meeting_date
|
|||||||
|
|
||||||
$current_status = $existing ? $existing['rsvp_status'] : null;
|
$current_status = $existing ? $existing['rsvp_status'] : null;
|
||||||
|
|
||||||
// Wenn explizit "accepted" oder "maybe" gewählt wurde → NICHT überschreiben!
|
|
||||||
if ($current_status === 'accepted' || $current_status === 'maybe') {
|
if ($current_status === 'accepted' || $current_status === 'maybe') {
|
||||||
return $current_status;
|
return $current_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nur wenn Status "declined" oder NULL → auf "declined" setzen
|
|
||||||
if ($existing) {
|
if ($existing) {
|
||||||
$upd = mysqli_prepare($conn, "UPDATE meeting_teilnehmer SET rsvp_status = 'declined', attended = 0 WHERE meeting_id = ? AND user_id = ?");
|
$upd = mysqli_prepare($conn, "UPDATE meeting_teilnehmer SET rsvp_status = 'declined', attended = 0 WHERE meeting_id = ? AND user_id = ?");
|
||||||
mysqli_stmt_bind_param($upd, "ii", $meeting_id, $user_id);
|
mysqli_stmt_bind_param($upd, "ii", $meeting_id, $user_id);
|
||||||
@@ -181,36 +179,66 @@ if ($row) {
|
|||||||
mysqli_stmt_close($attendees_stmt);
|
mysqli_stmt_close($attendees_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- ZAHLENDE PERSON BESTIMMEN ---
|
// --- ZAHLENDE PERSON BESTIMMEN (MIT GEBURTSTAGS-REGEL) ---
|
||||||
$next_payer_username = null;
|
$next_payer_username = null;
|
||||||
if ($total_accepted > 0) {
|
if ($total_accepted > 0) {
|
||||||
$sql_next_payer = "
|
$current_year = date('Y');
|
||||||
|
$meeting_date = $row['meeting_date'];
|
||||||
|
|
||||||
|
// Kandidaten holen
|
||||||
|
$sql_candidates = "
|
||||||
SELECT
|
SELECT
|
||||||
|
u.id,
|
||||||
u.username,
|
u.username,
|
||||||
|
u.birthday,
|
||||||
|
u.last_birthday_year,
|
||||||
(SELECT COUNT(*) FROM meeting_teilnehmer WHERE user_id = u.id AND paid = 1) AS paid_count
|
(SELECT COUNT(*) FROM meeting_teilnehmer WHERE user_id = u.id AND paid = 1) AS paid_count
|
||||||
FROM meeting_teilnehmer mt
|
FROM meeting_teilnehmer mt
|
||||||
JOIN users u ON mt.user_id = u.id
|
JOIN users u ON mt.user_id = u.id
|
||||||
WHERE mt.meeting_id = ? AND mt.rsvp_status = 'accepted'
|
WHERE mt.meeting_id = ? AND mt.rsvp_status = 'accepted'
|
||||||
ORDER BY paid_count ASC
|
ORDER BY u.username
|
||||||
";
|
";
|
||||||
$stmt_next_payer = mysqli_prepare($conn, $sql_next_payer);
|
|
||||||
mysqli_stmt_bind_param($stmt_next_payer, "i", $meeting_id);
|
$stmt_candidates = mysqli_prepare($conn, $sql_candidates);
|
||||||
mysqli_stmt_execute($stmt_next_payer);
|
mysqli_stmt_bind_param($stmt_candidates, "i", $meeting_id);
|
||||||
$result_next_payer = mysqli_stmt_get_result($stmt_next_payer);
|
mysqli_stmt_execute($stmt_candidates);
|
||||||
$payer_candidates = [];
|
$candidates = mysqli_fetch_all(mysqli_stmt_get_result($stmt_candidates), MYSQLI_ASSOC);
|
||||||
$min_paid_count = -1;
|
mysqli_stmt_close($stmt_candidates);
|
||||||
while ($row_payer = mysqli_fetch_assoc($result_next_payer)) {
|
|
||||||
if ($min_paid_count == -1 || $row_payer['paid_count'] < $min_paid_count) {
|
$birthday_payers = [];
|
||||||
$min_paid_count = $row_payer['paid_count'];
|
$regular_payers = [];
|
||||||
$payer_candidates = [$row_payer['username']];
|
|
||||||
} elseif ($row_payer['paid_count'] == $min_paid_count) {
|
foreach ($candidates as $c) {
|
||||||
$payer_candidates[] = $row_payer['username'];
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt_next_payer);
|
|
||||||
if (!empty($payer_candidates)) {
|
// Priorität: Geburtstagskinder zuerst
|
||||||
sort($payer_candidates);
|
if (!empty($birthday_payers)) {
|
||||||
$next_payer_username = $payer_candidates[0];
|
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'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +311,6 @@ $german_weekdays = [
|
|||||||
<p class="text-muted">nächster Termin:</p>
|
<p class="text-muted">nächster Termin:</p>
|
||||||
<p class="text-muted h3 fw-bold mb-2"><?= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) ?></p>
|
<p class="text-muted h3 fw-bold mb-2"><?= $german_weekday . ' ' . date('d.m.Y H:i', strtotime($row['meeting_date'])) ?></p>
|
||||||
<?php
|
<?php
|
||||||
// Prüfen, ob der aktuelle Benutzer bereits einen aktiven Vorschlag hat
|
|
||||||
$has_active_proposal = false;
|
$has_active_proposal = false;
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$check_proposal = mysqli_prepare($conn, "
|
$check_proposal = mysqli_prepare($conn, "
|
||||||
@@ -332,9 +359,7 @@ $german_weekdays = [
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- TODO: Fehler, wenn Kommentar weggelassen wird-->
|
<div class="d-flex justify-content-center pt-2 pb-3" style="max-width: 500px; margin-left: auto; margin-right: auto; flex-direction: column; align-items: center;">
|
||||||
<div class="d-flex justify-content-center pt-2 pb-3" style="max-width: 500px; margin-left: auto; margin-right: auto; flex-direction: column; align-items: center;" <!-- inline-css-ok -->
|
|
||||||
|
|
||||||
<?php if ($user_attendance_status === 'accepted'): ?>
|
<?php if ($user_attendance_status === 'accepted'): ?>
|
||||||
<p class="text-success fw-bold mb-4">Du hast zugesagt!</p>
|
<p class="text-success fw-bold mb-4">Du hast zugesagt!</p>
|
||||||
<div class="d-flex justify-content-center">
|
<div class="d-flex justify-content-center">
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
// Fehleranzeige für Entwicklung (optional)
|
|
||||||
// error_reporting(E_ALL);
|
|
||||||
// ini_set('display_errors', 1);
|
|
||||||
|
|
||||||
include('inc/check_login.php');
|
include('inc/check_login.php');
|
||||||
include('inc/db.php');
|
include('inc/db.php');
|
||||||
require_once 'inc/helpers.php';
|
require_once 'inc/helpers.php';
|
||||||
|
|
||||||
// Meeting-ID prüfen
|
|
||||||
if (!isset($_GET['id'])) {
|
if (!isset($_GET['id'])) {
|
||||||
$_SESSION['error_message'] = "Keine Meeting-ID angegeben.";
|
$_SESSION['error_message'] = "Keine Meeting-ID angegeben.";
|
||||||
header("Location: index.php");
|
header("Location: index.php");
|
||||||
@@ -15,12 +10,9 @@ if (!isset($_GET['id'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$meeting_id = intval($_GET['id']);
|
$meeting_id = intval($_GET['id']);
|
||||||
|
|
||||||
// Quelle merken (für Weiterleitung)
|
|
||||||
$source_page = isset($_GET['source']) && $_GET['source'] === 'history' ? 'history' : 'index';
|
$source_page = isset($_GET['source']) && $_GET['source'] === 'history' ? 'history' : 'index';
|
||||||
$cancel_link = $source_page === 'history' ? 'history.php' : 'index.php';
|
$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 = ?");
|
$stmt = mysqli_prepare($conn, "SELECT meeting_date, color_id, reason FROM meetings WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
@@ -33,7 +25,6 @@ if (!$meeting) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Farben und Benutzer laden
|
|
||||||
$colors = [];
|
$colors = [];
|
||||||
$colors_result = mysqli_query($conn, "SELECT id, name FROM colors ORDER BY name");
|
$colors_result = mysqli_query($conn, "SELECT id, name FROM colors ORDER BY name");
|
||||||
while ($row = mysqli_fetch_assoc($colors_result)) {
|
while ($row = mysqli_fetch_assoc($colors_result)) {
|
||||||
@@ -46,7 +37,6 @@ while ($row = mysqli_fetch_assoc($users_result)) {
|
|||||||
$users[] = $row;
|
$users[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bestehende Teilnehmerdaten laden
|
|
||||||
$existing_feedback = [];
|
$existing_feedback = [];
|
||||||
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid FROM meeting_teilnehmer WHERE meeting_id = ?");
|
$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);
|
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
||||||
@@ -60,9 +50,7 @@ mysqli_stmt_close($stmt);
|
|||||||
$message = '';
|
$message = '';
|
||||||
$message_type = '';
|
$message_type = '';
|
||||||
|
|
||||||
// POST-Verarbeitung
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
// Meeting-Daten aktualisieren (nur im History-Modus)
|
|
||||||
if ($source_page === 'history') {
|
if ($source_page === 'history') {
|
||||||
$meeting_date = $_POST['meeting_date'] ?? '';
|
$meeting_date = $_POST['meeting_date'] ?? '';
|
||||||
$color_id = intval($_POST['color_id'] ?? 0);
|
$color_id = intval($_POST['color_id'] ?? 0);
|
||||||
@@ -97,7 +85,24 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt_insert);
|
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') {
|
if ($source_page === 'index') {
|
||||||
$stmt_complete = mysqli_prepare($conn, "UPDATE meetings SET is_completed = 1 WHERE id = ?");
|
$stmt_complete = mysqli_prepare($conn, "UPDATE meetings SET is_completed = 1 WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt_complete, "i", $meeting_id);
|
mysqli_stmt_bind_param($stmt_complete, "i", $meeting_id);
|
||||||
@@ -112,7 +117,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$message_type = 'warning';
|
$message_type = 'warning';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔁 Zurück zur ursprünglichen Quelle
|
|
||||||
header("Location: " . $cancel_link);
|
header("Location: " . $cancel_link);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user