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/docsvia Nginx/router.php, or direct/docs.php). - Server Discovery (
lines 6-20): Scansdocuments/pl/anddocuments/en/viascandir(), strips.,.., and.DS_Store, embeds JSON mapfilesData = {"pl": [...], "en": [...]}into an inline<script>. - Client Initialization (
lines 88-140): SetsdocsLangfrom PHP$current_lang, activates PL/EN toggle opacity (1vs0.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.
- Trigger:
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) anddocuments/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()setsfilePath = '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/...→ HTTP404! - BR-DOC-03 (Duplicate File Maintenance Hazard):
docs.phpanddocumentation.phpare near-exact copies differing ONLY in<link rel="canonical">(docs.phpvsdocumentation.php, line 31) and the back buttonhref(/vsindex.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=0is 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.phpdoes 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 servingGET /documents/{pl|en}/{filename}.pdf. - Files Read: Local directory listing of
documents/pl/anddocuments/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/todocuments/(commitf27c77c): When Astro Starlight Docs-as-Code was introduced indocs/, PDFs were moved fromdocs/{pl,en}/todocuments/{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 Message | Root Cause in Code | How to Verify | Fix |
|---|---|---|---|
| Selecting a document shows a 404 or homepage inside the PDF iframe | User visited /documentation/ (with trailing slash) and relative documents/${docsLang}/... resolved to /documentation/documents/... (documentation.php:131) | Inspect <iframe id="pdfViewer"> src in DevTools | Change template string to root-absolute `/documents/${docsLang}/${select.value}#toolbar=0` |
| PDF dropdown is empty | documents/pl or documents/en directory missing or unreadable by PHP user | ls -la documents/pl documents/en | Verify deployment includes documents/ directory with read permissions |