From 1eb3aceeb4092d6750c7ee0ec005c566c805225c Mon Sep 17 00:00:00 2001 From: cproudlock Date: Tue, 9 Dec 2025 10:23:01 -0500 Subject: [PATCH] Fix pctypeid UPDATE, add installedApps handling, fix network_map IDF query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- api.asp | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ network_map.asp | 6 +-- 2 files changed, 121 insertions(+), 3 deletions(-) diff --git a/api.asp b/api.asp index 399ff3f..071c776 100644 --- a/api.asp +++ b/api.asp @@ -122,6 +122,10 @@ Sub UpdateCompleteAsset() lastBootTime = Trim(Request.Form("lastBootTime") & "") End If + ' Installed apps (optional) - JSON array of tracked apps + Dim installedApps + installedApps = Request.Form("installedApps") + ' DNC/GE registry data dncDualPathEnabled = Request.Form("dncDualPathEnabled") dncPath1Name = Trim(Request.Form("dncPath1Name") & "") @@ -419,6 +423,14 @@ Sub UpdateCompleteAsset() UpdateWarrantyData machineid, warrantyEndDate, warrantyStatus, warrantyServiceLevel, warrantyDaysRemaining 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) Dim responseObj Set responseObj = Server.CreateObject("Scripting.Dictionary") @@ -431,6 +443,7 @@ Sub UpdateCompleteAsset() responseObj.Add "commConfigsCount", commConfigCount responseObj.Add "dncConfigSuccess", dncSuccess responseObj.Add "relationshipCreated", relationshipCreated + responseObj.Add "installedAppsCount", installedAppsCount SendResponse responseObj End Sub @@ -664,6 +677,110 @@ Sub UpdateInstalledApps() SendResponse responseObj 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() ' Simple health check endpoint Dim responseObj, connStatus @@ -957,6 +1074,7 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT "serialnumber = '" & safeSerial & "', " & _ "modelnumberid = " & sqlModelId & ", " & _ "machinetypeid = " & CLng(machineTypeId) & ", " & _ + "pctypeid = " & CLng(pctypeId) & ", " & _ "loggedinuser = " & sqlUserId & ", " & _ "machinenumber = " & sqlMachineNum & ", " & _ "osid = " & sqlOsId & ", " & _ diff --git a/network_map.asp b/network_map.asp index 23df3a9..5dc1b2c 100644 --- a/network_map.asp +++ b/network_map.asp @@ -239,14 +239,14 @@ strSQL = "SELECT printers.printerid AS id, machines.machinenumber AS name, machi "UNION ALL " &_ "" &_ "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 " &_ "FROM machines m " &_ "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 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.mapleft IS NOT NULL " &_ "AND m.maptop IS NOT NULL " &_