Files
shopdb/devicecamera.asp
cproudlock a4096ace94 Fix network device description/machinenotes display and edit
- Fix ADO cursor issue where reading rs("description") twice caused
  empty values (IsNull check consumed the field value)
- Change all device pages to read description field once using
  `description = rs("description") & ""` pattern
- Add deviceDescription variable in displaydevice.asp
- Fix machinetypeid mapping: IDF=17, Camera=18 (was swapped)
- Add model dropdown fix to include currently assigned model
- Add server application tracking feature
- Various other improvements and fixes

Files affected:
- displaydevice.asp, displaylocationdevice.asp
- deviceaccesspoint.asp, deviceserver.asp, deviceswitch.asp
- devicecamera.asp, deviceidf.asp
- savenetworkdevice.asp, networkdevices.asp

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 13:47:56 -05:00

650 lines
28 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
Dim cameraid, isNewRecord
cameraid = Request.QueryString("id")
If cameraid = "" Or cameraid = "0" Then
isNewRecord = True
cameraid = 0
Else
isNewRecord = False
End If
' If editing, fetch existing data
Dim rs, cameraname, modelid, idfid, serialnumber, macaddress, ipaddress, fqdn, description, maptop, mapleft, isactive
Dim vendorname, modelnumber, idfname
If Not isNewRecord Then
Dim strSQL
strSQL = "SELECT mac.machineid, mac.alias AS cameraname, mac.modelnumberid AS modelid, " & _
"mac.serialnumber, mac.fqdn, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _
"m.modelnumber, v.vendor, c.address AS ipaddress, c.macaddress, " & _
"mr.related_machineid AS idfid, idf.alias AS idfname " & _
"FROM machines mac " & _
"LEFT JOIN models m ON mac.modelnumberid = m.modelnumberid " & _
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
"LEFT JOIN communications c ON mac.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
"LEFT JOIN machinerelationships mr ON mac.machineid = mr.machineid AND mr.relationshiptypeid = " & _
"(SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Connected To' LIMIT 1) " & _
"LEFT JOIN machines idf ON mr.related_machineid = idf.machineid AND idf.machinetypeid = 17 " & _
"WHERE mac.machineid = " & cameraid & " AND mac.machinetypeid = 18"
Set rs = objConn.Execute(strSQL)
If rs.EOF Then
Response.Write("Camera not found")
Response.End
End If
If Not IsNull(rs("cameraname")) Then cameraname = rs("cameraname") Else cameraname = ""
If Not IsNull(rs("modelid")) Then modelid = rs("modelid") Else modelid = ""
If Not IsNull(rs("idfid")) Then
idfid = rs("idfid")
Else
idfid = ""
End If
If Not IsNull(rs("serialnumber")) Then serialnumber = rs("serialnumber") Else serialnumber = ""
If Not IsNull(rs("macaddress")) Then
macaddress = rs("macaddress")
Else
macaddress = ""
End If
If Not IsNull(rs("ipaddress")) Then
ipaddress = rs("ipaddress")
Else
ipaddress = ""
End If
If Not IsNull(rs("fqdn")) Then fqdn = rs("fqdn") & "" Else fqdn = ""
description = rs("description") & ""
If Not IsNull(rs("maptop")) Then maptop = rs("maptop") Else maptop = ""
If Not IsNull(rs("mapleft")) Then mapleft = rs("mapleft") Else mapleft = ""
If Not IsNull(rs("isactive")) Then isactive = rs("isactive") Else isactive = 1
If Not IsNull(rs("vendor")) Then vendorname = rs("vendor") Else vendorname = ""
If Not IsNull(rs("modelnumber")) Then modelnumber = rs("modelnumber") Else modelnumber = ""
If Not IsNull(rs("idfname")) Then
idfname = rs("idfname")
Else
idfname = ""
End If
rs.Close
Set rs = Nothing
Else
' New record defaults
cameraname = ""
modelid = ""
idfid = ""
serialnumber = ""
macaddress = ""
ipaddress = ""
fqdn = ""
description = ""
maptop = ""
mapleft = ""
isactive = 1 ' Active by default for new records
vendorname = ""
modelnumber = ""
idfname = ""
End If
%>
<body class="bg-theme <%Response.Write(theme)%>">
<!-- start loader -->
<div id="pageloader-overlay" class="visible incoming"><div class="loader-wrapper-outer"><div class="loader-wrapper-inner" ><div class="loader"></div></div></div></div>
<!-- end loader -->
<!-- Start wrapper-->
<div id="wrapper">
<!--#include file="./includes/leftsidebar.asp"-->
<!--Start topbar header-->
<!--#include file="./includes/topbarheader.asp"-->
<!--End topbar header-->
<div class="clearfix"></div>
<div class="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumb -->
<div class="row mt-3">
<div class="col-lg-12">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="networkdevices.asp">Network Devices</a></li>
<li class="breadcrumb-item"><a href="networkdevices.asp?filter=Camera">Cameras</a></li>
<li class="breadcrumb-item active"><%If isNewRecord Then Response.Write("Add Camera") Else Response.Write("Edit Camera")%></li>
</ol>
</nav>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h5 class="card-title">
<i class="zmdi zmdi-videocam"></i>
<%If isNewRecord Then Response.Write("Add Camera") Else Response.Write("Edit Camera: " & Server.HTMLEncode(cameraname))%>
</h5>
<hr>
<form method="post" action="savenetworkdevice.asp">
<input type="hidden" name="type" value="camera">
<input type="hidden" name="id" value="<%=cameraid%>">
<div class="form-group row">
<label class="col-sm-3 col-form-label">Camera Name <span class="text-danger">*</span></label>
<div class="col-sm-9">
<input type="text" name="cameraname" class="form-control"
value="<%=Server.HTMLEncode(cameraname)%>"
required maxlength="100"
placeholder="e.g., Entrance-Camera, Loading-Dock-Cam-1">
<small class="form-text text-muted">
Short name to identify this camera
</small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">IDF Location <span class="text-danger">*</span></label>
<div class="col-sm-9">
<div class="input-group">
<select name="idfid" id="idfid_add" required class="form-control">
<option value="">-- Select IDF --</option>
<%
Dim strSQL2, rsIDFs
strSQL2 = "SELECT machineid, alias AS idfname FROM machines WHERE machinetypeid = 17 AND isactive = 1 ORDER BY alias"
Set rsIDFs = objConn.Execute(strSQL2)
If rsIDFs.EOF Then
Response.Write("<option value='' disabled>No IDFs available - add one first</option>")
Else
Do While Not rsIDFs.EOF
Dim selectedIDF
selectedIDF = ""
If Not IsNull(idfid) And idfid <> "" Then
If CStr(rsIDFs("machineid")) = CStr(idfid) Then
selectedIDF = "selected"
End If
End If
%>
<option value="<%=rsIDFs("machineid")%>" <%=selectedIDF%>>
<%=Server.HTMLEncode(rsIDFs("idfname"))%>
</option>
<%
rsIDFs.MoveNext
Loop
End If
rsIDFs.Close
Set rsIDFs = Nothing
%>
<option value="new">+ Add New IDF</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addIdfBtn_add">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
<small class="form-text text-muted">Select the IDF where this camera is located</small>
</div>
</div>
<!-- Hidden section for adding new IDF -->
<div id="newIdfSection_add" class="form-group row" style="display:none;">
<div class="col-sm-9 offset-sm-3">
<div style="padding:15px; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.1); border-radius:5px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New IDF</h6>
<div class="form-group">
<label for="newidfname_add">IDF Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newidfname_add" name="newidfname"
maxlength="50" placeholder="e.g., Main-IDF, Building A IDF">
</div>
<div class="form-group">
<label for="newidfdescription_add">Description</label>
<textarea class="form-control" id="newidfdescription_add" name="newidfdescription"
rows="2" maxlength="255"
placeholder="Additional notes about this IDF location..."></textarea>
</div>
<button type="button" class="btn btn-sm btn-secondary" id="cancelNewIdf_add">
<i class="zmdi zmdi-close"></i> Cancel
</button>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Model</label>
<div class="col-sm-9">
<div class="input-group">
<select name="modelid" id="modelid" class="form-control">
<option value="">-- Select Model --</option>
<%
Dim strSQL3, rsModels, currentModelId
' Show Camera models (machinetypeid = 18) plus currently assigned model
If IsNumeric(modelid) Then currentModelId = CLng(modelid) Else currentModelId = 0
strSQL3 = "SELECT m.modelnumberid, m.modelnumber, v.vendor " & _
"FROM models m " & _
"INNER JOIN vendors v ON m.vendorid = v.vendorid " & _
"WHERE m.isactive = 1 AND (m.machinetypeid = 18 OR m.modelnumberid = " & currentModelId & ") " & _
"ORDER BY v.vendor, m.modelnumber"
Set rsModels = objConn.Execute(strSQL3)
Do While Not rsModels.EOF
Dim selected
selected = ""
If Not IsNull(modelid) And modelid <> "" Then
If CStr(rsModels("modelnumberid")) = CStr(modelid) Then
selected = "selected"
End If
End If
%>
<option value="<%=rsModels("modelnumberid")%>" <%=selected%>>
<%=Server.HTMLEncode(rsModels("vendor") & " - " & rsModels("modelnumber"))%>
</option>
<%
rsModels.MoveNext
Loop
rsModels.Close
Set rsModels = Nothing
%>
<option value="new">+ Add New Model</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addModelBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
<small class="form-text text-muted">
Select a model or click "New" to add one
</small>
</div>
</div>
<!-- Hidden section for adding new model -->
<div id="newModelSection" class="form-group row" style="display:none;">
<div class="col-sm-9 offset-sm-3">
<div style="padding:15px; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.1); border-radius:5px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New Model</h6>
<div class="form-group">
<label for="newmodelnumber">Model Number <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newmodelnumber" name="newmodelnumber"
maxlength="255" placeholder="e.g., Axis P3245-V">
</div>
<div class="form-group">
<label for="newvendorid">Vendor <span class="text-danger">*</span></label>
<div class="input-group">
<select class="form-control" id="newvendorid" name="newvendorid">
<option value="">-- Select Vendor --</option>
<%
Dim rsVendors
strSQL3 = "SELECT vendorid, vendor FROM vendors WHERE isactive = 1 ORDER BY vendor ASC"
Set rsVendors = objConn.Execute(strSQL3)
While Not rsVendors.EOF
Response.Write("<option value='" & rsVendors("vendorid") & "'>" & Server.HTMLEncode(rsVendors("vendor")) & "</option>")
rsVendors.MoveNext
Wend
rsVendors.Close
Set rsVendors = Nothing
%>
<option value="new">+ Add New Vendor</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addVendorBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
</div>
<!-- Hidden section for adding new vendor -->
<div id="newVendorSection" style="display:none; padding:15px; background:rgba(255,255,255,0.05); border:1px solid rgba(255,255,255,0.15); border-radius:5px; margin-bottom:15px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New Vendor</h6>
<div class="form-group">
<label for="newvendorname">Vendor Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newvendorname" name="newvendorname"
maxlength="50" placeholder="e.g., Axis, Hikvision, Dahua">
</div>
<button type="button" class="btn btn-sm btn-secondary" id="cancelNewVendor">
<i class="zmdi zmdi-close"></i> Cancel
</button>
</div>
<div class="form-group">
<label for="newmodelmachinetypeid">Machine Type <span class="text-danger">*</span></label>
<select class="form-control" id="newmodelmachinetypeid" name="newmodelmachinetypeid">
<option value="">-- Select Machine Type --</option>
<%
Dim rsMachineTypes
strSQL2 = "SELECT machinetypeid, machinetype FROM machinetypes WHERE isactive = 1 ORDER BY machinetype ASC"
Set rsMachineTypes = objConn.Execute(strSQL2)
While Not rsMachineTypes.EOF
Response.Write("<option value='" & rsMachineTypes("machinetypeid") & "'>" & Server.HTMLEncode(rsMachineTypes("machinetype")) & "</option>")
rsMachineTypes.MoveNext
Wend
rsMachineTypes.Close
Set rsMachineTypes = Nothing
%>
</select>
</div>
<div class="form-group">
<label for="newmodelnotes">Model Notes</label>
<textarea class="form-control" id="newmodelnotes" name="newmodelnotes"
rows="2" maxlength="255"
placeholder="Additional notes about this model..."></textarea>
</div>
<div class="form-group">
<label for="newmodeldocpath">Documentation Path</label>
<input type="text" class="form-control" id="newmodeldocpath" name="newmodeldocpath"
maxlength="255" placeholder="\\server\docs\model.pdf or http://...">
</div>
<button type="button" class="btn btn-sm btn-secondary" id="cancelNewModel">
<i class="zmdi zmdi-close"></i> Cancel
</button>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">MAC Address</label>
<div class="col-sm-9">
<input type="text" name="macaddress" class="form-control"
value="<%=Server.HTMLEncode(macaddress)%>"
maxlength="17" pattern="^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"
placeholder="e.g., 00:11:22:33:44:55 or 00-11-22-33-44-55">
<small class="form-text text-muted">
Hardware MAC address (format: XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX)
</small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Serial Number</label>
<div class="col-sm-9">
<input type="text" name="serialnumber" class="form-control"
value="<%=Server.HTMLEncode(serialnumber)%>"
maxlength="100" placeholder="e.g., CAM123456789">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">IP Address</label>
<div class="col-sm-9">
<input type="text" name="ipaddress" class="form-control"
value="<%=Server.HTMLEncode(ipaddress)%>"
maxlength="45" pattern="^[0-9\.:]*$"
placeholder="e.g., 192.168.1.100">
<small class="form-text text-muted">
IPv4 or IPv6 address
</small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">FQDN</label>
<div class="col-sm-9">
<input type="text" name="fqdn" class="form-control"
value="<%=Server.HTMLEncode(fqdn)%>"
maxlength="255"
placeholder="e.g., cam01.security.company.com">
<small class="form-text text-muted">
Fully Qualified Domain Name (optional)
</small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Description</label>
<div class="col-sm-9">
<textarea name="description" class="form-control" rows="3"
maxlength="255" placeholder="Detailed notes about this camera..."><%=Server.HTMLEncode(description)%></textarea>
<small class="form-text text-muted">
Optional: Location, viewing angle, or other notes
</small>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label"></label>
<div class="col-sm-9">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="isactive" name="isactive" value="1"
<%If isactive = True Or isactive = 1 Then Response.Write("checked")%>>
<label class="custom-control-label" for="isactive">Active</label>
</div>
<small class="form-text text-muted">
Inactive devices are hidden from most lists and the network map
</small>
</div>
</div>
<!-- Hidden coordinate fields - populated by map selector -->
<input type="hidden" id="maptop" name="maptop" value="<%=maptop%>">
<input type="hidden" id="mapleft" name="mapleft" value="<%=mapleft%>">
<div class="form-group row">
<label class="col-sm-3 col-form-label">Map Position (Optional)</label>
<div class="col-sm-9">
<button type="button" class="btn btn-secondary" id="selectLocationBtn">
<i class="zmdi zmdi-pin"></i> Select Location on Map
</button>
<div id="coordinateDisplay" style="margin-top:10px; color:#aaa; font-size:13px;">
<%If maptop <> "" And mapleft <> "" Then
Response.Write("Current position: X=" & mapleft & ", Y=" & maptop)
Else
Response.Write("No position set - click button to select")
End If%>
</div>
<small class="form-text text-muted">
Click to select this camera's position on the network map
</small>
</div>
</div>
<hr>
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<button type="submit" class="btn btn-success">
<i class="zmdi zmdi-save"></i>
<%If isNewRecord Then Response.Write("Add Camera") Else Response.Write("Save Changes")%>
</button>
<a href="networkdevices.asp?filter=Camera" class="btn btn-secondary">
<i class="zmdi zmdi-close"></i> Cancel
</a>
<%If Not isNewRecord Then%>
<button type="button" class="btn btn-danger float-right" onclick="confirmDelete()">
<i class="zmdi zmdi-delete"></i> Delete
</button>
<%End If%>
</div>
</div>
</form>
</div>
</div>
</div>
</div><!--End Row-->
</div><!-- End container-fluid-->
</div><!--End content-wrapper-->
<!--Start Back To Top Button-->
<a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
<!--End Back To Top Button-->
<!--Start footer-->
<footer class="footer">
</footer>
<!--End footer-->
</div><!--End wrapper-->
<!-- Bootstrap core JavaScript-->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<script>
function confirmDelete() {
if (confirm('Are you sure you want to delete this camera? This action cannot be undone.')) {
var form = document.createElement('form');
form.method = 'POST';
form.action = 'savenetworkdevice.asp';
var typeInput = document.createElement('input');
typeInput.type = 'hidden';
typeInput.name = 'type';
typeInput.value = 'camera';
form.appendChild(typeInput);
var idInput = document.createElement('input');
idInput.type = 'hidden';
idInput.name = 'id';
idInput.value = '<%=cameraid%>';
form.appendChild(idInput);
var deleteInput = document.createElement('input');
deleteInput.type = 'hidden';
deleteInput.name = 'delete';
deleteInput.value = '1';
form.appendChild(deleteInput);
document.body.appendChild(form);
form.submit();
}
}
// Model/Vendor nested add functionality
$(document).ready(function() {
// IDF nested add functionality
$('#addIdfBtn_add, #idfid_add').on('change click', function() {
if ($('#idfid_add').val() === 'new' || $(this).attr('id') === 'addIdfBtn_add') {
$('#idfid_add').val('new');
$('#newIdfSection_add').slideDown();
$('#newidfname_add').prop('required', true);
}
});
$('#cancelNewIdf_add').on('click', function() {
$('#newIdfSection_add').slideUp();
$('#idfid_add').val('');
$('#newidfname_add').val('').prop('required', false);
$('#newidfdescription_add').val('');
});
// Show/hide new model section
$('#addModelBtn, #modelid').on('change click', function() {
if ($('#modelid').val() === 'new' || $(this).attr('id') === 'addModelBtn') {
$('#modelid').val('new');
$('#newModelSection').slideDown();
$('#newmodelnumber').prop('required', true);
$('#newvendorid').prop('required', true);
}
});
$('#cancelNewModel').on('click', function() {
$('#newModelSection').slideUp();
$('#newVendorSection').slideUp();
$('#modelid').val('');
$('#newmodelnumber').val('').prop('required', false);
$('#newvendorid').val('').prop('required', false);
$('#newmodelnotes').val('');
$('#newmodeldocpath').val('');
$('#newvendorname').val('').prop('required', false);
});
// Show/hide new vendor section
$('#addVendorBtn, #newvendorid').on('change click', function() {
if ($('#newvendorid').val() === 'new' || $(this).attr('id') === 'addVendorBtn') {
$('#newvendorid').val('new');
$('#newVendorSection').slideDown();
$('#newvendorname').prop('required', true);
}
});
$('#cancelNewVendor').on('click', function() {
$('#newVendorSection').slideUp();
$('#newvendorid').val('');
$('#newvendorname').val('').prop('required', false);
});
// Form validation
$('form').on('submit', function(e) {
// Validate IDF
if ($('#idfid_add').val() === 'new') {
if ($('#newidfname_add').val().trim() === '') {
e.preventDefault();
alert('Please enter an IDF name or select an existing IDF');
$('#newidfname_add').focus();
return false;
}
} else if ($('#idfid_add').val() === '' || !$('#idfid_add').val()) {
e.preventDefault();
alert('Please select an IDF location for this camera');
$('#idfid_add').focus();
return false;
}
// If adding new model, make sure fields are filled
if ($('#modelid').val() === 'new') {
if ($('#newmodelnumber').val().trim() === '') {
e.preventDefault();
alert('Please enter a model number or select an existing model');
$('#newmodelnumber').focus();
return false;
}
if ($('#newvendorid').val() === '' || $('#newvendorid').val() === 'new') {
// If vendor is 'new', check vendor name
if ($('#newvendorid').val() === 'new') {
if ($('#newvendorname').val().trim() === '') {
e.preventDefault();
alert('Please enter a vendor name or select an existing vendor');
$('#newvendorname').focus();
return false;
}
} else {
e.preventDefault();
alert('Please select a vendor or add a new one');
$('#newvendorid').focus();
return false;
}
}
}
});
});
</script>
<!--#include file="./includes/map_picker.asp"-->
</body>
</html>
<%
objConn.Close
%>