# VoC Portal — Setup & Deployment

## Layout
```
VoC Web/
  config/        config.php            (secrets — OUTSIDE webroot)
  src/           PHP classes + bootstrap
  public/        <-- web docroot points HERE
    admin/       admin portal
    s/           public survey
    assets/      css, js, qr/
  bin/           CLI scripts (admin, sentiment, import)
  sql/           schema + seed
  docs/
```

## 1. Database
Create a MySQL/MariaDB database + user, then load:
```sql
SOURCE sql/schema.sql;
SOURCE sql/seed.sql;                    -- curricula, training types, delivery methods
SOURCE sql/seed_template_participant.sql; -- default participant survey (v1)
```

## 2. Configure
Edit `config/config.php`:
- `DB_*` — database credentials
- `APP_BASE_URL` — public URL of the portal, **no trailing slash** (e.g. `https://voc.novares.my`)
- `FRANCHISEE_CODE` — already `401400` (DC Malaysia)

The Claude API key (cron/import only) comes from the environment, never the file:
```
export ANTHROPIC_API_KEY=sk-ant-...
```

## 3. Webroot
Point the domain/subdomain document root to **`public/`**. `config/`, `src/`, `bin/`, `sql/`
must stay **above** the webroot so they're never served. On shared hosting, either set the
docroot to `public/` or symlink it.

Ensure `public/assets/qr/` is writable by the web server (for generated QR codes).

## 4. Create the first admin
```
php bin/create_admin.php "Your Name" you@dalecarnegie.com "a-strong-password"
```
Then sign in at `/admin/login.php`.

## 5. Historical data (optional)
Import 2021–2025 history (239 classes, 3,134 responses, 6,874 comments), all scored
with the locked formula:
```sql
SOURCE sql/import_history.sql;   -- re-runnable; clears prior imported rows first
```
Then in the portal, **Reference → Programs**, assign a curriculum to the ~11 ambiguous
programs (CPD, HCMR, BOITEL, a few seminars).

To regenerate the import SQL from the workbooks (run anywhere with Python 3):
```
python3 bin/build_history_sql.py /path/to/unzipped/VOC\ \&\ NPS\ Results > sql/import_history.sql
```

## 6. Sentiment worker (cron)
Scores open-text comments for sentiment + themes via Claude (Haiku). Text only — no PII.
Set the key in the environment and run nightly:
```
ANTHROPIC_API_KEY=sk-ant-...  php /home/<acct>/voc/bin/sentiment.php
```
cPanel → Cron Jobs, e.g. `15 2 * * *` (02:15 daily). First run backfills history
(safe to re-run; it only processes comments without a sentiment yet).

## Requirements
PHP 8.0+ with `pdo_mysql`, `mbstring`, `curl`. QR codes render client-side (a small JS
library from CDN). Cron access for the nightly sentiment worker (`bin/sentiment.php`).
