Add inline machine type creation and employee search results
- Add "+ New" button for machine types when adding models on network device pages (firewall, switch, server, access point, camera) - Machine type dropdown now grouped by category (Equipment, Network, PC) - Add firewall device type to savenetworkdevice.asp - Remove employee autocomplete dropdown from global search bar - Add employee search results to search.asp results page - Update data_cache.asp with null-safe CLng handling Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
Dim modelnumber, vendorid, notes, documentationpath
|
||||
Dim newvendorname, isprinter, ispc, ismachine
|
||||
Dim modelisprinter, modelispc, modelismachine
|
||||
Dim machinetypeid, newmachinetypename, newmachinetypecategory
|
||||
|
||||
modelnumber = Trim(Request.Form("modelnumber"))
|
||||
vendorid = Trim(Request.Form("vendorid"))
|
||||
@@ -37,6 +38,11 @@
|
||||
modelispc = Request.Form("modelispc")
|
||||
modelismachine = Request.Form("modelismachine")
|
||||
|
||||
' Machine type fields
|
||||
machinetypeid = Trim(Request.Form("machinetypeid"))
|
||||
newmachinetypename = Trim(Request.Form("newmachinetypename"))
|
||||
newmachinetypecategory = Trim(Request.Form("newmachinetypecategory"))
|
||||
|
||||
' Validate required fields
|
||||
If modelnumber = "" Then
|
||||
objConn.Close
|
||||
@@ -176,6 +182,87 @@
|
||||
Set cmdUpdateVendor = Nothing
|
||||
End If
|
||||
|
||||
' Handle new machine type creation if needed
|
||||
If machinetypeid = "new" Then
|
||||
If newmachinetypename = "" Then
|
||||
objConn.Close
|
||||
ShowError "Machine type name is required when adding a new type.", "addmodel.asp"
|
||||
Response.End
|
||||
End If
|
||||
|
||||
If Len(newmachinetypename) > 50 Then
|
||||
objConn.Close
|
||||
ShowError "Machine type name too long.", "addmodel.asp"
|
||||
Response.End
|
||||
End If
|
||||
|
||||
' Check if machine type already exists
|
||||
Dim checkMTSQL, rsMTCheck, cmdMTCheck
|
||||
checkMTSQL = "SELECT COUNT(*) as cnt FROM machinetypes WHERE LOWER(machinetype) = LOWER(?)"
|
||||
Set cmdMTCheck = Server.CreateObject("ADODB.Command")
|
||||
cmdMTCheck.ActiveConnection = objConn
|
||||
cmdMTCheck.CommandText = checkMTSQL
|
||||
cmdMTCheck.CommandType = 1
|
||||
cmdMTCheck.Parameters.Append cmdMTCheck.CreateParameter("@machinetype", 200, 1, 50, newmachinetypename)
|
||||
Set rsMTCheck = cmdMTCheck.Execute
|
||||
If Not rsMTCheck.EOF Then
|
||||
If Not IsNull(rsMTCheck("cnt")) Then
|
||||
If CLng(rsMTCheck("cnt")) > 0 Then
|
||||
rsMTCheck.Close
|
||||
Set rsMTCheck = Nothing
|
||||
Set cmdMTCheck = Nothing
|
||||
objConn.Close
|
||||
ShowError "Machine type '" & Server.HTMLEncode(newmachinetypename) & "' already exists.", "addmodel.asp"
|
||||
Response.End
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
rsMTCheck.Close
|
||||
Set rsMTCheck = Nothing
|
||||
Set cmdMTCheck = Nothing
|
||||
|
||||
' Default category if not provided
|
||||
If newmachinetypecategory = "" Then newmachinetypecategory = "Equipment"
|
||||
|
||||
' Insert new machine type
|
||||
Dim mtSQL, cmdMT
|
||||
mtSQL = "INSERT INTO machinetypes (machinetype, isactive, category) VALUES (?, 1, ?)"
|
||||
Set cmdMT = Server.CreateObject("ADODB.Command")
|
||||
cmdMT.ActiveConnection = objConn
|
||||
cmdMT.CommandText = mtSQL
|
||||
cmdMT.CommandType = 1
|
||||
cmdMT.Parameters.Append cmdMT.CreateParameter("@machinetype", 200, 1, 50, newmachinetypename)
|
||||
cmdMT.Parameters.Append cmdMT.CreateParameter("@category", 200, 1, 50, newmachinetypecategory)
|
||||
|
||||
On Error Resume Next
|
||||
cmdMT.Execute
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
Set cmdMT = Nothing
|
||||
objConn.Close
|
||||
ShowError "Error creating machine type: " & Server.HTMLEncode(Err.Description), "addmodel.asp"
|
||||
Response.End
|
||||
End If
|
||||
|
||||
' Get the new machine type ID
|
||||
Set rsMTCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
|
||||
machinetypeid = 0
|
||||
If Not rsMTCheck.EOF Then
|
||||
If Not IsNull(rsMTCheck("newid")) Then
|
||||
machinetypeid = CLng(rsMTCheck("newid"))
|
||||
End If
|
||||
End If
|
||||
rsMTCheck.Close
|
||||
Set rsMTCheck = Nothing
|
||||
Set cmdMT = Nothing
|
||||
On Error Goto 0
|
||||
ElseIf machinetypeid <> "" Then
|
||||
' Validate existing machine type ID
|
||||
If Not IsNumeric(machinetypeid) Or CLng(machinetypeid) < 1 Then
|
||||
machinetypeid = ""
|
||||
End If
|
||||
End If
|
||||
|
||||
' Check if model already exists for this vendor using parameterized query
|
||||
checkSQL = "SELECT COUNT(*) as cnt FROM models WHERE LOWER(modelnumber) = LOWER(?) AND vendorid = ?"
|
||||
Set cmdCheck = Server.CreateObject("ADODB.Command")
|
||||
@@ -203,7 +290,11 @@
|
||||
|
||||
' Insert the new model using parameterized query
|
||||
Dim modelSQL, cmdModel
|
||||
modelSQL = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) VALUES (?, ?, ?, ?, 1)"
|
||||
If machinetypeid <> "" And IsNumeric(machinetypeid) Then
|
||||
modelSQL = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, machinetypeid, isactive) VALUES (?, ?, ?, ?, ?, 1)"
|
||||
Else
|
||||
modelSQL = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) VALUES (?, ?, ?, ?, 1)"
|
||||
End If
|
||||
Set cmdModel = Server.CreateObject("ADODB.Command")
|
||||
cmdModel.ActiveConnection = objConn
|
||||
cmdModel.CommandText = modelSQL
|
||||
@@ -212,6 +303,9 @@
|
||||
cmdModel.Parameters.Append cmdModel.CreateParameter("@vendorid", 3, 1, , CLng(vendorid))
|
||||
cmdModel.Parameters.Append cmdModel.CreateParameter("@notes", 200, 1, 255, notes)
|
||||
cmdModel.Parameters.Append cmdModel.CreateParameter("@documentationpath", 200, 1, 255, documentationpath)
|
||||
If machinetypeid <> "" And IsNumeric(machinetypeid) Then
|
||||
cmdModel.Parameters.Append cmdModel.CreateParameter("@machinetypeid", 3, 1, , CLng(machinetypeid))
|
||||
End If
|
||||
|
||||
On Error Resume Next
|
||||
cmdModel.Execute
|
||||
|
||||
Reference in New Issue
Block a user