# PropEase × Mappls — Zero-Touch Integration

**selleraddplot.php is never edited.** Upload files, set one config line,
done. A PHP auto-prepend hook injects the `<script>` tag into the page's
HTML output, and the JS auto-detects your Locality/City/District fields
by name.

---

## Files in this package

| File | Purpose | Edit? |
|---|---|---|
| `mappls_config.php` | Your Mappls API credentials | **YES** — paste keys |
| `mappls_auth.php` | OAuth2 token cache | no |
| `mappls_proxy.php` | Server endpoint the browser calls | no |
| `mappls_inject.php` | Auto-runs before selleraddplot.php, injects `<script>` | no |
| `mappls_autocomplete.js` | Self-bootstrapping dropdown | no |
| `mappls_path.php` | Diagnostic — prints your server paths | delete after use |
| `.user.ini` | Tells PHP to run the inject hook | **YES** — one path line |
| `.htaccess.snippet` | Blocks access to cache files | append to your .htaccess |

---

## Install in 5 steps

### 1. Upload all files to the same directory as `selleraddplot.php`

Via cPanel File Manager or `cp` in your terminal. Include the hidden
files (`.user.ini`, `.htaccess.snippet`) — most upload tools hide them
by default, so enable "show hidden files" first.

### 2. Visit `mappls_path.php` once in a browser

```
https://study24.in/mappls_path.php
```

It prints the **exact absolute path** you need for `.user.ini`. Copy it.
Then delete `mappls_path.php`.

### 3. Edit `.user.ini`

Replace the placeholder path with the one from step 2:

```ini
auto_prepend_file = "/home/your_actual_user/public_html/mappls_inject.php"
```

PHP caches `.user.ini` for ~5 minutes. Either wait, or touch a PHP file
to force a reload.

### 4. Edit `mappls_config.php`

Paste your credentials from `apis.mappls.com/console` → your project:

```php
'client_id'     => '...',
'client_secret' => '...',
'rest_key'      => '...',
```

### 5. Append `.htaccess.snippet` to your existing `.htaccess`

Protects the hidden token/usage cache files from being served publicly.

---

## Verify it's working

1. Open `https://study24.in/selleraddplot.php` and view page source.
   Search for `mappls-autocomplete` — you should see the injected
   `<script>` tag just before `</body>`.
2. Open DevTools → Network. Type "patn" in the Locality field.
   You should see a request to `mappls_proxy.php?action=autosuggest&q=patn`
   returning JSON suggestions.
3. Click a suggestion — City, District, lat/lng auto-fill.

**If the `<script>` tag is NOT in the page source:**
- `.user.ini` isn't being read. Wait 5 minutes (cache), or:
- Uncomment the `<Files "selleraddplot.php">` block in
  `.htaccess.snippet` and use `php_value auto_prepend_file` instead.
  Namecheap's LiteSpeed usually allows this.

---

## How the auto-detection works

The JS scans all `<input>` elements and attaches the dropdown to any
whose **id** or **name** matches:

- `locality`, `area`, `landmark`, `neighborhood` → primary source
- `city`, `town` → fallback source if no locality exists

On selection, it fills sibling inputs matching:

- `district`
- `address`, `full_address`, `addr`, `street_address`
- `pincode`, `pin`, `postal_code`, `zip`
- `latitude`, `lat`
- `longitude`, `lng`, `lon`
- `state`

A `MutationObserver` re-scans if your 7-step form swaps step content,
so the widget works on every step that has address fields.

---

## Safety features

- **Client secret never reaches the browser** — proxy pattern.
- **Daily quota cap** (default 2500 hits) in `mappls_config.php`.
  Prevents runaway usage from a buggy loop.
- **Silent Nominatim fallback** if Mappls quota is exhausted, credentials
  fail, or the API is down. User never sees an error.
- **Session-cache** on the client — duplicate queries cost 0 hits.
- **300ms debounce** — typing "patna" = 1 hit, not 5.
- **Scoped to `selleraddplot.php` only** via filename check in
  `mappls_inject.php`. Other pages (api.php, login.php, etc.) are
  unaffected even though the prepend runs on every request.

---

## Rolling back

Delete `.user.ini` (or comment out the `auto_prepend_file` line).
Everything else is self-contained and inactive without that hook.
No trace left on selleraddplot.php because you never touched it.
