```
---
## File 3: addinfrastructure.asp (Add Form)
### Logic Flow
```vbscript
<%
' Get device type
Dim deviceType
deviceType = Request.QueryString("type")
' Validate
If deviceType <> "server" AND deviceType <> "switch" AND deviceType <> "camera" Then
deviceType = "server"
End If
' Set variables
Dim pageTitle, listUrl
Select Case deviceType
Case "server"
pageTitle = "Server"
listUrl = "displayinfrastructure.asp?type=server"
Case "switch"
pageTitle = "Switch"
listUrl = "displayinfrastructure.asp?type=switch"
Case "camera"
pageTitle = "Camera"
listUrl = "displayinfrastructure.asp?type=camera"
End Select
%>
Add <%=pageTitle%>
```
---
## File 4: saveinfrastructure_direct.asp (Universal Save)
### Logic Flow
```vbscript
<%
' Get device type
Dim deviceType
deviceType = Request.Form("type")
' Validate type
If deviceType <> "server" AND deviceType <> "switch" AND deviceType <> "camera" Then
Response.Write("Error: Invalid device type")
Response.End
End If
' Set table name and ID field based on type
Dim tableName, idField, listUrl
Select Case deviceType
Case "server"
tableName = "servers"
idField = "serverid"
listUrl = "displayinfrastructure.asp?type=server"
Case "switch"
tableName = "switches"
idField = "switchid"
listUrl = "displayinfrastructure.asp?type=switch"
Case "camera"
tableName = "cameras"
idField = "cameraid"
listUrl = "displayinfrastructure.asp?type=camera"
End Select
' Get form data
Dim deviceId, modelid, serialnumber, ipaddress, description
deviceId = GetSafeInteger("FORM", "id", 0, 0, 999999)
modelid = GetSafeInteger("FORM", "modelid", 0, 0, 999999)
serialnumber = GetSafeString("FORM", "serialnumber", "", 0, 100, "^[A-Za-z0-9\-]+$")
ipaddress = GetSafeString("FORM", "ipaddress", "", 0, 15, "^[0-9\.]+$")
description = GetSafeString("FORM", "description", "", 0, 255, "")
' Determine INSERT or UPDATE
Dim strSQL
If deviceId = 0 Then
' INSERT - New device
strSQL = "INSERT INTO " & tableName & " (modelid, serialnumber, ipaddress, description, isactive) " & _
"VALUES (?, ?, ?, ?, 1)"
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(modelid, serialnumber, ipaddress, description))
Else
' UPDATE - Existing device
strSQL = "UPDATE " & tableName & " " & _
"SET modelid = ?, serialnumber = ?, ipaddress = ?, description = ? " & _
"WHERE " & idField & " = ?"
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(modelid, serialnumber, ipaddress, description, deviceId))
End If
Call CleanupResources()
' Redirect back to list
Response.Redirect(listUrl)
%>
```
---
## Navigation Menu
### leftsidebar.asp Update
```html
```
---
## Pros vs Cons
### Unified Approach (Option 2) - RECOMMENDED
**Pros:**
- ✅ Only 4 files to create (vs 12)
- ✅ DRY - no code duplication
- ✅ Easy to maintain - fix once, works for all
- ✅ Easy to extend - add "UPS" or "Firewall" by just adding cases
- ✅ Consistent UI across all infrastructure
- ✅ Matches database design (vw_network_devices already unifies them)
**Cons:**
- ⚠️ Slightly more complex logic (Select Case statements)
- ⚠️ URLs less intuitive (type parameter required)
- ⚠️ Harder to customize one type differently later
### Separate Pages Approach (Option 1)
**Pros:**
- ✅ URLs cleaner (displayservers.asp vs displayinfrastructure.asp?type=server)
- ✅ Simpler per-file logic (no branching)
- ✅ Easy to customize one type differently
- ✅ More explicit/clear what page does
**Cons:**
- ❌ 12 files instead of 4 (3x code duplication)
- ❌ Bug fixes need to be applied 3 times
- ❌ UI inconsistencies more likely
- ❌ Adding new type = 4 more files
---
## Hybrid Approach (Best of Both?)
**Could also do:**
- Use unified pages for LIST/ADD/SAVE (shared logic)
- Use separate pages for DETAIL if they differ significantly
Example:
```
displayinfrastructure.asp?type=server (unified list)
addinfrastructure.asp?type=server (unified add form)
saveinfrastructure_direct.asp (unified save)
displayserver.asp?id=5 (separate detail - if servers need special fields)
displayswitch.asp?id=12 (separate detail - if switches different)
displaycamera.asp?id=3 (separate detail - if cameras different)
```
But for infrastructure devices with identical schemas, I'd stick with **fully unified**.
---
## My Recommendation
**Go with Option 2 (Unified Pages) because:**
1. Servers, switches, and cameras have **identical schemas** (modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive)
2. They have **identical CRUD operations** (add, edit, view, delete)
3. The database already unifies them (`vw_network_devices`)
4. Much faster to implement (4 files vs 12)
5. Easier to maintain long-term
---
**Ready to implement?** I can create the 4 unified infrastructure files now.