# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Setup

```bash
composer install        # installs PHPMailer (only external dependency)
```

Import `sql/schema.sql` once into the MySQL database to create tables and seed the 4 default questions.

## Architecture

Three public-facing PHP pages, no framework, no build step.

| File | Role |
|------|------|
| `questionnaire.php` | Public form reached via `?id=TOKEN`. Shows form (pending) or thank-you (submitted). |
| `sender.php` | Internal page: generates token, creates `questionnaires` row, sends email via PHPMailer. |
| `dashboard.php` | Internal page: Tab A = CRUD for clients/accounts/creatives/questions. Tab B = view/filter/export responses. |
| `config.php` | DB constants, mail constants, `getPDO()` singleton. |
| `sql/schema.sql` | DDL + seed data for 4 initial questions. |
| `assets/css/style.css` | All styles (vanilla CSS, no preprocessor). |

## Data model key points

- `questionnaires` holds the token and `sent_to` email. `sent_to` is **not** surfaced in the responses dashboard — anonymity is intentional.
- `responses` (client/account selection) and `response_answers` (one row per question) are separate so the question count can grow without schema changes.
- Deleting a `response` cascades to `response_answers`. Deleting a `questionnaire` cascades to `response`.

## Token / submission flow

```
sender.php  → INSERT questionnaires (status=pending, sent_to=email)
            → PHPMailer sends link: APP_URL/questionnaire.php?id=TOKEN

questionnaire.php POST → atomic UPDATE questionnaires SET status='submitted' WHERE status='pending'
                       → INSERT responses + response_answers
                       → PRG redirect (prevents double-submit on refresh)
```

## Configuration

`config.php` contains DB credentials and SMTP settings. Update `APP_URL` to the real domain before deploying. Default SMTP port is 465 (SSL); adjust `MAIL_SMTP_HOST` and `MAIL_SMTP_PORT` to match the hosting provider.

## CSV export

`dashboard.php?export_csv=1` outputs a UTF-8 BOM CSV (semicolon-delimited for Excel compatibility). Columns are dynamic: Data, Cliente, Account, then one column per question ordered by `position`. Respects `client_id`/`account_id` filter params.