Files
shopdb/savemachine_direct.asp
cproudlock 65b622c361 Add USB checkout system and SSO profile page
New Features:
- USB Device checkout/check-in system with barcode scanning
  - displayusb.asp: List all USB devices with status
  - addusb.asp: Add new USB devices via barcode scan
  - checkout_usb.asp/savecheckout_usb.asp: Check out USB to SSO
  - checkin_usb.asp/savecheckin_usb.asp: Check in with wipe confirmation
  - usb_history.asp: Full checkout history with filters
  - api_usb.asp: JSON API for AJAX lookups
- displayprofile.asp: SSO profile page showing user info and USB history
- Date/time format changed to 12-hour (MM/DD/YYYY h:mm AM/PM)
- SSO links in USB history now link to profile page via search

Database:
- New machinetypeid 44 for USB devices
- New usb_checkouts table for tracking checkouts

Cleanup:
- Removed v2 folder (duplicate/old files)
- Removed old debug/test files
- Removed completed migration documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 11:16:14 -05:00

702 lines
27 KiB
Plaintext

<%
'=============================================================================
' FILE: savemachine_direct.asp
' PURPOSE: Create new machine with nested entity creation (vendor, model, business unit)
' SECURITY: Parameterized queries, HTML encoding, input validation
' UPDATED: 2025-10-27 - Migrated to secure patterns
' REFACTORED: 2025-10-27 - Removed machinetypeid (now inherited from models table)
' NOTE: Machines now inherit machinetypeid from their model. Each model has one machine type.
'=============================================================================
%>
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/response.asp"-->
<%
' Get and validate all inputs
Dim machinenumber, modelid, businessunitid, alias, machinenotes, mapleft, maptop
machinenumber = Trim(Request.Form("machinenumber"))
modelid = Trim(Request.Form("modelid"))
businessunitid = Trim(Request.Form("businessunitid"))
alias = Trim(Request.Form("alias"))
machinenotes = Trim(Request.Form("machinenotes"))
mapleft = Trim(Request.Form("mapleft"))
maptop = Trim(Request.Form("maptop"))
' Get form inputs for new business unit
Dim newbusinessunit
newbusinessunit = Trim(Request.Form("newbusinessunit"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelimage, newmodelmachinetypeid
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelimage = Trim(Request.Form("newmodelimage"))
newmodelmachinetypeid = Trim(Request.Form("newmodelmachinetypeid"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Get form inputs for new machine type
Dim newmachinetype, newmachinedescription, newfunctionalaccountid
newmachinetype = Trim(Request.Form("newmachinetype"))
newmachinedescription = Trim(Request.Form("newmachinedescription"))
newfunctionalaccountid = Trim(Request.Form("newfunctionalaccountid"))
' Get form inputs for new functional account
Dim newfunctionalaccount, newfunctionalaccountdescription
newfunctionalaccount = Trim(Request.Form("newfunctionalaccount"))
newfunctionalaccountdescription = Trim(Request.Form("newfunctionalaccountdescription"))
' Validate required fields
If machinenumber = "" Then
ShowError "Machine number is required.", "addmachine.asp"
objConn.Close
Response.End
End If
' Validate ID fields - allow "new" as a valid value
If modelid <> "new" And Not IsNumeric(modelid) Then
ShowError "Invalid model ID.", "addmachine.asp"
objConn.Close
Response.End
End If
If businessunitid <> "new" And Not IsNumeric(businessunitid) Then
ShowError "Invalid business unit ID.", "addmachine.asp"
objConn.Close
Response.End
End If
' Validate field lengths
If Len(machinenumber) > 50 Or Len(alias) > 50 Then
ShowError "Field length exceeded.", "addmachine.asp"
objConn.Close
Response.End
End If
' Check if machine number already exists
Dim checkSQL, rsCheck, cmdCheck
checkSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinenumber = ?"
Set cmdCheck = Server.CreateObject("ADODB.Command")
cmdCheck.ActiveConnection = objConn
cmdCheck.CommandText = checkSQL
cmdCheck.CommandType = 1
cmdCheck.Parameters.Append cmdCheck.CreateParameter("@machinenumber", 200, 1, 50, machinenumber)
Set rsCheck = cmdCheck.Execute
If Not rsCheck.EOF Then
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Set cmdCheck = Nothing
objConn.Close
ShowError "Machine number '" & machinenumber & "' already exists.", "addmachine.asp"
Response.End
End If
End If
rsCheck.Close
Set rsCheck = Nothing
Set cmdCheck = Nothing
' Handle new business unit creation
If businessunitid = "new" Then
If Len(newbusinessunit) = 0 Then
objConn.Close
ShowError "New business unit name is required", "addmachine.asp"
Response.End
End If
If Len(newbusinessunit) > 50 Then
objConn.Close
ShowError "Business unit name too long", "addmachine.asp"
Response.End
End If
' Insert new business unit using parameterized query
Dim sqlNewBU, cmdNewBU
sqlNewBU = "INSERT INTO businessunits (businessunit, isactive) VALUES (?, 1)"
Set cmdNewBU = Server.CreateObject("ADODB.Command")
cmdNewBU.ActiveConnection = objConn
cmdNewBU.CommandText = sqlNewBU
cmdNewBU.CommandType = 1
cmdNewBU.Parameters.Append cmdNewBU.CreateParameter("@businessunit", 200, 1, 50, newbusinessunit)
On Error Resume Next
cmdNewBU.Execute
If Err.Number <> 0 Then
Set cmdNewBU = Nothing
objConn.Close
ShowError "Error creating new business unit: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created business unit ID
Dim rsNewBU
Set rsNewBU = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
businessunitid = CLng(rsNewBU("newid"))
rsNewBU.Close
Set rsNewBU = Nothing
Set cmdNewBU = Nothing
On Error Goto 0
End If
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
objConn.Close
ShowError "New model number is required", "addmachine.asp"
Response.End
End If
If Len(newvendorid) = 0 Then
objConn.Close
ShowError "Vendor is required for new model", "addmachine.asp"
Response.End
End If
' Handle new machine type creation (nested in new model)
If newmodelmachinetypeid = "new" Then
If Len(newmachinetype) = 0 Then
objConn.Close
ShowError "New machine type name is required", "addmachine.asp"
Response.End
End If
If Len(newfunctionalaccountid) = 0 Then
objConn.Close
ShowError "Functional account is required for new machine type", "addmachine.asp"
Response.End
End If
If Len(newmachinetype) > 50 Or Len(newmachinedescription) > 255 Then
objConn.Close
ShowError "Machine type field length exceeded", "addmachine.asp"
Response.End
End If
' Handle new functional account creation (nested in new machine type)
If newfunctionalaccountid = "new" Then
If Len(newfunctionalaccount) = 0 Then
objConn.Close
ShowError "New functional account name is required", "addmachine.asp"
Response.End
End If
If Len(newfunctionalaccount) > 50 Or Len(newfunctionalaccountdescription) > 255 Then
objConn.Close
ShowError "Functional account field length exceeded", "addmachine.asp"
Response.End
End If
' Insert new functional account using parameterized query
Dim sqlNewFA, cmdNewFA
sqlNewFA = "INSERT INTO functionalaccounts (functionalaccount, description, isactive) VALUES (?, ?, 1)"
Set cmdNewFA = Server.CreateObject("ADODB.Command")
cmdNewFA.ActiveConnection = objConn
cmdNewFA.CommandText = sqlNewFA
cmdNewFA.CommandType = 1
cmdNewFA.Parameters.Append cmdNewFA.CreateParameter("@functionalaccount", 200, 1, 50, newfunctionalaccount)
' Handle optional description
If Len(newfunctionalaccountdescription) > 0 Then
cmdNewFA.Parameters.Append cmdNewFA.CreateParameter("@description", 200, 1, 255, newfunctionalaccountdescription)
Else
cmdNewFA.Parameters.Append cmdNewFA.CreateParameter("@description", 200, 1, 255, Null)
End If
On Error Resume Next
cmdNewFA.Execute
If Err.Number <> 0 Then
Set cmdNewFA = Nothing
objConn.Close
ShowError "Error creating new functional account: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created functional account ID
Dim rsNewFA
Set rsNewFA = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newfunctionalaccountid = CLng(rsNewFA("newid"))
rsNewFA.Close
Set rsNewFA = Nothing
Set cmdNewFA = Nothing
On Error Goto 0
End If
' Insert new machine type using parameterized query
Dim sqlNewMT, cmdNewMT
sqlNewMT = "INSERT INTO machinetypes (machinetype, machinedescription, functionalaccountid, isactive) VALUES (?, ?, ?, 1)"
Set cmdNewMT = Server.CreateObject("ADODB.Command")
cmdNewMT.ActiveConnection = objConn
cmdNewMT.CommandText = sqlNewMT
cmdNewMT.CommandType = 1
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@machinetype", 200, 1, 50, newmachinetype)
' Handle optional description
If Len(newmachinedescription) > 0 Then
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@machinedescription", 200, 1, 255, newmachinedescription)
Else
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@machinedescription", 200, 1, 255, Null)
End If
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@functionalaccountid", 3, 1, , CLng(newfunctionalaccountid))
On Error Resume Next
cmdNewMT.Execute
If Err.Number <> 0 Then
Set cmdNewMT = Nothing
objConn.Close
ShowError "Error creating new machine type: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created machine type ID
Dim rsNewMT
Set rsNewMT = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newmodelmachinetypeid = CLng(rsNewMT("newid"))
rsNewMT.Close
Set rsNewMT = Nothing
Set cmdNewMT = Nothing
On Error Goto 0
End If
If Len(newmodelmachinetypeid) = 0 Or (newmodelmachinetypeid <> "new" And Not IsNumeric(newmodelmachinetypeid)) Then
ShowError "Machine type is required for new model. Please select a machine type from the dropdown.", "addmachine.asp"
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Or Len(newmodelimage) > 100 Then
objConn.Close
ShowError "Model field length exceeded", "addmachine.asp"
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
objConn.Close
ShowError "New vendor name is required", "addmachine.asp"
Response.End
End If
If Len(newvendorname) > 50 Then
objConn.Close
ShowError "Vendor name too long", "addmachine.asp"
Response.End
End If
' Insert new vendor using parameterized query (with ismachine=1)
Dim sqlNewVendor, cmdNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES (?, 1, 0, 0, 1)"
Set cmdNewVendor = Server.CreateObject("ADODB.Command")
cmdNewVendor.ActiveConnection = objConn
cmdNewVendor.CommandText = sqlNewVendor
cmdNewVendor.CommandType = 1
cmdNewVendor.Parameters.Append cmdNewVendor.CreateParameter("@vendor", 200, 1, 50, newvendorname)
On Error Resume Next
cmdNewVendor.Execute
If Err.Number <> 0 Then
Set cmdNewVendor = Nothing
objConn.Close
ShowError "Error creating new vendor: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created vendor ID
Dim rsNewVendor
Set rsNewVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newvendorid = CLng(rsNewVendor("newid"))
rsNewVendor.Close
Set rsNewVendor = Nothing
Set cmdNewVendor = Nothing
On Error Goto 0
End If
' Set default image if not specified
Dim modelImageValue
If Len(newmodelimage) > 0 Then
modelImageValue = newmodelimage
Else
modelImageValue = "default.png"
End If
' Insert new model using parameterized query (including machinetypeid)
Dim sqlNewModel, cmdNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, machinetypeid, image, isactive) VALUES (?, ?, ?, ?, 1)"
Set cmdNewModel = Server.CreateObject("ADODB.Command")
cmdNewModel.ActiveConnection = objConn
cmdNewModel.CommandText = sqlNewModel
cmdNewModel.CommandType = 1
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@modelnumber", 200, 1, 50, newmodelnumber)
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@vendorid", 3, 1, , CLng(newvendorid))
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@machinetypeid", 3, 1, , CLng(newmodelmachinetypeid))
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@image", 200, 1, 100, modelImageValue)
On Error Resume Next
cmdNewModel.Execute
If Err.Number <> 0 Then
Set cmdNewModel = Nothing
objConn.Close
ShowError "Error creating new model: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelid = CLng(rsNewModel("newid"))
rsNewModel.Close
Set rsNewModel = Nothing
Set cmdNewModel = Nothing
On Error Goto 0
End If
' Get the machinetypeid from the selected model
Dim modelMachineTypeId, rsModelType
modelMachineTypeId = 1 ' Default fallback
Set rsModelType = objConn.Execute("SELECT machinetypeid FROM models WHERE modelnumberid = " & CLng(modelid))
If Not rsModelType.EOF Then
If Not IsNull(rsModelType("machinetypeid")) Then
modelMachineTypeId = CLng(rsModelType("machinetypeid"))
End If
End If
rsModelType.Close
Set rsModelType = Nothing
' Build INSERT statement with parameterized query
' NOTE: machinetypeid is inherited from the model's machinetypeid
Dim strSQL, cmdMachine
strSQL = "INSERT INTO machines (machinenumber, modelnumberid, machinetypeid, businessunitid, alias, machinenotes, mapleft, maptop, isactive, islocationonly) " & _
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, 0)"
Set cmdMachine = Server.CreateObject("ADODB.Command")
cmdMachine.ActiveConnection = objConn
cmdMachine.CommandText = strSQL
cmdMachine.CommandType = 1
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@machinenumber", 200, 1, 50, machinenumber)
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@modelnumberid", 3, 1, , CLng(modelid))
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@machinetypeid", 3, 1, , modelMachineTypeId)
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@businessunitid", 3, 1, , CLng(businessunitid))
' Handle optional alias
If alias <> "" Then
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@alias", 200, 1, 50, alias)
Else
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@alias", 200, 1, 50, Null)
End If
' Handle optional machinenotes
If machinenotes <> "" Then
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@machinenotes", 200, 1, 500, machinenotes)
Else
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@machinenotes", 200, 1, 500, Null)
End If
' Handle optional map coordinates
If mapleft <> "" And maptop <> "" And IsNumeric(mapleft) And IsNumeric(maptop) Then
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@mapleft", 3, 1, , CLng(mapleft))
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@maptop", 3, 1, , CLng(maptop))
Else
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@mapleft", 3, 1, , Null)
cmdMachine.Parameters.Append cmdMachine.CreateParameter("@maptop", 3, 1, , Null)
End If
On Error Resume Next
cmdMachine.Execute
If Err.Number <> 0 Then
Set cmdMachine = Nothing
objConn.Close
ShowError Err.Description, "addmachine.asp"
Response.End
End If
Set cmdMachine = Nothing
' Get the new machine ID
Dim newMachineId
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newMachineId = CLng(rsCheck("newid"))
rsCheck.Close
Set rsCheck = Nothing
' Link selected PC to this machine by updating its machinenumber field
Dim pcid, pcidVal
pcid = Trim(Request.Form("pcid") & "")
If pcid <> "" And IsNumeric(pcid) Then
pcidVal = CLng(pcid)
If pcidVal > 0 Then
Dim updatePCSQL, cmdUpdatePC
updatePCSQL = "UPDATE pc SET machinenumber = ? WHERE pcid = ?"
Set cmdUpdatePC = Server.CreateObject("ADODB.Command")
cmdUpdatePC.ActiveConnection = objConn
cmdUpdatePC.CommandText = updatePCSQL
cmdUpdatePC.CommandType = 1
cmdUpdatePC.Parameters.Append cmdUpdatePC.CreateParameter("@machinenumber", 200, 1, 50, machinenumber)
cmdUpdatePC.Parameters.Append cmdUpdatePC.CreateParameter("@pcid", 3, 1, , pcidVal)
On Error Resume Next
cmdUpdatePC.Execute
Set cmdUpdatePC = Nothing
On Error Goto 0
End If
End If
'=============================================================================
' SAVE NETWORK COMMUNICATIONS (up to 3 interfaces)
'=============================================================================
' Get Network_Interface communication type ID
Dim comstypeid
Set rsCheck = objConn.Execute("SELECT comstypeid FROM comstypes WHERE typename = 'Network_Interface'")
If Not rsCheck.EOF Then
comstypeid = rsCheck("comstypeid")
rsCheck.Close
' Process up to 3 interfaces
Dim ip1, mac1, ip2, mac2, ip3, mac3
ip1 = Trim(Request.Form("ip1"))
mac1 = Trim(Request.Form("mac1"))
ip2 = Trim(Request.Form("ip2"))
mac2 = Trim(Request.Form("mac2"))
ip3 = Trim(Request.Form("ip3"))
mac3 = Trim(Request.Form("mac3"))
' Interface 1 (Primary)
If ip1 <> "" Or mac1 <> "" Then
Dim cmdComm1, ip1Val, mac1Val
If ip1 <> "" Then ip1Val = ip1 Else ip1Val = Null
If mac1 <> "" Then mac1Val = mac1 Else mac1Val = Null
Set cmdComm1 = Server.CreateObject("ADODB.Command")
cmdComm1.ActiveConnection = objConn
cmdComm1.CommandText = "INSERT INTO communications (machineid, comstypeid, address, macaddress, interfacename, isprimary, isactive) VALUES (?, ?, ?, ?, ?, 1, 1)"
cmdComm1.CommandType = 1
cmdComm1.Parameters.Append cmdComm1.CreateParameter("@machineid", 3, 1, , newMachineId)
cmdComm1.Parameters.Append cmdComm1.CreateParameter("@comstypeid", 3, 1, , comstypeid)
cmdComm1.Parameters.Append cmdComm1.CreateParameter("@address", 200, 1, 50, ip1Val)
cmdComm1.Parameters.Append cmdComm1.CreateParameter("@macaddress", 200, 1, 50, mac1Val)
cmdComm1.Parameters.Append cmdComm1.CreateParameter("@interfacename", 200, 1, 50, "Interface 1")
On Error Resume Next
cmdComm1.Execute
Set cmdComm1 = Nothing
On Error Goto 0
End If
' Interface 2 (Optional)
If ip2 <> "" Or mac2 <> "" Then
Dim cmdComm2, ip2Val, mac2Val
If ip2 <> "" Then ip2Val = ip2 Else ip2Val = Null
If mac2 <> "" Then mac2Val = mac2 Else mac2Val = Null
Set cmdComm2 = Server.CreateObject("ADODB.Command")
cmdComm2.ActiveConnection = objConn
cmdComm2.CommandText = "INSERT INTO communications (machineid, comstypeid, address, macaddress, interfacename, isprimary, isactive) VALUES (?, ?, ?, ?, ?, 0, 1)"
cmdComm2.CommandType = 1
cmdComm2.Parameters.Append cmdComm2.CreateParameter("@machineid", 3, 1, , newMachineId)
cmdComm2.Parameters.Append cmdComm2.CreateParameter("@comstypeid", 3, 1, , comstypeid)
cmdComm2.Parameters.Append cmdComm2.CreateParameter("@address", 200, 1, 50, ip2Val)
cmdComm2.Parameters.Append cmdComm2.CreateParameter("@macaddress", 200, 1, 50, mac2Val)
cmdComm2.Parameters.Append cmdComm2.CreateParameter("@interfacename", 200, 1, 50, "Interface 2")
On Error Resume Next
cmdComm2.Execute
Set cmdComm2 = Nothing
On Error Goto 0
End If
' Interface 3 (Optional)
If ip3 <> "" Or mac3 <> "" Then
Dim cmdComm3, ip3Val, mac3Val
If ip3 <> "" Then ip3Val = ip3 Else ip3Val = Null
If mac3 <> "" Then mac3Val = mac3 Else mac3Val = Null
Set cmdComm3 = Server.CreateObject("ADODB.Command")
cmdComm3.ActiveConnection = objConn
cmdComm3.CommandText = "INSERT INTO communications (machineid, comstypeid, address, macaddress, interfacename, isprimary, isactive) VALUES (?, ?, ?, ?, ?, 0, 1)"
cmdComm3.CommandType = 1
cmdComm3.Parameters.Append cmdComm3.CreateParameter("@machineid", 3, 1, , newMachineId)
cmdComm3.Parameters.Append cmdComm3.CreateParameter("@comstypeid", 3, 1, , comstypeid)
cmdComm3.Parameters.Append cmdComm3.CreateParameter("@address", 200, 1, 50, ip3Val)
cmdComm3.Parameters.Append cmdComm3.CreateParameter("@macaddress", 200, 1, 50, mac3Val)
cmdComm3.Parameters.Append cmdComm3.CreateParameter("@interfacename", 200, 1, 50, "Interface 3")
On Error Resume Next
cmdComm3.Execute
Set cmdComm3 = Nothing
On Error Goto 0
End If
End If
'=============================================================================
' SAVE MACHINE RELATIONSHIPS
'=============================================================================
Dim controllingpc, dualpathid, controllingpcVal, dualpathidVal
controllingpc = Trim(Request.Form("controllingpc") & "")
dualpathid = Trim(Request.Form("dualpathid") & "")
' Get relationship type IDs
Dim controlsTypeID, dualpathTypeID
Set rsCheck = objConn.Execute("SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Controls'")
If Not rsCheck.EOF Then controlsTypeID = rsCheck("relationshiptypeid")
rsCheck.Close
Set rsCheck = objConn.Execute("SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Dualpath'")
If Not rsCheck.EOF Then dualpathTypeID = rsCheck("relationshiptypeid")
rsCheck.Close
' Create Controls relationship (PC controls this equipment)
If controllingpc <> "" And IsNumeric(controllingpc) Then
controllingpcVal = CLng(controllingpc)
If controllingpcVal > 0 Then
Dim cmdRelPC
Set cmdRelPC = Server.CreateObject("ADODB.Command")
cmdRelPC.ActiveConnection = objConn
cmdRelPC.CommandText = "INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive) VALUES (?, ?, ?, 1)"
cmdRelPC.CommandType = 1
cmdRelPC.Parameters.Append cmdRelPC.CreateParameter("@machineid", 3, 1, , controllingpcVal)
cmdRelPC.Parameters.Append cmdRelPC.CreateParameter("@related_machineid", 3, 1, , newMachineId)
cmdRelPC.Parameters.Append cmdRelPC.CreateParameter("@relationshiptypeid", 3, 1, , controlsTypeID)
On Error Resume Next
cmdRelPC.Execute
Set cmdRelPC = Nothing
On Error Goto 0
End If
End If
' Create Dualpath relationship (bidirectional)
If dualpathid <> "" And IsNumeric(dualpathid) Then
dualpathidVal = CLng(dualpathid)
If dualpathidVal > 0 Then
Dim cmdRelDual1, cmdRelDual2
' Direction 1: new machine -> dualpath machine
Set cmdRelDual1 = Server.CreateObject("ADODB.Command")
cmdRelDual1.ActiveConnection = objConn
cmdRelDual1.CommandText = "INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive) VALUES (?, ?, ?, 1)"
cmdRelDual1.CommandType = 1
cmdRelDual1.Parameters.Append cmdRelDual1.CreateParameter("@machineid", 3, 1, , newMachineId)
cmdRelDual1.Parameters.Append cmdRelDual1.CreateParameter("@related_machineid", 3, 1, , dualpathidVal)
cmdRelDual1.Parameters.Append cmdRelDual1.CreateParameter("@relationshiptypeid", 3, 1, , dualpathTypeID)
On Error Resume Next
cmdRelDual1.Execute
Set cmdRelDual1 = Nothing
' Direction 2: dualpath machine -> new machine
Set cmdRelDual2 = Server.CreateObject("ADODB.Command")
cmdRelDual2.ActiveConnection = objConn
cmdRelDual2.CommandText = "INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive) VALUES (?, ?, ?, 1)"
cmdRelDual2.CommandType = 1
cmdRelDual2.Parameters.Append cmdRelDual2.CreateParameter("@machineid", 3, 1, , dualpathidVal)
cmdRelDual2.Parameters.Append cmdRelDual2.CreateParameter("@related_machineid", 3, 1, , newMachineId)
cmdRelDual2.Parameters.Append cmdRelDual2.CreateParameter("@relationshiptypeid", 3, 1, , dualpathTypeID)
cmdRelDual2.Execute
Set cmdRelDual2 = Nothing
On Error Goto 0
End If
End If
'=============================================================================
' SAVE COMPLIANCE DATA
'=============================================================================
Dim thirdpartymanaged, thirdpartyvendorid, otassetsystem, dodassettype
thirdpartymanaged = Trim(Request.Form("thirdpartymanaged"))
thirdpartyvendorid = Trim(Request.Form("thirdpartyvendorid"))
otassetsystem = Trim(Request.Form("otassetsystem"))
dodassettype = Trim(Request.Form("dodassettype"))
' Handle new third party vendor creation
If thirdpartyvendorid = "new" Then
Dim newthirdpartyvendorname
newthirdpartyvendorname = Trim(Request.Form("newthirdpartyvendorname"))
If Len(newthirdpartyvendorname) = 0 Then
objConn.Close
ShowError "New third party vendor name is required", "addmachine.asp"
Response.End
End If
If Len(newthirdpartyvendorname) > 50 Then
objConn.Close
ShowError "Third party vendor name too long", "addmachine.asp"
Response.End
End If
' Insert new third party vendor
Dim sqlNewTPVendor, cmdNewTPVendor
sqlNewTPVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES (?, 1, 0, 0, 0)"
Set cmdNewTPVendor = Server.CreateObject("ADODB.Command")
cmdNewTPVendor.ActiveConnection = objConn
cmdNewTPVendor.CommandText = sqlNewTPVendor
cmdNewTPVendor.CommandType = 1
cmdNewTPVendor.Parameters.Append cmdNewTPVendor.CreateParameter("@vendor", 200, 1, 50, newthirdpartyvendorname)
On Error Resume Next
cmdNewTPVendor.Execute
If Err.Number <> 0 Then
Set cmdNewTPVendor = Nothing
objConn.Close
ShowError "Error creating new third party vendor: " & Err.Description, "addmachine.asp"
Response.End
End If
' Get the newly created vendor ID
Dim rsNewTPVendor
Set rsNewTPVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
thirdpartyvendorid = CLng(rsNewTPVendor("newid"))
rsNewTPVendor.Close
Set rsNewTPVendor = Nothing
Set cmdNewTPVendor = Nothing
On Error Goto 0
End If
If thirdpartymanaged <> "" Or thirdpartyvendorid <> "" Or dodassettype <> "" Then
Dim cmdCompliance, tpmVal, tpvendorName, dodassetVal
If thirdpartymanaged <> "" Then tpmVal = thirdpartymanaged Else tpmVal = Null
If dodassettype <> "" Then dodassetVal = dodassettype Else dodassetVal = Null
' Get vendor name from ID if a vendor was selected
tpvendorName = Null
If thirdpartyvendorid <> "" And IsNumeric(thirdpartyvendorid) Then
Dim rsVendorName
Set rsVendorName = objConn.Execute("SELECT vendor FROM vendors WHERE vendorid = " & CLng(thirdpartyvendorid))
If Not rsVendorName.EOF Then
tpvendorName = rsVendorName("vendor")
End If
rsVendorName.Close
Set rsVendorName = Nothing
End If
Set cmdCompliance = Server.CreateObject("ADODB.Command")
cmdCompliance.ActiveConnection = objConn
cmdCompliance.CommandText = "INSERT INTO compliance (machineid, isthirdpartymanaged, thirdpartymanager, dodassettype) VALUES (?, ?, ?, ?)"
cmdCompliance.CommandType = 1
cmdCompliance.Parameters.Append cmdCompliance.CreateParameter("@machineid", 3, 1, , newMachineId)
cmdCompliance.Parameters.Append cmdCompliance.CreateParameter("@isthirdpartymanaged", 200, 1, 1, tpmVal)
cmdCompliance.Parameters.Append cmdCompliance.CreateParameter("@thirdpartymanager", 200, 1, 255, tpvendorName)
cmdCompliance.Parameters.Append cmdCompliance.CreateParameter("@dodassettype", 200, 1, 100, dodassetVal)
On Error Resume Next
cmdCompliance.Execute
Set cmdCompliance = Nothing
On Error Goto 0
End If
objConn.Close
If CLng(newMachineId) > 0 Then
ShowSuccess "Machine created successfully.", "displaymachine.asp?machineid=" & newMachineId, "machine details"
Else
ShowError "Machine was not added successfully.", "addmachine.asp"
End If
%>