% ' Initialize error handling Call InitializeErrorHandling("search.asp") theme = Request.Cookies("theme") IF theme = "" THEN theme="bg-theme1" END IF ' Get and validate search parameter search = Request.Querystring("search") search = Replace(search, "+", " ") search = Trim(search) ' Keep a display version with spaces for user-facing messages Dim searchDisplay searchDisplay = search ' Get highlight parameter for shared links Dim highlightId, isShared highlightId = Request.QueryString("highlight") isShared = (Request.QueryString("shared") = "1") ' Basic validation - prevent empty searches If search = "" Then Call HandleValidationError("default.asp", "REQUIRED_FIELD") End If ' Length validation - prevent excessively long inputs If Len(search) > 200 Then Call HandleValidationError("default.asp", "INVALID_INPUT") End If ' ------------------------------- Search For Machine Number or Hostname ---------------------------------------------------------- ' 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 searchIsPC, searchRedirectPage ' PC if pctypeid IS NOT NULL searchIsPC = Not IsNull(rs("pctypeid")) rs.Close Set rs = Nothing Call CleanupResources() ' 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 rs.Close Set rs = Nothing '----------------------------- Search for Applications directly ---------------------------------------------------------------- ' If only one application matches, redirect directly to it ' Normalize search by removing hyphens and underscores Dim normalizedSearch normalizedSearch = search normalizedSearch = Replace(normalizedSearch, "-", " ") normalizedSearch = Replace(normalizedSearch, "_", " ") normalizedSearch = Replace(normalizedSearch, " ", " ") ' Double spaces to single ' Search using REPLACE to normalize app names in the same way strSQL = "SELECT appid FROM applications WHERE " & _ "REPLACE(REPLACE(REPLACE(appname, '-', ' '), '_', ' '), ' ', ' ') LIKE ? " & _ "AND isactive = 1" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array("%" & normalizedSearch & "%")) Dim appMatchCount, firstAppId appMatchCount = 0 If Not rs.EOF Then firstAppId = rs("appid") appMatchCount = 1 rs.MoveNext If Not rs.EOF Then appMatchCount = 2 ' More than one match End If End If rs.Close Set rs = Nothing ' Disabled auto-redirect - always show results in search.asp for consistency ' If appMatchCount = 1 Then ' Call CleanupResources() ' Response.Redirect "./displaytopic.asp?appid=" & firstAppId ' Response.End ' End If search = Replace(search, " ", "+") '----------------------------- Search for CSF Printer Name ---------------------------------------------------------------- If (Left(LCase(search), 3)) = "csf" And Len(search) = 5 Then strSQL = "SELECT printerid FROM printers WHERE printercsfname = ?" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search)) If Not rs.EOF Then printerid = rs("printerid") rs.Close Set rs = Nothing Call CleanupResources() Response.Redirect "./displayprinter.asp?printerid=" & printerid Response.End End If rs.Close Set rs = Nothing End If '----------------------------- Search for Printer Serial Number (exact match) ---------------------------------------------------------------- strSQL = "SELECT printerid FROM printers WHERE serialnumber = ? AND isactive = 1" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search)) If Not rs.EOF Then printerid = rs("printerid") rs.Close Set rs = Nothing Call CleanupResources() Response.Redirect "./displayprinter.asp?printerid=" & printerid Response.End End If rs.Close Set rs = Nothing '----------------------------- Search for Printer FQDN (exact match) ---------------------------------------------------------------- strSQL = "SELECT printerid FROM printers WHERE fqdn = ? AND isactive = 1" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search)) If Not rs.EOF Then printerid = rs("printerid") rs.Close Set rs = Nothing Call CleanupResources() Response.Redirect "./displayprinter.asp?printerid=" & printerid Response.End End If rs.Close Set rs = Nothing '----------------------------------Is this an IP address ------------------------------------------------------------------------------------- ' Validate IP address format before query If ValidateIPAddress(search) Then strSQL = "SELECT subnetid FROM subnets WHERE subnets.isactive = 1 AND INET_ATON(?) >= ipstart AND INET_ATON(?) <= ipend" Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(search, search)) If Not rs.EOF Then subnetid = rs("subnetid") rs.Close Set rs = Nothing Call CleanupResources() Response.Redirect "./displaysubnet.asp?subnetid=" & subnetid & "&search=" & Server.URLEncode(search) Response.End End If rs.Close Set rs = Nothing End If ' ------------------------------- Is this an SSO redirect to displayprofile.asp ---------------------------------------------------------- If IsNumeric(search) And Len(search) = 9 Then Call CleanupResources() Response.Redirect "./displayprofile.asp?sso=" & search Response.End End If ' ----------------------------------Is this a SNOW ticket----------------------------------- If (Left(LCase(search), 5)) = "geinc" Then Call CleanupResources() Response.Write("") Response.End End If If (Left(LCase(search), 5)) = "gechg" Then Call CleanupResources() Response.Write("") Response.End End If If (Left(LCase(search), 5)) = "gerit" Then Call CleanupResources() Response.Write("") Response.End End If If (Left(LCase(search), 5)) = "gesct" Then Call CleanupResources() Response.Write("") Response.End End If %>
| Topic | Description | Relevance | ||
|---|---|---|---|---|
| ") ' Column 2: App name with icon (matches sidebar) Response.Write(" | " & Server.HTMLEncode(appname) & " | ") ' Column 3: View details link Response.Write("View Application Details | ") ' Column 4: Relevance badge Response.Write("" & FormatNumber(relevanceScore, 1) & " | ") ' Column 5: Share button Response.Write("") ElseIf resultType = "kb" Then ' KB format: linkid|appid|appname|shortdescription|linkurl|clicks linkid = dataFields(0) appid = dataFields(1) appname = dataFields(2) shortdesc = dataFields(3) linkurl = dataFields(4) clicks = dataFields(5) rowId = "result-" & linkid If highlightId <> "" And CStr(linkid) = CStr(highlightId) And Request.QueryString("type") <> "app" Then rowStyle = " class='highlighted-result'" Else rowStyle = "" End If Response.Write(" |
| ") ' Column 2: App name with KB icon (matches sidebar) Response.Write(" | " & Server.HTMLEncode(appname) & " | ") ' Column 3: Description Response.Write("" & Server.HTMLEncode(shortdesc) & " | ") ' Column 4: Relevance badge Response.Write("" & FormatNumber(relevanceScore, 1) & " | ") ' Column 5: Share button Response.Write("") ElseIf resultType = "notification" Then ' Notification format: notificationid|notification|starttime|endtime|ticketnumber|link notifId = dataFields(0) notifText = dataFields(1) notifStart = dataFields(2) notifEnd = dataFields(3) notifTicket = dataFields(4) notifLink = dataFields(5) rowId = "notification-result-" & notifId If highlightId <> "" And CStr(notifId) = CStr(highlightId) And Request.QueryString("type") = "notification" Then rowStyle = " class='highlighted-result'" Else rowStyle = "" End If Response.Write(" |
| ") ' Column 2: Notification icon - link to notifications page (matches KB article pattern) Response.Write(" | Notification | ") ' Column 3: Notification text links to edit (like clicking event in calendar) notifDisplay = Server.HTMLEncode(notifText) If notifTicket <> "" Then notifDisplay = notifDisplay & " " & Server.HTMLEncode(notifTicket) & "" End If Response.Write("" & notifDisplay & " | ") ' Column 4: Relevance badge Response.Write("" & FormatNumber(relevanceScore, 1) & " | ") ' Column 5: Share button Response.Write("") ElseIf resultType = "machine" Then ' 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 rowStyle = " class='highlighted-result'" Else rowStyle = "" End If Response.Write(" |
| ") ' Column 2: Machine/PC icon - link to appropriate list page (matches sidebar) Response.Write(" | " & machineLabel & " | ") ' Column 3: Machine number/alias or hostname links to appropriate detail page Response.Write("" & Server.HTMLEncode(machineDispText) & " " & Server.HTMLEncode(machineType) & " | ") ' Column 4: Relevance badge Response.Write("" & FormatNumber(relevanceScore, 1) & " | ") ' Column 5: Share button Response.Write("") ElseIf resultType = "printer" Then ' Printer format: printerid|printerDisplay|modelnumber|serialnumber printerId = dataFields(0) printerDispText = dataFields(1) printerModel = dataFields(2) printerSerial = dataFields(3) rowId = "printer-result-" & printerId If highlightId <> "" And CStr(printerId) = CStr(highlightId) And Request.QueryString("type") = "printer" Then rowStyle = " class='highlighted-result'" Else rowStyle = "" End If Response.Write(" |
| ") ' Column 2: Printer icon - link to printers page (matches sidebar) Response.Write(" | Printer | ") ' Column 3: Printer name links to printer detail printerDetailText = Server.HTMLEncode(printerDispText) If Not IsNull(printerModel) And printerModel <> "" Then printerDetailText = printerDetailText & " " & Server.HTMLEncode(printerModel) & "" End If Response.Write("" & printerDetailText & " | ") ' Column 4: Relevance badge Response.Write("" & FormatNumber(relevanceScore, 1) & " | ") ' Column 5: Share button Response.Write("") End If Response.Write(" |