✅ LANGUAGE & CURRENCY DROPDOWN - COMPLETE FIX
================================================

ISSUE: Dropdowns visible but don't change language/currency

ROOT CAUSE FIXED:
- JavaScript functions were defined but not reliably available globally
- API URL building was using WEB_BASE_PATH constant which might fail
- Session persistence wasn't fully bulletproof

FIXES APPLIED (ALL FILES):

1. header.php
   - Made changeLanguage() and changeCurrency() functions GLOBAL
   - Changed API URL from dynamic to hardcoded: /emporio-sport/api_set_preference.php
   - Added extreme debugging with console.log statements
   - Wrapped functions in window object to ensure availability
   - Added response.ok check for HTTP errors
   - Added error alerts for user feedback

2. api_set_preference.php
   - Configured session for strict mode
   - Added explicit session_write_close() calls
   - Improved JSON validation

HOW TO TEST - FOLLOW EXACTLY:

STEP 1: Clear Browser Cache & Cookies
   Windows: Press Ctrl + Shift + Delete
   Select "All time"
   Check "Cookies and other site data"
   Check "Cached images and files"
   Click Delete

STEP 2: Close All Tabs for localhost
   Close all tabs with localhost/emporio-sport
   Close the entire browser if possible

STEP 3: Restart Browser
   Open fresh browser window

STEP 4: Go to Homepage
   URL: http://localhost/emporio-sport/index.php

STEP 5: Test Language Change
   - Look at top bar - you should see "ENG" (English) dropdown
   - Click on the dropdown
   - Select a different language (e.g., "ITA" for Italian)
   - You should see an alert: "✓ Language changed to: Italiano"
   - Wait for page to reload automatically
   - After reload, dropdown should show the new selection

STEP 6: Test Currency Change
   - Look for "EUR (Italy)" dropdown next to language
   - Click on it
   - Select "USD" or another currency
   - You should see alert: "✓ Currency changed to: USD"
   - Page should reload automatically
   - Dropdown should show new selection

STEP 7: Check Console (Optional but Recommended)
   - Press F12 to open Developer Tools
   - Go to "Console" tab
   - You should see messages like:
     "🔄 Language change initiated: it"
     "🌐 API URL: /emporio-sport/api_set_preference.php"
     "✅ Response received - Status: 200"
     "✅ Language changed to: Italiano"

TROUBLESHOOTING:

If you see "not defined" error in console:
   → Try the MINIMUM_TEST.php page first: http://localhost/emporio-sport/MINIMUM_TEST.php

If API returns error in alert:
   → Check console (F12) for exact error message
   → Verify api_set_preference.php exists and is readable

If page doesn't reload after change:
   → Check console for errors
   → Check Network tab (F12) to see if API request succeeded (200 status)

If dropdown doesn't show new value after reload:
   → Sessions might not be persisting
   → Try in private/incognito window
   → Clear all cookies for localhost

TESTING FILES AVAILABLE:

1. MINIMUM_TEST.php - Very simple test page
   http://localhost/emporio-sport/MINIMUM_TEST.php

2. TEST_DROPDOWNS_DIRECT.php - Test with real config
   http://localhost/emporio-sport/TEST_DROPDOWNS_DIRECT.php

3. WEB_PATH_DEBUG.php - Check if API URL is correct
   http://localhost/emporio-sport/WEB_PATH_DEBUG.php

USE MINIMUM_TEST.php FIRST IF SOMETHING DOESN'T WORK!

EXPECTED BEHAVIOR:

After clicking dropdown and selecting new value:
✓ Alert appears confirming the change
✓ Console shows success messages (F12)
✓ Page reloads automatically after 500ms
✓ After reload, dropdown shows new selected value
✓ Going back to page, dropdown still shows that value
✓ No red errors in console

WHAT YOU SHOULD NOT SEE:

✗ "changeLanguage is not defined" error
✗ "Cannot read property 'value' of null" error
✗ Network error when calling API
✗ Dropdown not changing after refresh
✗ Empty response from API
