============================================================
GMIND INSTITUTE — Offer Popup Fix (Complete Package)
============================================================

ROOT CAUSE:
The settings table has TWO unique column pairs:
  key_name (UNIQUE) + value          — old schema
  setting_key (UNIQUE) + setting_value — new schema

When admin saved offer_popup settings, the INSERT only wrote
to setting_key/setting_value, leaving key_name as empty string ''.
Since key_name has a UNIQUE constraint, every INSERT collided
on key_name='' and OVERWROTE the same row!

Result: Only 1 corrupted row with offer_popup_enabled = "Learn More"

FIX:
1. Upload ALL files to your server (maintaining directory structure)
2. Run the diagnostic test OR the SQL fix script
3. Re-enable popup from admin and save
4. Clear browser cache and test

============================================================
UPLOAD INSTRUCTIONS:
============================================================

Upload the ENTIRE contents of this zip to:
  /home/advaysin/public_html/gmind/

The directory structure inside this zip matches your server:

  app/Controllers/HomeController.php
  app/Models/Setting.php
  app/Views/home/index.php
  admin/Controllers/AdminOfferPopupController.php
  admin/Controllers/AdminSettingsController.php
  public/js/main.js
  public/css/style.css
  public/popup-test.php        ← DIAGNOSTIC TOOL (DELETE AFTER USE)
  database/fix_offer_popup_corrupted.sql

============================================================
STEP-BY-STEP:
============================================================

Step 1: Upload all files to your server via cPanel File Manager or FTP

Step 2: Fix the corrupted database — Choose ONE method:

  METHOD A (Easiest): 
    Visit https://advaysingh.co.in/gmind/popup-test.php
    Click the "Fix Corrupted Offer Popup Data" button
  
  METHOD B (Manual SQL):
    Go to phpMyAdmin > advaysin_gmind database
    Import database/fix_offer_popup_corrupted.sql

Step 3: Go to Admin > Offer Popup
  - Enable the popup toggle
  - Add title, description, image
  - Click Save

Step 4: Clear browser cache (Ctrl+Shift+R)
  Visit https://advaysingh.co.in/gmind/
  The popup should appear after 2 seconds!

Step 5: DELETE popup-test.php from your server!
  It contains database credentials and should not stay online.

============================================================
WHAT WAS FIXED IN EACH FILE:
============================================================

1. AdminOfferPopupController.php
   - upsertSetting() now writes to BOTH key_name/value AND 
     setting_key/setting_value to prevent UNIQUE constraint collisions

2. AdminSettingsController.php
   - Same fix applied to all INSERT queries

3. HomeController.php
   - Popup data now read from BOTH column pairs
   - Direct DB query instead of relying on Setting model cache

4. Setting.php (Model)
   - getAll() now reads from both key_name/value AND 
     setting_key/setting_value, merging results

5. public/js/main.js
   - Contains initOfferPopup() function (was missing from public/)

6. public/css/style.css
   - Contains .offer-popup-* CSS rules (was missing from public/)

7. public/popup-test.php
   - Diagnostic tool with one-click database fix button
