# Deployment Checklist: Certificate Verification System

Complete checklist for deploying the certificate verification system to production.

## Pre-Deployment Verification ✓

- [x] Certificate helper functions defined (`find_certificate()`, `all_certificates()`)
- [x] `/verify` route handler implemented in index.php
- [x] JSON API endpoint working
- [x] HTML page form working
- [x] Auto-verification from URL parameters working
- [x] Sample certificate data prepared (EA-DEMO-2026-0001)
- [x] Database migration SQL ready
- [x] Documentation complete
- [x] Code reviewed

## Files to Deploy

### Core Files (REQUIRED)
- ✓ `index.php` (updated with /verify route)
- ✓ `app/helpers.php` (added certificate functions)

### Database Files (REQUIRED)
- ✓ `database/upgrade-certificates.sql` (create table + sample data)

### Documentation
- ✓ `CERTIFICATE-VERIFICATION.md` (implementation guide)
- ✓ `TEST-CERTIFICATE-VERIFICATION.md` (testing guide)
- ✓ `DEPLOYMENT-CHECKLIST.md` (this file)

## Deployment Steps

### Step 1: Upload Files to cPanel

**Via cPanel File Manager:**
1. Log in to cPanel
2. Navigate to `public_html/`
3. Upload updated files:
   - `index.php`
   - `app/helpers.php`
4. Verify permissions are 644 (read/write for owner)

**Or via FTP/SFTP:**
```bash
ftp/sftp> put index.php /public_html/
ftp/sftp> put app/helpers.php /public_html/app/
```

### Step 2: Import Database Schema

**Via cPanel phpMyAdmin:**
1. Log in to phpMyAdmin
2. Select database: `expertin_eac`
3. Click **Import** tab
4. Upload file: `database/upgrade-certificates.sql`
5. Click **Go**

**Or via cPanel Terminal:**
```bash
mysql -u expertin_eac -p < database/upgrade-certificates.sql
```

**Password:** localdev (from .env)

### Step 3: Verify Deployment

Run this SQL to confirm certificate exists:
```sql
SELECT certificate_id, internee_name, status 
FROM certificates 
WHERE certificate_id = 'EA-DEMO-2026-0001';
```

**Expected Output:**
```
EA-DEMO-2026-0001 | Aafrah Hajira | published
```

## Testing URLs

After deployment, test these URLs on your live domain:

### Test 1: Verification Page (Empty Form)
```
https://www.expertaims.com/verify
```
**Expected:** Beautiful form with "Verify Your Certificate" heading

### Test 2: Direct Certificate Lookup (Auto-Verify)
```
https://www.expertaims.com/verify?id=EA-DEMO-2026-0001
```
**Expected:** Form auto-filled and certificate details displayed:
- ✓ Certificate Verified
- Name: Aafrah Hajira
- Role: Summer Internship
- Company: ExpertAims Consultancy LLP
- Location: Kuwait Office
- Duration: Jun 20, 2026 to Jul 20, 2026

### Test 3: API Endpoint
```
curl "https://www.expertaims.com/verify?id=EA-DEMO-2026-0001"
```
**Expected:** JSON response with certificate data

### Test 4: Invalid Certificate ID
```
https://www.expertaims.com/verify?id=INVALID
```
**Expected:** Error message "Certificate not found"

## QR Code for Certificate PDF

Add this QR code link to the certificate PDF:
```
https://www.expertaims.com/verify?id=EA-DEMO-2026-0001
```

When users scan it:
1. Opens verification page
2. Form auto-fills with certificate ID
3. Certificate details display instantly

## Rollback Plan (If Needed)

If deployment fails:
1. Restore previous `index.php` from backup
2. Keep database (no data loss)
3. Contact support

To fully rollback database:
```sql
DROP TABLE IF EXISTS certificates;
```

But keep the table for future use if possible.

## Post-Deployment Tasks

- [ ] Test all URLs above
- [ ] Verify certificate data displays correctly
- [ ] Test on mobile device
- [ ] Check browser console for errors (F12)
- [ ] Monitor cPanel error logs
- [ ] Share verification page link with interns
- [ ] Add QR code to certificate PDF (if printing)
- [ ] Update website footer (if needed) with link to verification

## Maintenance

### Adding More Certificates
```sql
INSERT INTO certificates (
  certificate_id, internee_name, email, education, institution,
  role, company, location, start_date, end_date, issued_date,
  description, status
) VALUES (
  'EA-IN-2026-0721',           -- Unique ID
  'Name Here',                  -- Full name
  'email@example.com',          -- Email (optional)
  'Degree/Program',             -- Education
  'College Name',               -- Institution
  'Summer Internship',          -- Role
  'ExpertAims Consultancy LLP', -- Company
  'Kuwait Office',              -- Location
  '2026-06-20',                 -- Start date (YYYY-MM-DD)
  '2026-07-20',                 -- End date (YYYY-MM-DD)
  '2026-07-20',                 -- Issue date (YYYY-MM-DD)
  'Notes here',                 -- Description (optional)
  'published'                   -- Status
);
```

### Managing Certificates

**View all certificates:**
```sql
SELECT * FROM certificates ORDER BY issued_date DESC;
```

**Change certificate status to draft (hide from verification):**
```sql
UPDATE certificates SET status = 'draft' WHERE certificate_id = 'EA-DEMO-2026-0001';
```

**Change back to published:**
```sql
UPDATE certificates SET status = 'published' WHERE certificate_id = 'EA-DEMO-2026-0001';
```

**Delete a certificate:**
```sql
DELETE FROM certificates WHERE certificate_id = 'EA-IN-2026-0721';
```

## Support & Troubleshooting

### "Certificate not found" error
- Verify SQL was imported: Check phpMyAdmin for `certificates` table
- Verify certificate status is "published" (not "draft")
- Check certificate_id is exactly correct (case-sensitive: EA-DEMO-2026-0001)

### "Database connection error"
- Check .env file has correct credentials
- Verify MySQL is running in cPanel
- Check database name is correct in .env

### Certificate form not loading
- Check browser console (F12 → Console tab)
- Verify index.php was uploaded correctly
- Check file permissions (should be 644)

### JSON API returns 404
- Verify index.php has /verify route (line 213)
- Check mod_rewrite is enabled (needed for routes)
- Try direct URL: `/index.php?verify&id=...` (if rewrite fails)

## Success Indicators

✓ System is working correctly if:
1. `/verify` page loads with form
2. `/verify?id=EA-DEMO-2026-0001` shows certificate details
3. JSON API returns valid certificate data
4. Invalid IDs show appropriate error
5. No PHP errors in logs
6. Mobile view is responsive
7. Page loads within 2 seconds

## Version Info

**System Version:** 1.1  
**Release Date:** July 16, 2026  
**Sample Certificate:** EA-DEMO-2026-0001 (Aafrah Hajira)  
**Status:** Ready for Production Deployment ✓

---

## Quick Deployment Command

Copy and paste this to deploy via SSH:

```bash
# Backup current index.php
cp index.php index.php.backup

# Upload new files (replace with actual FTP/SFTP commands)
# scp index.php user@server:/path/to/public_html/
# scp app/helpers.php user@server:/path/to/public_html/app/

# Import database
mysql -u expertin_eac -p < database/upgrade-certificates.sql

# Verify
mysql -u expertin_eac -p -e "SELECT certificate_id, internee_name FROM certificates;" expertin_eac

echo "Deployment complete! Test at: https://www.expertaims.com/verify?id=EA-DEMO-2026-0001"
```

---

**Ready to deploy?** ✓ All systems go!
