0) { $restarbeitHinweis = true; } else { $sperrHinweis = app_feature_tenant_notice_html('paypal_inbox'); $hasAccess = false; } } $flash = null; if ($hasAccess && isset($_SESSION['flash_paypal'])) { $flash = $_SESSION['flash_paypal']; unset($_SESSION['flash_paypal']); } $suchbegriff = trim((string)($_SERVER['REQUEST_METHOD'] === 'POST' ? ($_POST['return_q'] ?? '') : ($_GET['q'] ?? ''))); $returnQuery = $suchbegriff !== '' ? '?q=' . urlencode($suchbegriff) : ''; function paypal_select_options(array $members, array $suggestions = [], int $selectedId = 0): string { $suggestedIds = []; foreach ($suggestions as $suggestion) { $suggestedIds[(int)$suggestion['participant_id']] = true; } $html = ''; if ($suggestions !== []) { $html .= ''; foreach ($suggestions as $suggestion) { $id = (int)$suggestion['participant_id']; $html .= ''; } $html .= ''; } $html .= ''; foreach ($members as $member) { $id = (int)$member['participant_id']; if (isset($suggestedIds[$id])) { continue; } $html .= ''; } $html .= ''; return $html; } function paypal_payment_matches_query(array $payment, string $query): bool { $query = imports_normalize_match_text($query); if ($query === '') { return true; } $text = imports_normalize_match_text( (string)$payment['payer_name'] . ' ' . (string)($payment['note'] ?? '') . ' ' . (string)($payment['transaction_code'] ?? '') ); return str_contains($text, $query); } if ($hasAccess && $_SERVER['REQUEST_METHOD'] === 'POST') { $aktion = (string)($_POST['aktion'] ?? ''); $paymentId = (int)($_POST['payment_id'] ?? 0); $actorUserId = $saasUser['user_id'] ?? null; if ($aktion === 'zuordnen') { $participantId = (int)($_POST['participant_id'] ?? 0); if ($participantId <= 0) { $flash = ['type' => 'error', 'text' => 'Bitte ein Mitglied auswählen.']; } else { $result = paypal_assign_payment($pdo, $tenantId, $paymentId, $participantId, $actorUserId); $erfolgstext = 'Zahlung wurde zugeordnet und als Einzahlung gebucht.'; // Wurde dabei der PayPal-Name gelernt, gehoert das in die Meldung - // sonst wirkt die stillschweigende Aenderung am Mitglied wie Magie. if (($result['learned_paypal_name'] ?? null) !== null) { $erfolgstext .= ' Der PayPal-Name „' . $result['learned_paypal_name'] . '" ist jetzt bei diesem Mitglied hinterlegt – künftige Zahlungen' . ' werden automatisch zugeordnet.'; } $flash = $result['ok'] ? ['type' => 'success', 'text' => $erfolgstext] : ['type' => 'error', 'text' => $result['error'] ?? 'Die Zuordnung ist fehlgeschlagen.']; } } elseif ($aktion === 'ignorieren') { $result = paypal_ignore_payment($pdo, $tenantId, $paymentId, $actorUserId); $flash = $result['ok'] ? ['type' => 'success', 'text' => 'Zahlung wurde als erledigt markiert.'] : ['type' => 'error', 'text' => $result['error'] ?? 'Die Aktion ist fehlgeschlagen.']; } // Post-Redirect-Get gegen Doppelbuchung per Refresh. $_SESSION['flash_paypal'] = $flash; header('Location: paypal-zuordnung.php' . $returnQuery); exit; } $inboxAddress = null; $offene = []; $mitglieder = []; if ($hasAccess) { $token = paypal_inbox_ensure_token($pdo, $tenantId); $inboxAddress = paypal_inbox_address_for_token($token); $offene = paypal_fetch_unmatched($pdo, $tenantId); $mitglieder = ledger_fetch_participant_summaries($pdo, $tenantId, ['active_only' => true]); } $offeneGefiltert = array_values(array_filter($offene, static fn(array $payment): bool => paypal_payment_matches_query($payment, $suchbegriff))); include "header.php"; include "headerline.php"; include "nav.php"; ?>