# Website announcements

Administrators manage announcements at `/zarzadzanie/komunikaty/`. This feature only delivers
website messages; it does not send email or SMS. The administration page requires
`LEVEL_ADMIN` and a hard login. Mutations require POST and scoped CSRF protection.

## Content and scheduling

An announcement has an optional title, required Markdown body, optional button
label and URL (both or neither), presentation (`flash` or `infobox`), audience,
start/end datetimes and an enabled flag. Supported Markdown is intentionally
limited to paragraphs, line breaks, bold text and links. Raw HTML and images are
not interpreted. URLs must be HTTP/HTTPS or a local path beginning with a single
slash; unsafe schemes, backslashes and control characters are rejected.

The editor defaults to now and now plus 14 days in Europe/Warsaw. Visibility uses
`starts_datetime <= now < ends_datetime`. Disabling stops subsequent delivery;
already rendered pages are not updated live. Editing or re-enabling preserves the
announcement ID and therefore preserves browser dismissal state. Create a new
announcement for a new emission. Records are not permanently deleted.

Audiences are everyone, authenticated visitors, current RollPoints members,
authenticated nonmembers and instructors (including administrators). Membership
belongs to the signed-in account, not the selected child. Both RollPoints-specific
audiences are suppressed when RollPoints is disabled. Eligibility is evaluated
server-side on each delivery request, independently of the administrative preview.

The editor's Preview button renders the actual selected modal or infobox on the
editor page, using the same shared PHP template as published announcements. Infobox
previews appear below navigation; modal previews enter the automatic modal queue.
Explicit preview replaces normal announcements for that response. It does
not save content, create browser-session cookies, read or modify dismissal history,
or suppress an already viewed announcement. The optional action uses `btn-sm`.
Infoboxes use the Bootstrap primary variant for their side accent. The infobox
close button has the tooltip “Zamknij i nie pokazuj więcej”; ordinary
dismissal still lasts seven days, while dismissing a preview has no lasting effect.

## Flash overlap confirmation

Before saving an enabled flash, the model checks other enabled flashes with
overlapping time intervals and potentially overlapping audiences. Touching interval
boundaries are not overlaps. Members and nonmembers are disjoint; instructors may
overlap either group. The check does not depend on current audience size, feature
availability or previous browser dismissals, and includes future schedules.

An overlap prevents the initial save. The administrator sees the conflicting
messages and schedules in an automatically opened modal after the form response,
following any operational modals, and must explicitly confirm. The shared confirmation modal
uses “Wróć do edycji” and “Zapisz mimo ostrzeżenia”. Server-side confirmation binds
the submitted content, edited ID and conflict snapshot. The final POST recomputes
the snapshot; changed content or conflicts require a new confirmation. CSRF and
authorization checks still apply. JavaScript alone cannot authorize this save.

## Delivery and browser state

The shared page header obtains eligible messages from the model and renders their
HTML in the shared template directly below navigation. Messages are ordered by
start datetime and then ID. There is no announcement page or JSON delivery endpoint.
The `ZarzadzanieController` manages editing and disabling. Files, API responses,
print layouts and pages without navigation do not include announcements.

All operational messages use `Mini\Libs\UiMessage` for their alert or Bootstrap
modal HTML. It escapes plain text and only accepts prepared HTML through the
explicit `body_html` option; application views escape any dynamic values before
building that HTML. The generator supports multiple links or buttons, form
submit actions, optional icons, Bootstrap variants, dismissal behavior and
browser-memory policy. Flash retains PHP-session transport; confirmation
triggers retain `data-confirmation-*`, the original form submission and CSRF.
The common JavaScript in `application.js` handles modal order, browser memory
and dismissal. It does not fetch announcements or generate their content.

Operational message containers carry `data-nosnippet`. This asks Google not
to use their text in search-result snippets; it is not a fragment-level
`noindex` rule. Public guidance, static business-rule explanations, payment
instructions and help are regular page content and remain outside the
operational renderer. The unconfirmed-phone notice, class pass restrictions,
child-enrollment guidance and the large calendar text are intentionally static
and nondismissible. The small calendar hint uses the shared renderer with a
seven-day cookie dismissal. AJAX errors clone server-rendered alert
markup and fill only its text node, without native browser `alert()`.

Operational Flash messages retain their existing escaping and contract. Website
flashes follow operational messages in the shared automatic Bootstrap modal queue.
They have OK and an optional link button; Escape and backdrop clicks do not dismiss
them. An omitted title displays “Informacja”. A flash is marked as seen only on
`shown.bs.modal`, not when rendered or queued.

A browser-session cookie provides a session marker independent of login/logout;
localStorage records seen flash IDs against that marker. Tabs share that state,
with Web Locks coordinating delivery where supported. Browser session restoration
may preserve the session cookie. Clearing site data clears the remembered state.

Infobox dismissal stores an expiry seven days after clicking × in a cookie,
shared across accounts and guest visits in the same browser. The shared renderer
filters cookie-backed alerts before emitting HTML, so dismissed boxes never flash
during page loading. Cookie names derive from stable memory keys; TTL remains
configurable in seconds, with Path=/, SameSite=Lax and Secure on HTTPS. Session
alerts use session cookies. Preview ignores cookies and does not write them.
No earlier localStorage infobox state is migrated (the feature was not deployed).
Cookies must be forwarded to PHP; full-page caches must respect these cookies.
Following
the optional link does not dismiss the infobox. There is no database record of
views or dismissals and no cross-device synchronization. Browser storage failures
may cause repeated messages but must not prevent normal use.

## Deployment and verification

The additive `database/migrations/20260921120000_add_announcements.sql` migration creates the announcement table without
historical backfill or seeded messages. Run it through the normal migration runner
before enabling the new code. Re-running the migration is safe. No configuration,
ignored assets, file moves or Sass compilation are required. A code rollback leaves
the additive table in place. No production or test-next deployment is implicit.

Verify all audiences and scheduling boundaries, restricted Markdown/URL handling,
admin authorization/CSRF, conflict confirmation and changed-conflict rejection.
Verify the shared modal sequence, login/logout and multiple tabs, seven-day
infobox dismissal, preview without changing browser state, keyboard access and
mobile layout. Database tests must use an isolated `codex_rollpoints_*` database,
never the application database. Public FAQ does not need to change: there is no
new customer workflow requiring instructions.

Focused checks (run PHP and Node in the existing project containers):

```sh
php tests/announcement_rules_test.php
php tests/announcement_admin_controller_test.php
php tests/request_error_handling_test.php
node tests/announcements_client_test.js
node tests/announcement_modal_queue_test.js
```

After preparing an isolated schema and applying the announcement migration there,
run `tests/announcement_database_test.php` with `RP_TEST_DATABASE` set to that
schema and `RP_TEST_ENABLED=1`, then `RP_TEST_ENABLED=0`. Fixtures are rolled back.
