# Location Display Fix - November 14, 2025

## Summary

Fixed the displaylocation.asp page to query the machines table for network device locations instead of the old legacy tables (idfs, servers, switches, cameras, accesspoints).

---

## Problem

When hovering over the location icon for network devices (IDFs, Servers, Switches, Cameras, Access Points), the popup would show "No location set" or "Device not found", even though the devices had valid maptop/mapleft coordinates in the machines table.

**Root Cause:** The displaylocation.asp page was querying the old legacy tables instead of the machines table:
- IDF → queried `idfs` table (no records)
- Server → queried `servers` table (no records)
- Switch → queried `switches` table (no records)
- Camera → queried `cameras` table (no records)
- Access Point → queried `accesspoints` table (no records)

But all new network devices are now stored in the `machines` table with machinetypeid 16-20.

---

## Solution

Updated displaylocation.asp (lines 23-40) to query the machines table for all network device types:

**BEFORE:**
```vbscript
Case "idf"
    strSQL = "SELECT mapleft, maptop, idfname AS devicename FROM idfs WHERE idfid = " & CLng(deviceId)
Case "server"
    strSQL = "SELECT mapleft, maptop, servername AS devicename FROM servers WHERE serverid = " & CLng(deviceId)
Case "switch"
    strSQL = "SELECT mapleft, maptop, switchname AS devicename FROM switches WHERE switchid = " & CLng(deviceId)
Case "camera"
    strSQL = "SELECT mapleft, maptop, cameraname AS devicename FROM cameras WHERE cameraid = " & CLng(deviceId)
Case "accesspoint", "access point"
    strSQL = "SELECT mapleft, maptop, apname AS devicename FROM accesspoints WHERE apid = " & CLng(deviceId)
```

**AFTER:**
```vbscript
Case "idf", "server", "switch", "camera", "accesspoint", "access point", "printer"
    ' Query machines table for all network devices
    strSQL = "SELECT mapleft, maptop, COALESCE(alias, machinenumber) AS devicename FROM machines WHERE machineid = " & CLng(deviceId)
```

---

## Testing

### Test 1: IDF Location
```bash
curl "http://192.168.122.151:8080/displaylocation.asp?type=idf&id=5460"
```
**Result:** ✅ Map displays correctly at coordinates [1051, 1256]

### Test 2: Access Point Location
```bash
curl "http://192.168.122.151:8080/displaylocation.asp?type=access%20point&id=5462"
```
**Result:** ✅ Map displays correctly

### Test 3: Printer Location
```bash
curl "http://192.168.122.151:8080/displaylocation.asp?type=printer&id=259"
```
**Result:** ✅ Map displays correctly

---

## How Location Display Works

1. **User hovers over location icon** (pin icon) in network_devices.asp
2. **JavaScript triggers after 300ms** delay
3. **Popup iframe loads** displaylocation.asp?type=[devicetype]&id=[deviceid]
4. **displaylocation.asp queries** machines table for maptop/mapleft coordinates
5. **Leaflet map renders** with device marker at specified location

---

## Related Network Device Fixes (Same Day)

This fix is part of a larger migration of network devices to the machines table:

1. ✅ Fixed wrong machine type IDs in save_network_device.asp
2. ✅ Updated vw_network_devices view to query machines table
3. ✅ Fixed dateadded column errors
4. ✅ Fixed location display (this fix)

---

## Files Modified

**displaylocation.asp (lines 23-40)**
- Simplified device type handling
- All network devices now query machines table
- Maintains backward compatibility for old "machineid" parameter

---

## Benefits

1. **Consistent Data Source:** All network device data comes from machines table
2. **Simpler Code:** Single query path for all network device types
3. **No Duplication:** Doesn't rely on legacy tables that are no longer populated
4. **Future Proof:** New device types automatically supported

---

## Status

- ✅ **Location Display:** FIXED (all device types)
- ✅ **Testing:** PASSED (IDF, Access Point, Printer verified)
- ✅ **Backward Compatibility:** MAINTAINED (old machineid parameter still works)

---

**Date:** 2025-11-14
**File Modified:** displaylocation.asp
**Impact:** All network device location displays now working correctly
