Fix search routing for PCs and WinRM remote update script
- search.asp: Route to displaypc.asp for PCs (machinetypeid 33-43 or machinetypeid 1 with hostname), displaymachine.asp for equipment - search.asp: Add hostname search capability for PCs - Update-ShopfloorPCs-Remote.ps1: Fix hashtable conversion bug that caused empty API errors - pass $result directly instead of PSObject.Properties 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
87
search.asp
87
search.asp
@@ -63,17 +63,33 @@
|
||||
Call HandleValidationError("default.asp", "INVALID_INPUT")
|
||||
End If
|
||||
|
||||
' ------------------------------- Search For Machine Number ----------------------------------------------------------
|
||||
' ------------------------------- Search For Machine Number or Hostname ----------------------------------------------------------
|
||||
|
||||
strSQL = "SELECT machineid FROM machines WHERE (machinenumber = ? OR alias LIKE ?) AND machines.isactive = 1"
|
||||
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search, "%" & search & "%"))
|
||||
' 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 " & _
|
||||
"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 <> "")
|
||||
|
||||
rs.Close
|
||||
Set rs = Nothing
|
||||
Call CleanupResources()
|
||||
Response.Redirect "./displaymachine.asp?machineid=" & machineid
|
||||
|
||||
' Route to appropriate detail page based on PC vs Equipment
|
||||
If searchIsPC Then
|
||||
Response.Redirect "./displaypc.asp?machineid=" & machineid
|
||||
Else
|
||||
Response.Redirect "./displaymachine.asp?machineid=" & machineid
|
||||
End If
|
||||
Response.End
|
||||
End If
|
||||
|
||||
@@ -477,30 +493,46 @@ 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, mt.machinetype " & _
|
||||
strSQL = "SELECT m.machineid, m.machinenumber, m.alias, m.hostname, mo.machinetypeid, mt.machinetype " & _
|
||||
"FROM machines m " & _
|
||||
"INNER JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid " & _
|
||||
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " & _
|
||||
"LEFT JOIN machinetypes mt ON mo.machinetypeid = mt.machinetypeid " & _
|
||||
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " & _
|
||||
"WHERE (m.machinenumber LIKE ? OR m.alias LIKE ? OR m.machinenotes LIKE ? OR mt.machinetype LIKE ? OR v.vendor LIKE ?) " & _
|
||||
"WHERE (m.machinenumber LIKE ? OR m.alias LIKE ? OR m.machinenotes LIKE ? OR mt.machinetype LIKE ? OR v.vendor LIKE ? OR m.hostname LIKE ?) " & _
|
||||
" AND m.isactive = 1 " & _
|
||||
"LIMIT 10"
|
||||
|
||||
Set rsMachines = ExecuteParameterizedQuery(objConn, strSQL, Array("%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%"))
|
||||
Set rsMachines = ExecuteParameterizedQuery(objConn, strSQL, Array("%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%", "%" & searchTerm & "%"))
|
||||
|
||||
Response.Write("<!-- DEBUG: Checking machines for search term -->")
|
||||
|
||||
Do While Not rsMachines.EOF And totalCount < 100
|
||||
machineDispText = rsMachines("machinenumber")
|
||||
If Not IsNull(rsMachines("alias")) And rsMachines("alias") <> "" Then
|
||||
machineDispText = machineDispText & " (" & rsMachines("alias") & ")"
|
||||
' 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 <> "")
|
||||
|
||||
If isPC Then
|
||||
machineDispText = rsMachines("hostname") & ""
|
||||
If machineDispText = "" Then machineDispText = rsMachines("machinenumber") & ""
|
||||
Else
|
||||
machineDispText = rsMachines("machinenumber") & ""
|
||||
If Not IsNull(rsMachines("alias")) And rsMachines("alias") <> "" Then
|
||||
machineDispText = machineDispText & " (" & rsMachines("alias") & ")"
|
||||
End If
|
||||
End If
|
||||
|
||||
Response.Write("<!-- DEBUG: Found machine - ID: " & rsMachines("machineid") & ", Number: " & rsMachines("machinenumber") & " -->")
|
||||
Response.Write("<!-- DEBUG: Found machine - ID: " & rsMachines("machineid") & ", Number: " & rsMachines("machinenumber") & ", TypeID: " & machTypeId & ", IsPC: " & isPC & " -->")
|
||||
|
||||
appResults(totalCount, 0) = "machine"
|
||||
appResults(totalCount, 1) = rsMachines("machineid") & "|" & machineDispText & "|" & rsMachines("machinetype")
|
||||
' Include isPC flag in data: machineid|machineDisplay|machinetype|isPC
|
||||
appResults(totalCount, 1) = rsMachines("machineid") & "|" & machineDispText & "|" & rsMachines("machinetype") & "|" & CStr(isPC)
|
||||
' Score of 15 for machines (moderate priority)
|
||||
appResults(totalCount, 2) = 15
|
||||
appResults(totalCount, 3) = rsMachines("machineid")
|
||||
@@ -708,10 +740,27 @@ Next
|
||||
Response.Write("<td><button class='btn btn-sm btn-outline-primary share-btn' onclick='shareNotificationResult(" & notifId & ", """ & JavaScriptEncode(cleanSearch) & """)' title='Share this notification'><i class='zmdi zmdi-share'></i></button></td>")
|
||||
|
||||
ElseIf resultType = "machine" Then
|
||||
' Machine format: machineid|machineDisplay|machinetype
|
||||
' Machine format: machineid|machineDisplay|machinetype|isPC
|
||||
machineId = dataFields(0)
|
||||
machineDispText = dataFields(1)
|
||||
machineType = dataFields(2)
|
||||
Dim machineIsPC, machineDetailPage, machineListPage, machineIcon, machineIconColor, machineLabel
|
||||
machineIsPC = (UBound(dataFields) >= 3 And dataFields(3) = "True")
|
||||
|
||||
' Set page, icon and label based on PC vs Equipment
|
||||
If machineIsPC Then
|
||||
machineDetailPage = "displaypc.asp"
|
||||
machineListPage = "displaypcs.asp"
|
||||
machineIcon = "zmdi-desktop-windows"
|
||||
machineIconColor = "text-primary"
|
||||
machineLabel = "PC"
|
||||
Else
|
||||
machineDetailPage = "displaymachine.asp"
|
||||
machineListPage = "displaymachines.asp"
|
||||
machineIcon = "zmdi-reader"
|
||||
machineIconColor = "text-warning"
|
||||
machineLabel = "Machine"
|
||||
End If
|
||||
|
||||
rowId = "machine-result-" & machineId
|
||||
If highlightId <> "" And CStr(machineId) = CStr(highlightId) And Request.QueryString("type") = "machine" Then
|
||||
@@ -725,17 +774,17 @@ Next
|
||||
' Column 1: Empty for machines
|
||||
Response.Write("<td> </td>")
|
||||
|
||||
' Column 2: Machine icon - link to machines page (matches sidebar)
|
||||
Response.Write("<td><a href='./displaymachines.asp'><i class='zmdi zmdi-reader text-warning' style='margin-right: 5px;'></i>Machine</a></td>")
|
||||
' Column 2: Machine/PC icon - link to appropriate list page (matches sidebar)
|
||||
Response.Write("<td><a href='./" & machineListPage & "'><i class='zmdi " & machineIcon & " " & machineIconColor & "' style='margin-right: 5px;'></i>" & machineLabel & "</a></td>")
|
||||
|
||||
' Column 3: Machine number/alias links to machine detail
|
||||
Response.Write("<td><a href='./displaymachine.asp?machineid=" & machineId & "'>" & Server.HTMLEncode(machineDispText) & " <span class='badge badge-info'>" & Server.HTMLEncode(machineType) & "</span></a></td>")
|
||||
' Column 3: Machine number/alias or hostname links to appropriate detail page
|
||||
Response.Write("<td><a href='./" & machineDetailPage & "?machineid=" & machineId & "'>" & Server.HTMLEncode(machineDispText) & " <span class='badge badge-info'>" & Server.HTMLEncode(machineType) & "</span></a></td>")
|
||||
|
||||
' Column 4: Relevance badge
|
||||
Response.Write("<td><span class='badge " & badgeClass & "'><i class='zmdi zmdi-trending-up'></i> " & FormatNumber(relevanceScore, 1) & "</span></td>")
|
||||
|
||||
' Column 5: Share button
|
||||
Response.Write("<td><button class='btn btn-sm btn-outline-primary share-btn' onclick='shareMachineResult(" & machineId & ", """ & JavaScriptEncode(cleanSearch) & """)' title='Share this machine'><i class='zmdi zmdi-share'></i></button></td>")
|
||||
Response.Write("<td><button class='btn btn-sm btn-outline-primary share-btn' onclick='shareMachineResult(" & machineId & ", """ & JavaScriptEncode(cleanSearch) & """)' title='Share this " & LCase(machineLabel) & "'><i class='zmdi zmdi-share'></i></button></td>")
|
||||
|
||||
ElseIf resultType = "printer" Then
|
||||
' Printer format: printerid|printerDisplay|modelnumber|serialnumber
|
||||
|
||||
Reference in New Issue
Block a user