Fix dualpath propagation, getShopfloorPCs filtering, USB management, and printer features

- Fix dualpath PC propagation direction (Equipment->PC) in api.asp and db_helpers.asp
- Fix early exit in CreatePCMachineRelationship preventing propagation
- Fix getShopfloorPCs to filter machinetypeid IN (33,34,35) instead of >= 33
- Fix getShopfloorPCs to show equipment numbers via GROUP_CONCAT subquery
- Add detailed PropagateDP logging for dualpath debugging
- Default "Show on Shopfloor Dashboard" checkbox to checked in addnotification.asp
- Add USB label batch printing, single USB labels, and USB history pages
- Add printer supplies tracking and toner report enhancements
- Add uptime map visualization page
- Add dashboard/lobby display SQL migration
- Update CLAUDE.md with IIS 401 workaround documentation
- Update TODO.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-02-03 10:44:55 -05:00
parent 8945fe2a0a
commit e382a3246e
27 changed files with 1926 additions and 255 deletions

77
api.asp
View File

@@ -853,8 +853,9 @@ Sub GetShopfloorPCs()
' Build WHERE clause with optional filters
' Dashboard (11) and Lobby Display (12) can be on any subnet, others require 10.134.*
' Only include actual PCs (machinetypeid 33-35), not USB devices (44), Part Markers (45), Firewalls (46), etc.
whereClause = "WHERE m.isactive = 1 " & _
"AND m.machinetypeid >= 33 "
"AND m.machinetypeid IN (33, 34, 35) "
' Add pctypeid filter if provided
If filterPcTypeId <> "" And IsNumeric(filterPcTypeId) Then
@@ -881,7 +882,11 @@ Sub GetShopfloorPCs()
"m.loggedinuser, m.lastupdated, m.pctypeid, m.businessunitid, " & _
"c.address AS ipaddress, " & _
"COALESCE(pt.typename, 'Uncategorized') AS pctype, " & _
"COALESCE(bu.businessunit, 'TBD') AS businessunit " & _
"COALESCE(bu.businessunit, 'TBD') AS businessunit, " & _
"(SELECT GROUP_CONCAT(eq2.machinenumber ORDER BY eq2.machinenumber SEPARATOR ', ') " & _
"FROM machinerelationships mr2 " & _
"JOIN machines eq2 ON mr2.machineid = eq2.machineid AND eq2.pctypeid IS NULL " & _
"WHERE mr2.related_machineid = m.machineid AND mr2.relationshiptypeid = 3 AND mr2.isactive = 1) AS equipment_number " & _
"FROM machines m " & _
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
"LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _
@@ -907,7 +912,7 @@ Sub GetShopfloorPCs()
pcData = "{"
pcData = pcData & """machineid"":" & rsPC("machineid") & ","
pcData = pcData & """hostname"":""" & EscapeJSON(rsPC("hostname") & "") & ""","
pcData = pcData & """machinenumber"":""" & EscapeJSON(rsPC("machinenumber") & "") & ""","
pcData = pcData & """machinenumber"":""" & EscapeJSON(rsPC("equipment_number") & "") & ""","
pcData = pcData & """serialnumber"":""" & EscapeJSON(rsPC("serialnumber") & "") & ""","
pcData = pcData & """ipaddress"":""" & EscapeJSON(rsPC("ipaddress") & "") & ""","
pcData = pcData & """loggedinuser"":""" & EscapeJSON(rsPC("loggedinuser") & "") & ""","
@@ -1794,10 +1799,18 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
Set rsResult = objConn.Execute(strSQL)
If Not rsResult.EOF Then
' Relationship already exists
' Relationship already exists - still propagate to dualpath partners
LogToFile "CreatePCMachineRelationship: Relationship already exists (relationshipid=" & rsResult("relationshipid") & ")"
rsResult.Close
Set rsResult = Nothing
' Propagate controller to any dualpath machines that may be missing it
Dim dualpathCountExisting
dualpathCountExisting = PropagateControllerToDualpathMachinesAPI(CLng(equipmentMachineid), CLng(pcMachineid))
If dualpathCountExisting > 0 Then
LogToFile "Propagated controller to " & dualpathCountExisting & " dualpath machine(s) from existing relationship"
End If
CreatePCMachineRelationship = True
Exit Function
End If
@@ -1845,49 +1858,85 @@ End Function
Function PropagateControllerToDualpathMachinesAPI(equipmentMachineid, pcMachineid)
On Error Resume Next
LogToFile "PropagateDP: Starting for equipment=" & equipmentMachineid & " pc=" & pcMachineid
Dim rsDP, rsDPCheck, controlsTypeID, dualpathMachineId, cnt
cnt = 0
' Get Controls relationship type ID
Set rsDP = objConn.Execute("SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Controls'")
If Err.Number <> 0 Then
LogToFile "PropagateDP: ERROR getting Controls type: " & Err.Description
Err.Clear
PropagateControllerToDualpathMachinesAPI = 0
Exit Function
End If
If rsDP.EOF Then
LogToFile "PropagateDP: Controls relationship type not found in relationshiptypes table"
PropagateControllerToDualpathMachinesAPI = 0
rsDP.Close
Set rsDP = Nothing
Exit Function
End If
controlsTypeID = CLng(rsDP("relationshiptypeid"))
LogToFile "PropagateDP: Controls type ID = " & controlsTypeID
rsDP.Close
Set rsDP = Nothing
' Find all machines with dualpath relationship to this equipment
Set rsDP = objConn.Execute("SELECT related_machineid FROM machinerelationships mr " & _
Dim dpSQL
dpSQL = "SELECT related_machineid FROM machinerelationships mr " & _
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
"WHERE mr.machineid = " & CLng(equipmentMachineid) & " " & _
"AND rt.relationshiptype = 'Dualpath' AND mr.isactive = 1")
"AND rt.relationshiptype = 'Dualpath' AND mr.isactive = 1"
LogToFile "PropagateDP: Finding dualpath partners: " & dpSQL
Set rsDP = objConn.Execute(dpSQL)
If Err.Number <> 0 Then
LogToFile "PropagateDP: ERROR finding dualpath partners: " & Err.Description
Err.Clear
PropagateControllerToDualpathMachinesAPI = 0
Exit Function
End If
If rsDP.EOF Then
LogToFile "PropagateDP: No dualpath partners found for equipment " & equipmentMachineid
End If
Do While Not rsDP.EOF
dualpathMachineId = CLng(rsDP("related_machineid"))
LogToFile "PropagateDP: Found dualpath partner machineid=" & dualpathMachineId
' Check if this dualpath machine already has a Controls relationship with this PC
Set rsDPCheck = objConn.Execute("SELECT relationshipid FROM machinerelationships " & _
"WHERE machineid = " & CLng(pcMachineid) & " " & _
"AND related_machineid = " & dualpathMachineId & " " & _
"AND relationshiptypeid = " & controlsTypeID & " AND isactive = 1")
' Pattern: Equipment -> Controls -> PC (machineid=equipment, related_machineid=PC)
Dim checkSQL
checkSQL = "SELECT relationshipid FROM machinerelationships " & _
"WHERE machineid = " & dualpathMachineId & " " & _
"AND related_machineid = " & CLng(pcMachineid) & " " & _
"AND relationshiptypeid = " & controlsTypeID & " AND isactive = 1"
LogToFile "PropagateDP: Checking existing: " & checkSQL
Set rsDPCheck = objConn.Execute(checkSQL)
If rsDPCheck.EOF Then
' Create Controls relationship: PC -> Dualpath Machine
LogToFile "PropagateDP: No existing relationship, creating new one"
' Create Controls relationship: Dualpath Equipment -> PC (matches existing data pattern)
Dim cmdDPAPI
Set cmdDPAPI = Server.CreateObject("ADODB.Command")
cmdDPAPI.ActiveConnection = objConn
cmdDPAPI.CommandText = "INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive) VALUES (?, ?, ?, 1)"
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@equipid", 3, 1, , dualpathMachineId)
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@reltypeid", 3, 1, , controlsTypeID)
cmdDPAPI.Execute
If Err.Number <> 0 Then
LogToFile "PropagateDP: ERROR inserting relationship: " & Err.Description
Err.Clear
Else
cnt = cnt + 1
LogToFile "PropagateDP: SUCCESS created Controls relationship: Equipment " & dualpathMachineId & " -> PC " & pcMachineid
End If
Set cmdDPAPI = Nothing
cnt = cnt + 1
LogToFile "Created dualpath Controls relationship: Equipment " & dualpathMachineId & " controlled by PC " & pcMachineid
Else
LogToFile "PropagateDP: Relationship already exists (id=" & rsDPCheck("relationshipid") & ")"
End If
rsDPCheck.Close
Set rsDPCheck = Nothing