Skip to content
📦 ARCHIVED SNAPSHOT (v1.0) You are viewing historical business logic and documentation for Webpage (planovi.app) v1.0 (frozen on 2026-11-23, commit 69f9463). Switch to Latest →

8. Legal Document Viewer

Repository: Webpage (planovi-webpage) • Rule Prefix: BR-DOC • Documented Rules: 6 • Open [TEAM_WHY_NEEDED] Questions: 2

1. Business Purpose & Actors

  • Problem solved: Provides public, in-browser viewing of official PLANOVI legal documents (Privacy Policy and Terms & Conditions) in both Polish and English without requiring file downloads.
  • Actors: Prospective and current users reviewing privacy/GDPR terms (linked from footer and cookie banner), regulators/auditors.

2. All Features & End-to-End Flows

  • Flow A — Document Listing & PDF Preview (documentation.php:1-143, docs.php:1-143):
    • Trigger: GET /documentation (or /docs via Nginx/router.php, or direct /docs.php).
    • Server Discovery (lines 6-20): Scans documents/pl/ and documents/en/ via scandir(), strips ., .., and .DS_Store, embeds JSON map filesData = {"pl": [...], "en": [...]} into an inline <script>.
    • Client Initialization (lines 88-140): Sets docsLang from PHP $current_lang, activates PL/EN toggle opacity (1 vs 0.6), populates <select id="fileSelect"> formatting each filename via .replace('.pdf', '').replace(/_/g, ' ').toUpperCase().
    • Selection (loadFile()): Sets <iframe id="pdfViewer" src="documents/${docsLang}/${select.value}#toolbar=0">, shows iframe, hides placeholder.

3. Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-DOC-01 (Filesystem-Driven Catalog): Available documents are dynamically enumerated from documents/pl/ (polityka_prywatnosci.pdf, regulamin.pdf) and documents/en/ (privacy_policy.pdf, terms_and_conditions.pdf); any file placed in those directories (except ., .., .DS_Store) appears automatically without code changes (documentation.php:10-18).
  • BR-DOC-02 (Trailing-Slash Relative Iframe Path Bug): loadFile() sets filePath = 'documents/' + docsLang + '/' + select.value + '#toolbar=0' (missing leading /; documentation.php:131, docs.php:131). If visited at /documentation/ or /docs/ (with trailing slash), the browser requests /documentation/documents/pl/... → HTTP 404!
  • BR-DOC-03 (Duplicate File Maintenance Hazard): docs.php and documentation.php are near-exact copies differing ONLY in <link rel="canonical"> (docs.php vs documentation.php, line 31) and the back button href (/ vs index.php, line 74).
  • BR-DOC-04 (Non-PDF Files Not Filtered): scandir() excludes only ., .., .DS_Store, not non-PDF files or subdirectories (documentation.php:13).
  • BR-DOC-05 (Toolbar Suppression Portability): Appending #toolbar=0 is a browser-dependent PDF viewer hint (honored by Chromium PDFium, ignored by several mobile browsers and Safari iOS, where inline PDF iframes may render only page 1 or require download).
  • BR-DOC-06 (No Deep-Linking to a Specific Document): documentation.php does not read a query parameter (e.g. ?doc=privacy_policy.pdf), so clicking "Privacy Policy" in the cookie banner or waitlist consent opens the viewer in its empty placeholder state requiring manual dropdown selection.

4. State Machines & Data Lifecycle

Client UI states: Placeholder (docsPlaceholder visible, pdfViewer hidden) → [select file] → Viewing PDF (pdfViewer visible) → [switch PL/EN docsLang] → Placeholder (resets dropdown and hides iframe).

5. Technical Contract (Inputs → Processing → Side Effects)

  • Endpoints: GET /documentation, GET /documentation.php, GET /docs.php, plus direct static PDF serving GET /documents/{pl|en}/{filename}.pdf.
  • Files Read: Local directory listing of documents/pl/ and documents/en/.
  • Side Effects: None (read-only static file serving).

6. Cross-Repository Dependencies

None (PDF files are committed directly inside documents/).

7. Why It Works This Way (Decisions, Trade-offs & Workarounds)

  • Rename from docs/ to documents/ (commit f27c77c): When Astro Starlight Docs-as-Code was introduced in docs/, PDFs were moved from docs/{pl,en}/ to documents/{pl,en}/ to avoid directory collision.
  • [TEAM_WHY_NEEDED: Why do both docs.php and documentation.php exist as near-identical files? Should docs.php be removed or 301-redirected to /documentation?]
  • [TEAM_WHY_NEEDED: Should documentation.php support ?doc=<filename> deep links (and root-absolute /documents/... iframe paths) so Privacy Policy links from the waitlist and cookie banner open the Privacy Policy PDF directly?]

8. Debugging, Logs & Common Failure Modes

Symptom / Error MessageRoot Cause in CodeHow to VerifyFix
Selecting a document shows a 404 or homepage inside the PDF iframeUser visited /documentation/ (with trailing slash) and relative documents/${docsLang}/... resolved to /documentation/documents/... (documentation.php:131)Inspect <iframe id="pdfViewer"> src in DevToolsChange template string to root-absolute `/documents/${docsLang}/${select.value}#toolbar=0`
PDF dropdown is emptydocuments/pl or documents/en directory missing or unreadable by PHP userls -la documents/pl documents/enVerify deployment includes documents/ directory with read permissions