# Door Certificates Module

Self-contained PHP/MySQL module for SAMCON Associates (Pvt.) Ltd. fire door QR verification.

## Upload

1. Upload the full `V2` folder to the website root.
2. Edit `V2/config.php` with cPanel MySQL credentials.
3. Change `DC_SETUP_KEY` to a private value.
4. Open `https://your-domain.com/V2/setup.php`.
5. Enter the setup key and create the first admin user.
6. Delete `setup.php` after setup.
7. Login at `https://your-domain.com/V2/admin/login.php`.

## QR Codes

Each door gets a public ID such as `FD-2026-001-1000` and a private token.
The QR link contains both values, so the visible ID is readable but other records
cannot be easily guessed.

The module saves QR PNG images using a public QR image endpoint. If the server
cannot reach that endpoint, the label page still displays a QR image directly
from the endpoint in the browser.

Saved QR PNGs are stored under `V2/storage/qrcodes`. The parent `storage`
folder includes an `.htaccess` deny rule, so Apache should not serve those files
directly. Certificate pages embed the QR as image data generated by PHP.

## Brand Assets

The certificate and label use:

- `V2/assets/brand/samcon-pvt-ltd-logo.jpeg` for labels and certificate output
- `V2/assets/brand/footer.jpeg`

Replace these files with updated artwork when branding changes.

Generated certificates include a computer-generated certificate notice instead
of a physical signature block.

## Certificate Downloads

Public users can download:

- A browser-rendered PDF generated from the live HTML certificate in
  `V2/templates/certificate` using `V2/assets/html2pdf.bundle.min.js`.

The public Word DOCX certificate download is disabled in V2. The generated
certificate uses the V2 HTML/CSS layout, pulls live door values from the
database, and the public PDF route opens the same HTML/CSS certificate export
page so direct downloads and fallbacks match the rendered certificate.

## Admin Records

The V2 admin door list includes search, filters, and pagination. Search covers
door ID, door number, PO number, client, project, site, area, category, fire
rating, and standards. Filters are available for client/project, category,
status, PO number, and standard.

Standards are managed from `admin/standards.php`. Door records can select more
than one active standard; selected standards display together on labels,
certificates, verification pages, and CSV exports.

## Company Standard Certificates

Put company standard certificates in `V2/storage/company-certificates`.
Use lowercase slug file names based on the standard. For one standard:

- `ul-10c.jpeg`
- `nfpa-252.pdf`
- `bs-476.pdf`

When one uploaded certificate covers multiple standards, join the standard slugs
with double underscores:

- `ul-10c__nfpa-252.pdf`
- `ul-10c__nfpa-252__fm-4100__bs-476.pdf`

When a public user opens a door QR page, the `View Standards` button appears only
when a file matches the saved Standards field. The file is served through
`company-certificate.php`, so users can only view or download the certificate
listed for that verified door.

## Backups

Admins can download a current door data CSV from `admin/export-doors.php` or the
`Backup CSV` button in the admin navigation.

For automatic cPanel backups, create a cron job that runs the PHP CLI script:

```sh
php /home/ACCOUNT/public_html/V2/cron/backup-doors.php
```

The script writes timestamped CSV files to `V2/storage/backups`.
That folder includes an `.htaccess` deny rule so the generated backup files are
not publicly browsable on Apache hosting.
