Die Zugriffspruefung lief bisher in 19 Dateien auf einen Fallback gegen die Legacy-Tabelle kl_Mitarbeiter (checkKaffeelisteAdmin/-Access). Der Zugang haengt jetzt ausschliesslich an der SaaS-Anmeldung. - Fallback-Bloecke in allen 19 Dateien entfernt, ebenso getUserName/getUserId - functions.php besteht nur noch aus der SaaS-Anmeldung; die per String zusammengebaute Abfrage "WHERE Email like '<eingabe>'" ist damit weg - config.php baut keine sqlsrv-Verbindung mehr auf, der Kompatibilitaetslayer lib/sqlsrv_mysql_compat.php ist verwaist und entfaellt - Auto-Login per DEV_AUTH_EMAIL gibt es nicht mehr: er meldete jeden Besucher an und machte damit den Login-Schutz unpruefbar. Angemeldet wird auch lokal ueber login.php; die Variable dient nur noch scripts/init-mysql-dev.php http-smoke war an die Golden-Master-Daten des Default-Mandanten gebunden und hatte deshalb sechs dauerhaft rote Pruefungen. Der Test legt sich jetzt einen eigenen Mandanten mit bekannten Salden an, meldet sich per HTTP an und raeumt danach auf. Geschuetzte Seiten werden nicht mehr ueber das Wort "Login" im Text geprueft, sondern ueber die tatsaechliche 302-Umleitung. http-smoke 27 PASS / 6 FAIL -> 33 PASS / 0 FAIL role-matrix 55 PASS / 0 FAIL -> unveraendert tenant-isolation 9 PASS / 1 FAIL -> 11 PASS / 1 FAIL (Altfehler) Ausserdem "keine Zugang" -> "keinen Zugang" in zwei Fehlermeldungen; der Rollentest erkannte die Ablehnung an genau diesem Tippfehler und wurde mitgezogen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
191 lines
6.6 KiB
PHP
191 lines
6.6 KiB
PHP
<?php
|
|
|
|
include "functions.php";
|
|
require_once __DIR__ . "/app/ledger.php";
|
|
|
|
// Teilnehmer-ID aus dem Journal. "user_id" bleibt als Alias erhalten, damit
|
|
// aeltere Links und Lesezeichen weiter funktionieren.
|
|
$participantId = filter_input(INPUT_GET, 'participant_id', FILTER_VALIDATE_INT);
|
|
if ($participantId === null || $participantId === false) {
|
|
$participantId = filter_input(INPUT_GET, 'user_id', FILTER_VALIDATE_INT);
|
|
}
|
|
if ($participantId === null) {
|
|
http_response_code(400);
|
|
exit('Fehlender Parameter');
|
|
}
|
|
if ($participantId === false || $participantId <= 0) {
|
|
http_response_code(400);
|
|
exit('Ungültige Teilnehmer-ID');
|
|
}
|
|
|
|
$pdo = app_db_pdo();
|
|
$saasUser = saas_current_user($pdo);
|
|
$tenantId = 0;
|
|
$hasAccess = false;
|
|
|
|
if ($saasUser !== null && saas_user_has_role(['owner', 'admin', 'treasurer'], $saasUser)) {
|
|
$tenantId = (int)$saasUser['tenant_id'];
|
|
$hasAccess = true;
|
|
}
|
|
|
|
$participant = $hasAccess
|
|
? ledger_fetch_participant_summary($pdo, $tenantId, $participantId)
|
|
: null;
|
|
$settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null;
|
|
$paymentEntries = $participant !== null
|
|
? ledger_fetch_recent_entries($pdo, $tenantId, [
|
|
'participant_id' => $participant['participant_id'],
|
|
'type' => 'payment',
|
|
'limit' => 100,
|
|
])
|
|
: [];
|
|
$consumptionEntries = $participant !== null
|
|
? ledger_fetch_recent_entries($pdo, $tenantId, [
|
|
'participant_id' => $participant['participant_id'],
|
|
'type' => 'consumption',
|
|
'limit' => 100,
|
|
])
|
|
: [];
|
|
|
|
function teilnehmerauswertung_money(int $cents): string
|
|
{
|
|
return saas_format_money_cents($cents) . ' €';
|
|
}
|
|
|
|
function teilnehmerauswertung_date(string $value): string
|
|
{
|
|
try {
|
|
return (new DateTimeImmutable($value))->format('d.m.Y');
|
|
} catch (Throwable $e) {
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
function teilnehmerauswertung_current_name(?array $saasUser): string
|
|
{
|
|
return trim((string)($saasUser['display_name'] ?? ''));
|
|
}
|
|
|
|
function teilnehmerauswertung_paypal_action(string $template, string $amount): string
|
|
{
|
|
return trim($template) . $amount;
|
|
}
|
|
|
|
function teilnehmerauswertung_render_payments(array $entries): void
|
|
{
|
|
echo "<h4>Letzte Einzahlungen</h4>";
|
|
echo "<table><tr><th style='width:120px'>Datum</th><th>Einzahlung</th></tr>";
|
|
if ($entries === []) {
|
|
echo "<tr><td colspan='2'>Keine Einzahlungen vorhanden.</td></tr>";
|
|
}
|
|
foreach ($entries as $entry) {
|
|
echo "<tr>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_money((int)$entry['amount_cents'])) . "</td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
|
|
function teilnehmerauswertung_render_consumption(array $entries): void
|
|
{
|
|
echo "<h4>Letzte Striche</h4>";
|
|
echo "<table><tr><th style='width:120px'>Datum</th><th>Striche</th><th>Kosten</th></tr>";
|
|
if ($entries === []) {
|
|
echo "<tr><td colspan='3'>Keine Striche vorhanden.</td></tr>";
|
|
}
|
|
foreach ($entries as $entry) {
|
|
echo "<tr>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
|
|
echo "<td>" . number_format((int)($entry['marks_count'] ?? 0), 0, ',', '.') . "</td>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_money(abs((int)$entry['amount_cents']))) . "</td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
|
|
include "header.php";
|
|
include "headerline.php";
|
|
include "nav.php";
|
|
?>
|
|
|
|
<section id="banner">
|
|
<div class="content">
|
|
<?php
|
|
if ($hasAccess && $participant !== null) {
|
|
$balanceCents = (int)$participant['balance_cents'];
|
|
$balance = teilnehmerauswertung_money($balanceCents);
|
|
$currentName = teilnehmerauswertung_current_name($saasUser);
|
|
$paypalEnabled = $settings !== null
|
|
&& (int)$settings['paypal_enabled'] === 1
|
|
&& trim((string)$settings['paypal_url_template']) !== '';
|
|
?>
|
|
<h2>Auswertung</h2>
|
|
<?php if ($currentName !== ''): ?>
|
|
Hallo <?php echo saas_html($currentName); ?>!<br><br>
|
|
<?php endif; ?>
|
|
|
|
<h2>Gesamtausgabe und Gesamtstriche</h2>
|
|
<p>Name: <?php echo saas_html($participant['display_name']); ?></p>
|
|
<p>E-Mail: <?php echo saas_html((string)($participant['email'] ?? '')); ?></p>
|
|
Gesamtausgabe: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_costs_cents'])); ?><br>
|
|
Gesamtstriche: <?php echo number_format((int)$participant['total_marks'], 0, ',', '.'); ?><br>
|
|
<p>Gesamteinzahlung: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_payments_cents'])); ?></p>
|
|
<?php
|
|
if ($balanceCents > 0) {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Guthaben)</b></p>";
|
|
} elseif ($balanceCents < 0) {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Schulden)</b></p>";
|
|
} else {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . "</b></p>";
|
|
}
|
|
?>
|
|
|
|
<h2>Jahresübersicht</h2>
|
|
Ausgabe im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_costs_cents'])); ?><br>
|
|
Gesamtstriche im aktuellen Jahr: <?php echo number_format((int)$participant['year_marks'], 0, ',', '.'); ?><br>
|
|
<p>Gesamteinzahlung im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_payments_cents'])); ?></p>
|
|
|
|
<?php if ($paypalEnabled): ?>
|
|
<h2>PayPal-Einzahlungen</h2>
|
|
<b>Bezahle immer über die Freunde-Funktion von PayPal. Ansonsten stellen wir 20% des Betrags als Gebühr in Rechnung.</b><br>
|
|
<br>
|
|
<?php
|
|
$paypalTemplate = trim((string)$settings['paypal_url_template']);
|
|
if ($balanceCents < 0) {
|
|
$debtCents = abs($balanceCents);
|
|
$debtAmount = teilnehmerauswertung_money($debtCents);
|
|
echo '<form action="' . saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, saas_format_money_cents($debtCents))) . '" target="_blank"><button type="submit">' . saas_html($debtAmount) . ' bezahlen</button></form>';
|
|
}
|
|
?>
|
|
<ul class="actions">
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '5')); ?>" target="_blank"><button type="submit">5,00 € einzahlen</button></form></li>
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '10')); ?>" target="_blank"><button type="submit">10,00 € einzahlen</button></form></li>
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '15')); ?>" target="_blank"><button type="submit">15,00 € einzahlen</button></form></li>
|
|
</ul>
|
|
<?php endif; ?>
|
|
|
|
<br><br>
|
|
<?php
|
|
teilnehmerauswertung_render_payments($paymentEntries);
|
|
echo "<br>";
|
|
teilnehmerauswertung_render_consumption($consumptionEntries);
|
|
?>
|
|
<br><br>
|
|
|
|
<form action="namenanpassen.php" method="get">
|
|
<button type="submit">Namensanpassung</button>
|
|
</form>
|
|
<?php
|
|
} elseif ($hasAccess) {
|
|
echo "<h2>Auswertung</h2>";
|
|
echo "<p>Mitarbeiter wurde im aktuellen Mandanten nicht gefunden.</p>";
|
|
} else {
|
|
echo "<h2>Kein Zugriff</h2>";
|
|
}
|
|
?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php include "footer.php"; ?>
|