faq.php zeigte bislang fuer jeden Mandanten denselben, komplett AOK-spezifischen Inhalt (Kaffeemaschinen-Bedienung, interner Ansprechpartner) - fuer andere Kunden unbrauchbar und inhaltlich falsch. - Neue Tabelle faq_entries (tenant-scoped, Soft-Delete, sort_order). - Migration uebernimmt die bisherigen AOK-Inhalte einmalig als FAQ des migrierten Default-Mandanten; andere Mandanten sehen sie nicht. - Neue Mandanten bekommen bei der Registrierung automatisch eine kurze generische Starter-FAQ (faq_seed_default_entries), frei editierbar. - faq.php: lesbar fuer alle angemeldeten Mitglieder eines Mandanten, Anlegen/Bearbeiten/Entfernen auf owner/admin beschraenkt. - Landingpage verweist nicht mehr auf faq.php (jetzt interner, mandantengebundener Inhalt statt oeffentlicher Marketing-Seite). Live getestet: AOK-Carry-over fuer Default-Mandant, frisch registrierter Test-Mandant bekam isolierte generische Starter-FAQ, Anlegen mit HTML-Payload (korrekt escaped), Bearbeiten und Soft-Delete geprueft. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
163 lines
5.0 KiB
PHP
163 lines
5.0 KiB
PHP
<?php
|
|
|
|
include "functions.php";
|
|
require_once __DIR__ . "/app/ledger.php";
|
|
require_once __DIR__ . "/app/faq.php";
|
|
require_once __DIR__ . "/app/audit.php";
|
|
app_require_csrf();
|
|
include "header.php";
|
|
include "headerline.php";
|
|
include "nav.php";
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!-- Banner -->
|
|
<section id="banner">
|
|
<div class="content">
|
|
|
|
<?php
|
|
|
|
$pdo = app_db_pdo();
|
|
$saasUser = saas_current_user($pdo);
|
|
$tenantId = 0;
|
|
$hasAccess = false;
|
|
$kannVerwalten = false;
|
|
|
|
if ($saasUser !== null) {
|
|
$tenantId = (int)$saasUser['tenant_id'];
|
|
$hasAccess = true;
|
|
$kannVerwalten = saas_user_has_role(['owner', 'admin'], $saasUser);
|
|
}
|
|
|
|
if (!$hasAccess && $saasUser === null && checkKaffeelisteAccess($conn, $mailadress)) {
|
|
$tenant = ledger_fetch_default_tenant($pdo);
|
|
if ($tenant !== null) {
|
|
$tenantId = (int)$tenant['id'];
|
|
$hasAccess = true;
|
|
$kannVerwalten = checkKaffeelisteAdmin($conn, $mailadress);
|
|
}
|
|
}
|
|
|
|
if (!$hasAccess) {
|
|
echo "<h2>Kein Zugriff</h2>";
|
|
include "footer.php";
|
|
exit;
|
|
}
|
|
|
|
$meldung = null;
|
|
$fehler = null;
|
|
$bearbeitenId = null;
|
|
|
|
if ($kannVerwalten && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$aktion = $_POST['aktion'] ?? '';
|
|
$actorUserId = $saasUser['user_id'] ?? null;
|
|
|
|
if ($aktion === 'anlegen') {
|
|
if (faq_create($pdo, $tenantId, (string)($_POST['question'] ?? ''), (string)($_POST['answer'] ?? ''))) {
|
|
app_audit_log($pdo, $tenantId, $actorUserId, 'faq.created', 'faq_entry', null);
|
|
$meldung = 'Frage wurde hinzugefügt.';
|
|
} else {
|
|
$fehler = 'Bitte Frage und Antwort ausfüllen.';
|
|
}
|
|
} elseif ($aktion === 'bearbeiten') {
|
|
$bearbeitenId = (int)($_POST['id'] ?? 0);
|
|
} elseif ($aktion === 'speichern') {
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
if (faq_update($pdo, $tenantId, $id, (string)($_POST['question'] ?? ''), (string)($_POST['answer'] ?? ''))) {
|
|
app_audit_log($pdo, $tenantId, $actorUserId, 'faq.updated', 'faq_entry', $id);
|
|
$meldung = 'Frage wurde aktualisiert.';
|
|
} else {
|
|
$fehler = 'Bitte Frage und Antwort ausfüllen.';
|
|
$bearbeitenId = $id;
|
|
}
|
|
} elseif ($aktion === 'loeschen') {
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
if (faq_soft_delete($pdo, $tenantId, $id)) {
|
|
app_audit_log($pdo, $tenantId, $actorUserId, 'faq.deleted', 'faq_entry', $id);
|
|
$meldung = 'Frage wurde entfernt.';
|
|
}
|
|
}
|
|
}
|
|
|
|
$eintraege = faq_fetch_all($pdo, $tenantId);
|
|
$bearbeitenEintrag = null;
|
|
if ($bearbeitenId !== null) {
|
|
foreach ($eintraege as $eintrag) {
|
|
if ($eintrag['id'] === $bearbeitenId) {
|
|
$bearbeitenEintrag = $eintrag;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<h2>FAQ - Kaffeeliste</h2>
|
|
|
|
<?php if ($meldung !== null): ?>
|
|
<div class="hint-box success"><p><?php echo saas_html($meldung); ?></p></div>
|
|
<?php endif; ?>
|
|
<?php if ($fehler !== null): ?>
|
|
<div class="hint-box error"><p><?php echo saas_html($fehler); ?></p></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($eintraege === []): ?>
|
|
<p>Für dieses Team wurden noch keine Fragen hinterlegt.</p>
|
|
<?php endif; ?>
|
|
|
|
<?php foreach ($eintraege as $eintrag): ?>
|
|
<div class="faq-entry">
|
|
<?php if ($kannVerwalten && $bearbeitenEintrag !== null && $bearbeitenEintrag['id'] === $eintrag['id']): ?>
|
|
<form method="post" action="faq.php">
|
|
<?php echo app_csrf_field(); ?>
|
|
<input type="hidden" name="aktion" value="speichern">
|
|
<input type="hidden" name="id" value="<?php echo (int)$eintrag['id']; ?>">
|
|
<label>Frage:</label><br>
|
|
<input type="text" name="question" value="<?php echo saas_html($eintrag['question']); ?>" required style="width:100%"><br><br>
|
|
<label>Antwort:</label><br>
|
|
<textarea name="answer" required style="width:100%"><?php echo saas_html($eintrag['answer']); ?></textarea><br><br>
|
|
<button type="submit">Speichern</button>
|
|
<a href="faq.php" class="button">Abbrechen</a>
|
|
</form>
|
|
<?php else: ?>
|
|
<p><b><?php echo saas_html($eintrag['question']); ?></b></p>
|
|
<p><?php echo nl2br(saas_html($eintrag['answer'])); ?></p>
|
|
<?php if ($kannVerwalten): ?>
|
|
<form method="post" action="faq.php" style="display:inline">
|
|
<?php echo app_csrf_field(); ?>
|
|
<input type="hidden" name="aktion" value="bearbeiten">
|
|
<input type="hidden" name="id" value="<?php echo (int)$eintrag['id']; ?>">
|
|
<button type="submit">Bearbeiten</button>
|
|
</form>
|
|
<form method="post" action="faq.php" style="display:inline" onsubmit="return confirm('Diese Frage wirklich entfernen?');">
|
|
<?php echo app_csrf_field(); ?>
|
|
<input type="hidden" name="aktion" value="loeschen">
|
|
<input type="hidden" name="id" value="<?php echo (int)$eintrag['id']; ?>">
|
|
<button type="submit">Entfernen</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<br>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if ($kannVerwalten): ?>
|
|
<h3>Neue Frage hinzufügen</h3>
|
|
<form method="post" action="faq.php">
|
|
<?php echo app_csrf_field(); ?>
|
|
<input type="hidden" name="aktion" value="anlegen">
|
|
<label>Frage:</label><br>
|
|
<input type="text" name="question" required style="width:100%"><br><br>
|
|
<label>Antwort:</label><br>
|
|
<textarea name="answer" required style="width:100%"></textarea><br><br>
|
|
<button type="submit">Frage hinzufügen</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</section>
|
|
|
|
<?php include "footer.php"; ?>
|