Replace machinetypeid 33-43 checks with pctypeid throughout codebase
- PCs now identified by pctypeid IS NOT NULL (not machinetypeid >= 33) - Equipment identified by pctypeid IS NULL (not machinetypeid < 33) - Updated 8 files: search.asp, savemachineedit.asp, displaymachine.asp, displaypc.asp, displaypcs.asp, machine_map.asp, displaymachines.asp, api.asp - Simplified queries and removed redundant machinetypeid checks - Updated all related comments to reflect new pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
6
api.asp
6
api.asp
@@ -28,7 +28,7 @@ Response.ContentType = "application/json"
|
||||
' Purpose: Receive PC asset data from PowerShell scripts and store in Phase 2 schema
|
||||
' Created: 2025-11-13
|
||||
' Modified: 2025-11-21 - Use sql.asp include for database connection
|
||||
' Schema: Phase 2 (machines table, machinetypeid 33-43 for PCs)
|
||||
' Schema: Phase 2 (machines table, pctypeid IS NOT NULL for PCs)
|
||||
' ============================================================================
|
||||
|
||||
' Error handling wrapper
|
||||
@@ -847,7 +847,7 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
|
||||
|
||||
LogToFile "Vendor ID: " & vendorId & ", Model ID: " & modelId & ", Machine Type ID: " & machineTypeId
|
||||
|
||||
' Check if PC already exists (Phase 2: identify PCs by machinetypeid 33,34,35)
|
||||
' Check if PC already exists (Phase 2: identify PCs by pctypeid IS NOT NULL)
|
||||
Dim strSQL, rsResult, safeHostname
|
||||
safeHostname = Replace(hostname, "'", "''")
|
||||
strSQL = "SELECT machineid FROM machines WHERE hostname = '" & safeHostname & "' AND pctypeid IS NOT NULL"
|
||||
@@ -1337,7 +1337,7 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
' Find equipment by machine number (Phase 2: PCs are machinetypeid 33-43, Equipment is 1-32)
|
||||
' Find equipment by machine number (Phase 2: PCs have pctypeid IS NOT NULL, Equipment has pctypeid IS NULL)
|
||||
Dim strSQL, rsResult, safeMachineNumber
|
||||
safeMachineNumber = Replace(machineNumber, "'", "''")
|
||||
strSQL = "SELECT machineid FROM machines WHERE machinenumber = '" & safeMachineNumber & "' AND pctypeid IS NULL"
|
||||
|
||||
@@ -290,7 +290,7 @@ strControlPCSQL = "SELECT m.machineid, m.hostname, m.machinenumber FROM machiner
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"JOIN machines m ON mr.machineid = m.machineid " & _
|
||||
"WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _
|
||||
"AND m.machinetypeid >= 33 LIMIT 1"
|
||||
"AND m.pctypeid IS NOT NULL LIMIT 1"
|
||||
Set rsControlPC = ExecuteParameterizedQuery(objConn, strControlPCSQL, Array(machineid))
|
||||
|
||||
If rsControlPC.EOF Then
|
||||
@@ -300,7 +300,7 @@ If rsControlPC.EOF Then
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"JOIN machines m ON mr.related_machineid = m.machineid " & _
|
||||
"WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _
|
||||
"AND m.machinetypeid >= 33 LIMIT 1"
|
||||
"AND m.pctypeid IS NOT NULL LIMIT 1"
|
||||
Set rsControlPC = ExecuteParameterizedQuery(objConn, strControlPCSQL, Array(machineid))
|
||||
End If
|
||||
|
||||
@@ -412,7 +412,7 @@ End If
|
||||
<tbody>
|
||||
<%
|
||||
' Query PCs that control this machine (directly or via dualpath)
|
||||
' Check both directions - the PC is identified by machinetypeid IN (33-43)
|
||||
' Check both directions - the PC is identified by pctypeid IS NOT NULL
|
||||
' Use GROUP_CONCAT to combine multiple IPs into one row per PC
|
||||
strSQL2 = "SELECT m.machineid, m.machinenumber, m.hostname, GROUP_CONCAT(DISTINCT c.address ORDER BY c.address SEPARATOR ', ') as address, 'Controls' as relationshiptype " & _
|
||||
"FROM machinerelationships mr " & _
|
||||
|
||||
@@ -82,15 +82,14 @@
|
||||
|
||||
<%
|
||||
' Build WHERE clause with optional BU filter
|
||||
' NOTE: Filter on machines.machinetypeid to exclude PCs (33-43) and network devices (16-20)
|
||||
' Equipment types are 1-15
|
||||
' NOTE: pctypeid IS NULL filters out PCs; also exclude LocationOnly (1) and network devices (16-20)
|
||||
Dim whereClause
|
||||
whereClause = "models.machinetypeid = machinetypes.machinetypeid AND " &_
|
||||
"machines.modelnumberid = models.modelnumberid AND " &_
|
||||
"models.vendorid = vendors.vendorid AND " &_
|
||||
"machines.businessunitid = businessunits.businessunitID AND " &_
|
||||
"machines.isactive = 1 AND islocationonly=0 AND machines.pctypeid IS NULL AND " &_
|
||||
"models.machinetypeid NOT IN (1, 16, 17, 18, 19, 20, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43)"
|
||||
"models.machinetypeid NOT IN (1, 16, 17, 18, 19, 20)"
|
||||
|
||||
' Add BU filter if specified
|
||||
If filterBU <> "" And IsNumeric(filterBU) Then
|
||||
|
||||
@@ -373,7 +373,7 @@ strControlledEquipSQL = "SELECT m.machineid, m.machinenumber FROM machinerelatio
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"JOIN machines m ON mr.related_machineid = m.machineid " & _
|
||||
"WHERE mr.machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _
|
||||
"AND m.machinetypeid < 33 LIMIT 1"
|
||||
"AND m.pctypeid IS NULL LIMIT 1"
|
||||
Set rsControlledEquip = ExecuteParameterizedQuery(objConn, strControlledEquipSQL, Array(machineid))
|
||||
|
||||
If rsControlledEquip.EOF Then
|
||||
@@ -383,7 +383,7 @@ If rsControlledEquip.EOF Then
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"JOIN machines m ON mr.machineid = m.machineid " & _
|
||||
"WHERE mr.related_machineid = ? AND rt.relationshiptype = 'Controls' AND mr.isactive = 1 " & _
|
||||
"AND m.machinetypeid < 33 LIMIT 1"
|
||||
"AND m.pctypeid IS NULL LIMIT 1"
|
||||
Set rsControlledEquip = ExecuteParameterizedQuery(objConn, strControlledEquipSQL, Array(machineid))
|
||||
End If
|
||||
|
||||
@@ -495,7 +495,7 @@ End If
|
||||
<tbody>
|
||||
<%
|
||||
' Query machines that THIS PC controls
|
||||
' Check both directions - the equipment is identified by machinetypeid NOT IN (33-43)
|
||||
' Check both directions - the equipment is identified by pctypeid IS NULL
|
||||
strSQL2 = "SELECT m.machineid, m.machinenumber, mt.machinetype, mo.modelnumber, 'Controls' as relationshiptype " & _
|
||||
"FROM machinerelationships mr " & _
|
||||
"JOIN machines m ON (mr.machineid = m.machineid OR mr.related_machineid = m.machineid) " & _
|
||||
|
||||
@@ -140,7 +140,7 @@ Set rsStatus = Nothing
|
||||
"LEFT JOIN communications c ON c.machineid = m.machineid AND c.isprimary = 1 " & _
|
||||
"LEFT JOIN machinestatus ON m.machinestatusid = machinestatus.machinestatusid " & _
|
||||
"LEFT JOIN machinerelationships mr ON (mr.machineid = m.machineid OR mr.related_machineid = m.machineid) AND mr.isactive = 1 AND mr.relationshiptypeid = 3 " & _
|
||||
"LEFT JOIN machines eq ON (eq.machineid = mr.related_machineid OR eq.machineid = mr.machineid) AND eq.machineid <> m.machineid AND eq.machinetypeid < 33 " & _
|
||||
"LEFT JOIN machines eq ON (eq.machineid = mr.related_machineid OR eq.machineid = mr.machineid) AND eq.machineid <> m.machineid AND eq.pctypeid IS NULL " & _
|
||||
"WHERE m.isactive = 1 AND m.pctypeid IS NOT NULL"
|
||||
|
||||
' Apply filters
|
||||
|
||||
@@ -293,8 +293,7 @@ strSQL = "SELECT m.machineid, m.machinenumber, m.alias, m.serialnumber, " &_
|
||||
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " &_
|
||||
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " &_
|
||||
"LEFT JOIN machinestatus ms ON m.machinestatusid = ms.machinestatusid " &_
|
||||
"WHERE mo.machinetypeid < 33 " &_
|
||||
"AND m.pctypeid IS NULL " &_
|
||||
"WHERE m.pctypeid IS NULL " &_
|
||||
"AND m.isactive = 1 " &_
|
||||
"AND m.mapleft IS NOT NULL " &_
|
||||
"AND m.maptop IS NOT NULL " &_
|
||||
|
||||
@@ -553,15 +553,12 @@
|
||||
If Not rsCheck.EOF Then dualpathTypeID = rsCheck("relationshiptypeid")
|
||||
rsCheck.Close
|
||||
|
||||
' Check if this machine is a PC (machinetypeid >= 33) to determine relationship direction
|
||||
Dim isPC, currentMachineTypeID
|
||||
' Check if this machine is a PC (pctypeid IS NOT NULL) to determine relationship direction
|
||||
Dim isPC
|
||||
isPC = False
|
||||
Set rsCheck = objConn.Execute("SELECT machinetypeid FROM machines WHERE machineid = " & CLng(machineid))
|
||||
Set rsCheck = objConn.Execute("SELECT pctypeid FROM machines WHERE machineid = " & CLng(machineid))
|
||||
If Not rsCheck.EOF Then
|
||||
currentMachineTypeID = rsCheck("machinetypeid")
|
||||
If Not IsNull(currentMachineTypeID) And currentMachineTypeID >= 33 Then
|
||||
isPC = True
|
||||
End If
|
||||
isPC = Not IsNull(rsCheck("pctypeid"))
|
||||
End If
|
||||
rsCheck.Close
|
||||
|
||||
|
||||
26
search.asp
26
search.asp
@@ -65,20 +65,16 @@
|
||||
|
||||
' ------------------------------- Search For Machine Number or Hostname ----------------------------------------------------------
|
||||
|
||||
' Also search by hostname for PCs, and get machinetypeid from models table to determine PC vs Equipment
|
||||
strSQL = "SELECT m.machineid, m.hostname, mo.machinetypeid FROM machines m " & _
|
||||
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " & _
|
||||
' Also search by hostname for PCs, use pctypeid to determine PC vs Equipment
|
||||
strSQL = "SELECT m.machineid, m.hostname, m.pctypeid FROM machines m " & _
|
||||
"WHERE (m.machinenumber = ? OR m.alias LIKE ? OR m.hostname = ?) AND m.isactive = 1"
|
||||
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search, "%" & search & "%", search))
|
||||
|
||||
If Not rs.EOF Then
|
||||
machineid = rs("machineid")
|
||||
Dim searchMachTypeId, searchIsPC, searchRedirectPage, searchHostname
|
||||
searchMachTypeId = 0
|
||||
If Not IsNull(rs("machinetypeid")) Then searchMachTypeId = CLng(rs("machinetypeid"))
|
||||
searchHostname = rs("hostname") & ""
|
||||
' PC if machinetypeid 33-43, OR if machinetypeid is 1 (default) and has a hostname
|
||||
searchIsPC = (searchMachTypeId >= 33 And searchMachTypeId <= 43) Or (searchMachTypeId = 1 And searchHostname <> "")
|
||||
Dim searchIsPC, searchRedirectPage
|
||||
' PC if pctypeid IS NOT NULL
|
||||
searchIsPC = Not IsNull(rs("pctypeid"))
|
||||
|
||||
rs.Close
|
||||
Set rs = Nothing
|
||||
@@ -493,10 +489,9 @@ rsNotif.Close
|
||||
Set rsNotif = Nothing
|
||||
|
||||
' Now get Machines (by machine number, alias, notes, machine type, or vendor)
|
||||
' NOTE: machinetypeid is now sourced from models table (models.machinetypeid) not machines table
|
||||
' Also search by hostname for PCs
|
||||
Dim rsMachines
|
||||
strSQL = "SELECT m.machineid, m.machinenumber, m.alias, m.hostname, mo.machinetypeid, mt.machinetype " & _
|
||||
strSQL = "SELECT m.machineid, m.machinenumber, m.alias, m.hostname, m.pctypeid, mt.machinetype " & _
|
||||
"FROM machines m " & _
|
||||
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " & _
|
||||
"LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid " & _
|
||||
@@ -511,12 +506,9 @@ Response.Write("<!-- DEBUG: Checking machines for search term -->")
|
||||
|
||||
Do While Not rsMachines.EOF And totalCount < 100
|
||||
' Determine display text - use hostname for PCs, machinenumber for equipment
|
||||
' PCs have machinetypeid 33-43, OR machinetypeid 1 (default) with a hostname
|
||||
Dim isPC, machTypeId, loopHostname
|
||||
machTypeId = 0
|
||||
If Not IsNull(rsMachines("machinetypeid")) Then machTypeId = CLng(rsMachines("machinetypeid"))
|
||||
loopHostname = rsMachines("hostname") & ""
|
||||
isPC = (machTypeId >= 33 And machTypeId <= 43) Or (machTypeId = 1 And loopHostname <> "")
|
||||
' PCs identified by pctypeid IS NOT NULL
|
||||
Dim isPC
|
||||
isPC = Not IsNull(rsMachines("pctypeid"))
|
||||
|
||||
If isPC Then
|
||||
machineDispText = rsMachines("hostname") & ""
|
||||
|
||||
Reference in New Issue
Block a user