Fix pctypeid UPDATE, add installedApps handling, fix network_map IDF query

- api.asp: Add pctypeid to UPDATE statement so PC type changes are saved
  (was only set on INSERT, not UPDATE - Heat Treat PCs stayed as Shopfloor)
- api.asp: Add installedApps parameter and SaveInstalledApps() function
  to save tracked apps during updateCompleteAsset calls
- network_map.asp: Fix query to use m.machinetypeid instead of mo.machinetypeid
  (IDFs and other network devices weren't appearing on map)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-09 10:23:01 -05:00
parent 5c2b9105b8
commit 1eb3aceeb4
2 changed files with 121 additions and 3 deletions

118
api.asp
View File

@@ -122,6 +122,10 @@ Sub UpdateCompleteAsset()
lastBootTime = Trim(Request.Form("lastBootTime") & "") lastBootTime = Trim(Request.Form("lastBootTime") & "")
End If End If
' Installed apps (optional) - JSON array of tracked apps
Dim installedApps
installedApps = Request.Form("installedApps")
' DNC/GE registry data ' DNC/GE registry data
dncDualPathEnabled = Request.Form("dncDualPathEnabled") dncDualPathEnabled = Request.Form("dncDualPathEnabled")
dncPath1Name = Trim(Request.Form("dncPath1Name") & "") dncPath1Name = Trim(Request.Form("dncPath1Name") & "")
@@ -419,6 +423,14 @@ Sub UpdateCompleteAsset()
UpdateWarrantyData machineid, warrantyEndDate, warrantyStatus, warrantyServiceLevel, warrantyDaysRemaining UpdateWarrantyData machineid, warrantyEndDate, warrantyStatus, warrantyServiceLevel, warrantyDaysRemaining
End If End If
' Update installed apps if provided
Dim installedAppsCount
installedAppsCount = 0
If installedApps <> "" Then
installedAppsCount = SaveInstalledApps(machineid, installedApps)
LogToFile "Installed apps saved: " & installedAppsCount
End If
' Send success response (flattened to avoid nested dictionary issues) ' Send success response (flattened to avoid nested dictionary issues)
Dim responseObj Dim responseObj
Set responseObj = Server.CreateObject("Scripting.Dictionary") Set responseObj = Server.CreateObject("Scripting.Dictionary")
@@ -431,6 +443,7 @@ Sub UpdateCompleteAsset()
responseObj.Add "commConfigsCount", commConfigCount responseObj.Add "commConfigsCount", commConfigCount
responseObj.Add "dncConfigSuccess", dncSuccess responseObj.Add "dncConfigSuccess", dncSuccess
responseObj.Add "relationshipCreated", relationshipCreated responseObj.Add "relationshipCreated", relationshipCreated
responseObj.Add "installedAppsCount", installedAppsCount
SendResponse responseObj SendResponse responseObj
End Sub End Sub
@@ -664,6 +677,110 @@ Sub UpdateInstalledApps()
SendResponse responseObj SendResponse responseObj
End Sub End Sub
' ============================================================================
' SaveInstalledApps - Save installed apps for a PC (callable from UpdateCompleteAsset)
' Returns: count of apps saved
' ============================================================================
Function SaveInstalledApps(machineid, installedAppsJson)
On Error Resume Next
SaveInstalledApps = 0
If machineid = 0 Or installedAppsJson = "" Then
Exit Function
End If
LogToFile "SaveInstalledApps: machineid=" & machineid & ", raw JSON length=" & Len(installedAppsJson)
' Parse JSON array of apps
Dim appsArray
appsArray = ParseJSONArray(installedAppsJson)
If Not IsArray(appsArray) Then
LogToFile "SaveInstalledApps: Failed to parse JSON array"
Exit Function
End If
LogToFile "SaveInstalledApps: Parsed " & (UBound(appsArray) + 1) & " apps"
' Clear existing app mappings for this PC
Dim deleteSQL
deleteSQL = "DELETE FROM installedapps WHERE machineid = " & CLng(machineid)
objConn.Execute deleteSQL
If Err.Number <> 0 Then
LogToFile "SaveInstalledApps: DELETE error: " & Err.Description
Err.Clear
End If
' Insert new app mappings
Dim appCount, i, appName, appVersion, appid, appversionid, appidStr, insertSQL
Dim safeVer, verSQL, rsVer
appCount = 0
Err.Clear
For i = 0 To UBound(appsArray)
' Get appid directly (pre-mapped from PowerShell)
appid = 0
appidStr = Trim(GetJSONValue(appsArray(i), "appid") & "")
If appidStr <> "" And IsNumeric(appidStr) Then appid = CLng(appidStr)
' Get version and app name for logging
appVersion = Trim(GetJSONValue(appsArray(i), "version") & "")
appName = Trim(GetJSONValue(appsArray(i), "appname") & "")
If appid > 0 Then
appversionid = 0
Err.Clear
' Version lookup and creation
If appVersion <> "" And Not IsNull(appVersion) Then
safeVer = Replace(appVersion, "'", "''")
verSQL = "SELECT appversionid FROM appversions WHERE appid = " & CLng(appid) & " AND version = '" & safeVer & "'"
rs.Open verSQL, objConn, 0, 1
If Err.Number <> 0 Then
Err.Clear
ElseIf Not rs.EOF Then
appversionid = CLng(rs("appversionid"))
Else
' Version not found - create it
If rs.State = 1 Then rs.Close
verSQL = "INSERT INTO appversions (appid, version) VALUES (" & CLng(appid) & ", '" & safeVer & "')"
objConn.Execute verSQL
If Err.Number = 0 Then
rs.Open "SELECT LAST_INSERT_ID() AS newid", objConn, 0, 1
If Err.Number = 0 And Not rs.EOF Then
appversionid = CLng(rs("newid"))
End If
If Err.Number <> 0 Then Err.Clear
Else
Err.Clear
End If
End If
If rs.State = 1 Then rs.Close
End If
' Insert app
If appversionid > 0 Then
insertSQL = "INSERT INTO installedapps (machineid, appid, appversionid) VALUES (" & CLng(machineid) & ", " & CLng(appid) & ", " & CLng(appversionid) & ")"
Else
insertSQL = "INSERT INTO installedapps (machineid, appid) VALUES (" & CLng(machineid) & ", " & CLng(appid) & ")"
End If
objConn.Execute insertSQL
If Err.Number = 0 Then
appCount = appCount + 1
Else
LogToFile "SaveInstalledApps: INSERT error for appid " & appid & ": " & Err.Description
Err.Clear
End If
End If
Next
LogToFile "SaveInstalledApps: Saved " & appCount & " apps"
SaveInstalledApps = appCount
End Function
Sub GetDashboardData() Sub GetDashboardData()
' Simple health check endpoint ' Simple health check endpoint
Dim responseObj, connStatus Dim responseObj, connStatus
@@ -957,6 +1074,7 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
"serialnumber = '" & safeSerial & "', " & _ "serialnumber = '" & safeSerial & "', " & _
"modelnumberid = " & sqlModelId & ", " & _ "modelnumberid = " & sqlModelId & ", " & _
"machinetypeid = " & CLng(machineTypeId) & ", " & _ "machinetypeid = " & CLng(machineTypeId) & ", " & _
"pctypeid = " & CLng(pctypeId) & ", " & _
"loggedinuser = " & sqlUserId & ", " & _ "loggedinuser = " & sqlUserId & ", " & _
"machinenumber = " & sqlMachineNum & ", " & _ "machinenumber = " & sqlMachineNum & ", " & _
"osid = " & sqlOsId & ", " & _ "osid = " & sqlOsId & ", " & _

View File

@@ -239,14 +239,14 @@ strSQL = "SELECT printers.printerid AS id, machines.machinenumber AS name, machi
"UNION ALL " &_ "UNION ALL " &_
"" &_ "" &_
"SELECT m.machineid AS id, m.machinenumber AS name, m.alias, " &_ "SELECT m.machineid AS id, m.machinenumber AS name, m.alias, " &_
"m.mapleft, m.maptop, c.address AS ipaddress, mo.machinetypeid, " &_ "m.mapleft, m.maptop, c.address AS ipaddress, m.machinetypeid, " &_
"mt.machinetype AS type, mo.modelnumber, v.vendor, 'machines' AS source " &_ "mt.machinetype AS type, mo.modelnumber, v.vendor, 'machines' AS source " &_
"FROM machines m " &_ "FROM machines m " &_
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " &_ "LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " &_
"LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid " &_ "LEFT JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid " &_
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " &_ "LEFT JOIN vendors v ON mo.vendorid = v.vendorid " &_
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " &_ "LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " &_
"WHERE mo.machinetypeid IN (16, 17, 18, 19, 20) " &_ "WHERE m.machinetypeid IN (16, 17, 18, 19, 20) " &_
"AND m.isactive = 1 " &_ "AND m.isactive = 1 " &_
"AND m.mapleft IS NOT NULL " &_ "AND m.mapleft IS NOT NULL " &_
"AND m.maptop IS NOT NULL " &_ "AND m.maptop IS NOT NULL " &_