===============================================
FIELD MAPPING: FORMS → DATABASE/ENV
SSCI Office Platform - Profile & Settings
===============================================

═══════════════════════════════════════════════════════════════════════════════
SECTION 1: PROFILE PAGE FORMS
═══════════════════════════════════════════════════════════════════════════════

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 1: PROFILE INFORMATION TAB                                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/profile.php (Form: #profileForm)                         │
│ API Action: saveProfile                                                     │
│ API Handler: handleSaveProfile() in app/api.php                            │
│                                                                             │
│ Form Field → POST Key → Database Table.Column                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Name Input              → name            → users.name                  │
│ 2. Phone Input             → phone           → users.phone                 │
│ 3. WhatsApp Input          → whatsapp        → users.whatsapp              │
│ 4. Address Textarea        → address         → users.address               │
│ 5. Photo (Cropped Base64)  → photo           → users.photo                 │
│    (Hidden field: #photoData)                                               │
│                                                                             │
│ SQL: UPDATE users SET name=?, phone=?, whatsapp=?, address=?, photo=?    │
│      WHERE id=?                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 2: SECURITY SETTINGS TAB                                              │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/profile.php (Form: #securityForm)                       │
│ API Action: changePassword                                                  │
│ API Handler: handleChangePassword() in app/api.php                        │
│                                                                             │
│ Form Field → POST Key → Database Table.Column                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Current Password Input  → current_password → users.password (VERIFY)   │
│ 2. New Password Input      → new_password     → users.password (HASH)     │
│ 3. Confirm Password Input  → confirm_password → users.password (HASH)     │
│                                                                             │
│ SQL: UPDATE users SET password=PASSWORD_HASH(?) WHERE id=?               │
│ Note: Passwords are hashed with password_hash() function                   │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 3: PREFERENCES TAB                                                     │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/profile.php (Form: #preferencesForm)                    │
│ API Action: savePreferences                                                 │
│ API Handler: handleSavePreferences() in app/api.php                       │
│                                                                             │
│ Form Field → POST Key → Database Table.Column                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Language Select         → language               → users.language       │
│ 2. Email Notifications     → email_notifications    → users.email_notifications
│    (Checkbox)                 (1 if checked, 0 if unchecked)              │
│ 3. In-App Notifications    → in_app_notifications   → users.in_app_notifications
│    (Checkbox)                 (1 if checked, 0 if unchecked)              │
│ 4. SMS Notifications       → sms_notifications      → users.sms_notifications
│    (Checkbox)                 (1 if checked, 0 if unchecked)              │
│                                                                             │
│ SQL: UPDATE users SET language=?, email_notifications=?,                  │
│      in_app_notifications=?, sms_notifications=? WHERE id=?              │
└─────────────────────────────────────────────────────────────────────────────┘

═══════════════════════════════════════════════════════════════════════════════
SECTION 2: SETTINGS PAGE FORMS
═══════════════════════════════════════════════════════════════════════════════

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 1: GENERAL SETTINGS TAB                                               │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #generalSettingsForm)         │
│ API Action: saveGeneralSettings                                             │
│ API Handler: handleSaveGeneralSettings() in app/api.php                   │
│                                                                             │
│ Form Field → POST Key → Database Table.Column                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Site Name Input         → site_name       → settings.site_name         │
│ 2. Site Acronym Input      → site_acronym    → settings.site_acronym      │
│ 3. Email Input             → email           → settings.email              │
│ 4. Phone Input             → phone           → settings.phone              │
│ 5. Address Textarea        → address         → settings.address            │
│                                                                             │
│ SQL: UPDATE settings SET site_name=?, site_acronym=?, email=?,           │
│      phone=?, address=? WHERE 1 LIMIT 1                                   │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 2: APPEARANCE SETTINGS TAB                                            │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #appearanceSettingsForm)      │
│ API Action: saveAppearanceSettings                                          │
│ API Handler: handleSaveAppearanceSettings() in app/api.php                │
│                                                                             │
│ Form Field → POST Key → Database Table.Column                             │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Primary Color Picker    → primary_color   → settings.primary_color     │
│ 2. Color Hex Input         → primary_color_hex → settings.primary_color   │
│ 3. Logo File Upload        → logo            → settings.logo              │
│ 4. Letterhead File Upload  → letterhead      → settings.letterhead        │
│                                                                             │
│ SQL: UPDATE settings SET primary_color=?, logo=?, letterhead=?           │
│      WHERE 1 LIMIT 1                                                       │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 3: EMAIL SETTINGS TAB                                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #emailSettingsForm)           │
│ API Action: saveEmailSettings                                               │
│ API Handler: handleSaveEmailSettings() in app/api.php                     │
│                                                                             │
│ Form Field → POST Key → Database/ENV Storage                              │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Enable Email (Checkbox) → email_enabled    → settings.email_enabled    │
│ 2. SMTP Host Input         → smtp_host        → settings.smtp_host + .env │
│ 3. SMTP Port Number        → smtp_port        → settings.smtp_port + .env │
│ 4. SMTP User Input         → smtp_user        → settings.smtp_user + .env │
│ 5. SMTP Password Input     → smtp_password    → settings.smtp_password    │
│ 6. From Email Input        → smtp_from        → settings.smtp_from + .env │
│                                                                             │
│ SQL: UPDATE settings SET email_enabled=?, smtp_host=?, smtp_port=?,      │
│      smtp_user=?, smtp_password=?, smtp_from=? WHERE 1 LIMIT 1           │
│ ENV: Updated via updateEnvFile() function                                  │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 4: NOTIFICATION SETTINGS TAB                                          │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #notificationSettingsForm)    │
│ API Action: saveNotificationSettings                                        │
│ API Handler: handleSaveNotificationSettings() in app/api.php              │
│                                                                             │
│ Form Field → POST Key → Database/ENV Storage                              │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. SMS Enable (Checkbox)   → sms_enabled      → settings.sms_enabled      │
│ 2. SMS Gateway Token       → sms_gateway_token → settings.sms_gateway_token
│ 3. WhatsApp API Token      → whatsapp_api_token → settings.whatsapp_api_token
│ 4. Push Enable (Checkbox)  → push_enabled     → settings.push_enabled     │
│                                                                             │
│ SQL: UPDATE settings SET sms_enabled=?, sms_gateway_token=?,             │
│      whatsapp_api_token=?, push_enabled=? WHERE 1 LIMIT 1                │
│ ENV: Updated via updateEnvFile() function                                  │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 5: APPLICATION SETTINGS (Advanced Tab)                               │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #appSettingsForm)             │
│ API Action: saveAppSettings                                                 │
│ API Handler: handleSaveAppSettings() in app/api.php                       │
│                                                                             │
│ Form Field → POST Key → Storage Location                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. Debug Mode (Checkbox)   → app_debug        → .env (APP_DEBUG)          │
│ 2. Application URL         → app_url          → .env (APP_URL)            │
│ 3. Application Key         → app_key          → .env (APP_KEY)            │
│                                                                             │
│ ENV: Updated via updateEnvFile() function                                  │
│ Note: These are stored in .env file, NOT in database                       │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ FORM 6: DATABASE SETTINGS (Advanced Tab)                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│ File: views/admin/settings/index.php (Form: #databaseSettingsForm)        │
│ API Action: saveDatabaseSettings                                            │
│ API Handler: handleSaveDatabaseSettings() in app/api.php                  │
│                                                                             │
│ Form Field → POST Key → Storage Location                                  │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. DB Host Input           → db_host         → .env (DB_HOST)             │
│ 2. DB Port Number          → db_port         → .env (DB_PORT)             │
│ 3. DB Name Input           → db_name         → .env (DB_NAME)             │
│ 4. DB User Input           → db_user         → .env (DB_USER)             │
│ 5. DB Password Input       → db_password     → .env (DB_PASSWORD)         │
│                                                                             │
│ ENV: Updated via updateEnvFile() function                                  │
│ Note: These are stored in .env file, NOT in database                       │
│       Password field is optional (leave blank to keep current)              │
└─────────────────────────────────────────────────────────────────────────────┘

═══════════════════════════════════════════════════════════════════════════════
SUMMARY OF DATABASE CHANGES REQUIRED
═══════════════════════════════════════════════════════════════════════════════

USERS TABLE (9 columns to add):
✓ phone                    VARCHAR(20)
✓ whatsapp                 VARCHAR(20)
✓ address                  TEXT
✓ photo                    LONGTEXT
✓ language                 VARCHAR(5)
✓ email_notifications      TINYINT(1)
✓ in_app_notifications     TINYINT(1)
✓ sms_notifications        TINYINT(1)

SETTINGS TABLE (18 columns to add):
✓ site_name                VARCHAR(255)
✓ site_acronym             VARCHAR(50)
✓ email                    VARCHAR(255)
✓ phone                    VARCHAR(20)
✓ address                  TEXT
✓ primary_color            VARCHAR(7)
✓ logo                     LONGTEXT
✓ letterhead               LONGTEXT
✓ email_enabled            TINYINT(1)
✓ smtp_host                VARCHAR(255)
✓ smtp_port                INT
✓ smtp_user                VARCHAR(255)
✓ smtp_password            VARCHAR(255)
✓ smtp_from                VARCHAR(255)
✓ sms_enabled              TINYINT(1)
✓ sms_gateway_token        VARCHAR(500)
✓ whatsapp_api_token       VARCHAR(500)
✓ push_enabled             TINYINT(1)
✓ vapid_public_key         LONGTEXT
✓ vapid_private_key        LONGTEXT
✓ updated_at               TIMESTAMP

ENV FILE FIELDS (stored in .env, NOT in database):
→ APP_DEBUG                (Boolean)
→ APP_URL                  (String)
→ APP_KEY                  (String)
→ DB_HOST                  (String)
→ DB_PORT                  (Integer)
→ DB_NAME                  (String)
→ DB_USER                  (String)
→ DB_PASSWORD              (String)
→ EMAIL_ENABLED            (Boolean)
→ SMTP_HOST                (String)
→ SMTP_PORT                (Integer)
→ SMTP_USER                (String)
→ SMTP_PASSWORD            (String)
→ SMTP_FROM                (String)
→ SMS_ENABLED              (Boolean)
→ SMS_GATEWAY_TOKEN        (String)
→ WHATSAPP_API_TOKEN       (String)
→ PUSH_ENABLED             (Boolean)

═══════════════════════════════════════════════════════════════════════════════
EXECUTION INSTRUCTIONS
═══════════════════════════════════════════════════════════════════════════════

1. Run the ALTER_SCRIPTS.sql file in phpMyAdmin or MySQL command line:
   mysql -u wankpsdj_user -pSuccess@1990 wankpsdj_ssci_office < ALTER_SCRIPTS.sql

2. Verify the changes:
   - Log in to phpMyAdmin
   - Check users table → Verify 8 new columns are present
   - Check settings table → Verify 20 new columns are present

3. Test the forms:
   - Fill out profile form → Submit → Check users table for data
   - Fill out settings form → Submit → Check settings table and .env file

═══════════════════════════════════════════════════════════════════════════════
