# Food Pantry Handout

Android app + separate MySQL/PHP API for monthly food pantry distribution.

## Features

- **User & admin login** (same screen; admin tools unlock for admins)
- **Once-per-month pickup** enforced by `pickups.month_key` unique constraint
- **Homescreen**: login, account, locations, schedule, chat, admin tools
- **Account fields**: photo, name, address, city, state, zip, dependents, isAdmin, isProxy, isUser, isBanned
- **Admin**: user database (photo + full info), ID barcode scan check-in
- **Camera ID scan** (PDF417 / barcode on license back) for signup and check-in
- **Chat**: help requests + **proxy requests** with tappable **Offer to proxy** for proxy-enabled users (`foodpantry://proxy/offer?...`)
- **Offline**: Room SQLite on device; dirty rows sync when online
- **Admin sync**: upload/download over network; **USB JSON export** for sneaker-net to the server PC

## Project layout

```
food-pantry/
  server/          PHP API + MySQL schema (XAMPP)
  android/         Kotlin Jetpack Compose app
  docs/            Notes
```

## 1. Database server setup (XAMPP)

1. Start **Apache** + **MySQL**
2. Open the portal: [http://localhost/food-pantry/](http://localhost/food-pantry/)
3. Click **Install / repair database** (or open [http://localhost/food-pantry/server/install.php](http://localhost/food-pantry/server/install.php))
4. Optional: [http://localhost/food-pantry/server/seed_admin.php](http://localhost/food-pantry/server/seed_admin.php)
   - Admin email: `admin@foodpantry.local`
   - Password: `Admin123!`

### Working API URLs

Use the `api.php?r=` form (reliable on XAMPP without rewrite quirks):

| Purpose | URL |
|--------|-----|
| Health | http://localhost/food-pantry/server/api.php?r=/ |
| Login (POST JSON) | http://localhost/food-pantry/server/api.php?r=/auth/login |
| Also works | http://localhost/food-pantry/server/api/?r=/ |

Android emulator base URL is already set to:

`http://10.0.2.2/food-pantry/server/api.php/`

(the app rewrites paths to `?r=/...` automatically)

Physical device: change `API_BASE_URL` in `android/app/build.gradle.kts` to your PC LAN IP, e.g.  
`http://192.168.1.10/food-pantry/server/api.php/`

### Roles

- **User**: account, locations, schedule, chat, request proxy
- **Proxy**: same + tap **Offer to proxy pickup** on proxy requests
- **Admin**: user DB, check-in + ID scan, sync upload/download, USB export

### Offline / USB

- Check-ins and chat made offline are marked dirty in Room
- **Sync → Upload to server** when data connection is available
- **Export JSON for USB**: writes under app files `exports/`; copy to the server PC and POST via `/sync/upload` (or paste into a small import tool)

## Security notes

- Change JWT secret and admin password before any real deployment
- Use HTTPS in production; cleartext is enabled for local XAMPP only
- ID barcode data is sensitive PII — protect the MySQL host and device storage
