Remove unused and backup ASP files

Cleanup:
- 41 backup/broken files (.backup*, .broken, .bak)
- 3 duplicate PC listing files (listpcs.asp, pclist.asp, pcs.asp)
- 6 unused utility files:
  - aspJSON.asp (test stub)
  - printerlookup.asp (unused, had SQL injection)
  - bulkupdatenotificationtypes.asp
  - cleanupduplicateprintersexecute.asp
  - checkprintermachinescount.asp
  - checkduplicateprinters.asp
- backup/ directory with old v2 design assets
- Include backup files (.production, .produciton typo)

Total: 69 files removed
This commit is contained in:
cproudlock
2025-12-10 20:45:23 -05:00
parent 249bfbba8c
commit 9fc3420716
69 changed files with 0 additions and 22235 deletions

View File

@@ -1,215 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form inputs for KB article
Dim linkurl, shortdescription, keywords, appid
linkurl = Trim(Request.Form("linkurl"))
shortdescription = Trim(Request.Form("shortdescription"))
keywords = Trim(Request.Form("keywords"))
appid = Trim(Request.Form("appid"))
' Get form inputs for new topic
Dim newappname, newappdescription, newsupportteamid
Dim newapplicationnotes, newinstallpath, newdocumentationpath, newisactive
newappname = Trim(Request.Form("newappname"))
newappdescription = Trim(Request.Form("newappdescription"))
newsupportteamid = Trim(Request.Form("newsupportteamid"))
newapplicationnotes = Trim(Request.Form("newapplicationnotes"))
newinstallpath = Trim(Request.Form("newinstallpath"))
newdocumentationpath = Trim(Request.Form("newdocumentationpath"))
newisactive = Request.Form("newisactive")
' Get form inputs for new support team
Dim newsupportteamname, newsupportteamurl, newappownerid
newsupportteamname = Trim(Request.Form("newsupportteamname"))
newsupportteamurl = Trim(Request.Form("newsupportteamurl"))
newappownerid = Trim(Request.Form("newappownerid"))
' Get form inputs for new app owner
Dim newappownername, newappownersso
newappownername = Trim(Request.Form("newappownername"))
newappownersso = Trim(Request.Form("newappownersso"))
' Basic validation for KB article
If Len(linkurl) = 0 Or Len(shortdescription) = 0 Or Len(appid) = 0 Then
Response.Write("Required fields missing")
objConn.Close
Response.End
End If
If Len(linkurl) > 2000 Or Len(shortdescription) > 500 Or Len(keywords) > 500 Then
Response.Write("Field length exceeded")
objConn.Close
Response.End
End If
' Handle new topic creation
If appid = "new" Then
If Len(newappname) = 0 Then
Response.Write("New topic name is required")
objConn.Close
Response.End
End If
If Len(newsupportteamid) = 0 Then
Response.Write("Support team is required for new topic")
objConn.Close
Response.End
End If
' Validate field lengths for new topic
If Len(newappname) > 50 Or Len(newappdescription) > 255 Or Len(newapplicationnotes) > 512 Or Len(newinstallpath) > 255 Or Len(newdocumentationpath) > 512 Then
Response.Write("New topic field length exceeded")
objConn.Close
Response.End
End If
' Handle new support team creation (nested)
If newsupportteamid = "new" Then
If Len(newsupportteamname) = 0 Then
Response.Write("New support team name is required")
objConn.Close
Response.End
End If
If Len(newappownerid) = 0 Then
Response.Write("App owner is required for new support team")
objConn.Close
Response.End
End If
If Len(newsupportteamname) > 50 Or Len(newsupportteamurl) > 512 Then
Response.Write("New support team field length exceeded")
objConn.Close
Response.End
End If
' Handle new app owner creation (doubly nested)
If newappownerid = "new" Then
If Len(newappownername) = 0 Or Len(newappownersso) = 0 Then
Response.Write("App owner name and SSO are required")
objConn.Close
Response.End
End If
If Len(newappownername) > 50 Or Len(newappownersso) > 255 Then
Response.Write("App owner field length exceeded")
objConn.Close
Response.End
End If
' Escape single quotes for new app owner
Dim escapedOwnerName, escapedOwnerSSO
escapedOwnerName = Replace(newappownername, "'", "''")
escapedOwnerSSO = Replace(newappownersso, "'", "''")
' Insert new app owner
Dim sqlNewOwner
sqlNewOwner = "INSERT INTO appowners (appowner, sso, isactive) " & _
"VALUES ('" & escapedOwnerName & "', '" & escapedOwnerSSO & "', 1)"
On Error Resume Next
objConn.Execute sqlNewOwner
If Err.Number <> 0 Then
Response.Write("Error creating new app owner: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created app owner ID
Dim rsNewOwner
Set rsNewOwner = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newappownerid = rsNewOwner("newid")
rsNewOwner.Close
Set rsNewOwner = Nothing
On Error Goto 0
End If
' Escape single quotes for new support team
Dim escapedTeamName, escapedTeamURL
escapedTeamName = Replace(newsupportteamname, "'", "''")
escapedTeamURL = Replace(newsupportteamurl, "'", "''")
' Insert new support team with selected or newly created app owner
Dim sqlNewTeam
sqlNewTeam = "INSERT INTO supportteams (teamname, teamurl, appownerid, isactive) " & _
"VALUES ('" & escapedTeamName & "', '" & escapedTeamURL & "', " & newappownerid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewTeam
If Err.Number <> 0 Then
Response.Write("Error creating new support team: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created support team ID
Dim rsNewTeam
Set rsNewTeam = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newsupportteamid = rsNewTeam("newid")
rsNewTeam.Close
Set rsNewTeam = Nothing
On Error Goto 0
End If
' Escape single quotes for new topic
Dim escapedAppName, escapedAppDesc, escapedAppNotes, escapedInstallPath, escapedDocPath
escapedAppName = Replace(newappname, "'", "''")
escapedAppDesc = Replace(newappdescription, "'", "''")
escapedAppNotes = Replace(newapplicationnotes, "'", "''")
escapedInstallPath = Replace(newinstallpath, "'", "''")
escapedDocPath = Replace(newdocumentationpath, "'", "''")
' Convert isactive checkbox
Dim isActiveValue
If newisactive = "1" Then
isActiveValue = 1
Else
isActiveValue = 0
End If
' Insert new application/topic
Dim sqlNewApp
sqlNewApp = "INSERT INTO applications (appname, appdescription, supportteamid, applicationnotes, installpath, documentationpath, isactive, isinstallable, ishidden, isprinter, islicenced) " & _
"VALUES ('" & escapedAppName & "', '" & escapedAppDesc & "', " & newsupportteamid & ", '" & escapedAppNotes & "', '" & escapedInstallPath & "', '" & escapedDocPath & "', " & isActiveValue & ", 0, 0, 0, 0)"
On Error Resume Next
objConn.Execute sqlNewApp
If Err.Number <> 0 Then
Response.Write("Error creating new topic: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created topic ID
Dim rsNewApp
Set rsNewApp = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
appid = rsNewApp("newid")
rsNewApp.Close
Set rsNewApp = Nothing
On Error Goto 0
End If
' Escape single quotes for KB article
linkurl = Replace(linkurl, "'", "''")
shortdescription = Replace(shortdescription, "'", "''")
keywords = Replace(keywords, "'", "''")
' Build INSERT statement for KB article
Dim strSQL
strSQL = "INSERT INTO knowledgebase (linkurl, shortdescription, keywords, appid, isactive, clicks) " & _
"VALUES ('" & linkurl & "', '" & shortdescription & "', '" & keywords & "', " & appid & ", 1, 0)"
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("displayknowledgebase.asp?status=added")
Else
objConn.Close
Response.Redirect("displayknowledgebase.asp?status=error&msg=" & Server.URLEncode("Error: " & Err.Description))
End If
%>

File diff suppressed because it is too large Load Diff

View File

@@ -1,815 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<link rel="stylesheet" href="./leaflet/leaflet.css">
<script src="./leaflet/leaflet.js"></script>
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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">
<div class="row mt-3">
<div class="col-lg-8 offset-lg-2">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h5 class="card-title" style="margin:0;">
<i class="zmdi zmdi-memory"></i> Add Machine
</h5>
<a href="./displaymachines.asp" class="btn btn-sm btn-secondary">
<i class="zmdi zmdi-arrow-left"></i> Back
</a>
</div>
<form method="post" action="./savemachine_direct.asp">
<div class="form-group">
<label for="machinenumber">Machine Number <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="machinenumber" name="machinenumber"
required maxlength="50" placeholder="e.g., M-1001">
<small class="form-text text-muted">Unique identifier for this machine</small>
</div>
<div class="form-group">
<label for="modelid">Model <span class="text-danger">*</span></label>
<div class="input-group">
<select class="form-control" id="modelid" name="modelid" required>
<option value="">-- Select Model --</option>
<%
Dim strSQL, rsModels
strSQL = "SELECT models.*, vendors.vendor FROM models " &_
"INNER JOIN vendors ON models.vendorid = vendors.vendorid " &_
"WHERE vendors.ismachine = 1 AND models.isactive = 1 " &_
"ORDER BY vendors.vendor ASC, models.modelnumber ASC"
Set rsModels = objconn.Execute(strSQL)
While Not rsModels.EOF
Response.Write("<option value='" & rsModels("modelnumberid") & "'>" & Server.HTMLEncode(rsModels("vendor") & " - " & rsModels("modelnumber")) & "</option>")
rsModels.MoveNext
Wend
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>
</div>
<!-- New Model Section -->
<div id="newModelSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #667eea; background-color:rgba(102,126,234,0.05); margin-bottom:15px;">
<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="50">
</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
strSQL = "SELECT * FROM vendors WHERE ismachine = 1 AND isactive = 1 ORDER BY vendor ASC"
Set rsVendors = objconn.Execute(strSQL)
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>
<!-- New Vendor Section -->
<div id="newVendorSectionMachine" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #764ba2; background-color:rgba(118,75,162,0.05); 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">
</div>
</div>
<div class="form-group">
<label for="newmodelimage">Image Filename (Optional)</label>
<input type="text" class="form-control" id="newmodelimage" name="newmodelimage" maxlength="100" placeholder="e.g., haas-vf2.jpg">
<small class="form-text text-muted">Filename of image in images/machines/</small>
</div>
</div>
<div class="form-group">
<label for="machinetypeid">Function/Type <span class="text-danger">*</span></label>
<div class="input-group">
<select class="form-control" id="machinetypeid" name="machinetypeid" required>
<option value="">-- Select Function --</option>
<%
Dim rsTypes
strSQL = "SELECT * FROM machinetypes WHERE isactive = 1 ORDER BY machinetype ASC"
Set rsTypes = objconn.Execute(strSQL)
While Not rsTypes.EOF
Response.Write("<option value='" & rsTypes("machinetypeid") & "'>" & Server.HTMLEncode(rsTypes("machinetype")) & "</option>")
rsTypes.MoveNext
Wend
rsTypes.Close
Set rsTypes = Nothing
%>
<option value="new">+ Add New Machine Type</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addMachineTypeBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
<small class="form-text text-muted">What this machine does (e.g., CNC, Mill, Lathe)</small>
</div>
<!-- New Machine Type Section -->
<div id="newMachineTypeSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #667eea; background-color:rgba(102,126,234,0.05); margin-bottom:15px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New Machine Type</h6>
<div class="form-group">
<label for="newmachinetype">Machine Type Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newmachinetype" name="newmachinetype" maxlength="50">
</div>
<div class="form-group">
<label for="newmachinedescription">Description (Optional)</label>
<textarea class="form-control" id="newmachinedescription" name="newmachinedescription" rows="2" maxlength="255"></textarea>
</div>
<div class="form-group">
<label for="newfunctionalaccountid">Functional Account <span class="text-danger">*</span></label>
<div class="input-group">
<select class="form-control" id="newfunctionalaccountid" name="newfunctionalaccountid">
<option value="">-- Select Functional Account --</option>
<%
Dim rsFuncAccts
strSQL = "SELECT * FROM functionalaccounts WHERE isactive = 1 ORDER BY functionalaccount ASC"
Set rsFuncAccts = objconn.Execute(strSQL)
While Not rsFuncAccts.EOF
Response.Write("<option value='" & rsFuncAccts("functionalaccountid") & "'>" & Server.HTMLEncode(rsFuncAccts("functionalaccount")) & "</option>")
rsFuncAccts.MoveNext
Wend
rsFuncAccts.Close
Set rsFuncAccts = Nothing
%>
<option value="new">+ Add New Functional Account</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addFunctionalAccountBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
<small class="form-text text-muted">For billing purposes</small>
</div>
<!-- New Functional Account Section -->
<div id="newFunctionalAccountSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #764ba2; background-color:rgba(118,75,162,0.05); margin-bottom:15px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New Functional Account</h6>
<div class="form-group">
<label for="newfunctionalaccount">Functional Account Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newfunctionalaccount" name="newfunctionalaccount" maxlength="50">
</div>
</div>
</div>
<div class="form-group">
<label for="businessunitid">Business Unit <span class="text-danger">*</span></label>
<div class="input-group">
<select class="form-control" id="businessunitid" name="businessunitid" required>
<option value="">-- Select BU --</option>
<%
Dim rsBU
strSQL = "SELECT * FROM businessunits WHERE isactive = 1 ORDER BY businessunit ASC"
Set rsBU = objconn.Execute(strSQL)
While Not rsBU.EOF
Response.Write("<option value='" & rsBU("businessunitid") & "'>" & Server.HTMLEncode(rsBU("businessunit")) & "</option>")
rsBU.MoveNext
Wend
rsBU.Close
Set rsBU = Nothing
%>
<option value="new">+ Add New Business Unit</option>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addBusinessUnitBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
</div>
<!-- New Business Unit Section -->
<div id="newBusinessUnitSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #667eea; background-color:rgba(102,126,234,0.05); margin-bottom:15px;">
<h6 class="mb-3"><i class="zmdi zmdi-plus-circle"></i> New Business Unit</h6>
<div class="form-group">
<label for="newbusinessunit">Business Unit Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="newbusinessunit" name="newbusinessunit" maxlength="50">
</div>
</div>
<div class="form-group">
<label for="alias">Alias (Optional)</label>
<input type="text" class="form-control" id="alias" name="alias"
maxlength="50" placeholder="Friendly name or nickname">
</div>
<div class="form-group">
<label for="machinenotes">Notes (Optional)</label>
<textarea class="form-control" id="machinenotes" name="machinenotes"
rows="3" placeholder="Additional notes about this machine"></textarea>
</div>
<div class="form-group">
<label for="pcserialnumber">Scan PC Serial Number (Optional)</label>
<input type="text" class="form-control" id="pcserialnumber" placeholder="Scan or type PC serial number...">
<small class="form-text text-muted">Scan the PC serial number to auto-select from dropdown below</small>
</div>
<div class="form-group">
<label for="pcid">Associated PC (Optional)</label>
<select class="form-control" id="pcid" name="pcid">
<option value="">-- Select PC --</option>
<%
Dim rsPCs
strSQL = "SELECT pcid, hostname, serialnumber FROM pc WHERE isactive = 1 AND (machinenumber IS NULL OR machinenumber = '') ORDER BY hostname ASC"
Set rsPCs = objconn.Execute(strSQL)
While Not rsPCs.EOF
Dim pcDisplay
pcDisplay = ""
If NOT IsNull(rsPCs("hostname")) AND rsPCs("hostname") <> "" Then
pcDisplay = rsPCs("hostname")
If NOT IsNull(rsPCs("serialnumber")) AND rsPCs("serialnumber") <> "" Then
pcDisplay = pcDisplay & " (" & rsPCs("serialnumber") & ")"
End If
ElseIf NOT IsNull(rsPCs("serialnumber")) AND rsPCs("serialnumber") <> "" Then
pcDisplay = rsPCs("serialnumber")
Else
pcDisplay = "PC ID: " & rsPCs("pcid")
End If
Response.Write("<option value='" & rsPCs("pcid") & "' data-serialnumber='" & Server.HTMLEncode(rsPCs("serialnumber")) & "'>" & Server.HTMLEncode(pcDisplay) & "</option>")
rsPCs.MoveNext
Wend
rsPCs.Close
Set rsPCs = Nothing
%>
</select>
<small class="form-text text-muted">Or manually select a PC to link to this machine</small>
</div>
<hr>
<h6 class="mb-3">Location (Optional)</h6>
<div class="form-group row">
<label class="col-lg-3 col-form-label">Map X:</label>
<div class="col-lg-9">
<input type="text" id="mapleft" name="mapleft" class="form-control" placeholder="Leave blank if unknown">
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label">Map Y:</label>
<div class="col-lg-9">
<input type="text" id="maptop" name="maptop" class="form-control" placeholder="Leave blank if unknown">
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label"></label>
<div class="col-lg-9">
<button type="button" class="btn btn-secondary" id="selectLocationBtn">
<i class="zmdi zmdi-pin"></i> Select Location on Map
</button>
</div>
</div>
<hr>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary btn-lg">
<i class="zmdi zmdi-check"></i> Add Machine
</button>
<a href="./displaymachines.asp" class="btn btn-secondary btn-lg">
<i class="zmdi zmdi-close"></i> Cancel
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- End Row -->
<!-- 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">
<div class="container">
<div class="text-center">
</div>
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Map Location Picker Modal -->
<style>
#mapPickerModal {
display: none;
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.7);
}
#mapPickerContent {
background-color: #1f1f1f;
margin: 2% auto;
padding: 0;
border: 2px solid #667eea;
border-radius: 8px;
width: 70%;
max-width: 900px;
box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}
#mapPickerHeader {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 20px;
border-radius: 6px 6px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
}
#mapPickerClose {
background: none;
border: none;
color: white;
font-size: 28px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
}
#mapPickerClose:hover {
background: rgba(255, 255, 255, 0.2);
}
#mapPickerBody {
padding: 15px;
background: #2a2a2a;
}
#locationPickerMap {
width: 100%;
height: 500px;
background: #1a1a1a;
border-radius: 4px;
}
#mapPickerFooter {
padding: 12px 20px;
background: #1f1f1f;
border-top: 1px solid #444;
border-radius: 0 0 6px 6px;
display: flex;
justify-content: space-between;
align-items: center;
}
#selectedCoords {
color: #aaa;
font-size: 14px;
}
.map-picker-btn {
padding: 10px 24px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-left: 10px;
}
#confirmLocationBtn {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
}
#confirmLocationBtn:hover {
opacity: 0.9;
}
#cancelLocationBtn {
background: #555;
color: white;
}
#cancelLocationBtn:hover {
background: #666;
}
</style>
<div id="mapPickerModal">
<div id="mapPickerContent">
<div id="mapPickerHeader">
<span style="font-size:16px; font-weight:600;"><i class="zmdi zmdi-pin"></i> Select Machine Location</span>
<button id="mapPickerClose">&times;</button>
</div>
<div id="mapPickerBody">
<div id="locationPickerMap"></div>
</div>
<div id="mapPickerFooter">
<span id="selectedCoords">Click on the map to select a location</span>
<div>
<button id="cancelLocationBtn" class="map-picker-btn">Cancel</button>
<button id="confirmLocationBtn" class="map-picker-btn">Confirm Location</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
// Button click handlers to trigger dropdown selection
$('#addModelBtn').on('click', function() {
$('#modelid').val('new').trigger('change');
});
$('#addVendorBtn').on('click', function() {
$('#newvendorid').val('new').trigger('change');
});
$('#addMachineTypeBtn').on('click', function() {
$('#machinetypeid').val('new').trigger('change');
});
$('#addFunctionalAccountBtn').on('click', function() {
$('#newfunctionalaccountid').val('new').trigger('change');
});
$('#addBusinessUnitBtn').on('click', function() {
$('#businessunitid').val('new').trigger('change');
});
// Nested creation handlers for machines
$('#modelid').change(function() {
if ($(this).val() === 'new') {
$('#newModelSection').slideDown();
$('#newmodelnumber').prop('required', true);
$('#newvendorid').prop('required', true);
} else {
$('#newModelSection').slideUp();
$('#newmodelnumber').prop('required', false);
$('#newvendorid').prop('required', false);
$('#newvendorid').val('');
$('#newVendorSectionMachine').slideUp();
$('#newvendorname').prop('required', false);
}
});
$('#newvendorid').change(function() {
if ($(this).val() === 'new') {
$('#newVendorSectionMachine').slideDown();
$('#newvendorname').prop('required', true);
} else {
$('#newVendorSectionMachine').slideUp();
$('#newvendorname').prop('required', false);
}
});
$('#machinetypeid').change(function() {
if ($(this).val() === 'new') {
$('#newMachineTypeSection').slideDown();
$('#newmachinetype').prop('required', true);
$('#newfunctionalaccountid').prop('required', true);
} else {
$('#newMachineTypeSection').slideUp();
$('#newmachinetype').prop('required', false);
$('#newfunctionalaccountid').prop('required', false);
$('#newfunctionalaccountid').val('');
$('#newFunctionalAccountSection').slideUp();
$('#newfunctionalaccount').prop('required', false);
}
});
$('#newfunctionalaccountid').change(function() {
if ($(this).val() === 'new') {
$('#newFunctionalAccountSection').slideDown();
$('#newfunctionalaccount').prop('required', true);
} else {
$('#newFunctionalAccountSection').slideUp();
$('#newfunctionalaccount').prop('required', false);
}
});
$('#businessunitid').change(function() {
if ($(this).val() === 'new') {
$('#newBusinessUnitSection').slideDown();
$('#newbusinessunit').prop('required', true);
} else {
$('#newBusinessUnitSection').slideUp();
$('#newbusinessunit').prop('required', false);
}
});
// PC Serial Number Scanner Handler
$('#pcserialnumber').on('input', function() {
var scannedSerial = $(this).val().trim().toUpperCase();
if (scannedSerial.length > 0) {
// Search through PC dropdown options for matching serial number
var found = false;
$('#pcid option').each(function() {
var optionSerial = $(this).data('serialnumber');
if (optionSerial && optionSerial.toString().toUpperCase() === scannedSerial) {
$('#pcid').val($(this).val());
$('#pcid').css('border', '2px solid #28a745'); // Green border to indicate match
found = true;
return false; // Break the loop
}
});
if (!found) {
$('#pcid').val('');
$('#pcid').css('border', '1px solid #ced4da'); // Reset border
}
} else {
$('#pcid').val('');
$('#pcid').css('border', '1px solid #ced4da'); // Reset border
}
});
// Reset border when manually selecting from dropdown
$('#pcid').on('change', function() {
if ($(this).val() === '') {
$(this).css('border', '1px solid #ced4da');
}
});
// Form validation
$('form').on('submit', function(e) {
// Validate new model if selected
if ($('#modelid').val() === 'new') {
if ($('#newmodelnumber').val().trim() === '') {
alert('Please enter a model number for the new model.');
$('#newmodelnumber').focus();
e.preventDefault();
return false;
}
if ($('#newvendorid').val() === '') {
alert('Please select a vendor for the new model.');
$('#newvendorid').focus();
e.preventDefault();
return false;
}
// Validate new vendor if selected
if ($('#newvendorid').val() === 'new') {
if ($('#newvendorname').val().trim() === '') {
alert('Please enter a vendor name for the new vendor.');
$('#newvendorname').focus();
e.preventDefault();
return false;
}
}
}
// Validate new machine type if selected
if ($('#machinetypeid').val() === 'new') {
if ($('#newmachinetype').val().trim() === '') {
alert('Please enter a name for the new machine type.');
$('#newmachinetype').focus();
e.preventDefault();
return false;
}
if ($('#newfunctionalaccountid').val() === '') {
alert('Please select a functional account for the new machine type.');
$('#newfunctionalaccountid').focus();
e.preventDefault();
return false;
}
// Validate new functional account if selected
if ($('#newfunctionalaccountid').val() === 'new') {
if ($('#newfunctionalaccount').val().trim() === '') {
alert('Please enter a name for the new functional account.');
$('#newfunctionalaccount').focus();
e.preventDefault();
return false;
}
}
}
// Validate new business unit if selected
if ($('#businessunitid').val() === 'new') {
if ($('#newbusinessunit').val().trim() === '') {
alert('Please enter a name for the new business unit.');
$('#newbusinessunit').focus();
e.preventDefault();
return false;
}
}
});
// Map picker code
var pickerMap = null;
var currentMarker = null;
var selectedX = null;
var selectedY = null;
// Get current theme
var bodyClass = document.body.className;
var themeMatch = bodyClass.match(/bg-theme(\d+)/);
var theme = themeMatch ? 'bg-theme' + themeMatch[1] : 'bg-theme1';
// Theme-specific configurations
var themeConfig = {
'bg-theme1': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme2': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme3': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme4': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme5': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme6': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme7': { bg: '#0c675e', filter: 'brightness(0.8) contrast(1.1) hue-rotate(-10deg)' },
'bg-theme8': { bg: '#4a3020', filter: 'brightness(0.75) contrast(1.1) saturate(0.8)' },
'bg-theme9': { bg: '#29323c', filter: 'brightness(0.7) contrast(1.1)' },
'bg-theme10': { bg: '#795548', filter: 'brightness(0.8) contrast(1.05) sepia(0.2)' },
'bg-theme11': { bg: '#1565C0', filter: 'brightness(0.85) contrast(1.05) hue-rotate(-5deg)' },
'bg-theme12': { bg: '#65379b', filter: 'brightness(0.8) contrast(1.1) hue-rotate(5deg)' },
'bg-theme13': { bg: '#d03050', filter: 'brightness(0.85) contrast(1.05) saturate(0.9)' },
'bg-theme14': { bg: '#2a7a2e', filter: 'brightness(0.8) contrast(1.1) saturate(0.95)' },
'bg-theme15': { bg: '#4643d3', filter: 'brightness(0.85) contrast(1.05) hue-rotate(-5deg)' },
'bg-theme16': { bg: '#6a11cb', filter: 'brightness(0.8) contrast(1.1)' }
};
var config = themeConfig[theme] || { bg: '#1a1a1a', filter: 'brightness(0.7) contrast(1.1)' };
// Determine which map image to use based on theme
var lightThemes = ['bg-theme11', 'bg-theme13'];
var mapImage = lightThemes.includes(theme) ? './images/sitemap2025-light.png' : './images/sitemap2025-dark.png';
function updateCoordinateDisplay() {
if (selectedX !== null && selectedY !== null) {
var displayY = 2550 - selectedY;
$('#selectedCoords').text('Selected: X=' + Math.round(selectedX) + ', Y=' + Math.round(displayY));
} else {
$('#selectedCoords').text('Click on the map to select a location');
}
}
$('#selectLocationBtn').click(function() {
$('#mapPickerModal').fadeIn(200);
if (!pickerMap) {
// Initialize map
pickerMap = L.map('locationPickerMap', {
crs: L.CRS.Simple,
minZoom: -3
});
var bounds = [[0, 0], [2550, 3300]];
var image = L.imageOverlay(mapImage, bounds);
// Apply theme-specific filter
image.on('load', function() {
var imgElement = this.getElement();
if (imgElement) {
imgElement.style.filter = config.filter;
}
});
image.addTo(pickerMap);
pickerMap.fitBounds(bounds);
// Add click handler
pickerMap.on('click', function(e) {
selectedX = e.latlng.lng;
selectedY = e.latlng.lat;
// Remove existing marker
if (currentMarker) {
pickerMap.removeLayer(currentMarker);
}
// Add new marker
currentMarker = L.circleMarker([selectedY, selectedX], {
radius: 8,
fillColor: '#667eea',
color: '#fff',
weight: 2,
opacity: 1,
fillOpacity: 0.8
}).addTo(pickerMap);
updateCoordinateDisplay();
});
}
// Load existing coordinates if available
var existingLeft = $('#mapleft').val();
var existingTop = $('#maptop').val();
if (existingLeft && existingTop && existingLeft != '' && existingTop != '') {
selectedX = parseFloat(existingLeft);
selectedY = 2550 - parseFloat(existingTop);
if (currentMarker) {
pickerMap.removeLayer(currentMarker);
}
currentMarker = L.circleMarker([selectedY, selectedX], {
radius: 8,
fillColor: '#667eea',
color: '#fff',
weight: 2,
opacity: 1,
fillOpacity: 0.8
}).addTo(pickerMap);
// Pan to marker
pickerMap.panTo([selectedY, selectedX]);
updateCoordinateDisplay();
}
setTimeout(function() {
pickerMap.invalidateSize();
}, 250);
});
$('#confirmLocationBtn').click(function() {
if (selectedX !== null && selectedY !== null) {
var convertedY = 2550 - selectedY;
$('#mapleft').val(Math.round(selectedX));
$('#maptop').val(Math.round(convertedY));
updateCoordinateDisplay();
$('#mapPickerModal').fadeOut(200);
} else {
alert('Please select a location on the map first.');
}
});
$('#cancelLocationBtn, #mapPickerClose').click(function() {
$('#mapPickerModal').fadeOut(200);
});
});
</script>
</body>
</html>
<%
objConn.Close
%>

View File

@@ -1,128 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get form inputs
Dim vlan, ipstart, cidr, description, subnettypeid, cidrarray, ipend
vlan = Trim(Request.Form("vlan"))
ipstart = Trim(Request.Form("ipstart"))
cidr = Trim(Request.Form("cidr"))
description = Trim(Request.Form("description"))
subnettypeid = Trim(Request.Form("subnettypeid"))
' Validate required fields
If vlan = "" Or ipstart = "" Or cidr = "" Or subnettypeid = "" Then
Response.Write("<div class='alert alert-danger'>Error: Required field missing.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate VLAN is numeric
If Not IsNumeric(vlan) Then
Response.Write("<div class='alert alert-danger'>Error: VLAN must be numeric.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Basic IP address validation
If Len(ipstart) < 7 Or Len(ipstart) > 15 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid IP address.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate subnet type ID
If Not IsNumeric(subnettypeid) Or CLng(subnettypeid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid subnet type.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Parse CIDR value (expected format: "cidr,ipend")
If InStr(cidr, ",") = 0 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid CIDR format.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
cidrarray = Split(cidr, ",")
If UBound(cidrarray) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid CIDR format.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
ipend = Trim(cidrarray(1))
cidr = Trim(cidrarray(0))
' Validate CIDR is numeric
If Not IsNumeric(cidr) Or CInt(cidr) < 0 Or CInt(cidr) > 32 Then
Response.Write("<div class='alert alert-danger'>Error: CIDR must be between 0 and 32.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate ipend is numeric
If Not IsNumeric(ipend) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid IP end value.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate description length
If Len(description) > 500 Then
Response.Write("<div class='alert alert-danger'>Error: Description too long.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes
description = Replace(description, "'", "''")
ipstart = Replace(ipstart, "'", "''")
' Verify subnet type exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM subnettypes WHERE subnettypeid = " & subnettypeid
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck("cnt") = 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Subnet type not found.</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Insert
' Note: INET_ATON requires the IP address, ipend is added to the result
Dim strSQL
strSQL = "INSERT INTO subnets (vlan, description, cidr, ipstart, ipend, subnettypeid, isactive) " & _
"VALUES (" & vlan & ", '" & description & "', " & cidr & ", INET_ATON('" & ipstart & "'), (INET_ATON('" & ipstart & "') + " & ipend & "), " & subnettypeid & ", 1)"
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("./displaysubnets.asp")
Else
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='addsubnet.asp'>Go back</a>")
objConn.Close
End If
%>

View File

@@ -1,25 +0,0 @@
<select id="myselect" onchange="change_myselect(this.value)">
<option value="">Choose an option:</option>
<option value="customers">Customers</option>
<option value="products">Products</option>
<option value="suppliers">Suppliers</option>
</select>
<script>
function change_myselect(sel) {
const dbParam = JSON.stringify({table:sel,limit:20});
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
const myObj = JSON.parse(this.responseText);
let text = "<table border='1'>"
for (let x in myObj) {
text += "<tr><td>" + myObj[x].name + "</td></tr>";
}
text += "</table>"
document.getElementById("demo").innerHTML = text;
}
xmlhttp.open("POST", "http://10.48.130.158:8080/zabbix.php?action=dashboard.view&dashboardid=1&from=now-1h&to=now");
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("x=" + dbParam);
}
</script>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,261 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<style>
.notification-row {
padding: 15px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background: #fff;
}
.notification-row:hover {
background: #f8f9fa;
}
.notification-text {
font-weight: bold;
margin-bottom: 5px;
}
.notification-meta {
font-size: 0.9em;
color: #666;
}
.type-selector {
width: 200px;
}
.badge-tbd { background-color: #6c757d; }
.badge-awareness { background-color: #28a745; }
.badge-change { background-color: #ffc107; color: #212529; }
.badge-incident { background-color: #dc3545; }
.dark-mode .notification-row {
background: #2a2a2a;
border-color: #444;
color: #ddd;
}
.dark-mode .notification-row:hover {
background: #333;
}
.dark-mode .notification-meta {
color: #aaa;
}
</style>
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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">
<div class="row mt-3">
<div class="col-12">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h5 class="card-title" style="margin:0;">
<i class="zmdi zmdi-edit"></i> Bulk Update Notification Types
</h5>
<div>
<a href="./calendar.asp" class="btn btn-secondary">
<i class="zmdi zmdi-calendar"></i> Back to Calendar
</a>
<a href="./displaynotifications.asp" class="btn btn-secondary">
<i class="zmdi zmdi-view-list"></i> List View
</a>
</div>
</div>
<%
' Check for success/error messages
Dim updated, errors
updated = Request.QueryString("updated")
errors = Request.QueryString("errors")
If updated <> "" Then
%>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="zmdi zmdi-check-circle"></i>
<strong>Success!</strong> Updated <%=updated%> notification(s).
<% If errors <> "" And errors <> "0" Then %>
<br><strong>Warning:</strong> <%=errors%> notification(s) failed to update.
<% End If %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<% End If %>
<div class="alert alert-info">
<i class="zmdi zmdi-info"></i>
<strong>Instructions:</strong> Select the appropriate notification type for each notification below, then click "Save All Changes" at the bottom.
</div>
<div style="margin-bottom:20px;">
<h6>Notification Type Legend:</h6>
<span class="badge badge-tbd">TBD</span> - Type to be determined (gray on calendar)<br>
<span class="badge badge-awareness">Awareness</span> - General awareness notification (green on calendar)<br>
<span class="badge badge-change">Change</span> - Scheduled change or maintenance (yellow on calendar)<br>
<span class="badge badge-incident">Incident</span> - Active incident or outage (red on calendar)
</div>
<form id="bulkUpdateForm" method="POST" action="bulk_update_notification_types_process.asp">
<div style="margin-bottom:20px;">
<button type="button" class="btn btn-sm btn-secondary" onclick="setAllType(2)">Set All to Awareness</button>
<button type="button" class="btn btn-sm btn-warning" onclick="setAllType(3)">Set All to Change</button>
<button type="button" class="btn btn-sm btn-danger" onclick="setAllType(4)">Set All to Incident</button>
</div>
<%
' Fetch all active notifications
Dim strSQL, rs
strSQL = "SELECT n.notificationid, n.notification, n.starttime, n.endtime, n.ticketnumber, " & _
"n.notificationtypeid, nt.typename " & _
"FROM notifications n " & _
"LEFT JOIN notificationtypes nt ON n.notificationtypeid = nt.notificationtypeid " & _
"WHERE n.isactive = 1 " & _
"ORDER BY n.starttime DESC"
Set rs = objconn.Execute(strSQL)
Dim count
count = 0
If Not rs.EOF Then
Do While Not rs.EOF
count = count + 1
Dim currentType, currentTypeName
If IsNull(rs("notificationtypeid")) Then
currentType = 1
currentTypeName = "TBD"
Else
currentType = rs("notificationtypeid")
currentTypeName = rs("typename")
End If
%>
<div class="notification-row">
<div class="notification-text">
<%=rs("notification")%>
</div>
<div class="notification-meta">
<strong>Date:</strong> <%=FormatDateTime(rs("starttime"), 2)%>
<% If Not IsNull(rs("endtime")) And rs("endtime") <> "" Then %>
to <%=FormatDateTime(rs("endtime"), 2)%>
<% Else %>
<span class="badge badge-secondary">ONGOING</span>
<% End If %>
<% If Not IsNull(rs("ticketnumber")) And rs("ticketnumber") <> "" Then %>
| <strong>Ticket:</strong> <%=rs("ticketnumber")%>
<% End If %>
</div>
<div style="margin-top:10px;">
<label style="display:inline-block; width:150px;">Current Type:</label>
<span class="badge badge-<%=LCase(currentTypeName)%>"><%=currentTypeName%></span>
</div>
<div style="margin-top:10px;">
<label style="display:inline-block; width:150px;">New Type:</label>
<select name="type_<%=rs("notificationid")%>" class="form-control type-selector" style="display:inline-block;">
<option value="1"<% If currentType = 1 Then Response.Write(" selected") End If %>>TBD</option>
<option value="2"<% If currentType = 2 Then Response.Write(" selected") End If %>>Awareness</option>
<option value="3"<% If currentType = 3 Then Response.Write(" selected") End If %>>Change</option>
<option value="4"<% If currentType = 4 Then Response.Write(" selected") End If %>>Incident</option>
</select>
</div>
</div>
<%
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
objConn.Close
%>
<% If count > 0 Then %>
<div style="margin-top:30px; text-align:center;">
<button type="submit" class="btn btn-success btn-lg">
<i class="zmdi zmdi-check"></i> Save All Changes (<%=count%> notifications)
</button>
</div>
<% Else %>
<div class="alert alert-warning">
No active notifications found.
</div>
<% End If %>
</form>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
<div class="container">
<div class="text-center">
</div>
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.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 setAllType(typeId) {
var selects = document.querySelectorAll('.type-selector');
selects.forEach(function(select) {
select.value = typeId;
});
}
</script>
</body>
</html>

View File

@@ -1,222 +0,0 @@
<%@ Language=VBScript %>
<%
' ========================================================================
' Check All Warranties - Batch Process
' This page checks all PCs without warranty information against Dell API
' ========================================================================
On Error Resume Next
Response.Buffer = True
Response.ContentType = "application/json"
%>
<!--#include file="./includes/sql.asp"-->
<%
If Err.Number <> 0 Then
Response.Write "{""success"": false, ""error"": ""Database include error: " & Replace(Err.Description, """", "'") & """}"
Response.End
End If
' Configuration
Const VENDOR_API_URL = "http://10.48.130.113/vendor-api-proxy.php"
Const BATCH_SIZE = 10 ' Process 10 at a time
Dim strSQL
Dim serviceTags, serialNumber
Dim warrantyData, warrantyResults
Dim updated, errors, total
Dim response
Dim rsWarranties ' Create our own recordset object
' Note: objConn is declared in sql.asp include
' Initialize counters
updated = 0
errors = 0
' Find all PCs without warranty information
strSQL = "SELECT pcid, hostname, serialnumber " & _
"FROM pc " & _
"WHERE (warrantyenddate IS NULL OR warrantyenddate = '' OR warrantyenddate = '0000-00-00') " & _
"AND serialnumber IS NOT NULL " & _
"AND serialnumber <> 'N/A' " & _
"AND serialnumber <> '' " & _
"AND LENGTH(serialnumber) >= 5 " & _
"AND isactive = 1"
' Create and open recordset with cursor to support MoveFirst
Set rsWarranties = Server.CreateObject("ADODB.Recordset")
If Err.Number <> 0 Then
Response.Write "{""success"": false, ""error"": ""Failed to create recordset: " & Replace(Err.Description, """", "'") & """}"
Response.End
End If
rsWarranties.CursorLocation = 3 ' adUseClient
rsWarranties.Open strSQL, objConn
If Err.Number <> 0 Then
Response.Write "{""success"": false, ""error"": ""Failed to open recordset: " & Replace(Err.Description, """", "'") & """}"
Response.End
End If
' Check if we have any records
If rsWarranties.EOF Then
' No devices need warranty checks
Response.Write "{""success"": true, ""message"": ""No devices require warranty checks"", ""total"": 0, ""updated"": 0, ""errors"": 0}"
rsWarranties.Close
objConn.Close
Response.End
End If
' Count total records
Dim serviceTagList()
Dim deviceInfo()
Dim count
count = 0
Do While Not rsWarranties.EOF
count = count + 1
rsWarranties.MoveNext
Loop
total = count
' Reset to beginning
rsWarranties.MoveFirst
' Build arrays
ReDim serviceTagList(total - 1)
ReDim deviceInfo(total - 1)
count = 0
Do While Not rsWarranties.EOF
serialNumber = Trim(rsWarranties("serialnumber"))
serviceTagList(count) = serialNumber
Set deviceInfo(count) = CreateObject("Scripting.Dictionary")
deviceInfo(count)("pcid") = rsWarranties("pcid")
deviceInfo(count)("hostname") = rsWarranties("hostname")
deviceInfo(count)("serialnumber") = serialNumber
count = count + 1
rsWarranties.MoveNext
Loop
rsWarranties.Close
Set rsWarranties = Nothing
' Process in batches
Dim i, batchStart, batchEnd, batchTags
Dim batchTagsStr, apiUrl, xmlhttp
Dim responseText, json
For i = 0 To total - 1 Step BATCH_SIZE
batchStart = i
batchEnd = i + BATCH_SIZE - 1
If batchEnd >= total Then
batchEnd = total - 1
End If
' Build batch of service tags
batchTagsStr = ""
Dim j
For j = batchStart To batchEnd
If batchTagsStr <> "" Then
batchTagsStr = batchTagsStr & ","
End If
batchTagsStr = batchTagsStr & serviceTagList(j)
Next
' Call vendor API
apiUrl = VENDOR_API_URL & "?vendor=dell&action=warranty-batch&servicetags=" & Server.URLEncode(batchTagsStr)
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.setTimeouts 30000, 30000, 30000, 30000 ' 30 second timeout
On Error Resume Next
xmlhttp.Open "GET", apiUrl, False
xmlhttp.setRequestHeader "Accept", "application/json"
xmlhttp.Send
If Err.Number <> 0 Then
errors = errors + (batchEnd - batchStart + 1)
Err.Clear
Else
responseText = xmlhttp.responseText
' Parse JSON response (simplified - for production use proper JSON parser)
' For now, we'll extract warranty data using string parsing
If InStr(responseText, """success"":true") > 0 Then
' Process each warranty in batch
For j = batchStart To batchEnd
serialNumber = serviceTagList(j)
' Extract warranty data for this serial (simplified extraction)
Dim warrantyEndDate, serviceLevel, warrantyStatus
warrantyEndDate = ExtractWarrantyData(responseText, serialNumber, "warrantyEndDate")
serviceLevel = ExtractWarrantyData(responseText, serialNumber, "serviceLevel")
warrantyStatus = ExtractWarrantyData(responseText, serialNumber, "warrantyStatus")
If warrantyEndDate <> "" Then
' Update database
strSQL = "UPDATE pc SET " & _
"warrantyenddate = '" & Replace(warrantyEndDate, "'", "''") & "', " & _
"warrantystatus = '" & Replace(warrantyStatus, "'", "''") & "', " & _
"warrantylevel = '" & Replace(Left(serviceLevel, 100), "'", "''") & "' " & _
"WHERE pcid = " & deviceInfo(j)("pcid")
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
updated = updated + 1
Else
errors = errors + 1
Err.Clear
End If
On Error Goto 0
Else
errors = errors + 1
End If
Next
Else
errors = errors + (batchEnd - batchStart + 1)
End If
End If
On Error Goto 0
Set xmlhttp = Nothing
' Small delay between batches - ASP doesn't support WScript.Sleep
' Instead, we'll just continue without delay since batches are small
' If batchEnd < total - 1 Then
' ' No sleep available in ASP
' End If
Next
' Return response
Response.Write "{""success"": true, ""total"": " & total & ", ""updated"": " & updated & ", ""errors"": " & errors & ", ""message"": ""Updated " & updated & " of " & total & " warranty records""}"
objConn.Close
' Helper function to extract warranty data from JSON
Function ExtractWarrantyData(jsonText, serviceTag, fieldName)
Dim pattern, startPos, endPos, value
pattern = """serviceTag"":""" & serviceTag & """"
startPos = InStr(jsonText, pattern)
If startPos > 0 Then
' Find the field within this warranty object
Dim fieldPattern
fieldPattern = """" & fieldName & """:"""
startPos = InStr(startPos, jsonText, fieldPattern)
If startPos > 0 Then
startPos = startPos + Len(fieldPattern)
endPos = InStr(startPos, jsonText, """")
If endPos > startPos Then
value = Mid(jsonText, startPos, endPos - startPos)
ExtractWarrantyData = value
Exit Function
End If
End If
End If
ExtractWarrantyData = ""
End Function
%>

View File

@@ -1,58 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
Response.Write("<h1>Check for Duplicate Printer Machines</h1>")
Dim strSQL, rs
' Find duplicates by machinenumber
strSQL = "SELECT machinenumber, COUNT(*) as cnt " &_
"FROM machines " &_
"WHERE machinenumber LIKE '%-PRINTER' " &_
"GROUP BY machinenumber " &_
"HAVING COUNT(*) > 1 " &_
"ORDER BY cnt DESC, machinenumber"
set rs = objConn.Execute(strSQL)
Response.Write("<h3>Duplicate Machine Numbers:</h3>")
Response.Write("<table border='1' style='border-collapse:collapse'>")
Response.Write("<tr><th>Machine Number</th><th>Count</th></tr>")
Dim hasDuplicates
hasDuplicates = False
While Not rs.EOF
hasDuplicates = True
Response.Write("<tr>")
Response.Write("<td>" & Server.HTMLEncode(rs("machinenumber") & "") & "</td>")
Response.Write("<td>" & rs("cnt") & "</td>")
Response.Write("</tr>")
rs.MoveNext
Wend
Response.Write("</table>")
If Not hasDuplicates Then
Response.Write("<p style='color:green'>No duplicates found!</p>")
End If
rs.Close
' Show all printer machines grouped
Response.Write("<h3>All Printer Machines (grouped by name):</h3>")
strSQL = "SELECT machinenumber, COUNT(*) as cnt, GROUP_CONCAT(machineid) as ids " &_
"FROM machines " &_
"WHERE machinetypeid = 15 " &_
"GROUP BY machinenumber " &_
"ORDER BY machinenumber"
set rs = objConn.Execute(strSQL)
Response.Write("<table border='1' style='border-collapse:collapse'>")
Response.Write("<tr><th>Machine Number</th><th>Count</th><th>Machine IDs</th></tr>")
While Not rs.EOF
Response.Write("<tr>")
Response.Write("<td>" & Server.HTMLEncode(rs("machinenumber") & "") & "</td>")
Response.Write("<td>" & rs("cnt") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("ids") & "") & "</td>")
Response.Write("</tr>")
rs.MoveNext
Wend
Response.Write("</table>")
rs.Close
objConn.Close
%>

View File

@@ -1,42 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
Response.Write("<h1>Production Printer Machines Count</h1>")
Dim strSQL, rs
' Count printer machines
strSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinetypeid = 15"
set rs = objConn.Execute(strSQL)
Response.Write("<h3>Machines with Printer type (machinetypeid=15): " & rs("cnt") & "</h3>")
rs.Close
' Count machines with -PRINTER suffix
strSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinenumber LIKE '%-PRINTER'"
set rs = objConn.Execute(strSQL)
Response.Write("<h3>Machines with '-PRINTER' suffix: " & rs("cnt") & "</h3>")
rs.Close
' Show sample
Response.Write("<h3>Sample Printer Machines:</h3>")
strSQL = "SELECT m.machineid, m.machinenumber, m.alias, c.address as ipaddress " &_
"FROM machines m " &_
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.comstypeid = 1 " &_
"WHERE m.machinetypeid = 15 " &_
"ORDER BY m.machineid DESC LIMIT 10"
set rs = objConn.Execute(strSQL)
Response.Write("<table border='1' style='border-collapse:collapse'>")
Response.Write("<tr><th>ID</th><th>Machine Number</th><th>Alias</th><th>IP</th></tr>")
While Not rs.EOF
Response.Write("<tr>")
Response.Write("<td>" & rs("machineid") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("machinenumber") & "") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("alias") & "") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("ipaddress") & "") & "</td>")
Response.Write("</tr>")
rs.MoveNext
Wend
Response.Write("</table>")
rs.Close
objConn.Close
%>

View File

@@ -1,98 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
Response.Write("<h1>Cleanup Duplicate Printer Machines</h1>")
' First, show what will be deleted
Response.Write("<h2>Records that will be DELETED:</h2>")
Dim strSQL, rs
strSQL = "SELECT m1.machineid, m1.machinenumber, m1.alias, c.address as ipaddress " &_
"FROM machines m1 " &_
"LEFT JOIN communications c ON m1.machineid = c.machineid AND c.comstypeid = 1 " &_
"WHERE m1.machinetypeid = 15 " &_
"AND m1.machineid NOT IN ( " &_
" SELECT MIN(m2.machineid) " &_
" FROM machines m2 " &_
" WHERE m2.machinetypeid = 15 " &_
" GROUP BY m2.machinenumber " &_
") " &_
"ORDER BY m1.machinenumber, m1.machineid"
set rs = objConn.Execute(strSQL)
Response.Write("<table border='1' style='border-collapse:collapse'>")
Response.Write("<tr><th>Machine ID</th><th>Machine Number</th><th>Alias</th><th>IP</th></tr>")
Dim deleteCount
deleteCount = 0
While Not rs.EOF
deleteCount = deleteCount + 1
Response.Write("<tr>")
Response.Write("<td>" & rs("machineid") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("machinenumber") & "") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("alias") & "") & "</td>")
Response.Write("<td>" & Server.HTMLEncode(rs("ipaddress") & "") & "</td>")
Response.Write("</tr>")
rs.MoveNext
Wend
Response.Write("</table>")
rs.Close
Response.Write("<h3>Total records to delete: " & deleteCount & "</h3>")
' Now execute the DELETE
Response.Write("<h2>Executing DELETE...</h2>")
On Error Resume Next
strSQL = "DELETE m1 " &_
"FROM machines m1 " &_
"WHERE m1.machinetypeid = 15 " &_
"AND m1.machineid NOT IN ( " &_
" SELECT * FROM ( " &_
" SELECT MIN(m2.machineid) " &_
" FROM machines m2 " &_
" WHERE m2.machinetypeid = 15 " &_
" GROUP BY m2.machinenumber " &_
" ) AS keep_ids " &_
")"
objConn.Execute(strSQL)
If Err.Number <> 0 Then
Response.Write("<h3 style='color:red'>ERROR:</h3>")
Response.Write("<p>Error Number: " & Err.Number & "</p>")
Response.Write("<p>Error Description: " & Server.HTMLEncode(Err.Description) & "</p>")
Err.Clear
Else
Response.Write("<h3 style='color:green'>DELETE completed successfully!</h3>")
End If
On Error Goto 0
' Verify no duplicates remain
Response.Write("<h2>Verification - Remaining Duplicates:</h2>")
strSQL = "SELECT machinenumber, COUNT(*) as cnt " &_
"FROM machines " &_
"WHERE machinetypeid = 15 " &_
"GROUP BY machinenumber " &_
"HAVING COUNT(*) > 1"
set rs = objConn.Execute(strSQL)
If rs.EOF Then
Response.Write("<p style='color:green;font-weight:bold'>No duplicates remaining! ✓</p>")
Else
Response.Write("<p style='color:red;font-weight:bold'>WARNING: Duplicates still exist!</p>")
Response.Write("<table border='1' style='border-collapse:collapse'>")
Response.Write("<tr><th>Machine Number</th><th>Count</th></tr>")
While Not rs.EOF
Response.Write("<tr>")
Response.Write("<td>" & Server.HTMLEncode(rs("machinenumber") & "") & "</td>")
Response.Write("<td>" & rs("cnt") & "</td>")
Response.Write("</tr>")
rs.MoveNext
Wend
Response.Write("</table>")
End If
rs.Close
' Show final count
strSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinetypeid = 15"
set rs = objConn.Execute(strSQL)
Response.Write("<h3>Final printer machine count: " & rs("cnt") & "</h3>")
rs.Close
objConn.Close
%>

View File

@@ -1,473 +0,0 @@
<!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 serverid, isNewRecord
serverid = Request.QueryString("id")
If serverid = "" Or serverid = "0" Then
isNewRecord = True
serverid = 0
Else
isNewRecord = False
End If
' If editing, fetch existing data
Dim rs, servername, modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive
Dim vendorname, modelnumber
If Not isNewRecord Then
Dim strSQL
strSQL = "SELECT mac.machineid, mac.alias AS servername, mac.modelnumberid AS modelid, " & _
"mac.serialnumber, mac.machinenotes AS description, mac.maptop, mac.mapleft, mac.isactive, " & _
"m.modelnumber, v.vendor, c.address AS ipaddress " & _
"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 " & _
"WHERE mac.machineid = " & serverid & " AND mac.machinetypeid = 30"
Set rs = objConn.Execute(strSQL)
If rs.EOF Then
Response.Write("Server not found")
Response.End
End If
If Not IsNull(rs("servername")) Then servername = rs("servername") Else servername = ""
If Not IsNull(rs("modelid")) Then modelid = rs("modelid") Else modelid = ""
If Not IsNull(rs("serialnumber")) Then serialnumber = rs("serialnumber") Else serialnumber = ""
If Not IsNull(rs("ipaddress")) Then ipaddress = rs("ipaddress") Else ipaddress = ""
If Not IsNull(rs("description")) Then description = rs("description") Else 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 = ""
rs.Close
Set rs = Nothing
Else
' New record defaults
servername = ""
modelid = ""
serialnumber = ""
ipaddress = ""
description = ""
maptop = ""
mapleft = ""
isactive = 1 ' Active by default for new records
vendorname = ""
modelnumber = ""
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="network_devices.asp">Network Devices</a></li>
<li class="breadcrumb-item"><a href="network_devices.asp?filter=Server">Servers</a></li>
<li class="breadcrumb-item active"><%If isNewRecord Then Response.Write("Add Server") Else Response.Write("Edit Server")%></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-storage"></i>
<%If isNewRecord Then Response.Write("Add Server") Else Response.Write("Edit Server: " & Server.HTMLEncode(servername))%>
</h5>
<hr>
<form method="post" action="save_network_device.asp">
<input type="hidden" name="type" value="server">
<input type="hidden" name="id" value="<%=serverid%>">
<div class="form-group row">
<label class="col-sm-3 col-form-label">Server Name <span class="text-danger">*</span></label>
<div class="col-sm-9">
<input type="text" name="servername" class="form-control"
value="<%=Server.HTMLEncode(servername)%>"
required maxlength="100"
placeholder="e.g., DB-Server-01, App-Server-Primary">
<small class="form-text text-muted">
Short name to identify this server
</small>
</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 strSQL2, rsModels
strSQL2 = "SELECT m.modelnumberid, m.modelnumber, v.vendor " & _
"FROM models m " & _
"INNER JOIN vendors v ON m.vendorid = v.vendorid " & _
"WHERE m.isactive = 1 " & _
"ORDER BY v.vendor, m.modelnumber"
Set rsModels = objConn.Execute(strSQL2)
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., PowerEdge R740">
</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
strSQL2 = "SELECT vendorid, vendor FROM vendors WHERE isactive = 1 ORDER BY vendor ASC"
Set rsVendors = objConn.Execute(strSQL2)
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., Dell, HP, Cisco">
</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="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">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., SN123456789">
</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 or 2001:db8::1">
<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">Description</label>
<div class="col-sm-9">
<textarea name="description" class="form-control" rows="3"
maxlength="255" placeholder="Detailed notes about this server..."><%=Server.HTMLEncode(description)%></textarea>
<small class="form-text text-muted">
Optional: Purpose, rack location, 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 server'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 Server") Else Response.Write("Save Changes")%>
</button>
<a href="network_devices.asp?filter=Server" 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 server? This action cannot be undone.')) {
var form = document.createElement('form');
form.method = 'POST';
form.action = 'save_network_device.asp';
var typeInput = document.createElement('input');
typeInput.type = 'hidden';
typeInput.name = 'type';
typeInput.value = 'server';
form.appendChild(typeInput);
var idInput = document.createElement('input');
idInput.type = 'hidden';
idInput.name = 'id';
idInput.value = '<%=serverid%>';
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() {
// 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) {
// 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
%>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,793 +0,0 @@
<%
'=============================================================================
' FILE: displaymachine.asp
' PURPOSE: Display detailed machine information with edit capability
' SECURITY: Parameterized queries, HTML encoding, input validation
' UPDATED: 2025-11-07 - Fixed for Phase 2 schema (machines + communications)
'=============================================================================
%><!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
<link rel="stylesheet" href="./leaflet/leaflet.css">
<script src="./leaflet/leaflet.js"></script>
</head>
<%
theme = Request.Cookies("theme")
If theme = "" Then
theme = "bg-theme1"
End If
'=============================================================================
' SECURITY: Validate machineid parameter
'=============================================================================
Dim machineid
machineid = GetSafeInteger("QS", "machineid", 0, 1, 999999)
IF machineid = 0 THEN
objConn.Close
Response.Redirect("default.asp")
Response.End
END IF
'=============================================================================
' PHASE 2 SCHEMA: Query machines table with LEFT JOINs for optional data
' - No more pc/pc_network_interfaces/pc_dualpath_assignments tables
' - Use communications for network interfaces
' - Use machinerelationships for dualpath relationships
' - Use compliance for compliance data
'=============================================================================
strSQL = "SELECT machines.*, models.modelnumber, vendors.vendor, " & _
"businessunits.businessunit, machinetypes.machinetype " & _
"FROM machines " & _
"INNER JOIN models ON machines.modelnumberid = models.modelnumberid " & _
"INNER JOIN vendors ON models.vendorid = vendors.vendorid " & _
"INNER JOIN businessunits ON machines.businessunitid = businessunits.businessunitid " & _
"LEFT JOIN machinetypes ON models.machinetypeid = machinetypes.machinetypeid " & _
"WHERE machines.machineid = ?"
Set rs = ExecuteParameterizedQuery(objConn, strSQL, Array(machineid))
' Check if machine exists
If rs.EOF Then
rs.Close
Set rs = Nothing
objConn.Close
Response.Redirect("default.asp")
Response.End
End If
'=============================================================================
' Get primary network interface from communications table
'=============================================================================
Dim rsPrimaryNetwork, primaryIP, primaryMAC, primaryHostname, primaryInterface
primaryIP = ""
primaryMAC = ""
primaryHostname = ""
primaryInterface = ""
' Get hostname from machines table (for PCs)
If Not IsNull(rs("hostname")) And rs("hostname") & "" <> "" Then
primaryHostname = rs("hostname") & ""
End If
' Query for primary network interface
strSQL = "SELECT c.address, c.macaddress, c.interfacename " & _
"FROM communications c " & _
"INNER JOIN comstypes ct ON c.comstypeid = ct.comstypeid " & _
"WHERE c.machineid = ? AND ct.typename = 'Network_Interface' " & _
"AND c.isactive = 1 AND c.isprimary = 1 " & _
"LIMIT 1"
Set rsPrimaryNetwork = ExecuteParameterizedQuery(objConn, strSQL, Array(machineid))
If Not rsPrimaryNetwork.EOF Then
primaryIP = rsPrimaryNetwork("address") & ""
If Not IsNull(rsPrimaryNetwork("macaddress")) Then
primaryMAC = rsPrimaryNetwork("macaddress") & ""
End If
If Not IsNull(rsPrimaryNetwork("interfacename")) Then
primaryInterface = rsPrimaryNetwork("interfacename") & ""
End If
End If
rsPrimaryNetwork.Close
Set rsPrimaryNetwork = Nothing
' If no primary, get the first network interface
If primaryIP = "" Then
strSQL = "SELECT c.address, c.macaddress, c.interfacename " & _
"FROM communications c " & _
"INNER JOIN comstypes ct ON c.comstypeid = ct.comstypeid " & _
"WHERE c.machineid = ? AND ct.typename = 'Network_Interface' " & _
"AND c.isactive = 1 " & _
"ORDER BY c.comid ASC LIMIT 1"
Set rsPrimaryNetwork = ExecuteParameterizedQuery(objConn, strSQL, Array(machineid))
If Not rsPrimaryNetwork.EOF Then
primaryIP = rsPrimaryNetwork("address") & ""
If Not IsNull(rsPrimaryNetwork("macaddress")) Then
primaryMAC = rsPrimaryNetwork("macaddress") & ""
End If
If Not IsNull(rsPrimaryNetwork("interfacename")) Then
primaryInterface = rsPrimaryNetwork("interfacename") & ""
End If
End If
rsPrimaryNetwork.Close
Set rsPrimaryNetwork = Nothing
End If
'=============================================================================
' Query dualpath relationships from machinerelationships table
'=============================================================================
Dim rsDualpath, isDualpath, relatedMachineNumber, relatedMachineId
isDualpath = False
relatedMachineNumber = ""
relatedMachineId = 0
strSQL = "SELECT mr.related_machineid, m2.machinenumber " & _
"FROM machinerelationships mr " & _
"INNER JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
"INNER JOIN machines m2 ON mr.related_machineid = m2.machineid " & _
"WHERE mr.machineid = ? AND rt.relationshiptype = 'Dualpath' AND mr.isactive = 1 " & _
"LIMIT 1"
Set rsDualpath = ExecuteParameterizedQuery(objConn, strSQL, Array(machineid))
If Not rsDualpath.EOF Then
isDualpath = True
relatedMachineId = rsDualpath("related_machineid")
relatedMachineNumber = rsDualpath("machinenumber") & ""
End If
rsDualpath.Close
Set rsDualpath = Nothing
%>
<body class="bg-theme <%=Server.HTMLEncode(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">
<div class="row mt-3">
<div class="col-lg-4">
<div class="card profile-card-2">
<div class="card-img-block">
<img class="img-fluid" src="./images/machines/<%If Not IsNull(rs("image")) Then Response.Write(Server.HTMLEncode(rs("image") & "")) Else Response.Write("default.png") End If%>" alt="Card image cap">
</div>
<div class="card-body pt-5">
<img src="./images/machines/<%If Not IsNull(rs("image")) Then Response.Write(Server.HTMLEncode(rs("image") & "")) Else Response.Write("default.png") End If%>" alt="profile-image" class="profile">
<h5 class="card-title"><%=Server.HTMLEncode(rs("machinenumber") & "")%></h5>
<h5 class="card-title"><%=Server.HTMLEncode(rs("vendor") & "")%></h5>
<h5 class="card-text"><%=Server.HTMLEncode(rs("machinetype") & "")%></h5>
<p class="card-text"><%=Server.HTMLEncode(rs("machinedescription") & "")%></p>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<ul class="nav nav-tabs nav-tabs-primary top-icon nav-justified">
<li class="nav-item">
<a href="javascript:void();" data-target="#profile" data-toggle="pill" class="nav-link active"><i class="icon-wrench"></i> <span class="hidden-xs">Settings</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#network" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-network"></i> <span class="hidden-xs">Network</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#relationships" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-link"></i> <span class="hidden-xs">Relationships</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#compliance" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-lock"></i> <span class="hidden-xs">Compliance</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#applications" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-apps"></i> <span class="hidden-xs">Applications</span></a>
</li>
</ul>
<div class="tab-content p-3">
<div class="tab-pane active" id="profile">
<h5 class="mb-3">Configuration</h5>
<div class="row">
<div class="col-md-3">
<p class="mb-2"><strong>Machine #:</strong></p>
<p class="mb-2"><strong>Alias:</strong></p>
<p class="mb-2"><strong>Hostname:</strong></p>
<p class="mb-2"><strong>Location:</strong></p>
<p class="mb-2"><strong>Vendor:</strong></p>
<p class="mb-2"><strong>Model:</strong></p>
<p class="mb-2"><strong>Type:</strong></p>
<p class="mb-2"><strong>BU:</strong></p>
<p class="mb-2"><strong>Controller:</strong></p>
<p class="mb-2"><strong>Serial #:</strong></p>
<p class="mb-2"><strong>IP Address:</strong></p>
<p class="mb-2"><strong>VLAN:</strong></p>
<p class="mb-2"><strong>Criticality:</strong></p>
<p class="mb-2"><strong>Printer:</strong></p>
<% If isDualpath Then %>
<p class="mb-2"><strong>Dualpath:</strong></p>
<% End If %>
<p>
</p>
</div>
<div class="col-md-5">
<%
Dim machineNumVal, aliasVal, hostnameVal, vendorValM, modelValM, machineTypeVal, buVal
' Get values and default to N/A if empty
machineNumVal = rs("machinenumber") & ""
If machineNumVal = "" Then machineNumVal = "N/A"
aliasVal = rs("alias") & ""
If aliasVal = "" Then aliasVal = "N/A"
hostnameVal = primaryHostname
If hostnameVal = "" Then hostnameVal = "N/A"
vendorValM = rs("vendor") & ""
If vendorValM = "" Then vendorValM = "N/A"
modelValM = rs("modelnumber") & ""
If modelValM = "" Then modelValM = "N/A"
machineTypeVal = rs("machinetype") & ""
If machineTypeVal = "" Then machineTypeVal = "N/A"
buVal = rs("businessunit") & ""
If buVal = "" Then buVal = "N/A"
%>
<p class="mb-2">
<%
If machineNumVal <> "N/A" Then
%>
<span class="location-link" data-machineid="<%=Server.HTMLEncode(machineid)%>" style="cursor:pointer; color:#007bff;">
<i class="zmdi zmdi-pin" style="margin-right:4px;"></i><%=Server.HTMLEncode(machineNumVal)%>
</span>
<%
Else
Response.Write("N/A")
End If
%>
</p>
<p class="mb-2"><%=Server.HTMLEncode(aliasVal)%></p>
<p class="mb-2">
<%
If hostnameVal <> "N/A" And primaryIP <> "" Then
%>
<a href='com.realvnc.vncviewer.connect://<%=Server.HTMLEncode(primaryIP)%>:5900' title='VNC To Desktop'><%=Server.HTMLEncode(hostnameVal)%></a>
<%
Else
Response.Write(Server.HTMLEncode(hostnameVal))
End If
%>
</p>
<p class="mb-2">
<%
' Map location display
Dim mapLeft, mapTop
mapLeft = rs("mapleft") & ""
mapTop = rs("maptop") & ""
If mapLeft <> "" And mapTop <> "" Then
Response.Write("<i class='zmdi zmdi-pin'></i> Shop Floor (" & Server.HTMLEncode(mapLeft) & ", " & Server.HTMLEncode(mapTop) & ")")
Else
Response.Write("N/A")
End If
%>
</p>
<p class="mb-2"><%=Server.HTMLEncode(vendorValM)%></p>
<p class="mb-2"><%=Server.HTMLEncode(modelValM)%></p>
<p class="mb-2"><%=Server.HTMLEncode(machineTypeVal)%></p>
<p class="mb-2"><%=Server.HTMLEncode(buVal)%></p>
<%
' Controller information
' Controller info commented out - not in simplified query
' If Not IsNull(rs("controller_vendor")) And rs("controller_vendor") & "" <> "" Then
' Dim controllerDisplay
' controllerDisplay = rs("controller_vendor") & ""
' If Not IsNull(rs("controller_model")) And rs("controller_model") & "" <> "" Then
' controllerDisplay = controllerDisplay & " " & rs("controller_model") & ""
' End If
' Response.Write("<p class='mb-2'><i class='zmdi zmdi-memory'></i> " & Server.HTMLEncode(controllerDisplay) & "</p>")
' Else
Response.Write("<p class='mb-2'>N/A</p>")
' End If
' Serial number
If Not IsNull(rs("serialnumber")) And rs("serialnumber") & "" <> "" Then
Response.Write("<p class='mb-2'><code>" & Server.HTMLEncode(rs("serialnumber") & "") & "</code></p>")
Else
Response.Write("<p class='mb-2'>N/A</p>")
End If
' IP Address
If primaryIP <> "" Then
Response.Write("<p class='mb-2'><code>" & Server.HTMLEncode(primaryIP) & "</code></p>")
Else
Response.Write("<p class='mb-2'>N/A</p>")
End If
' VLAN
If Not IsNull(rs("vlan")) And rs("vlan") & "" <> "" Then
Response.Write("<p class='mb-2'>VLAN " & Server.HTMLEncode(rs("vlan") & "") & "</p>")
Else
Response.Write("<p class='mb-2'>N/A</p>")
End If
' Asset Criticality
If Not IsNull(rs("asset_criticality")) And rs("asset_criticality") & "" <> "" Then
Dim criticalityBadge, criticalityVal
criticalityVal = rs("asset_criticality") & ""
Select Case UCase(criticalityVal)
Case "HIGH"
criticalityBadge = "<i class='zmdi zmdi-alert-triangle'></i> High"
Case "MEDIUM"
criticalityBadge = "Medium"
Case "LOW"
criticalityBadge = "Low"
Case Else
criticalityBadge = Server.HTMLEncode(criticalityVal)
End Select
Response.Write("<p class='mb-2'>" & criticalityBadge & "</p>")
Else
Response.Write("<p class='mb-2'>N/A</p>")
End If
' Printer data - check if exists (LEFT JOIN may return NULL)
If Not IsNull(rs("printerid")) And rs("printerid") <> "" Then
Dim printerNameVal
printerNameVal = rs("printerwindowsname") & ""
If printerNameVal = "" Then printerNameVal = "Printer #" & rs("printerid")
Response.Write("<p class='mb-2'><a href='./displayprinter.asp?printerid=" & Server.HTMLEncode(rs("printerid") & "") & "'>" & Server.HTMLEncode(printerNameVal) & "</a></p>")
Else
Response.Write("<p class='mb-2'>N/A</p>")
End If
' Dualpath information
If isDualpath Then
Response.Write("<p class='mb-2'><a href='./displaymachine.asp?machineid=" & Server.HTMLEncode(relatedMachineId) & "'><i class='zmdi zmdi-swap'></i> " & Server.HTMLEncode(relatedMachineNumber) & "</a></p>")
End If
%>
</div>
<div class="col-md-4">
<h6 class="text-uppercase mb-2">Notes</h6>
<div class="alert alert-secondary" role="alert">
<%
Dim machineNotes
machineNotes = rs("machinenotes") & ""
If machineNotes <> "" Then
Response.Write("<small>" & Server.HTMLEncode(machineNotes) & "</small>")
Else
Response.Write("<small class='text-muted'>No notes</small>")
End If
%>
</div>
</div>
</div>
<!--/row-->
</div>
<div class="tab-pane" id="network">
<h5 class="mb-3">Network Interfaces</h5>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Interface</th>
<th>IP Address</th>
<th>MAC Address</th>
<th>Type</th>
<th>Primary</th>
</tr>
</thead>
<tbody>
<%
'=============================================================================
' Query all network interfaces from communications table
'=============================================================================
strSQL2 = "SELECT c.address, c.macaddress, c.interfacename, c.isprimary, c.isdhcp " & _
"FROM communications c " & _
"INNER JOIN comstypes ct ON c.comstypeid = ct.comstypeid " & _
"WHERE c.machineid = ? AND ct.typename = 'Network_Interface' AND c.isactive = 1 " & _
"ORDER BY c.isprimary DESC, c.comid ASC"
Set rs2 = ExecuteParameterizedQuery(objConn, strSQL2, Array(machineid))
If rs2.EOF Then
Response.Write("<tr><td colspan='5' class='text-center text-muted'><em>No network interfaces found</em></td></tr>")
Else
Do While Not rs2.EOF
Dim interfaceNameVal, ipAddressVal, macAddressVal, isPrimaryVal, isDHCPVal
interfaceNameVal = rs2("interfacename") & ""
If interfaceNameVal = "" Then interfaceNameVal = "Unknown"
ipAddressVal = rs2("address") & ""
If ipAddressVal = "" Then ipAddressVal = "N/A"
macAddressVal = rs2("macaddress") & ""
If macAddressVal = "" Then macAddressVal = "N/A"
isPrimaryVal = rs2("isprimary")
isDHCPVal = rs2("isdhcp")
Response.Write("<tr>")
Response.Write("<td>" & Server.HTMLEncode(interfaceNameVal) & "</td>")
Response.Write("<td><code>" & Server.HTMLEncode(ipAddressVal) & "</code></td>")
Response.Write("<td><code>" & Server.HTMLEncode(macAddressVal) & "</code></td>")
If isDHCPVal = 1 Or isDHCPVal = True Then
Response.Write("<td><span class='badge badge-info'>DHCP</span></td>")
Else
Response.Write("<td><span class='badge badge-secondary'>Static</span></td>")
End If
If isPrimaryVal = 1 Or isPrimaryVal = True Then
Response.Write("<td><i class='zmdi zmdi-check-circle text-success'></i></td>")
Else
Response.Write("<td></td>")
End If
Response.Write("</tr>")
rs2.MoveNext
Loop
End If
rs2.Close
Set rs2 = Nothing
%>
</tbody>
</table>
</div>
<h5 class="mb-3 mt-4">Other Communications</h5>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Type</th>
<th>Address/Port</th>
<th>Details</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<%
'=============================================================================
' Query other communication types (Serial, IP, USB, etc.)
'=============================================================================
strSQL2 = "SELECT c.address, c.port, c.portname, c.description, c.baud, c.databits, c.stopbits, c.parity, ct.typename " & _
"FROM communications c " & _
"INNER JOIN comstypes ct ON c.comstypeid = ct.comstypeid " & _
"WHERE c.machineid = ? AND ct.typename != 'Network_Interface' AND c.isactive = 1 " & _
"ORDER BY ct.typename, c.comid ASC"
Set rs2 = ExecuteParameterizedQuery(objConn, strSQL2, Array(machineid))
If rs2.EOF Then
Response.Write("<tr><td colspan='4' class='text-center text-muted'><em>No other communications found</em></td></tr>")
Else
Do While Not rs2.EOF
Dim typeNameVal, addressVal, detailsVal, descriptionVal
typeNameVal = rs2("typename") & ""
addressVal = rs2("address") & ""
' Build details based on type
detailsVal = ""
If typeNameVal = "Serial" Then
If Not IsNull(rs2("baud")) Then detailsVal = rs2("baud") & " baud"
If Not IsNull(rs2("databits")) And rs2("databits") & "" <> "" Then
If detailsVal <> "" Then detailsVal = detailsVal & ", "
detailsVal = detailsVal & rs2("databits") & "N" & rs2("stopbits") & ""
End If
ElseIf typeNameVal = "IP" Then
If Not IsNull(rs2("port")) Then detailsVal = "Port " & rs2("port")
End If
descriptionVal = rs2("description") & ""
If descriptionVal = "" Then descriptionVal = "-"
Response.Write("<tr>")
Response.Write("<td><span class='badge badge-primary'>" & Server.HTMLEncode(typeNameVal) & "</span></td>")
Response.Write("<td><code>" & Server.HTMLEncode(addressVal) & "</code></td>")
Response.Write("<td>" & Server.HTMLEncode(detailsVal) & "</td>")
Response.Write("<td>" & Server.HTMLEncode(descriptionVal) & "</td>")
Response.Write("</tr>")
rs2.MoveNext
Loop
End If
rs2.Close
Set rs2 = Nothing
%>
</tbody>
</table>
</div>
</div>
<div class="tab-pane" id="relationships">
<h5 class="mb-3">Machine Relationships</h5>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Relationship Type</th>
<th>Related Machine</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<%
'=============================================================================
' Query machine relationships from machinerelationships table
'=============================================================================
strSQL2 = "SELECT mr.related_machineid, mr.relationship_notes, rt.relationshiptype, m2.machinenumber " & _
"FROM machinerelationships mr " & _
"INNER JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
"INNER JOIN machines m2 ON mr.related_machineid = m2.machineid " & _
"WHERE mr.machineid = ? AND mr.isactive = 1 " & _
"ORDER BY rt.relationshiptype, m2.machinenumber"
Set rs2 = ExecuteParameterizedQuery(objConn, strSQL2, Array(machineid))
If rs2.EOF Then
Response.Write("<tr><td colspan='3' class='text-center text-muted'><em>No relationships found</em></td></tr>")
Else
Do While Not rs2.EOF
Dim relationshipTypeVal, relatedMachineVal, notesVal
relationshipTypeVal = rs2("relationshiptype") & ""
relatedMachineVal = rs2("machinenumber") & ""
notesVal = rs2("relationship_notes") & ""
If notesVal = "" Then notesVal = "-"
Response.Write("<tr>")
Response.Write("<td><span class='badge badge-info'>" & Server.HTMLEncode(relationshipTypeVal) & "</span></td>")
Response.Write("<td><a href='./displaymachine.asp?machineid=" & Server.HTMLEncode(rs2("related_machineid")) & "'>" & Server.HTMLEncode(relatedMachineVal) & "</a></td>")
Response.Write("<td>" & Server.HTMLEncode(notesVal) & "</td>")
Response.Write("</tr>")
rs2.MoveNext
Loop
End If
rs2.Close
Set rs2 = Nothing
%>
</tbody>
</table>
</div>
</div>
<div class="tab-pane" id="compliance">
<h5 class="mb-3">Compliance & Security</h5>
<div class="row">
<div class="col-md-6">
<h6 class="text-uppercase mb-3"><i class="zmdi zmdi-shield-check"></i> Management & Access</h6>
<p class="mb-2"><strong>Third Party Managed:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("is_third_party_managed")) And rs("is_third_party_managed") & "" <> "" Then
Dim thirdPartyVal
thirdPartyVal = rs("is_third_party_managed") & ""
If UCase(thirdPartyVal) = "YES" Or thirdPartyVal = "Yes" Then
Response.Write("Yes")
ElseIf UCase(thirdPartyVal) = "NO" Or thirdPartyVal = "No" Then
Response.Write("No")
Else
Response.Write(Server.HTMLEncode(thirdPartyVal))
End If
Else
Response.Write("<span class='text-muted'>Not Specified</span>")
End If
%>
</p>
<p class="mb-2"><strong>Managed By:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("third_party_manager")) And rs("third_party_manager") & "" <> "" Then
Response.Write("<i class='zmdi zmdi-accounts'></i> " & Server.HTMLEncode(rs("third_party_manager") & "") & "")
Else
Response.Write("<span class='text-muted'>Not Specified</span>")
End If
%>
</p>
<p class="mb-2"><strong>Last Scan:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("scan_date")) And rs("scan_date") & "" <> "" Then
Response.Write(Server.HTMLEncode(rs("scan_date") & ""))
Else
Response.Write("<span class='text-muted'>Never Scanned</span>")
End If
%>
</p>
<p class="mb-2"><strong>Scan Result:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("scan")) And rs("scan") & "" <> "" Then
Response.Write(Server.HTMLEncode(rs("scan") & ""))
Else
Response.Write("<span class='text-muted'>N/A</span>")
End If
%>
</p>
</div>
<div class="col-md-6">
<h6 class="text-uppercase mb-3"><i class="zmdi zmdi-factory"></i> OT Asset Information</h6>
<p class="mb-2"><strong>OT Asset System:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("ot_asset_system")) And rs("ot_asset_system") & "" <> "" Then
Response.Write(Server.HTMLEncode(rs("ot_asset_system") & ""))
Else
Response.Write("<span class='text-muted'>Not Specified</span>")
End If
%>
</p>
<p class="mb-2"><strong>OT Device Type:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("ot_asset_device_type")) And rs("ot_asset_device_type") & "" <> "" Then
Response.Write(Server.HTMLEncode(rs("ot_asset_device_type") & ""))
Else
Response.Write("<span class='text-muted'>Not Specified</span>")
End If
%>
</p>
<p class="mb-2"><strong>MFT:</strong></p>
<p class="mb-3">
<%
If Not IsNull(rs("mft")) And rs("mft") & "" <> "" Then
Response.Write(Server.HTMLEncode(rs("mft") & ""))
Else
Response.Write("<span class='text-muted'>Not Specified</span>")
End If
%>
</p>
<p class="mb-2"><strong>Deployment Notes:</strong></p>
<p class="mb-3">
<%
' TEXT fields in MySQL require special handling in classic ASP
Dim deploymentNotesValue
On Error Resume Next
deploymentNotesValue = ""
If Not IsNull(rs("deployment_notes")) Then
deploymentNotesValue = rs("deployment_notes").Value
End If
On Error Goto 0
If deploymentNotesValue <> "" And Not IsNull(deploymentNotesValue) Then
Response.Write("<small>" & Server.HTMLEncode(deploymentNotesValue) & "</small>")
Else
Response.Write("<span class='text-muted'>No deployment notes</span>")
End If
%>
</p>
</div>
</div>
</div>
<div class="tab-pane" id="applications">
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Application Name</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<%
'=============================================================================
' SECURITY: Use parameterized query for installed applications
'=============================================================================
strSQL2 = "SELECT app.appname, ia.version " & _
"FROM installedapps ia " & _
"INNER JOIN applications app ON ia.appid = app.appid " & _
"WHERE ia.machineid = ? AND ia.isactive = 1 " & _
"ORDER BY app.appname ASC"
Set rs2 = ExecuteParameterizedQuery(objConn, strSQL2, Array(machineid))
If rs2.EOF Then
Response.Write("<tr><td colspan='2' class='text-center text-muted'><em>No applications installed</em></td></tr>")
Else
Do While Not rs2.EOF
Dim appNameVal, versionVal
appNameVal = rs2("appname") & ""
versionVal = rs2("version") & ""
If versionVal = "" Then versionVal = "N/A"
Response.Write("<tr>")
Response.Write("<td>" & Server.HTMLEncode(appNameVal) & "</td>")
Response.Write("<td>" & Server.HTMLEncode(versionVal) & "</td>")
Response.Write("</tr>")
rs2.MoveNext
Loop
End If
rs2.Close
Set rs2 = Nothing
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!--start overlay-->
<div class="overlay toggle-menu"></div>
<!--end overlay-->
</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-->
<!--#include file="./includes/footer.asp"-->
<!--End footer-->
<!--start color switcher-->
<!--#include file="./includes/colorswitcher.asp"-->
<!--end color switcher-->
</div><!--End wrapper-->
<%
' Clean up
rs.Close
Set rs = Nothing
objConn.Close
Set objConn = Nothing
%>
<!-- 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>
<!-- simplebar js -->
<script src="./assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="./assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="./assets/js/app-script.js"></script>
<script>
// Location link click handler
$(document).ready(function() {
$('.location-link').click(function() {
var machineid = $(this).data('machineid');
window.location.href = './shopfloor.asp?highlight=' + machineid;
});
});
</script>
</body>
</html>

View File

@@ -1,837 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
pcid = Request.Querystring("pcid")
strSQL = "SELECT pc.*,vendors.*,models.*,pc_network_interfaces.*,machines.machineid,machines.machinenumber as machine_number,machines.alias,machines.machinetypeid,machinetypes.machinetype,machines.businessunitid,businessunits.businessunit,machines.printerid,printers.printerwindowsname,pctype.typename,functionalaccounts.functionalaccount,functionalaccounts.description as functionalaccount_description " & _
"FROM pc " & _
"LEFT JOIN models ON pc.modelnumberid=models.modelnumberid " & _
"LEFT JOIN vendors ON models.vendorid=vendors.vendorid " & _
"LEFT JOIN pc_network_interfaces ON pc_network_interfaces.pcid=pc.pcid " & _
"LEFT JOIN machines ON pc.machinenumber = machines.machinenumber " & _
"LEFT JOIN machinetypes ON machines.machinetypeid = machinetypes.machinetypeid " & _
"LEFT JOIN businessunits ON machines.businessunitid = businessunits.businessunitid " & _
"LEFT JOIN printers ON machines.printerid = printers.printerid " & _
"LEFT JOIN pctype ON pc.pctypeid = pctype.pctypeid " & _
"LEFT JOIN functionalaccounts ON pctype.functionalaccountid = functionalaccounts.functionalaccountid " & _
"WHERE pc.isactive=1 AND pc.pcid="&pcid
'response.write (strSQL)
'response.end
set rs = objconn.Execute(strSQL)
' Check if PC exists
IF rs.EOF THEN
objConn.Close
Response.Redirect("displaypcs.asp")
Response.End
END IF
' Get machine ID if it exists
IF NOT rs.EOF THEN
IF NOT IsNull(rs("machineid")) THEN
machineid = rs("machineid")
ELSE
machineid = 0
END IF
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">
<div class="row mt-3">
<div class="col-lg-4">
<div class="card profile-card-2">
<div class="card-img-block">
<img class="img-fluid" src="./images/computers/<%Response.Write(rs("image"))%>" alt="Card image cap">
</div>
<div class="card-body pt-5">
<img src="./images/computers/<%Response.Write(rs("image"))%>" alt="profile-image" class="profile">
<h5 class="card-title"><%Response.Write(rs("vendor"))%></h5>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<ul class="nav nav-tabs nav-tabs-primary top-icon nav-justified">
<li class="nav-item">
<a href="javascript:void();" data-target="#profile" data-toggle="pill" class="nav-link active"><i class="icon-wrench"></i> <span class="hidden-xs">Settings</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#applications" data-toggle="pill" class="nav-link"><i class="zmdi zmdi-apps"></i> <span class="hidden-xs">Applications</span></a>
</li>
<li class="nav-item">
<a href="javascript:void();" data-target="#edit" data-toggle="pill" class="nav-link"><i class="icon-note"></i> <span class="hidden-xs">Edit</span></a>
</li>
</ul>
<div class="tab-content p-3">
<div class="tab-pane active" id="profile">
<h5 class="mb-3">Configuration</h5>
<div class="row">
<div class="col-md-3">
<p class="mb-2"><strong>Vendor:</strong></p>
<p class="mb-2"><strong>Model:</strong></p>
<p class="mb-2"><strong>Serial:</strong></p>
<p class="mb-2"><strong>Hostname:</strong></p>
<p class="mb-2"><strong>Location:</strong></p>
<p class="mb-2"><strong>IP:</strong></p>
<p class="mb-2"><strong>Functional Account:</strong></p>
</div>
<div class="col-md-5">
<p class="mb-2"><%Response.Write(rs("vendor"))%></p>
<p class="mb-2"><%Response.Write(rs("modelnumber"))%></p>
<p class="mb-2"><%Response.Write(rs("serialnumber"))%></p>
<p class="mb-2"><a href="com.realvnc.vncviewer.connect://<%Response.Write(rs("ipaddress"))%>:5900" title="VNC To Desktop"><%Response.Write(rs("hostname"))%></a></p>
<p class="mb-2">
<%
IF machineid > 0 THEN
Dim locationDisplay
' Use alias if available, otherwise machine_number
IF NOT IsNull(rs("alias")) AND rs("alias") <> "" THEN
locationDisplay = rs("alias")
ELSE
locationDisplay = rs("machine_number")
END IF
Response.Write("<span class='location-link' data-machineid='" & machineid & "' style='cursor:pointer; color:#007bff;'><i class='zmdi zmdi-pin' style='margin-right:4px;'></i>" & locationDisplay & "</span>")
ELSE
Response.Write("<span class='text-muted'>Not assigned</span>")
END IF
%>
</p>
<p class="mb-2">
<%
IF NOT IsNull(rs("ipaddress")) AND rs("ipaddress") <> "" THEN
Response.Write(rs("ipaddress"))
ELSE
Response.Write("<span class='text-muted'>N/A</span>")
END IF
%>
</p>
<p class="mb-2">
<%
IF NOT IsNull(rs("functionalaccount")) AND rs("functionalaccount") <> "" THEN
Dim accountDisplay, descDisplay, extractedAccount
Dim pcTypeName
pcTypeName = ""
IF NOT IsNull(rs("typename")) THEN
pcTypeName = UCase(Trim(rs("typename") & ""))
END IF
' Check if loggedinuser exists and should be used
Dim useLoggedInUser
useLoggedInUser = False
IF NOT IsNull(rs("LoggedInUser")) AND rs("LoggedInUser") <> "" THEN
' Use loggedinuser for Standard, Engineer, or TBD types
IF pcTypeName = "STANDARD" OR pcTypeName = "ENGINEER" OR rs("functionalaccount") = "TBD" OR rs("functionalaccount") = "1" THEN
useLoggedInUser = True
END IF
END IF
IF useLoggedInUser THEN
accountDisplay = rs("LoggedInUser")
' Try to extract the account number from loggedinuser (format: lg[account]sd)
Dim loggedUser
loggedUser = rs("LoggedInUser")
IF Left(loggedUser, 2) = "lg" AND Right(loggedUser, 2) = "sd" AND Len(loggedUser) > 4 THEN
extractedAccount = Mid(loggedUser, 3, Len(loggedUser) - 4)
ELSE
extractedAccount = ""
END IF
ELSE
accountDisplay = "lg" & rs("functionalaccount") & "sd"
extractedAccount = ""
END IF
' Determine what description to show
Dim descField
descField = ""
' If showing plain SSO (not lg[account]sd format), label it as "SSO"
IF useLoggedInUser AND extractedAccount = "" THEN
descField = "SSO"
' If we extracted an account from loggedinuser, look up its description
ELSEIF extractedAccount <> "" THEN
Dim rsDesc, sqlDesc
sqlDesc = "SELECT description FROM functionalaccounts WHERE functionalaccount = '" & Replace(extractedAccount, "'", "''") & "' AND isactive = 1"
Set rsDesc = objConn.Execute(sqlDesc)
IF NOT rsDesc.EOF THEN
IF NOT IsNull(rsDesc("description")) AND rsDesc("description") <> "" THEN
descField = rsDesc("description") & ""
END IF
END IF
rsDesc.Close
Set rsDesc = Nothing
' Otherwise use functional account description from the query
ELSE
On Error Resume Next
descField = rs("functionalaccount_description") & ""
If descField = "" Then
descField = rs("description") & ""
End If
On Error Goto 0
END IF
IF descField <> "" AND NOT IsNull(descField) THEN
descDisplay = " - " & descField
ELSE
descDisplay = ""
END IF
Response.Write(accountDisplay & descDisplay)
ELSE
Response.Write("<span class='text-muted'>N/A</span>")
END IF
%>
</p>
</div>
</div>
<hr style="margin:20px 0;">
<h5 class="mb-3">Warranty Information</h5>
<div class="row">
<div class="col-md-3">
<p class="mb-2"><strong>Status:</strong></p>
<p class="mb-2"><strong>End Date:</strong></p>
<p class="mb-2"><strong>Days Remaining:</strong></p>
<p class="mb-2"><strong>Service Level:</strong></p>
<p class="mb-2"><strong>Last Checked:</strong></p>
</div>
<div class="col-md-9">
<%
Dim warrantyStatus, warrantyEndDate, warrantyDaysRemaining, warrantyServiceLevel, warrantyLastChecked
Dim warrantyStatusClass, warrantyBadge
warrantyStatus = rs("warrantystatus")
warrantyEndDate = rs("warrantyenddate")
warrantyDaysRemaining = rs("warrantydaysremaining")
warrantyServiceLevel = rs("warrantyservicelevel")
warrantyLastChecked = rs("warrantylastchecked")
' Determine warranty status badge
If IsNull(warrantyStatus) Or warrantyStatus = "" Then
warrantyBadge = "<span class='badge badge-secondary'>Unknown</span>"
ElseIf LCase(warrantyStatus) = "active" Then
If Not IsNull(warrantyDaysRemaining) And IsNumeric(warrantyDaysRemaining) Then
If warrantyDaysRemaining < 30 Then
warrantyBadge = "<span class='badge badge-warning'>Expiring Soon</span>"
Else
warrantyBadge = "<span class='badge badge-success'>Active</span>"
End If
Else
warrantyBadge = "<span class='badge badge-success'>Active</span>"
End If
ElseIf LCase(warrantyStatus) = "expired" Then
warrantyBadge = "<span class='badge badge-danger'>Expired</span>"
Else
warrantyBadge = "<span class='badge badge-info'>" & warrantyStatus & "</span>"
End If
%>
<p class="mb-2"><%Response.Write(warrantyBadge)%></p>
<p class="mb-2">
<%
If Not IsNull(warrantyEndDate) And warrantyEndDate <> "" And warrantyEndDate <> "0000-00-00" Then
Response.Write(warrantyEndDate)
Else
Response.Write("<span class='text-muted'>Not available</span>")
End If
%>
</p>
<p class="mb-2">
<%
If Not IsNull(warrantyDaysRemaining) And IsNumeric(warrantyDaysRemaining) Then
If warrantyDaysRemaining < 0 Then
Response.Write("<span class='text-danger'>" & Abs(warrantyDaysRemaining) & " days overdue</span>")
ElseIf warrantyDaysRemaining < 30 Then
Response.Write("<span class='text-warning'>" & warrantyDaysRemaining & " days</span>")
Else
Response.Write(warrantyDaysRemaining & " days")
End If
Else
Response.Write("<span class='text-muted'>Not available</span>")
End If
%>
</p>
<p class="mb-2">
<%
If Not IsNull(warrantyServiceLevel) And warrantyServiceLevel <> "" Then
Response.Write(warrantyServiceLevel)
Else
Response.Write("<span class='text-muted'>Not available</span>")
End If
%>
</p>
<p class="mb-2">
<%
If Not IsNull(warrantyLastChecked) And warrantyLastChecked <> "" Then
Response.Write(warrantyLastChecked)
Else
Response.Write("<span class='text-muted'>Never checked</span>")
End If
%>
</p>
</div>
</div>
</div>
<div class="tab-pane" id="applications">
<div class="table-responsive">
<table class="table table-hover table-striped">
<tbody>
<%
IF machineid > 0 THEN
strSQL2 = "SELECT * FROM installedapps,applications WHERE installedapps.appid=applications.appid AND installedapps.isactive=1 AND " &_
"installedapps.machineid=" & machineid & " ORDER BY appname ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<tr><td><span class='float-left font-weight-bold'>"&rs2("appname")&"</span></td></tr>")
rs2.movenext
wend
ELSE
Response.Write("<tr><td class='text-muted'>No machine assigned - cannot display installed applications</td></tr>")
END IF
%>
</tbody>
</table>
</div>
</div>
<div class="tab-pane" id="edit">
<form method="post" action="./updatepc_direct.asp" id="pcEditForm">
<input type="hidden" name="pcid" value="<%=pcid%>">
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Vendor:</label>
<div class="col-lg-9">
<div class="input-group">
<select name="vendorid" id="pcvendorid" class="form-control">
<option value='<%response.write(rs("vendorid"))%>'><%Response.Write(rs("vendor"))%></option>
<option value="new">+ Add New Vendor</option>
<%
strSQL2 = "Select * from vendors where ispc=1 and isactive=1 order by vendor ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<option value='"&rs2("vendorid")&"'>"&rs2("vendor")&"</option>")
rs2.movenext
wend
%>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addPCVendorBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
</div>
</div>
<!-- New Vendor Fields (hidden by default) -->
<div id="newPCVendorSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #28a745; background-color:rgba(40,167,69,0.05); margin-bottom:15px;">
<h6 style="color:#28a745; margin-bottom:15px;"><i class="zmdi zmdi-plus-circle"></i> New PC Vendor</h6>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Vendor Name:</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="newpcvendorname" name="newpcvendorname" placeholder="e.g., Dell, HP, Lenovo">
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Model</label>
<div class="col-lg-9">
<div class="input-group">
<select name="modelid" id="pcmodelid" class="form-control">
<option value='<%response.write(rs("modelnumberid"))%>'><%Response.Write(rs("modelnumber"))%></option>
<option value="new">+ Add New Model</option>
<%
strSQL2 = "Select * from vendors,models WHERE " & _
"models.vendorid = vendors.vendorid AND " & _
"vendors.ispc=1 AND models.isactive=1 ORDER BY modelnumber ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<option value='"&rs2("modelnumberid")&"'>"&rs2("modelnumber")&"</option>")
rs2.movenext
wend
%>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-info" id="addPCModelBtn">
<i class="zmdi zmdi-plus"></i> New
</button>
</div>
</div>
</div>
</div>
<!-- New Model Fields (hidden by default) -->
<div id="newPCModelSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #007bff; background-color:rgba(0,123,255,0.05); margin-bottom:15px;">
<h6 style="color:#007bff; margin-bottom:15px;"><i class="zmdi zmdi-plus-circle"></i> New PC Model</h6>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Model Number:</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="newpcmodelnumber" name="newpcmodelnumber" placeholder="e.g., OptiPlex 7090">
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Select Vendor:</label>
<div class="col-lg-9">
<select class="form-control" id="newpcmodelvendorid" name="newpcmodelvendorid">
<option value="">-- Select Vendor First --</option>
<%
Dim rs3, strSQL3
strSQL3 = "Select * from vendors where ispc=1 and isactive=1 order by vendor ASC"
set rs3 = objconn.Execute(strSQL3)
while not rs3.eof
Response.Write("<option value='"&rs3("vendorid")&"'>"&rs3("vendor")&"</option>")
rs3.movenext
wend
%>
</select>
<small class="form-text text-muted">Select existing vendor or create new one above</small>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Machine:</label>
<div class="col-lg-9">
<select name="machinenumber" class="form-control">
<%
IF NOT IsNull(rs("machine_number")) AND rs("machine_number") <> "" THEN
IF NOT IsNull(rs("alias")) AND rs("alias") <> "" THEN
Response.Write("<option value='" & rs("machine_number") & "'>" & rs("alias") & " (" & rs("machine_number") & ")</option>")
ELSE
Response.Write("<option value='" & rs("machine_number") & "'>" & rs("machine_number") & "</option>")
END IF
ELSE
Response.Write("<option value=''>-- Not Assigned --</option>")
END IF
strSQL2 = "SELECT machinenumber, alias FROM machines WHERE isactive=1 ORDER BY machinenumber ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
IF NOT IsNull(rs2("alias")) AND rs2("alias") <> "" THEN
Response.Write("<option value='" & rs2("machinenumber") & "'>" & rs2("alias") & " (" & rs2("machinenumber") & ")</option>")
ELSE
Response.Write("<option value='" & rs2("machinenumber") & "'>" & rs2("machinenumber") & "</option>")
END IF
rs2.movenext
wend
%>
</select>
</div>
</div>
<!-- Function, BU, and Printer fields commented out - they modify machines table, not pc table -->
<!--
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Function:</label>
<div class="col-lg-9">
<select name="machinetypeid" class="form-control" disabled>
<option value='<%response.write(rs("machinetypeid"))%>'><%Response.Write(rs("machinetype"))%></option>
<%
strSQL2 = "Select * FROM machinetypes WHERE machinetypes.isactive=1 ORDER BY machinetype ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<option value='"&rs2("machinetypeid")&"'>"&rs2("machinetype")&"</option>")
rs2.movenext
wend
%>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">BU:</label>
<div class="col-lg-9">
<select name="businessunitid" class="form-control" disabled>
<option value='<%response.write(rs("businessunitid"))%>'><%Response.Write(rs("businessunit"))%></option>
<%
strSQL2 = "Select * FROM businessunits WHERE businessunits.isactive=1 ORDER BY businessunit ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<option value='"&rs2("businessunitid")&"'>"&rs2("businessunit")&"</option>")
rs2.movenext
wend
%>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label">Printer:</label>
<div class="col-lg-9">
<select name="printerid" class="form-control" disabled>
<option value='<%response.write(rs("printerid"))%>'><%Response.Write(rs("printerwindowsname"))%></option>
<%
strSQL2 = "Select * FROM printers,models WHERE printers.modelid=models.modelnumberid AND printers.isactive=1 ORDER BY printerwindowsname ASC"
set rs2 = objconn.Execute(strSQL2)
while not rs2.eof
Response.Write("<option value='"&rs2("printerid")&"'>"&rs2("printerwindowsname")&" - " &rs2("modelnumber")&"</option>")
rs2.movenext
wend
%>
</select>
</div>
</div>
-->
<div class="form-group row">
<label class="col-lg-3 col-form-label form-control-label"></label>
<div class="col-lg-9">
<input type="reset" class="btn btn-secondary" value="Cancel">
<input type="submit" class="btn btn-primary" value="Save Changes">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!--start overlay-->
<div class="overlay toggle-menu"></div>
<!--end overlay-->
</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">
<div class="container">
<div class="text-center">
</div>
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Location map popup modal -->
<style>
.content-wrapper {
padding-bottom: 80px;
}
.footer {
position: relative !important;
bottom: auto !important;
}
/* Theme-specific styling for better visibility on all themes */
body.bg-theme1 .location-link,
body.bg-theme2 .location-link,
body.bg-theme3 .location-link,
body.bg-theme4 .location-link,
body.bg-theme5 .location-link,
body.bg-theme6 .location-link,
body.bg-theme7 .location-link,
body.bg-theme8 .location-link,
body.bg-theme9 .location-link,
body.bg-theme10 .location-link,
body.bg-theme11 .location-link,
body.bg-theme12 .location-link,
body.bg-theme13 .location-link,
body.bg-theme14 .location-link,
body.bg-theme15 .location-link,
body.bg-theme16 .location-link {
color: #fff !important;
}
.location-link:hover {
text-decoration: underline;
}
/* Theme-specific popup header colors */
body.bg-theme1 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme2 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme3 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme4 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme5 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme6 .location-popup-header { background: linear-gradient(45deg, #3a3a3a, #4a4a4a); }
body.bg-theme7 .location-popup-header { background: linear-gradient(45deg, #0c675e, #069e90); }
body.bg-theme8 .location-popup-header { background: linear-gradient(45deg, #a52a04, #4f5f58); }
body.bg-theme9 .location-popup-header { background: linear-gradient(45deg, #29323c, #485563); }
body.bg-theme10 .location-popup-header { background: linear-gradient(45deg, #795548, #945c48); }
body.bg-theme11 .location-popup-header { background: linear-gradient(45deg, #1565C0, #1E88E5); }
body.bg-theme12 .location-popup-header { background: linear-gradient(45deg, #65379b, #886aea); }
body.bg-theme13 .location-popup-header { background: linear-gradient(45deg, #ff5447, #f1076f); }
body.bg-theme14 .location-popup-header { background: linear-gradient(45deg, #08a50e, #69bb03); }
body.bg-theme15 .location-popup-header { background: linear-gradient(45deg, #6a11cb, #2575fc); }
body.bg-theme16 .location-popup-header { background: linear-gradient(45deg, #6a11cb, #cccccc); }
.location-popup-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9998;
display: none;
}
.location-popup {
position: fixed;
background: #1f1f1f;
border: 2px solid #667eea;
border-radius: 8px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
max-width: 90vw;
max-height: 90vh;
}
.location-popup-header {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 15px;
border-radius: 6px 6px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.location-popup-close {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
}
.location-popup-close:hover {
background: rgba(255, 255, 255, 0.2);
}
.location-popup-body {
padding: 0;
background: #2a2a2a;
}
.location-popup iframe {
display: block;
border: none;
border-radius: 0 0 6px 6px;
}
</style>
<script>
$(document).ready(function() {
console.log('Location hover script loaded');
console.log('Found location links:', $('.location-link').length);
// Create popup elements
var $overlay = $('<div class="location-popup-overlay"></div>').appendTo('body');
var $popup = $('<div class="location-popup"></div>').appendTo('body');
$popup.html(
'<div class="location-popup-header">' +
'<h6 style="margin:0; font-size:16px;"><i class="zmdi zmdi-pin"></i> <span class="location-title">Loading...</span></h6>' +
'<button class="location-popup-close" title="Close (Esc)">&times;</button>' +
'</div>' +
'<div class="location-popup-body">' +
'<iframe src="" width="440" height="340"></iframe>' +
'</div>'
);
var $iframe = $popup.find('iframe');
var $title = $popup.find('.location-title');
var currentMachineId = null;
// Function to show popup with smart positioning
function showLocationPopup(machineId, locationName, mouseEvent) {
if (currentMachineId === machineId && $popup.is(':visible')) {
return;
}
currentMachineId = machineId;
$title.text(locationName);
$iframe.attr('src', './displaylocation.asp?machineid=' + machineId);
// Position popup using viewport coordinates
var popupWidth = 440;
var popupHeight = 400;
var mouseX = mouseEvent.clientX;
var mouseY = mouseEvent.clientY;
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var left, top;
// Horizontal positioning
left = mouseX + 10;
if (left + popupWidth > windowWidth - 10) {
left = mouseX - popupWidth - 10;
}
if (left < 10) {
left = 10;
}
// Vertical positioning
var spaceBelow = windowHeight - mouseY;
var spaceAbove = mouseY;
if (spaceBelow >= popupHeight + 20) {
top = mouseY + 10;
} else if (spaceAbove >= popupHeight + 20) {
top = mouseY - popupHeight - 10;
} else {
top = Math.max(10, (windowHeight - popupHeight) / 2);
}
if (top < 10) {
top = 10;
}
if (top + popupHeight > windowHeight - 10) {
top = windowHeight - popupHeight - 10;
}
$popup.css({
left: left + 'px',
top: top + 'px',
display: 'block'
});
$overlay.fadeIn(200);
$popup.fadeIn(200);
}
function hideLocationPopup() {
$overlay.fadeOut(200);
$popup.fadeOut(200);
setTimeout(function() {
$iframe.attr('src', '');
currentMachineId = null;
}, 200);
}
var hoverTimer = null;
$('.location-link').on('mouseenter', function(e) {
console.log('Mouse entered location link');
var $link = $(this);
var machineId = $link.data('machineid');
var locationName = $link.text().trim();
var mouseEvent = e;
console.log('Machine ID:', machineId, 'Location:', locationName);
if (hoverTimer) {
clearTimeout(hoverTimer);
}
hoverTimer = setTimeout(function() {
console.log('Showing popup after 300ms delay');
showLocationPopup(machineId, locationName, mouseEvent);
}, 300);
});
$('.location-link').on('mouseleave', function() {
if (hoverTimer) {
clearTimeout(hoverTimer);
hoverTimer = null;
}
});
$popup.on('mouseenter', function() {
// Keep popup open when hovering over it
});
$popup.on('mouseleave', function() {
hideLocationPopup();
});
$overlay.on('click', hideLocationPopup);
$popup.find('.location-popup-close').on('click', hideLocationPopup);
$(document).on('keydown', function(e) {
if (e.key === 'Escape' && $popup.is(':visible')) {
hideLocationPopup();
}
});
// PC Vendor dropdown change handler
$('#pcvendorid').on('change', function() {
if ($(this).val() === 'new') {
$('#newPCVendorSection').slideDown();
} else {
$('#newPCVendorSection').slideUp();
}
});
// PC Vendor "+ New" button
$('#addPCVendorBtn').on('click', function() {
$('#pcvendorid').val('new').trigger('change');
});
// PC Model dropdown change handler
$('#pcmodelid').on('change', function() {
if ($(this).val() === 'new') {
$('#newPCModelSection').slideDown();
} else {
$('#newPCModelSection').slideUp();
}
});
// PC Model "+ New" button
$('#addPCModelBtn').on('click', function() {
$('#pcmodelid').val('new').trigger('change');
});
// When creating new vendor, automatically sync to model's vendor dropdown
$('#pcvendorid').on('change', function() {
var selectedVendorId = $(this).val();
if (selectedVendorId !== 'new' && selectedVendorId !== '') {
// Update the model vendor dropdown to match
$('#newpcmodelvendorid').val(selectedVendorId);
}
});
});
</script>
</body>
</html>
<% objConn.Close %>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,195 +0,0 @@
<%
' Easter Eggs for special SSOs
Dim showEasterEgg, easterEggType
showEasterEgg = False
easterEggType = ""
On Error Resume Next
IF IsNumeric(sso) THEN
IF CLng(sso) = 570005354 THEN
showEasterEgg = True
easterEggType = "developer"
ELSEIF CLng(sso) = 503432774 THEN
showEasterEgg = True
easterEggType = "documentation"
END IF
END IF
On Error Goto 0
IF showEasterEgg AND easterEggType = "developer" THEN
%>
<div class="card-body border-top border-light">
<div class="text-center mb-3">
<h6 class="text-warning"><i class="zmdi zmdi-star"></i> ACHIEVEMENT UNLOCKED <i class="zmdi zmdi-star"></i></h6>
<small class="text-muted">Secret Developer Stats</small>
</div>
<div class="media align-items-center">
<div><i class="zmdi zmdi-coffee" style="font-size: 40px; color: #8B4513;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Caffeine Consumption<span class="float-right">147%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-warning" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-bug" style="font-size: 40px; color: #28a745;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Bug Fixing Speed<span class="float-right">95%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-success" style="width:95%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-code" style="font-size: 40px; color: #17a2b8;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Google-Fu<span class="float-right">99%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-info" style="width:99%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-storage" style="font-size: 40px; color: #007bff;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Database Tinkering<span class="float-right">88%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-primary" style="width:88%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-fire" style="font-size: 40px; color: #dc3545;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Debugging<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-danger" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-shield-check" style="font-size: 40px; color: #ffc107;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Production Deployment Courage<span class="float-right">73%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-warning" style="width:73%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="text-center mt-3">
<span class="badge badge-danger m-1">Legacy Code Archaeologist</span>
<span class="badge badge-info m-1">Documentation Writer (Rare!)</span>
</div>
</div>
<%
ELSEIF showEasterEgg AND easterEggType = "documentation" THEN
%>
<div class="card-body border-top border-light">
<div class="text-center mb-3">
<h6 class="text-primary"><i class="zmdi zmdi-star"></i> LEGEND STATUS UNLOCKED <i class="zmdi zmdi-star"></i></h6>
<small class="text-muted">The Foundation Builder</small>
</div>
<div class="media align-items-center">
<div><i class="zmdi zmdi-book" style="font-size: 40px; color: #007bff;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Documentation Mastery<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-primary" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-assignment-check" style="font-size: 40px; color: #28a745;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Playbook Creation<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-success" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-wrench" style="font-size: 40px; color: #17a2b8;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Shopfloor Support<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-info" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-settings" style="font-size: 40px; color: #6c757d;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>CNC Procedure Expertise<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-secondary" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-time" style="font-size: 40px; color: #ffc107;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Reliability<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-warning" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="media align-items-center">
<div><i class="zmdi zmdi-flash" style="font-size: 40px; color: #dc3545;"></i></div>
<div class="media-body text-left ml-3">
<div class="progress-wrapper">
<p>Work Ethic<span class="float-right">100%</span></p>
<div class="progress" style="height: 5px;">
<div class="progress-bar bg-danger" style="width:100%"></div>
</div>
</div>
</div>
</div>
<hr>
<div class="text-center mt-3">
<span class="badge badge-primary m-1">Knowledge Architect</span>
<span class="badge badge-success m-1">Procedure Master</span>
<span class="badge badge-info m-1">Shopfloor Hero</span>
</div>
<div class="text-center mt-3">
<p class="text-muted mb-1"><i>"The procedures you built will keep this place running long after you're gone."</i></p>
<small class="text-muted">Thank you for the heavy lifting. You built the foundation we all stand on.</small>
</div>
</div>
<%
ELSE
%>

View File

@@ -1,187 +0,0 @@
<%@ Language=VBScript %>
<%
Option Explicit
%>
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/encoding.asp"-->
<!--#include file="./includes/error_handler.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
<%
'=============================================================================
' FILE: editapplication.asp
' PURPOSE: Update an existing application record
'
' PARAMETERS:
' appid (Form, Required) - Integer ID of application to update
' appname (Form, Required) - Application name (1-50 chars)
' appdescription (Form, Optional) - Description (max 255 chars)
' supportteamid (Form, Required) - Support team ID
' applicationnotes (Form, Optional) - Notes (max 512 chars)
' installpath (Form, Optional) - Installation path/URL (max 255 chars)
' documentationpath (Form, Optional) - Documentation path/URL (max 512 chars)
' image (Form, Optional) - Image filename (max 255 chars)
' isinstallable, isactive, ishidden, isprinter, islicenced (Form, Optional) - Checkboxes (0/1)
'
' SECURITY:
' - Uses parameterized queries
' - Validates all inputs
' - HTML encodes outputs
'
' AUTHOR: Claude Code
' CREATED: 2025-10-12
'=============================================================================
'-----------------------------------------------------------------------------
' INITIALIZATION
'-----------------------------------------------------------------------------
Call InitializeErrorHandling("editapplication.asp")
' Get and validate required inputs
Dim appid, appname, appdescription, supportteamid
Dim applicationnotes, installpath, documentationpath, image
Dim isinstallable, isactive, ishidden, isprinter, islicenced
appid = Trim(Request.Form("appid"))
appname = Trim(Request.Form("appname"))
appdescription = Trim(Request.Form("appdescription"))
supportteamid = Trim(Request.Form("supportteamid"))
applicationnotes = Trim(Request.Form("applicationnotes"))
installpath = Trim(Request.Form("installpath"))
documentationpath = Trim(Request.Form("documentationpath"))
image = Trim(Request.Form("image"))
' Checkboxes - convert to bit values
If Request.Form("isinstallable") = "1" Then
isinstallable = 1
Else
isinstallable = 0
End If
If Request.Form("isactive") = "1" Then
isactive = 1
Else
isactive = 0
End If
If Request.Form("ishidden") = "1" Then
ishidden = 1
Else
ishidden = 0
End If
If Request.Form("isprinter") = "1" Then
isprinter = 1
Else
isprinter = 0
End If
If Request.Form("islicenced") = "1" Then
islicenced = 1
Else
islicenced = 0
End If
'-----------------------------------------------------------------------------
' VALIDATE INPUTS
'-----------------------------------------------------------------------------
' Validate appid
If Not ValidateID(appid) Then
Call HandleValidationError("displayapplications.asp", "INVALID_ID")
End If
' Verify the application exists - DISABLED DUE TO CACHING ISSUE
' If Not RecordExists(objConn, "applications", "appid", appid) Then
' Call HandleValidationError("displayapplications.asp", "NOT_FOUND")
' End If
' Validate appname (required, 1-50 chars)
If Len(appname) < 1 Or Len(appname) > 50 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
' Validate supportteamid
If Not ValidateID(supportteamid) Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_ID")
End If
' Verify support team exists - DISABLED DUE TO CACHING ISSUE
' If Not RecordExists(objConn, "supportteams", "supporteamid", supportteamid) Then
' Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
' End If
' Validate field lengths
If Len(appdescription) > 255 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
If Len(applicationnotes) > 512 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
If Len(installpath) > 255 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
If Len(documentationpath) > 512 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
If Len(image) > 255 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
'-----------------------------------------------------------------------------
' DATABASE UPDATE
'-----------------------------------------------------------------------------
Dim strSQL
strSQL = "UPDATE applications SET " & _
"appname = ?, " & _
"appdescription = ?, " & _
"supportteamid = ?, " & _
"applicationnotes = ?, " & _
"installpath = ?, " & _
"documentationpath = ?, " & _
"image = ?, " & _
"isinstallable = ?, " & _
"isactive = ?, " & _
"ishidden = ?, " & _
"isprinter = ?, " & _
"islicenced = ? " & _
"WHERE appid = ?"
Dim recordsAffected
recordsAffected = ExecuteParameterizedUpdate(objConn, strSQL, Array( _
appname, _
appdescription, _
supportteamid, _
applicationnotes, _
installpath, _
documentationpath, _
image, _
isinstallable, _
isactive, _
ishidden, _
isprinter, _
islicenced, _
appid _
))
Call CheckForErrors()
'-----------------------------------------------------------------------------
' CLEANUP AND REDIRECT
'-----------------------------------------------------------------------------
Call CleanupResources()
If recordsAffected > 0 Then
Response.Redirect("displayapplication.asp?appid=" & Server.URLEncode(appid))
Else
Response.Write("<html><body>")
Response.Write("<h3>Error: No records were updated.</h3>")
Response.Write("<p><a href='displayapplication.asp?appid=" & Server.HTMLEncode(appid) & "'>Go Back</a></p>")
Response.Write("</body></html>")
End If
%>

View File

@@ -1,221 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get all form data
Dim appid, appname, appdescription, supportteamid
Dim applicationnotes, installpath, applicationlink, documentationpath, image
Dim isinstallable, isactive, ishidden, isprinter, islicenced
Dim newsupportteamname, newsupportteamurl, newappownerid
appid = Request.Form("appid")
appname = Trim(Request.Form("appname"))
appdescription = Trim(Request.Form("appdescription"))
supportteamid = Trim(Request.Form("supportteamid"))
applicationnotes = Trim(Request.Form("applicationnotes"))
installpath = Trim(Request.Form("installpath"))
applicationlink = Trim(Request.Form("applicationlink"))
documentationpath = Trim(Request.Form("documentationpath"))
image = Trim(Request.Form("image"))
' New support team fields
newsupportteamname = Trim(Request.Form("newsupportteamname"))
newsupportteamurl = Trim(Request.Form("newsupportteamurl"))
newappownerid = Trim(Request.Form("newappownerid"))
' Checkboxes
If Request.Form("isinstallable") = "1" Then isinstallable = 1 Else isinstallable = 0
If Request.Form("isactive") = "1" Then isactive = 1 Else isactive = 0
If Request.Form("ishidden") = "1" Then ishidden = 1 Else ishidden = 0
If Request.Form("isprinter") = "1" Then isprinter = 1 Else isprinter = 0
If Request.Form("islicenced") = "1" Then islicenced = 1 Else islicenced = 0
' Check if we need to create a new support team first
If supportteamid = "new" Then
If newsupportteamname = "" Then
Response.Write("<div class='alert alert-danger'>Error: Support team name is required.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newsupportteamname) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Support team name too long.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes for support team name and URL
Dim escapedTeamName, escapedTeamUrl
escapedTeamName = Replace(newsupportteamname, "'", "''")
escapedTeamUrl = Replace(newsupportteamurl, "'", "''")
' Check if support team already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM supportteams WHERE LOWER(teamname) = LOWER('" & escapedTeamName & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck.EOF Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Database query failed.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Support team '" & Server.HTMLEncode(newsupportteamname) & "' already exists.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Check if we need to create a new app owner first (nested creation)
If newappownerid = "new" Then
Dim newappownername, newappownersso
newappownername = Trim(Request.Form("newappownername"))
newappownersso = Trim(Request.Form("newappownersso"))
If newappownername = "" Or newappownersso = "" Then
Response.Write("<div class='alert alert-danger'>Error: App owner name and SSO are required.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newappownername) > 50 Or Len(newappownersso) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: App owner name or SSO too long.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes
Dim escapedOwnerName, escapedSSO
escapedOwnerName = Replace(newappownername, "'", "''")
escapedSSO = Replace(newappownersso, "'", "''")
' Check if app owner already exists
checkSQL = "SELECT COUNT(*) as cnt FROM appowners WHERE LOWER(appowner) = LOWER('" & escapedOwnerName & "') OR LOWER(sso) = LOWER('" & escapedSSO & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck.EOF Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Database query failed (app owner check).</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: App owner with this name or SSO already exists.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Insert new app owner
Dim ownerSQL
ownerSQL = "INSERT INTO appowners (appowner, sso, isactive) VALUES ('" & escapedOwnerName & "', '" & escapedSSO & "', 1)"
On Error Resume Next
objConn.Execute ownerSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating app owner: " & Err.Description & "</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new app owner ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newappownerid = rsCheck("newid")
rsCheck.Close
Else
' Validate existing app owner ID (only if not empty and not "new")
If newappownerid <> "" And newappownerid <> "new" Then
If Not IsNumeric(newappownerid) Or CLng(newappownerid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid app owner.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
End If
End If
' Insert new support team
Dim teamSQL
teamSQL = "INSERT INTO supportteams (teamname, teamurl, appownerid, isactive) VALUES ('" & escapedTeamName & "', '" & escapedTeamUrl & "', " & newappownerid & ", 1)"
On Error Resume Next
objConn.Execute teamSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating support team: " & Err.Description & "</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new support team ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
supportteamid = rsCheck("newid")
rsCheck.Close
Else
' Validate existing support team ID (only if not empty and not "new")
If supportteamid <> "" And supportteamid <> "new" Then
If Not IsNumeric(supportteamid) Or CLng(supportteamid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid support team ID.</div>")
Response.Write("<a href='displayapplication.asp?appid=" & appid & "'>Go back</a>")
objConn.Close
Response.End
End If
End If
End If
' Escape backslashes and single quotes for SQL
' Must escape backslashes FIRST, then quotes
appname = Replace(appname, "\", "\\")
appname = Replace(appname, "'", "''")
appdescription = Replace(appdescription, "\", "\\")
appdescription = Replace(appdescription, "'", "''")
applicationnotes = Replace(applicationnotes, "\", "\\")
applicationnotes = Replace(applicationnotes, "'", "''")
installpath = Replace(installpath, "\", "\\")
installpath = Replace(installpath, "'", "''")
applicationlink = Replace(applicationlink, "\", "\\")
applicationlink = Replace(applicationlink, "'", "''")
documentationpath = Replace(documentationpath, "\", "\\")
documentationpath = Replace(documentationpath, "'", "''")
image = Replace(image, "\", "\\")
image = Replace(image, "'", "''")
' Build UPDATE statement
Dim strSQL
strSQL = "UPDATE applications SET " & _
"appname = '" & appname & "', " & _
"appdescription = '" & appdescription & "', " & _
"supportteamid = " & supportteamid & ", " & _
"applicationnotes = '" & applicationnotes & "', " & _
"installpath = '" & installpath & "', " & _
"applicationlink = '" & applicationlink & "', " & _
"documentationpath = '" & documentationpath & "', " & _
"image = '" & image & "', " & _
"isinstallable = " & isinstallable & ", " & _
"isactive = " & isactive & ", " & _
"ishidden = " & ishidden & ", " & _
"isprinter = " & isprinter & ", " & _
"islicenced = " & islicenced & " " & _
"WHERE appid = " & appid
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("displayapplication.asp?appid=" & appid)
Else
Response.Write("Error: " & Err.Description)
objConn.Close
End If
%>

View File

@@ -1,96 +0,0 @@
<%@ Language=VBScript %>
<%
Option Explicit
%>
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/encoding.asp"-->
<!--#include file="./includes/error_handler.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
<%
'=============================================================================
' FILE: editapplication_v2.asp (TEST VERSION)
' PURPOSE: Update an existing application record
'=============================================================================
Call InitializeErrorHandling("editapplication_v2.asp")
' Get and validate inputs
Dim appid, appname, appdescription, supportteamid
Dim applicationnotes, installpath, documentationpath, image
Dim isinstallable, isactive, ishidden, isprinter, islicenced
appid = Trim(Request.Form("appid"))
appname = Trim(Request.Form("appname"))
appdescription = Trim(Request.Form("appdescription"))
supportteamid = Trim(Request.Form("supportteamid"))
applicationnotes = Trim(Request.Form("applicationnotes"))
installpath = Trim(Request.Form("installpath"))
documentationpath = Trim(Request.Form("documentationpath"))
image = Trim(Request.Form("image"))
' Checkboxes
If Request.Form("isinstallable") = "1" Then isinstallable = 1 Else isinstallable = 0
If Request.Form("isactive") = "1" Then isactive = 1 Else isactive = 0
If Request.Form("ishidden") = "1" Then ishidden = 1 Else ishidden = 0
If Request.Form("isprinter") = "1" Then isprinter = 1 Else isprinter = 0
If Request.Form("islicenced") = "1" Then islicenced = 1 Else islicenced = 0
' Validate appid
If Not ValidateID(appid) Then
Call HandleValidationError("displayapplications.asp", "INVALID_ID")
End If
' Validate appname (required, 1-50 chars)
If Len(appname) < 1 Or Len(appname) > 50 Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
End If
' Validate supportteamid
If Not ValidateID(supportteamid) Then
Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_ID")
End If
' Validate field lengths
If Len(appdescription) > 255 Then Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
If Len(applicationnotes) > 512 Then Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
If Len(installpath) > 255 Then Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
If Len(documentationpath) > 512 Then Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
If Len(image) > 255 Then Call HandleValidationError("displayapplication.asp?appid=" & appid, "INVALID_INPUT")
' DATABASE UPDATE
Dim strSQL
strSQL = "UPDATE applications SET " & _
"appname = ?, " & _
"appdescription = ?, " & _
"supportteamid = ?, " & _
"applicationnotes = ?, " & _
"installpath = ?, " & _
"documentationpath = ?, " & _
"image = ?, " & _
"isinstallable = ?, " & _
"isactive = ?, " & _
"ishidden = ?, " & _
"isprinter = ?, " & _
"islicenced = ? " & _
"WHERE appid = ?"
Dim recordsAffected
recordsAffected = ExecuteParameterizedUpdate(objConn, strSQL, Array( _
appname, appdescription, supportteamid, applicationnotes, _
installpath, documentationpath, image, _
isinstallable, isactive, ishidden, isprinter, islicenced, appid _
))
Call CheckForErrors()
Call CleanupResources()
If recordsAffected > 0 Then
Response.Redirect("displayapplication.asp?appid=" & Server.URLEncode(appid))
Else
Response.Write("<html><body>")
Response.Write("<h3>Error: No records were updated.</h3>")
Response.Write("<p><a href='displayapplication.asp?appid=" & Server.HTMLEncode(appid) & "'>Go Back</a></p>")
Response.Write("</body></html>")
End If
%>

View File

@@ -1,335 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
Dim machineid, isScanned
machineid = Request.QueryString("pcid") ' Parameter named pcid for backwards compatibility
If machineid = "" Then machineid = Request.QueryString("machineid")
isScanned = Request.QueryString("scanned")
' Validate machineid
If Not IsNumeric(machineid) Or CLng(machineid) < 1 Then
Response.Write("Invalid device ID")
Response.End
End If
' Get PC data using parameterized query - PHASE 2: Use machines table
Dim strSQL, rs
strSQL = "SELECT machines.*, machinestatus.machinestatus, pctype.typename " & _
"FROM machines " & _
"LEFT JOIN machinestatus ON machines.machinestatusid = machinestatus.machinestatusid " & _
"LEFT JOIN pctype ON machines.pctypeid = pctype.pctypeid " & _
"WHERE machines.machineid = ? AND machines.pctypeid IS NOT NULL"
Set rs = ExecuteParameterizedQuery(objconn, strSQL, Array(CLng(machineid)))
If rs.EOF Then
Response.Write("Device not found")
Response.End
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">
<div class="row mt-3">
<div class="col-lg-8 offset-lg-2">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h5 class="card-title" style="margin:0;">
<i class="zmdi zmdi-edit"></i> Edit Device - <span style="font-family:monospace;"><%=Server.HTMLEncode(rs("serialnumber"))%></span>
</h5>
<a href="./adddevice.asp" class="btn btn-sm btn-secondary">
<i class="zmdi zmdi-arrow-left"></i> Back to Scan
</a>
</div>
<%
Dim errorType, errorMsg
errorType = Request.QueryString("error")
errorMsg = Request.QueryString("msg")
If isScanned = "1" Then
%>
<div class="alert alert-warning">
<i class="zmdi zmdi-alert-triangle"></i> <strong>Device already exists!</strong> Update the details below.
</div>
<%
ElseIf errorType = "required" Then
%>
<div class="alert alert-danger">
<i class="zmdi zmdi-close-circle"></i> <strong>Error!</strong> Status is required.
</div>
<%
ElseIf errorType = "db" Then
%>
<div class="alert alert-danger">
<i class="zmdi zmdi-close-circle"></i> <strong>Database Error:</strong> <%=Server.HTMLEncode(errorMsg)%>
</div>
<%
End If
%>
<form method="post" action="./updatedevice_direct.asp" id="editForm">
<input type="hidden" name="pcid" value="<%=machineid%>">
<div class="form-group">
<label for="serialnumber">Serial Number</label>
<input type="text" class="form-control readonly-serial" id="serialnumber" name="serialnumber"
value="<%=Server.HTMLEncode(rs("serialnumber"))%>" readonly>
</div>
<div class="form-group">
<label for="machinestatusid">Status <span class="text-danger">*</span></label>
<select class="form-control" id="machinestatusid" name="machinestatusid" required>
<%
Dim rsStatus, sqlStatus
sqlStatus = "SELECT machinestatusid, machinestatus FROM machinestatus ORDER BY machinestatusid"
Set rsStatus = objconn.Execute(sqlStatus)
While Not rsStatus.EOF
Dim selectedStatus
selectedStatus = ""
If Not IsNull(rs("machinestatusid")) And rsStatus("machinestatusid") = rs("machinestatusid") Then
selectedStatus = " selected"
End If
Response.Write("<option value='" & rsStatus("machinestatusid") & "'" & selectedStatus & ">" & rsStatus("machinestatus") & "</option>")
rsStatus.MoveNext
Wend
rsStatus.Close
%>
</select>
</div>
<div class="form-group">
<label for="pctypeid">Type</label>
<select class="form-control" id="pctypeid" name="pctypeid">
<option value="">-- Not Set --</option>
<%
Dim rsType, sqlType
sqlType = "SELECT pctypeid, typename FROM pctype WHERE isactive = 1 ORDER BY displayorder"
Set rsType = objconn.Execute(sqlType)
While Not rsType.EOF
Dim selectedType
selectedType = ""
If Not IsNull(rs("pctypeid")) And rsType("pctypeid") = rs("pctypeid") Then
selectedType = " selected"
End If
Response.Write("<option value='" & rsType("pctypeid") & "'" & selectedType & ">" & rsType("typename") & "</option>")
rsType.MoveNext
Wend
rsType.Close
%>
</select>
</div>
<div class="form-group">
<label for="hostname">Hostname</label>
<input type="text" class="form-control" id="hostname" name="hostname"
value="<%If Not IsNull(rs("hostname")) Then Response.Write(Server.HTMLEncode(rs("hostname")))%>"
placeholder="e.g., DESKTOP-ABC123">
</div>
<div class="form-group">
<label for="modelnumberid">Model</label>
<div class="input-group">
<select class="form-control" id="modelnumberid" name="modelnumberid">
<option value="">-- Not Set --</option>
<option value="new">+ Add New Model</option>
<%
Dim rsModel, sqlModel
sqlModel = "SELECT models.modelnumberid, models.modelnumber, vendors.vendor " & _
"FROM models " & _
"INNER JOIN vendors ON models.vendorid = vendors.vendorid " & _
"WHERE vendors.ispc = 1 " & _
"ORDER BY vendors.vendor, models.modelnumber"
Set rsModel = objconn.Execute(sqlModel)
While Not rsModel.EOF
Dim selectedModel
selectedModel = ""
If Not IsNull(rs("modelnumberid")) And rsModel("modelnumberid") = rs("modelnumberid") Then
selectedModel = " selected"
End If
Response.Write("<option value='" & rsModel("modelnumberid") & "'" & selectedModel & ">" & rsModel("vendor") & " - " & rsModel("modelnumber") & "</option>")
rsModel.MoveNext
Wend
rsModel.Close
%>
</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>
</div>
<!-- New Model Fields (hidden by default) -->
<div id="newModelSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #007bff; background-color:rgba(0,123,255,0.05); margin-bottom:20px;">
<h6 style="color:#007bff; margin-bottom:15px;"><i class="zmdi zmdi-plus-circle"></i> New Model Details</h6>
<div class="form-group">
<label for="newmodelnumber">Model Number</label>
<input type="text" class="form-control" id="newmodelnumber" name="newmodelnumber" placeholder="e.g., OptiPlex 7090">
</div>
<div class="form-group">
<label for="newvendorid">Vendor</label>
<div class="input-group">
<select class="form-control" id="newvendorid" name="newvendorid">
<option value="">-- Select --</option>
<option value="new">+ Add New Vendor</option>
<%
Dim rsVendor, sqlVendor
sqlVendor = "SELECT vendorid, vendor FROM vendors WHERE ispc = 1 ORDER BY vendor"
Set rsVendor = objconn.Execute(sqlVendor)
While Not rsVendor.EOF
Response.Write("<option value='" & rsVendor("vendorid") & "'>" & rsVendor("vendor") & "</option>")
rsVendor.MoveNext
Wend
rsVendor.Close
%>
</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>
<!-- New Vendor Fields (nested, hidden by default) -->
<div id="newVendorSection" style="display:none; margin-left:20px; padding:15px; border-left:3px solid #28a745; background-color:rgba(40,167,69,0.05); margin-bottom:15px;">
<h6 style="color:#28a745; margin-bottom:15px;"><i class="zmdi zmdi-plus-circle"></i> New Vendor</h6>
<div class="form-group">
<label for="newvendorname">Vendor Name</label>
<input type="text" class="form-control" id="newvendorname" name="newvendorname" placeholder="e.g., Dell, HP, Lenovo">
</div>
</div>
</div>
<div class="form-group">
<label for="machinenumber">Machine Number</label>
<input type="text" class="form-control" id="machinenumber" name="machinenumber"
value="<%If Not IsNull(rs("machinenumber")) Then Response.Write(Server.HTMLEncode(rs("machinenumber")))%>"
placeholder="e.g., 101">
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="isactive" name="isactive" value="1"
<%If rs("isactive") = True Or rs("isactive") = 1 Then Response.Write("checked")%>>
<label class="custom-control-label" for="isactive">Active</label>
</div>
<small class="form-text text-muted">Default: Active (checked)</small>
</div>
<div class="text-center" style="margin-top:30px;">
<button type="submit" class="btn btn-primary btn-lg" id="saveBtn">
<i class="zmdi zmdi-check"></i> Save & Return to Scan
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</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">
<div class="container">
<div class="text-center">
</div>
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<script>
$(document).ready(function() {
// Auto-focus on status dropdown for quick keyboard selection
$('#machinestatusid').focus();
// Model dropdown change handler
$('#modelnumberid').on('change', function() {
if ($(this).val() === 'new') {
$('#newModelSection').slideDown();
} else {
$('#newModelSection').slideUp();
$('#newvendorid').val('');
$('#newVendorSection').hide();
}
});
// Model "+ New" button
$('#addModelBtn').on('click', function() {
$('#modelnumberid').val('new').trigger('change');
});
// Vendor dropdown change handler (nested)
$('#newvendorid').on('change', function() {
if ($(this).val() === 'new') {
$('#newVendorSection').slideDown();
} else {
$('#newVendorSection').slideUp();
}
});
// Vendor "+ New" button (nested)
$('#addVendorBtn').on('click', function() {
$('#newvendorid').val('new').trigger('change');
});
});
</script>
</body>
</html>
<%
rs.Close
objConn.Close
%>

File diff suppressed because it is too large Load Diff

View File

@@ -1,346 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim machineid, modelid, machinetypeid, businessunitid, printerid, mapleft, maptop
machineid = Trim(Request.Querystring("machineid"))
modelid = Trim(Request.Form("modelid"))
machinetypeid = Trim(Request.Form("machinetypeid"))
businessunitid = Trim(Request.Form("businessunitid"))
printerid = Trim(Request.Form("printerid"))
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 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
newfunctionalaccount = Trim(Request.Form("newfunctionalaccount"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelimage
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelimage = Trim(Request.Form("newmodelimage"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields
If Not IsNumeric(machineid) Or CLng(machineid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine ID.</div>")
Response.Write("<a href='displaymachines.asp'>Go back</a>")
objConn.Close
Response.End
End If
If modelid <> "new" And (Not IsNumeric(modelid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If machinetypeid <> "new" And (Not IsNumeric(machinetypeid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine type ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If businessunitid <> "new" And (Not IsNumeric(businessunitid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid business unit ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new business unit creation
If businessunitid = "new" Then
If Len(newbusinessunit) = 0 Then
Response.Write("<div class='alert alert-danger'>New business unit name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newbusinessunit) > 50 Then
Response.Write("<div class='alert alert-danger'>Business unit name too long</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedBUName
escapedBUName = Replace(newbusinessunit, "'", "''")
' Insert new business unit
Dim sqlNewBU
sqlNewBU = "INSERT INTO businessunits (businessunit, isactive) VALUES ('" & escapedBUName & "', 1)"
On Error Resume Next
objConn.Execute sqlNewBU
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new business unit: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Handle new machine type creation
If machinetypeid = "new" Then
If Len(newmachinetype) = 0 Then
Response.Write("<div class='alert alert-danger'>New machine type name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccountid) = 0 Then
Response.Write("<div class='alert alert-danger'>Functional account is required for new machine type</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmachinetype) > 50 Or Len(newmachinedescription) > 255 Then
Response.Write("<div class='alert alert-danger'>Machine type field length exceeded</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new functional account creation (nested)
If newfunctionalaccountid = "new" Then
If Len(newfunctionalaccount) = 0 Then
Response.Write("<div class='alert alert-danger'>New functional account name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccount) > 50 Then
Response.Write("<div class='alert alert-danger'>Functional account name too long</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedFAName
escapedFAName = Replace(newfunctionalaccount, "'", "''")
' Insert new functional account
Dim sqlNewFA
sqlNewFA = "INSERT INTO functionalaccounts (functionalaccount, isactive) VALUES ('" & escapedFAName & "', 1)"
On Error Resume Next
objConn.Execute sqlNewFA
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new functional account: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes
Dim escapedMTName, escapedMTDesc
escapedMTName = Replace(newmachinetype, "'", "''")
escapedMTDesc = Replace(newmachinedescription, "'", "''")
' Insert new machine type
Dim sqlNewMT
sqlNewMT = "INSERT INTO machinetypes (machinetype, machinedescription, functionalaccountid, isactive) " & _
"VALUES ('" & escapedMTName & "', '" & escapedMTDesc & "', " & newfunctionalaccountid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewMT
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new machine type: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created machine type ID
Dim rsNewMT
Set rsNewMT = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
machinetypeid = CLng(rsNewMT("newid"))
rsNewMT.Close
Set rsNewMT = Nothing
On Error Goto 0
End If
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Or Len(newmodelimage) > 100 Then
Response.Write("<div class='alert alert-danger'>Model field length exceeded</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Vendor name too long</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with ismachine=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & escapedVendorName & "', 1, 0, 0, 1)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes for model
Dim escapedModelNumber, escapedModelImage
escapedModelNumber = Replace(newmodelnumber, "'", "''")
escapedModelImage = Replace(newmodelimage, "'", "''")
' Set default image if not specified
If escapedModelImage = "" Then
escapedModelImage = "default.png"
End If
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, image, isactive) " & _
"VALUES ('" & escapedModelNumber & "', " & newvendorid & ", '" & escapedModelImage & "', 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Build UPDATE statement
Dim strSQL
strSQL = "UPDATE machines SET " & _
"modelnumberid = " & modelid & ", " & _
"machinetypeid = " & machinetypeid & ", " & _
"businessunitid = " & businessunitid
' Add optional printerid
If printerid <> "" And IsNumeric(printerid) Then
strSQL = strSQL & ", printerid = " & printerid
End If
' Add optional map coordinates
If mapleft <> "" And maptop <> "" And IsNumeric(mapleft) And IsNumeric(maptop) Then
strSQL = strSQL & ", mapleft = " & mapleft & ", maptop = " & maptop
End If
strSQL = strSQL & " WHERE machineid = " & machineid
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & machineid & "'>Go back</a>")
objConn.Close
Response.End
End If
objConn.Close
%>
<meta http-equiv="refresh" content="0; url=./displaymachine.asp?machineid=<%=Server.HTMLEncode(machineid)%>">
</div>
</body>
</html>

View File

@@ -1,410 +0,0 @@
<%
'=============================================================================
' FILE: editmacine.asp
' PURPOSE: Edit machine information with nested entity creation
' SECURITY: Parameterized queries, HTML encoding, input validation
' UPDATED: 2025-10-27 - Migrated to secure patterns
' NOTE: File has typo in name (macine vs machine) - preserved for compatibility
'=============================================================================
%><html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
</head>
<body>
<div class="page">
<%
'=============================================================================
' SECURITY: Validate machineid from querystring
'=============================================================================
Dim machineid
machineid = GetSafeInteger("QS", "machineid", 0, 1, 999999)
If machineid = 0 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine ID.</div>")
Response.Write("<a href='displaymachines.asp'>Go back</a>")
objConn.Close
Response.End
End If
'=============================================================================
' SECURITY: Get and validate all form inputs
'=============================================================================
Dim modelid, machinetypeid, businessunitid, printerid, mapleft, maptop
modelid = GetSafeString("FORM", "modelid", "", 1, 50, "")
machinetypeid = GetSafeString("FORM", "machinetypeid", "", 1, 50, "")
businessunitid = GetSafeString("FORM", "businessunitid", "", 1, 50, "")
printerid = GetSafeInteger("FORM", "printerid", 0, 0, 999999)
mapleft = GetSafeInteger("FORM", "mapleft", 0, 0, 9999)
maptop = GetSafeInteger("FORM", "maptop", 0, 0, 9999)
' Get form inputs for new business unit
Dim newbusinessunit
newbusinessunit = GetSafeString("FORM", "newbusinessunitname", "", 0, 50, "")
' Get form inputs for new machine type
Dim newmachinetype, newmachinedescription, newfunctionalaccountid
newmachinetype = GetSafeString("FORM", "newmachinetypename", "", 0, 50, "")
newmachinedescription = GetSafeString("FORM", "newmachinetypedescription", "", 0, 255, "")
newfunctionalaccountid = GetSafeString("FORM", "newfunctionalaccountid", "", 0, 50, "")
' Get form inputs for new functional account
Dim newfunctionalaccount
newfunctionalaccount = GetSafeString("FORM", "newfunctionalaccountname", "", 0, 50, "")
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelimage
newmodelnumber = GetSafeString("FORM", "newmodelnumber", "", 0, 255, "")
newvendorid = GetSafeString("FORM", "newvendorid", "", 0, 50, "")
newmodelimage = GetSafeString("FORM", "newmodelimage", "", 0, 255, "")
' Get form inputs for new vendor
Dim newvendorname
newvendorname = GetSafeString("FORM", "newvendorname", "", 0, 50, "")
'=============================================================================
' Validate required fields
'=============================================================================
If modelid <> "new" And (Not IsNumeric(modelid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
If machinetypeid <> "new" And (Not IsNumeric(machinetypeid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine type ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
If businessunitid <> "new" And (Not IsNumeric(businessunitid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid business unit ID.</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
'=============================================================================
' SECURITY: Handle new business unit creation with parameterized query
'=============================================================================
If businessunitid = "new" Then
If Len(newbusinessunit) = 0 Then
Response.Write("<div class='alert alert-danger'>New business unit name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Insert new business unit using parameterized query
Dim sqlNewBU
sqlNewBU = "INSERT INTO businessunits (businessunit, isactive) VALUES (?, 1)"
On Error Resume Next
Dim cmdNewBU
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)
cmdNewBU.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new business unit: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created business unit ID
Dim rsNewBU
Set rsNewBU = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
businessunitid = 0
If Not rsNewBU.EOF Then
If Not IsNull(rsNewBU("newid")) Then
businessunitid = CLng(rsNewBU("newid"))
End If
End If
rsNewBU.Close
Set rsNewBU = Nothing
Set cmdNewBU = Nothing
On Error Goto 0
End If
'=============================================================================
' SECURITY: Handle new machine type creation with parameterized query
'=============================================================================
If machinetypeid = "new" Then
If Len(newmachinetype) = 0 Then
Response.Write("<div class='alert alert-danger'>New machine type name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccountid) = 0 Then
Response.Write("<div class='alert alert-danger'>Functional account is required for new machine type</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new functional account creation (nested)
If newfunctionalaccountid = "new" Then
If Len(newfunctionalaccount) = 0 Then
Response.Write("<div class='alert alert-danger'>New functional account name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Insert new functional account using parameterized query
Dim sqlNewFA
sqlNewFA = "INSERT INTO functionalaccounts (functionalaccount, isactive) VALUES (?, 1)"
On Error Resume Next
Dim cmdNewFA
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)
cmdNewFA.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new functional account: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created functional account ID
Dim rsNewFA
Set rsNewFA = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newfunctionalaccountid = 0
If Not rsNewFA.EOF Then
If Not IsNull(rsNewFA("newid")) Then
newfunctionalaccountid = CLng(rsNewFA("newid"))
End If
End If
rsNewFA.Close
Set rsNewFA = Nothing
Set cmdNewFA = Nothing
On Error Goto 0
End If
' Insert new machine type using parameterized query
Dim sqlNewMT
sqlNewMT = "INSERT INTO machinetypes (machinetype, machinedescription, functionalaccountid, isactive) VALUES (?, ?, ?, 1)"
On Error Resume Next
Dim cmdNewMT
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)
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@machinedescription", 200, 1, 255, newmachinedescription)
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@functionalaccountid", 3, 1, , CLng(newfunctionalaccountid))
cmdNewMT.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new machine type: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created machine type ID
Dim rsNewMT
Set rsNewMT = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
machinetypeid = 0
If Not rsNewMT.EOF Then
If Not IsNull(rsNewMT("newid")) Then
machinetypeid = CLng(rsNewMT("newid"))
End If
End If
rsNewMT.Close
Set rsNewMT = Nothing
Set cmdNewMT = Nothing
On Error Goto 0
End If
'=============================================================================
' SECURITY: Handle new model creation with parameterized query
'=============================================================================
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Insert new vendor using parameterized query
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES (?, 1, 0, 0, 1)"
On Error Resume Next
Dim cmdNewVendor
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)
cmdNewVendor.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created vendor ID
Dim rsNewVendor
Set rsNewVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newvendorid = 0
If Not rsNewVendor.EOF Then
If Not IsNull(rsNewVendor("newid")) Then
newvendorid = CLng(rsNewVendor("newid"))
End If
End If
rsNewVendor.Close
Set rsNewVendor = Nothing
Set cmdNewVendor = Nothing
On Error Goto 0
End If
' Set default image if not specified
If newmodelimage = "" Then
newmodelimage = "default.png"
End If
' Insert new model using parameterized query
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, image, isactive) VALUES (?, ?, ?, 1)"
On Error Resume Next
Dim cmdNewModel
Set cmdNewModel = Server.CreateObject("ADODB.Command")
cmdNewModel.ActiveConnection = objConn
cmdNewModel.CommandText = sqlNewModel
cmdNewModel.CommandType = 1
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@modelnumber", 200, 1, 255, newmodelnumber)
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@vendorid", 3, 1, , CLng(newvendorid))
cmdNewModel.Parameters.Append cmdNewModel.CreateParameter("@image", 200, 1, 255, newmodelimage)
cmdNewModel.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelid = 0
If Not rsNewModel.EOF Then
If Not IsNull(rsNewModel("newid")) Then
modelid = CLng(rsNewModel("newid"))
End If
End If
rsNewModel.Close
Set rsNewModel = Nothing
Set cmdNewModel = Nothing
On Error Goto 0
End If
'=============================================================================
' SECURITY: Update machine using parameterized query
'=============================================================================
' Build UPDATE statement with parameterized query
Dim strSQL, paramCount
paramCount = 0
strSQL = "UPDATE machines SET modelnumberid = ?, machinetypeid = ?, businessunitid = ?"
paramCount = 3
' Add optional printerid
If printerid > 0 Then
strSQL = strSQL & ", printerid = ?"
paramCount = paramCount + 1
End If
' Add optional map coordinates
If mapleft > 0 And maptop > 0 Then
strSQL = strSQL & ", mapleft = ?, maptop = ?"
paramCount = paramCount + 2
End If
strSQL = strSQL & " WHERE machineid = ?"
On Error Resume Next
Dim cmdUpdate
Set cmdUpdate = Server.CreateObject("ADODB.Command")
cmdUpdate.ActiveConnection = objConn
cmdUpdate.CommandText = strSQL
cmdUpdate.CommandType = 1
' Add parameters in order
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@modelnumberid", 3, 1, , CLng(modelid))
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machinetypeid", 3, 1, , CLng(machinetypeid))
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@businessunitid", 3, 1, , CLng(businessunitid))
If printerid > 0 Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@printerid", 3, 1, , CLng(printerid))
End If
If mapleft > 0 And maptop > 0 Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@mapleft", 3, 1, , CLng(mapleft))
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@maptop", 3, 1, , CLng(maptop))
End If
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machineid", 3, 1, , CLng(machineid))
cmdUpdate.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='displaymachine.asp?machineid=" & Server.HTMLEncode(machineid) & "'>Go back</a>")
Set cmdUpdate = Nothing
objConn.Close
Response.End
End If
Set cmdUpdate = Nothing
On Error Goto 0
%>
<meta http-equiv="refresh" content="0; url=./displaymachine.asp?machineid=<%=Server.HTMLEncode(machineid)%>">
<%
'=============================================================================
' CLEANUP
'=============================================================================
objConn.Close
%>
</div>
</body>
</html>

View File

@@ -1,211 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim printerid, modelid, serialnumber, ipaddress, fqdn, printercsfname, printerwindowsname, machineid, maptop, mapleft
printerid = Trim(Request.Querystring("printerid"))
modelid = Trim(Request.Form("modelid"))
serialnumber = Trim(Request.Form("serialnumber"))
ipaddress = Trim(Request.Form("ipaddress"))
fqdn = Trim(Request.Form("fqdn"))
printercsfname = Trim(Request.Form("printercsfname"))
printerwindowsname = Trim(Request.Form("printerwindowsname"))
machineid = Trim(Request.Form("machineid"))
maptop = Trim(Request.Form("maptop"))
mapleft = Trim(Request.Form("mapleft"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelnotes, newmodeldocpath
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelnotes = Trim(Request.Form("newmodelnotes"))
newmodeldocpath = Trim(Request.Form("newmodeldocpath"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields
If Not IsNumeric(printerid) Or CLng(printerid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid printer ID.</div>")
Response.Write("<a href='displayprinters.asp'>Go back</a>")
objConn.Close
Response.End
End If
If modelid <> "new" And (Not IsNumeric(modelid)) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Not IsNumeric(machineid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine ID.</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(serialnumber) > 100 Or Len(fqdn) > 255 Or Len(printercsfname) > 50 Or Len(printerwindowsname) > 255 Then
Response.Write("<div class='alert alert-danger'>Error: Field length exceeded.</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 255 Or Len(newmodelnotes) > 255 Or Len(newmodeldocpath) > 255 Then
Response.Write("<div class='alert alert-danger'>Model field length exceeded</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Vendor name too long</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with isprinter=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & escapedVendorName & "', 1, 1, 0, 0)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Err.Description & "</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes for model
Dim escapedModelNumber, escapedModelNotes, escapedModelDocPath
escapedModelNumber = Replace(newmodelnumber, "'", "''")
escapedModelNotes = Replace(newmodelnotes, "'", "''")
escapedModelDocPath = Replace(newmodeldocpath, "'", "''")
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) " & _
"VALUES ('" & escapedModelNumber & "', " & newvendorid & ", '" & escapedModelNotes & "', '" & escapedModelDocPath & "', 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Err.Description & "</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes
serialnumber = Replace(serialnumber, "'", "''")
ipaddress = Replace(ipaddress, "'", "''")
fqdn = Replace(fqdn, "'", "''")
printercsfname = Replace(printercsfname, "'", "''")
printerwindowsname = Replace(printerwindowsname, "'", "''")
' Handle map coordinates - default to 50 if not provided
Dim maptopSQL, mapleftSQL
If maptop <> "" And IsNumeric(maptop) Then
maptopSQL = maptop
Else
maptopSQL = "50"
End If
If mapleft <> "" And IsNumeric(mapleft) Then
mapleftSQL = mapleft
Else
mapleftSQL = "50"
End If
' Build UPDATE statement
Dim strSQL
strSQL = "UPDATE printers SET " & _
"modelid = " & modelid & ", " & _
"serialnumber = '" & serialnumber & "', " & _
"ipaddress = '" & ipaddress & "', " & _
"fqdn = '" & fqdn & "', " & _
"printercsfname = '" & printercsfname & "', " & _
"printerwindowsname = '" & printerwindowsname & "', " & _
"machineid = " & machineid & ", " & _
"maptop = " & maptopSQL & ", " & _
"mapleft = " & mapleftSQL & " " & _
"WHERE printerid = " & printerid
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='displayprinter.asp?printerid=" & printerid & "'>Go back</a>")
objConn.Close
Response.End
End If
objConn.Close
%>
<meta http-equiv="refresh" content="0; url=./displayprinter.asp?printerid=<%=Server.HTMLEncode(printerid)%>">
</div>
</body>
</html>

View File

@@ -1,417 +0,0 @@
<%
' Universal data caching system for frequently accessed database queries
' Uses Application-level cache with configurable TTL (Time To Live)
' Cache durations in minutes
Const CACHE_DROPDOWN_TTL = 60 ' Dropdowns (vendors, models) - 1 hour
Const CACHE_LIST_TTL = 5 ' List pages (printers, machines) - 5 minutes
Const CACHE_STATIC_TTL = 1440 ' Static data (rarely changes) - 24 hours
'=============================================================================
' DROPDOWN DATA CACHING (Vendors, Models, etc.)
'=============================================================================
' Get all printer vendors (cached)
Function GetPrinterVendorsCached()
Dim cacheKey, cacheAge, cachedData
cacheKey = "dropdown_printer_vendors"
' Check cache
If Not IsEmpty(Application(cacheKey)) Then
cacheAge = DateDiff("n", Application(cacheKey & "_time"), Now())
If cacheAge < CACHE_DROPDOWN_TTL Then
GetPrinterVendorsCached = Application(cacheKey)
Exit Function
End If
End If
' Fetch from database
Dim sql, rs_temp, resultArray(), count, i
sql = "SELECT vendorid, vendor FROM vendors WHERE isprinter=1 AND isactive=1 ORDER BY vendor ASC"
Set rs_temp = objConn.Execute(sql)
' Count rows
count = 0
While Not rs_temp.EOF
count = count + 1
rs_temp.MoveNext
Wend
If count = 0 Then
Set rs_temp = Nothing
GetPrinterVendorsCached = Array()
Exit Function
End If
' Reset to beginning
rs_temp.MoveFirst
' Build array
ReDim resultArray(count - 1, 1) ' vendorid, vendor
i = 0
While Not rs_temp.EOF
resultArray(i, 0) = rs_temp("vendorid")
resultArray(i, 1) = rs_temp("vendor")
i = i + 1
rs_temp.MoveNext
Wend
rs_temp.Close
Set rs_temp = Nothing
' Cache it
Application.Lock
Application(cacheKey) = resultArray
Application(cacheKey & "_time") = Now()
Application.Unlock
GetPrinterVendorsCached = resultArray
End Function
' Get all printer models (cached)
Function GetPrinterModelsCached()
Dim cacheKey, cacheAge, cachedData
cacheKey = "dropdown_printer_models"
' Check cache
If Not IsEmpty(Application(cacheKey)) Then
cacheAge = DateDiff("n", Application(cacheKey & "_time"), Now())
If cacheAge < CACHE_DROPDOWN_TTL Then
GetPrinterModelsCached = Application(cacheKey)
Exit Function
End If
End If
' Fetch from database
Dim sql, rs_temp, resultArray(), count, i
sql = "SELECT models.modelnumberid, models.modelnumber, vendors.vendor " & _
"FROM vendors, models " & _
"WHERE models.vendorid = vendors.vendorid " & _
"AND vendors.isprinter=1 AND models.isactive=1 " & _
"ORDER BY modelnumber ASC"
Set rs_temp = objConn.Execute(sql)
' Count rows
count = 0
While Not rs_temp.EOF
count = count + 1
rs_temp.MoveNext
Wend
If count = 0 Then
Set rs_temp = Nothing
GetPrinterModelsCached = Array()
Exit Function
End If
' Reset to beginning
rs_temp.MoveFirst
' Build array
ReDim resultArray(count - 1, 2) ' modelnumberid, modelnumber, vendor
i = 0
While Not rs_temp.EOF
resultArray(i, 0) = rs_temp("modelnumberid")
resultArray(i, 1) = rs_temp("modelnumber")
resultArray(i, 2) = rs_temp("vendor")
i = i + 1
rs_temp.MoveNext
Wend
rs_temp.Close
Set rs_temp = Nothing
' Cache it
Application.Lock
Application(cacheKey) = resultArray
Application(cacheKey & "_time") = Now()
Application.Unlock
GetPrinterModelsCached = resultArray
End Function
'=============================================================================
' LIST PAGE CACHING (Printer list, Machine list, etc.)
'=============================================================================
' Get all active printers (cached) - for displayprinters.asp
Function GetPrinterListCached()
Dim cacheKey, cacheAge
cacheKey = "list_printers"
' Check cache
If Not IsEmpty(Application(cacheKey)) Then
cacheAge = DateDiff("n", Application(cacheKey & "_time"), Now())
If cacheAge < CACHE_LIST_TTL Then
GetPrinterListCached = Application(cacheKey)
Exit Function
End If
End If
' Fetch from database
Dim sql, rs_temp, resultArray(), count, i
sql = "SELECT printers.printerid AS printer, printers.*, vendors.*, models.*, machines.* " & _
"FROM printers, vendors, models, machines " & _
"WHERE printers.modelid=models.modelnumberid " & _
"AND models.vendorid=vendors.vendorid " & _
"AND printers.machineid=machines.machineid " & _
"AND printers.isactive=1 " & _
"ORDER BY machinenumber ASC"
Set rs_temp = objConn.Execute(sql)
' Count rows
count = 0
While Not rs_temp.EOF
count = count + 1
rs_temp.MoveNext
Wend
If count = 0 Then
Set rs_temp = Nothing
GetPrinterListCached = Array()
Exit Function
End If
rs_temp.MoveFirst
' Build array with all needed fields
ReDim resultArray(count - 1, 11) ' printer, image, installpath, machinenumber, machineid, vendor, modelnumber, documentationpath, printercsfname, ipaddress, serialnumber, islocationonly
i = 0
While Not rs_temp.EOF
resultArray(i, 0) = rs_temp("printer")
resultArray(i, 1) = rs_temp("image")
resultArray(i, 2) = rs_temp("installpath")
resultArray(i, 3) = rs_temp("machinenumber")
resultArray(i, 4) = rs_temp("machineid")
resultArray(i, 5) = rs_temp("vendor")
resultArray(i, 6) = rs_temp("modelnumber")
resultArray(i, 7) = rs_temp("documentationpath")
resultArray(i, 8) = rs_temp("printercsfname")
resultArray(i, 9) = rs_temp("ipaddress")
resultArray(i, 10) = rs_temp("serialnumber")
' Convert islocationonly bit to 1/0 integer (bit fields come as binary)
On Error Resume Next
If IsNull(rs_temp("islocationonly")) Then
resultArray(i, 11) = 0
Else
' Convert bit field to integer (0 or 1)
resultArray(i, 11) = Abs(CBool(rs_temp("islocationonly")))
End If
On Error Goto 0
i = i + 1
rs_temp.MoveNext
Wend
rs_temp.Close
Set rs_temp = Nothing
' Cache it
Application.Lock
Application(cacheKey) = resultArray
Application(cacheKey & "_time") = Now()
Application.Unlock
GetPrinterListCached = resultArray
End Function
'=============================================================================
' HELPER FUNCTIONS
'=============================================================================
' Render dropdown options from cached vendor data
Function RenderVendorOptions(selectedID)
Dim vendors, output, i
vendors = GetPrinterVendorsCached()
output = ""
On Error Resume Next
If Not IsArray(vendors) Or UBound(vendors) < 0 Then
RenderVendorOptions = ""
Exit Function
End If
On Error Goto 0
For i = 0 To UBound(vendors)
If CLng(vendors(i, 0)) = CLng(selectedID) Then
output = output & "<option value='" & vendors(i, 0) & "' selected>" & vendors(i, 1) & "</option>"
Else
output = output & "<option value='" & vendors(i, 0) & "'>" & vendors(i, 1) & "</option>"
End If
Next
RenderVendorOptions = output
End Function
' Render dropdown options from cached model data
Function RenderModelOptions(selectedID)
Dim models, output, i
models = GetPrinterModelsCached()
output = ""
On Error Resume Next
If Not IsArray(models) Or UBound(models) < 0 Then
RenderModelOptions = ""
Exit Function
End If
On Error Goto 0
For i = 0 To UBound(models)
If CLng(models(i, 0)) = CLng(selectedID) Then
output = output & "<option value='" & models(i, 0) & "' selected>" & models(i, 1) & "</option>"
Else
output = output & "<option value='" & models(i, 0) & "'>" & models(i, 1) & "</option>"
End If
Next
RenderModelOptions = output
End Function
' Get all support teams (cached) - for application dropdowns
Function GetSupportTeamsCached()
Dim cacheKey, cacheAge, cachedData
cacheKey = "dropdown_support_teams"
' Check cache
If Not IsEmpty(Application(cacheKey)) Then
cacheAge = DateDiff("n", Application(cacheKey & "_time"), Now())
If cacheAge < CACHE_DROPDOWN_TTL Then
GetSupportTeamsCached = Application(cacheKey)
Exit Function
End If
End If
' Fetch from database
Dim sql, rs_temp, resultArray(), count, i
sql = "SELECT supporteamid, teamname FROM supportteams WHERE isactive=1 ORDER BY teamname ASC"
Set rs_temp = objConn.Execute(sql)
' Count rows
count = 0
While Not rs_temp.EOF
count = count + 1
rs_temp.MoveNext
Wend
If count = 0 Then
Set rs_temp = Nothing
GetSupportTeamsCached = Array()
Exit Function
End If
' Reset to beginning
rs_temp.MoveFirst
' Build array
ReDim resultArray(count - 1, 1) ' supporteamid, teamname
i = 0
While Not rs_temp.EOF
resultArray(i, 0) = rs_temp("supporteamid")
resultArray(i, 1) = rs_temp("teamname")
i = i + 1
rs_temp.MoveNext
Wend
rs_temp.Close
Set rs_temp = Nothing
' Cache it
Application.Lock
Application(cacheKey) = resultArray
Application(cacheKey & "_time") = Now()
Application.Unlock
GetSupportTeamsCached = resultArray
End Function
' Render dropdown options from cached support team data
Function RenderSupportTeamOptions(selectedID)
Dim teams, output, i
teams = GetSupportTeamsCached()
output = ""
On Error Resume Next
If Not IsArray(teams) Or UBound(teams) < 0 Then
RenderSupportTeamOptions = ""
Exit Function
End If
On Error Goto 0
For i = 0 To UBound(teams)
If CLng(teams(i, 0)) = CLng(selectedID) Then
output = output & "<option value='" & teams(i, 0) & "' selected>" & Server.HTMLEncode(teams(i, 1)) & "</option>"
Else
output = output & "<option value='" & teams(i, 0) & "'>" & Server.HTMLEncode(teams(i, 1)) & "</option>"
End If
Next
RenderSupportTeamOptions = output
End Function
' Clear dropdown cache (call after adding/editing vendors or models)
Sub ClearDropdownCache()
Application.Lock
Application("dropdown_printer_vendors") = Empty
Application("dropdown_printer_vendors_time") = Empty
Application("dropdown_printer_models") = Empty
Application("dropdown_printer_models_time") = Empty
Application("dropdown_support_teams") = Empty
Application("dropdown_support_teams_time") = Empty
Application.Unlock
End Sub
' Clear list cache (call after adding/editing printers)
Sub ClearListCache()
Application.Lock
Application("list_printers") = Empty
Application("list_printers_time") = Empty
Application.Unlock
End Sub
' Clear ALL data cache
Sub ClearAllDataCache()
Dim key, keysToRemove(), count, i
count = 0
' First pass: collect keys to remove
ReDim keysToRemove(100) ' Initial size
For Each key In Application.Contents
If Left(key, 9) = "dropdown_" Or Left(key, 5) = "list_" Then
keysToRemove(count) = key
count = count + 1
If count Mod 100 = 0 Then
ReDim Preserve keysToRemove(count + 100)
End If
End If
Next
' Second pass: remove collected keys
Application.Lock
For i = 0 To count - 1
Application.Contents.Remove(keysToRemove(i))
Next
Application.Unlock
End Sub
' Get cache stats
Function GetCacheStats()
Dim stats, key, count
count = 0
For Each key In Application.Contents
If Left(key, 9) = "dropdown_" Or Left(key, 5) = "list_" Or Left(key, 7) = "zabbix_" Then
If Right(key, 5) <> "_time" And Right(key, 11) <> "_refreshing" Then
count = count + 1
End If
End If
Next
stats = "Cached items: " & count
GetCacheStats = stats
End Function
%>

View File

@@ -1,8 +0,0 @@
<%
' objConn - script-global connection object (no Dim for global scope)
Session.Timeout=15
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DSN=shopdb;Uid=root;Pwd=WJF11sql;Option=3;Pooling=True;Max Pool Size=100;"
objConn.Open
set rs = server.createobject("ADODB.Recordset")
%>

View File

@@ -1,8 +0,0 @@
<%
Dim objConn
Session.Timeout=15
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DSN=wjf_employees;Uid=root;Pwd=WJF11sql;Option=3;Pooling=True;Max Pool Size=100;"
objConn.Open
set rs = server.createobject("ADODB.Recordset")
%>

View File

@@ -1,130 +0,0 @@
<%
' Cached Zabbix API wrapper with background refresh
' Include the base zabbix.asp functions
%>
<!--#include file="./zabbix.asp"-->
<%
' Main cached function - returns data immediately, refreshes in background if stale
Function GetPrinterDataCached(hostIP)
Dim cacheKey, cacheAge, forceRefresh
cacheKey = "zabbix_" & hostIP
' Check if manual refresh was requested
forceRefresh = (Request.QueryString("refresh") = "1" And Request.QueryString("ip") = hostIP)
If forceRefresh Then
' Clear cache for manual refresh
Application.Lock
Application(cacheKey) = Empty
Application(cacheKey & "_time") = Empty
Application(cacheKey & "_refreshing") = "false"
Application.Unlock
End If
' Check if cache exists
If Not IsEmpty(Application(cacheKey)) And Not forceRefresh Then
cacheAge = DateDiff("n", Application(cacheKey & "_time"), Now())
' If cache is stale (>5 min) AND not already refreshing, trigger background update
If cacheAge >= 5 And Application(cacheKey & "_refreshing") <> "true" Then
' Mark as refreshing
Application.Lock
Application(cacheKey & "_refreshing") = "true"
Application.Unlock
' Trigger async background refresh (non-blocking)
On Error Resume Next
Dim http
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
' True = async (doesn't block user)
http.Open "GET", "http://localhost/refresh_zabbix_cache.asp?ip=" & Server.URLEncode(hostIP), True
http.Send
Set http = Nothing
On Error Goto 0
End If
' Return cached data immediately (user doesn't wait)
GetPrinterDataCached = Application(cacheKey)
Exit Function
End If
' No cache exists - fetch initial data (first time only, or after manual refresh)
Dim freshData, zabbixConnected, pingStatus, tonerJSON
zabbixConnected = ZabbixLogin()
If zabbixConnected = "1" Then
pingStatus = GetPrinterPingStatus(hostIP)
tonerJSON = GetPrinterTonerLevels(hostIP)
Else
pingStatus = "-1"
tonerJSON = ""
End If
' Store as array: [connected, pingStatus, tonerJSON]
Dim resultData(2)
resultData(0) = zabbixConnected
resultData(1) = pingStatus
resultData(2) = tonerJSON
' Cache the result
Application.Lock
Application(cacheKey) = resultData
Application(cacheKey & "_time") = Now()
Application(cacheKey & "_refreshing") = "false"
Application.Unlock
GetPrinterDataCached = resultData
End Function
' Helper function to get cache age (for display purposes)
Function GetCacheAge(hostIP)
Dim cacheKey, cacheTime
cacheKey = "zabbix_" & hostIP
If IsEmpty(Application(cacheKey & "_time")) Then
GetCacheAge = -1
Exit Function
End If
GetCacheAge = DateDiff("s", Application(cacheKey & "_time"), Now())
End Function
' Clear cache for a specific printer (called by manual refresh)
Sub ClearPrinterCache(hostIP)
Dim cacheKey
cacheKey = "zabbix_" & hostIP
Application.Lock
Application(cacheKey) = Empty
Application(cacheKey & "_time") = Empty
Application(cacheKey & "_refreshing") = "false"
Application.Unlock
End Sub
' Clear all Zabbix cache (admin function)
Sub ClearAllZabbixCache()
Dim key, keysToRemove(), count, i
count = 0
' First pass: collect keys to remove
ReDim keysToRemove(100) ' Initial size
For Each key In Application.Contents
If Left(key, 7) = "zabbix_" Then
keysToRemove(count) = key
count = count + 1
If count Mod 100 = 0 Then
ReDim Preserve keysToRemove(count + 100)
End If
End If
Next
' Second pass: remove collected keys
Application.Lock
For i = 0 To count - 1
Application.Contents.Remove(keysToRemove(i))
Next
Application.Unlock
End Sub
%>

View File

@@ -1,297 +0,0 @@
<%' Cache buster: 20251110-1430 %>
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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="row">
<div class="col-xl-auto">
<div class="card">
<div class="card-body">
<div style="margin-bottom:15px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:15px;">
<h5 class="card-title" style="margin:0;">PCs</h5>
<div>
<a href="./adddevice.asp" class="btn btn-primary">
<i class="zmdi zmdi-plus-circle"></i> Add Device
</a>
</div>
</div>
<%
Dim currentPCType, currentPCStatus, recentFilter, deviceTypeFilter, sel
currentPCType = Request.QueryString("pctype")
currentPCStatus = Request.QueryString("pcstatus")
recentFilter = Request.QueryString("recent")
deviceTypeFilter = Request.QueryString("devicetype")
%>
<div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">
<select id="deviceTypeFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('devicetype', this.value)">
<option value="">All Device Types</option>
<option value="laptop"<% If deviceTypeFilter = "laptop" Then Response.Write(" selected") End If%>>Laptops</option>
<option value="desktop"<% If deviceTypeFilter = "desktop" Then Response.Write(" selected") End If%>>Desktops</option>
</select>
<select id="pcTypeSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pctype', this.value)">
<option value="">All PC Types</option>
<%
Dim rsTypes, rsStatus, selectedAttr
Set rsTypes = objConn.Execute("SELECT pctypeid, typename FROM pctype WHERE isactive = '1' ORDER BY displayorder, typename")
While Not rsTypes.EOF
selectedAttr = ""
If CStr(rsTypes("pctypeid")) = CStr(currentPCType) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsTypes("pctypeid") & """" & selectedAttr & ">" & rsTypes("typename") & "</option>" & vbCrLf
rsTypes.MoveNext
Wend
rsTypes.Close
Set rsTypes = Nothing
%>
</select>
<select id="pcStatusSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pcstatus', this.value)">
<option value="">All Statuses</option>
<%
Set rsStatus = objConn.Execute("SELECT machinestatusid, machinestatus FROM machinestatus WHERE isactive = 1 ORDER BY machinestatusid")
While Not rsStatus.EOF
selectedAttr = ""
If CStr(rsStatus("machinestatusid")) = CStr(currentPCStatus) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsStatus("machinestatusid") & """" & selectedAttr & ">" & rsStatus("machinestatus") & "</option>" & vbCrLf
rsStatus.MoveNext
Wend
rsStatus.Close
Set rsStatus = Nothing
%>
</select>
<select id="recentFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('recent', this.value)">
<option value="">All Time</option>
<option value="7"<% If recentFilter = "7" Then Response.Write(" selected") End If%>>Last 7 Days</option>
</select>
<% If currentPCType <> "" Or currentPCStatus <> "" Or recentFilter <> "" Or deviceTypeFilter <> "" Then %>
<a href="listpcs.asp" class="btn btn-outline-secondary btn-sm">
<i class="zmdi zmdi-close"></i> Clear
</a>
<% End If %>
<button id="checkAllWarrantiesBtn" class="btn btn-info btn-sm" title="Check Dell warranty API for all PCs without warranty information" disabled>
<i class="zmdi zmdi-refresh"></i> Check Warranties
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Hostname</th>
<th scope="col">Serial</th>
<th scope="col">IP</th>
<th scope="col">Model</th>
<th scope="col">OS</th>
<th scope="col">Machine</th>
</tr>
</thead>
<tbody>
<%
' Build query based on filters
Dim pcTypeFilter, pcStatusFilter, recentDaysFilter, deviceTypeFilterSQL, whereClause
pcTypeFilter = Request.QueryString("pctype")
pcStatusFilter = Request.QueryString("pcstatus")
recentDaysFilter = Request.QueryString("recent")
deviceTypeFilterSQL = Request.QueryString("devicetype")
' Base query with LEFT JOINs to show all PCs
strSQL = "SELECT m.machineid, m.hostname, m.alias, m.serialnumber, m.machinenumber, m.pctypeid, m.machinestatusid, " & _
"m.modelnumberid, m.businessunitid, m.osid, m.loggedinuser, m.lastupdated, " & _
"vendors.vendor, models.modelnumber, operatingsystems.operatingsystem, " & _
"c.address AS ipaddress, c.macaddress, " & _
"models.machinetypeid, pctype.typename, machinestatus.machinestatus " & _
"FROM machines m " & _
"LEFT JOIN models ON m.modelnumberid = models.modelnumberid " & _
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " & _
"LEFT JOIN operatingsystems ON m.osid = operatingsystems.osid " & _
"LEFT JOIN communications c ON c.machineid = m.machineid AND c.isprimary = 1 " & _
"LEFT JOIN pctype ON m.pctypeid = pctype.pctypeid " & _
"LEFT JOIN machinestatus ON m.machinestatusid = machinestatus.machinestatusid " & _
"WHERE m.isactive = 1 AND m.pctypeid IS NOT NULL"
' Apply filters
whereClause = ""
If pcTypeFilter <> "" Then
whereClause = whereClause & "AND m.pctypeid = " & pcTypeFilter & " "
End If
If pcStatusFilter <> "" Then
whereClause = whereClause & "AND m.machinestatusid = " & pcStatusFilter & " "
End If
If recentDaysFilter <> "" And IsNumeric(recentDaysFilter) Then
whereClause = whereClause & "AND m.lastupdated >= DATE_SUB(NOW(), INTERVAL " & recentDaysFilter & " DAY) "
End If
' Filter by device type (laptop vs desktop) based on model name patterns
If deviceTypeFilterSQL = "laptop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%Latitude%' OR models.modelnumber LIKE '%Precision%' AND (models.modelnumber NOT LIKE '%Tower%')) "
ElseIf deviceTypeFilterSQL = "desktop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%OptiPlex%' OR models.modelnumber LIKE '%Tower%' OR models.modelnumber LIKE '%Micro%') "
End If
strSQL = strSQL & whereClause & " GROUP BY m.machineid ORDER BY m.machinenumber ASC, m.hostname ASC"
set rs = objconn.Execute(strSQL)
while not rs.eof
%>
<td><a href="./displaypc.asp?machineid=<%Response.Write(rs("machineid"))%>" title="Click to Show PC Details"><%
Dim displayName
If IsNull(rs("hostname")) Or rs("hostname") = "" Then
displayName = rs("serialnumber")
Else
displayName = rs("hostname")
End If
Response.Write(displayName)
%></a></td>
<td><%Response.Write(rs("serialnumber"))%></td>
<td><%Response.Write(rs("ipaddress"))%></td>
<td><%Response.Write(rs("modelnumber"))%></td>
<td><%Response.Write(rs("operatingsystem"))%></td>
<td><a href="./search.asp?search=<%Response.Write(rs("machinenumber"))%>" title="Click to Show Machine Details"><%Response.Write(rs("machinenumber"))%></td>
</tr>
<%
rs.movenext
wend
objConn.Close
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Filter Update Script -->
<script>
function updateFilter(param, value) {
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
if (value === '') {
params.delete(param);
} else {
params.set(param, value);
}
window.location.href = 'listpcs.asp' + (params.toString() ? '?' + params.toString() : '');
}
</script>
<!-- Warranty Check Script -->
<script>
$(document).ready(function() {
$('#checkAllWarrantiesBtn').on('click', function() {
var $btn = $(this);
var originalHtml = $btn.html();
// Confirm with user
if (!confirm('This will check the Dell warranty API for all PCs without warranty information.\n\nContinue?')) {
return;
}
// Disable button and show loading
$btn.prop('disabled', true);
$btn.html('<i class="zmdi zmdi-refresh zmdi-hc-spin"></i> Checking...');
// Call warranty check endpoint
$.ajax({
url: './check_all_warranties.asp',
type: 'GET',
dataType: 'json',
timeout: 300000, // 5 minute timeout
success: function(response) {
if (response.success) {
var message = 'Warranty Check Complete!\n\n' +
'Total Devices: ' + response.total + '\n' +
'Successfully Updated: ' + response.updated + '\n' +
'Errors: ' + response.errors;
if (response.errorDetails && response.errorDetails.length > 0) {
message += '\n\nError Details:\n';
for (var i = 0; i < response.errorDetails.length; i++) {
var err = response.errorDetails[i];
message += '- ' + err.pc + ' (' + err.serial + '): ' + err.reason + '\n';
}
}
message += '\n\nThe page will now reload to show updated information.';
alert(message);
location.reload();
} else {
alert('Error: ' + (response.message || 'Unknown error occurred'));
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
},
error: function(xhr, status, error) {
alert('Error checking warranties:\n' + error + '\n\nPlease try again or contact support.');
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
});
});
});
</script>
</body>
</html>

View File

@@ -1,443 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<link rel="stylesheet" href="./leaflet/leaflet.css">
<script src="./leaflet/leaflet.js"></script>
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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="row">
<div class="col-lg-9">
<div class="card">
<div class="card-body" style="padding:0;">
<div style="padding:15px; border-bottom:1px solid #444;">
<h5 class="card-title" style="margin:0; display:inline-block;">
<i class='zmdi zmdi-network'></i>&nbsp;&nbsp;Network Infrastructure Map
</h5>
<div style="float:right;">
<input type="text" id="machineSearch" class="form-control form-control-sm" placeholder="Search by name, IP, vendor, model..." style="display:inline-block; width:250px; margin-right:15px;">
<label style="margin-right:10px; display:inline-block; color:#aaa;">Filter by Type:</label>
<select id="machineTypeFilter" class="form-control form-control-sm" style="display:inline-block; width:200px;">
<option value="all">All Equipment</option>
<option value="Access Point">Access Point</option>
<option value="Camera">Camera</option>
<option value="IDF">IDF</option>
<option value="Printer">Printer</option>
<option value="Server">Server</option>
<option value="Switch">Switch</option>
</select>
</div>
</div>
<div id="map"></div>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="card">
<div class="card-header" style="background: linear-gradient(45deg, #667eea, #764ba2); color: white;">
<i class="zmdi zmdi-info"></i> Legend
</div>
<div class="card-body">
<p style="font-size:12px; color:#aaa; margin-bottom:15px;">
Equipment type color codes:
</p>
<div style="margin-bottom:20px;">
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#4CAF50; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">Printer</span>
</div>
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#2196F3; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">Access Point</span>
</div>
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#FF9800; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">IDF</span>
</div>
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#F44336; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">Camera</span>
</div>
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#9C27B0; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">Switch</span>
</div>
<div style="margin:8px 0; display:flex; align-items:center;">
<span style="display:inline-block; width:16px; height:16px; background:#607D8B; border-radius:50%; margin-right:10px; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></span>
<span style="font-size:13px; color:#fff;">Server</span>
</div>
</div>
<div style="margin-top:20px; padding:15px; background:#2a2a2a; border-radius:4px; font-size:12px;">
<strong style="color:#4fc3f7;">Tips:</strong>
<ul style="margin:8px 0; padding-left:20px; color:#aaa;">
<li style="margin:5px 0;">Hover over markers for details</li>
<li style="margin:5px 0;">Use search to find specific equipment</li>
<li style="margin:5px 0;">Filter by type to focus on specific equipment</li>
<li style="margin:5px 0;">Click "View Details" for full information</li>
</ul>
</div>
</div>
</div>
</div>
</div><!--End Row-->
</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">
</div>
</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>
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<script src="assets/js/sidebar-menu.js"></script>
<script src="assets/js/app-script.js"></script>
<style>
#map {
width: 100%;
height: calc(100vh - 250px);
min-height: 600px;
background-color: #1a1a1a;
}
.leaflet-control-zoom a {
background-color: #2a2a2a !important;
color: #fff !important;
border-color: #444 !important;
}
.leaflet-control-zoom a:hover {
background-color: #3a3a3a !important;
}
.leaflet-bar {
border: 1px solid #444 !important;
}
.leaflet-popup-content-wrapper {
background: #1f1f1f !important;
color: #fff !important;
box-shadow: 0 3px 14px rgba(0,0,0,0.6) !important;
border-radius: 4px !important;
padding: 0 !important;
}
.leaflet-popup-content {
margin: 0 !important;
}
.leaflet-popup-tip-container {
display: none !important;
}
.leaflet-popup-close-button {
color: #fff !important;
font-size: 24px !important;
padding: 4px 8px 0 0 !important;
}
.leaflet-control-attribution {
display: none !important;
}
</style>
<script>
// Get current theme
var bodyClass = document.body.className;
var themeMatch = bodyClass.match(/bg-theme(\d+)/);
var theme = themeMatch ? 'bg-theme' + themeMatch[1] : 'bg-theme1';
var themeConfig = {
'bg-theme1': { bg: '#2a2a2a', filter: 'brightness(0.7) contrast(1.1)', gradient: 'linear-gradient(45deg, #3a3a3a, #4a4a4a)' },
'bg-theme7': { bg: '#0c675e', filter: 'brightness(0.8) contrast(1.1) hue-rotate(-10deg)', gradient: 'linear-gradient(45deg, #0c675e, #069e90)' },
'bg-theme11': { bg: '#1565C0', filter: 'brightness(0.85) contrast(1.05) hue-rotate(-5deg)', gradient: 'linear-gradient(45deg, #1565C0, #1E88E5)' }
};
var config = themeConfig[theme] || { bg: '#1a1a1a', filter: 'brightness(0.7) contrast(1.1)', gradient: 'linear-gradient(45deg, #667eea, #764ba2)' };
document.getElementById('map').style.backgroundColor = config.bg;
var map = L.map('map', {
crs: L.CRS.Simple,
minZoom: -3
});
var bounds = [[0,0], [2550,3300]];
var lightThemes = ['bg-theme11', 'bg-theme13'];
var mapImage = lightThemes.includes(theme) ? './images/sitemap2025-light.png' : './images/sitemap2025-dark.png';
var image = L.imageOverlay(mapImage, bounds);
image.on('load', function() {
var imgElement = this.getElement();
if (imgElement) {
imgElement.style.filter = config.filter;
}
});
image.addTo(map);
var center = [1275, 1650];
map.setView(center, -2.3);
// Store machine data and markers
var machineMarkers = [];
// Machine type colors
var machineTypeColors = {
'Printer': '#4CAF50',
'Access Point': '#2196F3',
'IDF': '#FF9800',
'Camera': '#F44336',
'Switch': '#9C27B0',
'Server': '#607D8B',
'default': '#FFC107'
};
<%
' Query active network infrastructure machines with map coordinates
' Phase 3: Unified schema - printers stay separate, network devices in machines table
Dim strSQL, rs, mapleft, maptop, machineid, machinenumber, machineType, machineTypeId, modelnumber, vendor, alias, ipaddress, sourceTable
strSQL = "SELECT printers.printerid AS id, machines.machinenumber AS name, machines.alias, " &_
"printers.mapleft, printers.maptop, printers.ipaddress, NULL AS machinetypeid, " &_
"'Printer' AS type, models.modelnumber, vendors.vendor, 'printers' AS source " &_
"FROM printers " &_
"INNER JOIN machines ON printers.machineid = machines.machineid " &_
"LEFT JOIN models ON printers.modelid = models.modelnumberid " &_
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " &_
"WHERE printers.isactive = 1 " &_
"AND printers.mapleft IS NOT NULL " &_
"AND printers.maptop IS NOT NULL " &_
"UNION ALL " &_
"SELECT m.machineid AS id, m.machinenumber AS name, m.alias, " &_
"m.mapleft, m.maptop, c.address AS ipaddress, m.machinetypeid, " &_
"mt.machinetype AS type, mo.modelnumber, v.vendor, 'machines' AS source " &_
"FROM machines m " &_
"LEFT JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid " &_
"LEFT JOIN models mo ON m.modelnumberid = mo.modelnumberid " &_
"LEFT JOIN vendors v ON mo.vendorid = v.vendorid " &_
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid IN (1,3) " &_
"WHERE m.machinetypeid BETWEEN 30 AND 36 " &_
"AND m.isactive = 1 " &_
"AND m.mapleft IS NOT NULL " &_
"AND m.maptop IS NOT NULL " &_
"ORDER BY type, name ASC"
set rs = objConn.Execute(strSQL)
while not rs.eof
mapleft = rs("mapleft")
maptop = rs("maptop")
maptop = 2550-maptop
machineid = rs("id")
machinenumber = rs("name")
machineType = rs("type")
sourceTable = rs("source")
' machinetypeid may be NULL for infrastructure devices
if NOT IsNull(rs("machinetypeid")) then
machineTypeId = rs("machinetypeid")
else
machineTypeId = 0
end if
if NOT IsNull(rs("alias")) AND rs("alias") <> "" then
alias = rs("alias")
else
alias = machinenumber
end if
if NOT IsNull(rs("modelnumber")) then
modelnumber = rs("modelnumber")
else
modelnumber = "N/A"
end if
if NOT IsNull(rs("vendor")) then
vendor = rs("vendor")
else
vendor = "N/A"
end if
if NOT IsNull(rs("ipaddress")) then
ipaddress = rs("ipaddress")
else
ipaddress = "N/A"
end if
%>
(function() {
var machineId = '<%Response.Write(machineid)%>';
var machineName = '<%Response.Write(Server.HTMLEncode(alias))%>';
var machineNumber = '<%Response.Write(Server.HTMLEncode(machinenumber))%>';
var machineType = '<%Response.Write(Server.HTMLEncode(machineType))%>';
var machineTypeId = '<%Response.Write(machineTypeId)%>';
var model = '<%Response.Write(Server.HTMLEncode(modelnumber))%>';
var vendor = '<%Response.Write(Server.HTMLEncode(vendor))%>';
var ipAddress = '<%Response.Write(Server.HTMLEncode(ipaddress))%>';
var sourceTable = '<%Response.Write(sourceTable)%>';
// Get color for this machine type
var color = machineTypeColors[machineType] || machineTypeColors['default'];
// Create custom marker icon
var icon = L.divIcon({
html: '<div style="background:' + color + '; width:20px; height:20px; border-radius:50%; border:2px solid #fff; box-shadow:0 2px 5px rgba(0,0,0,0.5);"></div>',
iconSize: [20, 20],
iconAnchor: [10, 10],
popupAnchor: [0, -15],
className: 'custom-marker'
});
var marker = L.marker([<%Response.Write(maptop)%>, <%Response.Write(mapleft)%>], {
title: machineName,
icon: icon,
machineId: machineId,
machineTypeId: machineTypeId
}).addTo(map);
// Store marker with searchable data for filtering
machineMarkers.push({
marker: marker,
machineType: machineType,
searchData: {
name: machineName.toLowerCase(),
number: machineNumber.toLowerCase(),
type: machineType.toLowerCase(),
vendor: vendor.toLowerCase(),
model: model.toLowerCase(),
ip: ipAddress.toLowerCase()
}
});
// Open popup on hover, but don't close immediately on mouseout
// This allows users to click links in the popup
var popupTimeout;
marker.on('mouseover', function() {
clearTimeout(popupTimeout);
this.openPopup();
});
marker.on('mouseout', function(e) {
var popup = this.getPopup();
var popupElement = popup.getElement();
// Delay closing so user can move mouse to popup
popupTimeout = setTimeout(function() {
marker.closePopup();
}, 500); // 500ms delay
// Keep popup open if mouse moves over it
if (popupElement) {
popupElement.addEventListener('mouseenter', function() {
clearTimeout(popupTimeout);
});
popupElement.addEventListener('mouseleave', function() {
marker.closePopup();
});
}
});
// Determine the correct detail page URL based on source table
var detailUrl;
if (sourceTable === 'printers') {
detailUrl = './displayprinter.asp?printerid=' + machineId;
} else if (sourceTable === 'machines') {
detailUrl = './displaymachine.asp?machineid=' + machineId;
} else {
detailUrl = './network_devices.asp';
}
var popupContent = '<div style="background:#1f1f1f; color:#fff; min-width:250px; border-radius:4px; overflow:hidden;">' +
'<div style="background:' + config.gradient + '; padding:10px 15px; border-bottom:1px solid #444;">' +
'<h6 style="margin:0; color:#fff; font-size:14px;">' + machineName + '</h6>' +
'</div>' +
'<div style="padding:10px 15px; font-size:12px;">' +
'<div style="margin:5px 0;"><strong style="color:#aaa;">Number:</strong> <span style="color:#fff;">' + machineNumber + '</span></div>' +
'<div style="margin:5px 0;"><strong style="color:#aaa;">Type:</strong> <span style="color:' + color + '; font-weight:bold;">' + machineType + '</span></div>' +
(ipAddress !== 'N/A' ? '<div style="margin:5px 0;"><strong style="color:#aaa;">IP Address:</strong> <span style="color:#fff;">' + ipAddress + '</span></div>' : '') +
(vendor !== 'N/A' ? '<div style="margin:5px 0;"><strong style="color:#aaa;">Vendor:</strong> <span style="color:#fff;">' + vendor + '</span></div>' : '') +
(model !== 'N/A' ? '<div style="margin:5px 0;"><strong style="color:#aaa;">Model:</strong> <span style="color:#fff;">' + model + '</span></div>' : '') +
'</div>' +
'<div style="padding:10px 15px; border-top:1px solid #444; text-align:center;">' +
'<a href="' + detailUrl + '" style="display:inline-block; background:' + config.gradient + '; color:#fff; padding:8px 18px; border-radius:4px; text-decoration:none; font-size:13px; font-weight:500; transition:all 0.2s;" target="_blank" onmouseover="this.style.opacity=\'0.9\'" onmouseout="this.style.opacity=\'1\'"><i class="zmdi zmdi-eye"></i> View Details</a>' +
'</div>' +
'</div>';
marker.bindPopup(popupContent);
})();
<%
rs.movenext
wend
objConn.Close
%>
// Combined filter functionality (type + search)
function applyFilters() {
var selectedType = document.getElementById('machineTypeFilter').value;
var searchTerm = document.getElementById('machineSearch').value.toLowerCase().trim();
machineMarkers.forEach(function(item) {
var typeMatch = (selectedType === 'all' || item.machineType === selectedType);
var searchMatch = true;
if (searchTerm !== '') {
// Search across all searchable fields
searchMatch = item.searchData.name.indexOf(searchTerm) > -1 ||
item.searchData.number.indexOf(searchTerm) > -1 ||
item.searchData.type.indexOf(searchTerm) > -1 ||
item.searchData.vendor.indexOf(searchTerm) > -1 ||
item.searchData.model.indexOf(searchTerm) > -1 ||
item.searchData.ip.indexOf(searchTerm) > -1;
}
// Show marker only if it matches both type and search filters
if (typeMatch && searchMatch) {
item.marker.setOpacity(1);
} else {
item.marker.setOpacity(0.15);
}
});
}
// Listen to filter changes
document.getElementById('machineTypeFilter').addEventListener('change', applyFilters);
// Listen to search input with debouncing for better performance
var searchTimeout;
document.getElementById('machineSearch').addEventListener('input', function() {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(applyFilters, 300);
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -1,297 +0,0 @@
<%' Cache buster: 20251110-1432 %>
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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="row">
<div class="col-xl-auto">
<div class="card">
<div class="card-body">
<div style="margin-bottom:15px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:15px;">
<h5 class="card-title" style="margin:0;">PCs</h5>
<div>
<a href="./adddevice.asp" class="btn btn-primary">
<i class="zmdi zmdi-plus-circle"></i> Add Device
</a>
</div>
</div>
<%
Dim currentPCType, currentPCStatus, recentFilter, deviceTypeFilter, sel
currentPCType = Request.QueryString("pctype")
currentPCStatus = Request.QueryString("pcstatus")
recentFilter = Request.QueryString("recent")
deviceTypeFilter = Request.QueryString("devicetype")
%>
<div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">
<select id="deviceTypeFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('devicetype', this.value)">
<option value="">All Device Types</option>
<option value="laptop"<% If deviceTypeFilter = "laptop" Then Response.Write(" selected") End If%>>Laptops</option>
<option value="desktop"<% If deviceTypeFilter = "desktop" Then Response.Write(" selected") End If%>>Desktops</option>
</select>
<select id="pcTypeSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pctype', this.value)">
<option value="">All PC Types</option>
<%
Dim rsTypes, rsStatus, selectedAttr
Set rsTypes = objConn.Execute("SELECT pctypeid, typename FROM pctype WHERE isactive = '1' ORDER BY displayorder, typename")
While Not rsTypes.EOF
selectedAttr = ""
If CStr(rsTypes("pctypeid")) = CStr(currentPCType) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsTypes("pctypeid") & """" & selectedAttr & ">" & rsTypes("typename") & "</option>" & vbCrLf
rsTypes.MoveNext
Wend
rsTypes.Close
Set rsTypes = Nothing
%>
</select>
<select id="pcStatusSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pcstatus', this.value)">
<option value="">All Statuses</option>
<%
Set rsStatus = objConn.Execute("SELECT machinestatusid, machinestatus FROM machinestatus WHERE isactive = 1 ORDER BY machinestatusid")
While Not rsStatus.EOF
selectedAttr = ""
If CStr(rsStatus("machinestatusid")) = CStr(currentPCStatus) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsStatus("machinestatusid") & """" & selectedAttr & ">" & rsStatus("machinestatus") & "</option>" & vbCrLf
rsStatus.MoveNext
Wend
rsStatus.Close
Set rsStatus = Nothing
%>
</select>
<select id="recentFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('recent', this.value)">
<option value="">All Time</option>
<option value="7"<% If recentFilter = "7" Then Response.Write(" selected") End If%>>Last 7 Days</option>
</select>
<% If currentPCType <> "" Or currentPCStatus <> "" Or recentFilter <> "" Or deviceTypeFilter <> "" Then %>
<a href="pclist.asp" class="btn btn-outline-secondary btn-sm">
<i class="zmdi zmdi-close"></i> Clear
</a>
<% End If %>
<button id="checkAllWarrantiesBtn" class="btn btn-info btn-sm" title="Check Dell warranty API for all PCs without warranty information" disabled>
<i class="zmdi zmdi-refresh"></i> Check Warranties
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Hostname</th>
<th scope="col">Serial</th>
<th scope="col">IP</th>
<th scope="col">Model</th>
<th scope="col">OS</th>
<th scope="col">Machine</th>
</tr>
</thead>
<tbody>
<%
' Build query based on filters
Dim pcTypeFilter, pcStatusFilter, recentDaysFilter, deviceTypeFilterSQL, whereClause
pcTypeFilter = Request.QueryString("pctype")
pcStatusFilter = Request.QueryString("pcstatus")
recentDaysFilter = Request.QueryString("recent")
deviceTypeFilterSQL = Request.QueryString("devicetype")
' Base query with LEFT JOINs to show all PCs
strSQL = "SELECT m.machineid, m.hostname, m.alias, m.serialnumber, m.machinenumber, m.pctypeid, m.machinestatusid, " & _
"m.modelnumberid, m.businessunitid, m.osid, m.loggedinuser, m.lastupdated, " & _
"vendors.vendor, models.modelnumber, operatingsystems.operatingsystem, " & _
"c.address AS ipaddress, c.macaddress, " & _
"models.machinetypeid, pctype.typename, machinestatus.machinestatus " & _
"FROM machines m " & _
"LEFT JOIN models ON m.modelnumberid = models.modelnumberid " & _
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " & _
"LEFT JOIN operatingsystems ON m.osid = operatingsystems.osid " & _
"LEFT JOIN communications c ON c.machineid = m.machineid AND c.isprimary = 1 " & _
"LEFT JOIN pctype ON m.pctypeid = pctype.pctypeid " & _
"LEFT JOIN machinestatus ON m.machinestatusid = machinestatus.machinestatusid " & _
"WHERE m.isactive = 1 AND m.pctypeid IS NOT NULL"
' Apply filters
whereClause = ""
If pcTypeFilter <> "" Then
whereClause = whereClause & "AND m.pctypeid = " & pcTypeFilter & " "
End If
If pcStatusFilter <> "" Then
whereClause = whereClause & "AND m.machinestatusid = " & pcStatusFilter & " "
End If
If recentDaysFilter <> "" And IsNumeric(recentDaysFilter) Then
whereClause = whereClause & "AND m.lastupdated >= DATE_SUB(NOW(), INTERVAL " & recentDaysFilter & " DAY) "
End If
' Filter by device type (laptop vs desktop) based on model name patterns
If deviceTypeFilterSQL = "laptop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%Latitude%' OR models.modelnumber LIKE '%Precision%' AND (models.modelnumber NOT LIKE '%Tower%')) "
ElseIf deviceTypeFilterSQL = "desktop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%OptiPlex%' OR models.modelnumber LIKE '%Tower%' OR models.modelnumber LIKE '%Micro%') "
End If
strSQL = strSQL & whereClause & " GROUP BY m.machineid ORDER BY m.machinenumber ASC, m.hostname ASC"
set rs = objconn.Execute(strSQL)
while not rs.eof
%>
<td><a href="./displaypc.asp?machineid=<%Response.Write(rs("machineid"))%>" title="Click to Show PC Details"><%
Dim displayName
If IsNull(rs("hostname")) Or rs("hostname") = "" Then
displayName = rs("serialnumber")
Else
displayName = rs("hostname")
End If
Response.Write(displayName)
%></a></td>
<td><%Response.Write(rs("serialnumber"))%></td>
<td><%Response.Write(rs("ipaddress"))%></td>
<td><%Response.Write(rs("modelnumber"))%></td>
<td><%Response.Write(rs("operatingsystem"))%></td>
<td><a href="./search.asp?search=<%Response.Write(rs("machinenumber"))%>" title="Click to Show Machine Details"><%Response.Write(rs("machinenumber"))%></td>
</tr>
<%
rs.movenext
wend
objConn.Close
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Filter Update Script -->
<script>
function updateFilter(param, value) {
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
if (value === '') {
params.delete(param);
} else {
params.set(param, value);
}
window.location.href = 'pclist.asp' + (params.toString() ? '?' + params.toString() : '');
}
</script>
<!-- Warranty Check Script -->
<script>
$(document).ready(function() {
$('#checkAllWarrantiesBtn').on('click', function() {
var $btn = $(this);
var originalHtml = $btn.html();
// Confirm with user
if (!confirm('This will check the Dell warranty API for all PCs without warranty information.\n\nContinue?')) {
return;
}
// Disable button and show loading
$btn.prop('disabled', true);
$btn.html('<i class="zmdi zmdi-refresh zmdi-hc-spin"></i> Checking...');
// Call warranty check endpoint
$.ajax({
url: './check_all_warranties.asp',
type: 'GET',
dataType: 'json',
timeout: 300000, // 5 minute timeout
success: function(response) {
if (response.success) {
var message = 'Warranty Check Complete!\n\n' +
'Total Devices: ' + response.total + '\n' +
'Successfully Updated: ' + response.updated + '\n' +
'Errors: ' + response.errors;
if (response.errorDetails && response.errorDetails.length > 0) {
message += '\n\nError Details:\n';
for (var i = 0; i < response.errorDetails.length; i++) {
var err = response.errorDetails[i];
message += '- ' + err.pc + ' (' + err.serial + '): ' + err.reason + '\n';
}
}
message += '\n\nThe page will now reload to show updated information.';
alert(message);
location.reload();
} else {
alert('Error: ' + (response.message || 'Unknown error occurred'));
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
},
error: function(xhr, status, error) {
alert('Error checking warranties:\n' + error + '\n\nPlease try again or contact support.');
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
});
});
});
</script>
</body>
</html>

297
pcs.asp
View File

@@ -1,297 +0,0 @@
<%' Cache buster: 20251110-1430 %>
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
</head>
<%
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
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="row">
<div class="col-xl-auto">
<div class="card">
<div class="card-body">
<div style="margin-bottom:15px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:15px;">
<h5 class="card-title" style="margin:0;">PCs</h5>
<div>
<a href="./adddevice.asp" class="btn btn-primary">
<i class="zmdi zmdi-plus-circle"></i> Add Device
</a>
</div>
</div>
<%
Dim currentPCType, currentPCStatus, recentFilter, deviceTypeFilter, sel
currentPCType = Request.QueryString("pctype")
currentPCStatus = Request.QueryString("pcstatus")
recentFilter = Request.QueryString("recent")
deviceTypeFilter = Request.QueryString("devicetype")
%>
<div style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">
<select id="deviceTypeFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('devicetype', this.value)">
<option value="">All Device Types</option>
<option value="laptop"<% If deviceTypeFilter = "laptop" Then Response.Write(" selected") End If%>>Laptops</option>
<option value="desktop"<% If deviceTypeFilter = "desktop" Then Response.Write(" selected") End If%>>Desktops</option>
</select>
<select id="pcTypeSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pctype', this.value)">
<option value="">All PC Types</option>
<%
Dim rsTypes, rsStatus, selectedAttr
Set rsTypes = objConn.Execute("SELECT pctypeid, typename FROM pctype WHERE isactive = '1' ORDER BY displayorder, typename")
While Not rsTypes.EOF
selectedAttr = ""
If CStr(rsTypes("pctypeid")) = CStr(currentPCType) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsTypes("pctypeid") & """" & selectedAttr & ">" & rsTypes("typename") & "</option>" & vbCrLf
rsTypes.MoveNext
Wend
rsTypes.Close
Set rsTypes = Nothing
%>
</select>
<select id="pcStatusSelect" class="btn btn-secondary btn-sm" onchange="updateFilter('pcstatus', this.value)">
<option value="">All Statuses</option>
<%
Set rsStatus = objConn.Execute("SELECT machinestatusid, machinestatus FROM machinestatus WHERE isactive = 1 ORDER BY machinestatusid")
While Not rsStatus.EOF
selectedAttr = ""
If CStr(rsStatus("machinestatusid")) = CStr(currentPCStatus) Then
selectedAttr = " selected"
End If
Response.Write "<option value=""" & rsStatus("machinestatusid") & """" & selectedAttr & ">" & rsStatus("machinestatus") & "</option>" & vbCrLf
rsStatus.MoveNext
Wend
rsStatus.Close
Set rsStatus = Nothing
%>
</select>
<select id="recentFilter" class="btn btn-secondary btn-sm" onchange="updateFilter('recent', this.value)">
<option value="">All Time</option>
<option value="7"<% If recentFilter = "7" Then Response.Write(" selected") End If%>>Last 7 Days</option>
</select>
<% If currentPCType <> "" Or currentPCStatus <> "" Or recentFilter <> "" Or deviceTypeFilter <> "" Then %>
<a href="listpcs.asp" class="btn btn-outline-secondary btn-sm">
<i class="zmdi zmdi-close"></i> Clear
</a>
<% End If %>
<button id="checkAllWarrantiesBtn" class="btn btn-info btn-sm" title="Check Dell warranty API for all PCs without warranty information" disabled>
<i class="zmdi zmdi-refresh"></i> Check Warranties
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Hostname</th>
<th scope="col">Serial</th>
<th scope="col">IP</th>
<th scope="col">Model</th>
<th scope="col">OS</th>
<th scope="col">Machine</th>
</tr>
</thead>
<tbody>
<%
' Build query based on filters
Dim pcTypeFilter, pcStatusFilter, recentDaysFilter, deviceTypeFilterSQL, whereClause
pcTypeFilter = Request.QueryString("pctype")
pcStatusFilter = Request.QueryString("pcstatus")
recentDaysFilter = Request.QueryString("recent")
deviceTypeFilterSQL = Request.QueryString("devicetype")
' Base query with LEFT JOINs to show all PCs
strSQL = "SELECT m.machineid, m.hostname, m.alias, m.serialnumber, m.machinenumber, m.pctypeid, m.machinestatusid, " & _
"m.modelnumberid, m.businessunitid, m.osid, m.loggedinuser, m.lastupdated, " & _
"vendors.vendor, models.modelnumber, operatingsystems.operatingsystem, " & _
"c.address AS ipaddress, c.macaddress, " & _
"models.machinetypeid, pctype.typename, machinestatus.machinestatus " & _
"FROM machines m " & _
"LEFT JOIN models ON m.modelnumberid = models.modelnumberid " & _
"LEFT JOIN vendors ON models.vendorid = vendors.vendorid " & _
"LEFT JOIN operatingsystems ON m.osid = operatingsystems.osid " & _
"LEFT JOIN communications c ON c.machineid = m.machineid AND c.isprimary = 1 " & _
"LEFT JOIN pctype ON m.pctypeid = pctype.pctypeid " & _
"LEFT JOIN machinestatus ON m.machinestatusid = machinestatus.machinestatusid " & _
"WHERE m.isactive = 1 AND m.pctypeid IS NOT NULL"
' Apply filters
whereClause = ""
If pcTypeFilter <> "" Then
whereClause = whereClause & "AND m.pctypeid = " & pcTypeFilter & " "
End If
If pcStatusFilter <> "" Then
whereClause = whereClause & "AND m.machinestatusid = " & pcStatusFilter & " "
End If
If recentDaysFilter <> "" And IsNumeric(recentDaysFilter) Then
whereClause = whereClause & "AND m.lastupdated >= DATE_SUB(NOW(), INTERVAL " & recentDaysFilter & " DAY) "
End If
' Filter by device type (laptop vs desktop) based on model name patterns
If deviceTypeFilterSQL = "laptop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%Latitude%' OR models.modelnumber LIKE '%Precision%' AND (models.modelnumber NOT LIKE '%Tower%')) "
ElseIf deviceTypeFilterSQL = "desktop" Then
whereClause = whereClause & "AND (models.modelnumber LIKE '%OptiPlex%' OR models.modelnumber LIKE '%Tower%' OR models.modelnumber LIKE '%Micro%') "
End If
strSQL = strSQL & whereClause & " GROUP BY m.machineid ORDER BY m.machinenumber ASC, m.hostname ASC"
set rs = objconn.Execute(strSQL)
while not rs.eof
%>
<td><a href="./displaypc.asp?machineid=<%Response.Write(rs("machineid"))%>" title="Click to Show PC Details"><%
Dim displayName
If IsNull(rs("hostname")) Or rs("hostname") = "" Then
displayName = rs("serialnumber")
Else
displayName = rs("hostname")
End If
Response.Write(displayName)
%></a></td>
<td><%Response.Write(rs("serialnumber"))%></td>
<td><%Response.Write(rs("ipaddress"))%></td>
<td><%Response.Write(rs("modelnumber"))%></td>
<td><%Response.Write(rs("operatingsystem"))%></td>
<td><a href="./search.asp?search=<%Response.Write(rs("machinenumber"))%>" title="Click to Show Machine Details"><%Response.Write(rs("machinenumber"))%></td>
</tr>
<%
rs.movenext
wend
objConn.Close
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<!-- Filter Update Script -->
<script>
function updateFilter(param, value) {
var url = new URL(window.location.href);
var params = new URLSearchParams(url.search);
if (value === '') {
params.delete(param);
} else {
params.set(param, value);
}
window.location.href = 'listpcs.asp' + (params.toString() ? '?' + params.toString() : '');
}
</script>
<!-- Warranty Check Script -->
<script>
$(document).ready(function() {
$('#checkAllWarrantiesBtn').on('click', function() {
var $btn = $(this);
var originalHtml = $btn.html();
// Confirm with user
if (!confirm('This will check the Dell warranty API for all PCs without warranty information.\n\nContinue?')) {
return;
}
// Disable button and show loading
$btn.prop('disabled', true);
$btn.html('<i class="zmdi zmdi-refresh zmdi-hc-spin"></i> Checking...');
// Call warranty check endpoint
$.ajax({
url: './check_all_warranties.asp',
type: 'GET',
dataType: 'json',
timeout: 300000, // 5 minute timeout
success: function(response) {
if (response.success) {
var message = 'Warranty Check Complete!\n\n' +
'Total Devices: ' + response.total + '\n' +
'Successfully Updated: ' + response.updated + '\n' +
'Errors: ' + response.errors;
if (response.errorDetails && response.errorDetails.length > 0) {
message += '\n\nError Details:\n';
for (var i = 0; i < response.errorDetails.length; i++) {
var err = response.errorDetails[i];
message += '- ' + err.pc + ' (' + err.serial + '): ' + err.reason + '\n';
}
}
message += '\n\nThe page will now reload to show updated information.';
alert(message);
location.reload();
} else {
alert('Error: ' + (response.message || 'Unknown error occurred'));
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
},
error: function(xhr, status, error) {
alert('Error checking warranties:\n' + error + '\n\nPlease try again or contact support.');
$btn.prop('disabled', false);
$btn.html(originalHtml);
}
});
});
});
</script>
</body>
</html>

View File

@@ -1,32 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<%
' Lookup printer by IP address and redirect to displayprinter.asp
Dim ipaddress, strSQL, rs
ipaddress = Request.QueryString("ip")
If ipaddress <> "" Then
strSQL = "SELECT printerid FROM printers WHERE ipaddress = '" & Replace(ipaddress, "'", "''") & "' AND isactive = 1"
Set rs = objConn.Execute(strSQL)
If Not rs.EOF Then
Response.Redirect("displayprinter.asp?printerid=" & rs("printerid"))
Else
Response.Write("Printer not found with IP: " & Server.HTMLEncode(ipaddress))
End If
rs.Close
Set rs = Nothing
Else
Response.Write("No IP address provided")
End If
objConn.Close
%>
</body>
</html>

View File

@@ -1,448 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/error_handler.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
<%
' Universal save endpoint for all network devices (IDF, Server, Switch, Camera)
' Routes to appropriate table based on device type
' Get device type and ID
Dim deviceType, deviceId, isDelete
deviceType = Trim(Request.Form("type"))
deviceId = Trim(Request.Form("id"))
isDelete = Trim(Request.Form("delete"))
' Validate device type
If deviceType <> "idf" And deviceType <> "server" And deviceType <> "switch" And deviceType <> "camera" And deviceType <> "accesspoint" Then
Response.Write("<html><body><div style='color:red;'>Error: Invalid device type</div>")
Response.Write("<a href='network_devices.asp'>Back to Network Devices</a></body></html>")
objConn.Close
Response.End
End If
' Validate device ID
If deviceId = "" Then deviceId = "0"
If Not IsNumeric(deviceId) Then
Response.Write("<html><body><div style='color:red;'>Error: Invalid device ID</div>")
Response.Write("<a href='network_devices.asp'>Back to Network Devices</a></body></html>")
objConn.Close
Response.End
End If
' Map type to table and fields
Dim tableName, idField, nameField, redirectUrl
Select Case deviceType
Case "idf"
tableName = "idfs"
idField = "idfid"
nameField = "idfname"
redirectUrl = "network_devices.asp?filter=IDF"
Case "server"
tableName = "servers"
idField = "serverid"
nameField = "servername"
redirectUrl = "network_devices.asp?filter=Server"
Case "switch"
tableName = "switches"
idField = "switchid"
nameField = "switchname"
redirectUrl = "network_devices.asp?filter=Switch"
Case "camera"
tableName = "cameras"
idField = "cameraid"
nameField = "cameraname"
redirectUrl = "network_devices.asp?filter=Camera"
Case "accesspoint"
tableName = "accesspoints"
idField = "apid"
nameField = "apname"
redirectUrl = "network_devices.asp?filter=Access Point"
End Select
' Handle DELETE request
If isDelete = "1" Then
' Soft delete - set isactive = 0
Dim strDelete
strDelete = "UPDATE " & tableName & " SET isactive = 0 WHERE " & idField & " = " & deviceId
objConn.Execute(strDelete)
objConn.Close
Response.Redirect(redirectUrl)
Response.End
End If
' Get form data
Dim deviceName, description, maptop, mapleft, isactiveForm
deviceName = Trim(Request.Form(nameField))
description = Trim(Request.Form("description"))
maptop = Trim(Request.Form("maptop"))
mapleft = Trim(Request.Form("mapleft"))
isactiveForm = Trim(Request.Form("isactive"))
' Handle isactive - checkbox: checked=1, unchecked=empty string
' Default to 0 (inactive) if not provided (unchecked)
If isactiveForm = "1" Then
isactiveForm = "1"
Else
isactiveForm = "0"
End If
' Validate name field (required for all)
If deviceName = "" Then
Response.Write("<html><body><div style='color:red;'>Error: " & UCase(Left(nameField, 1)) & Mid(nameField, 2) & " is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(deviceName) > 100 Or Len(description) > 255 Then
Response.Write("<html><body><div style='color:red;'>Error: Field length exceeded</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Handle NULL values for optional numeric fields
If maptop = "" Or Not IsNumeric(maptop) Then maptop = "NULL" Else maptop = CLng(maptop)
If mapleft = "" Or Not IsNumeric(mapleft) Then mapleft = "NULL" Else mapleft = CLng(mapleft)
' Escape single quotes for SQL
deviceName = Replace(deviceName, "'", "''")
description = Replace(description, "'", "''")
' Build SQL based on device type
Dim strSQL
If deviceType = "idf" Then
' IDF - no model/vendor
If deviceId = "0" Then
' INSERT
strSQL = "INSERT INTO idfs (idfname, description, maptop, mapleft, isactive) " & _
"VALUES ('" & deviceName & "', '" & description & "', " & maptop & ", " & mapleft & ", " & isactiveForm & ")"
Else
' UPDATE
strSQL = "UPDATE idfs SET " & _
"idfname = '" & deviceName & "', " & _
"description = '" & description & "', " & _
"maptop = " & maptop & ", " & _
"mapleft = " & mapleft & ", " & _
"isactive = " & isactiveForm & " " & _
"WHERE idfid = " & deviceId
End If
ElseIf deviceType = "server" Or deviceType = "switch" Or deviceType = "accesspoint" Then
' Server/Switch/Access Point - has modelid but NO idfid
Dim modelid, serialnumber, ipaddress
modelid = Trim(Request.Form("modelid"))
serialnumber = Trim(Request.Form("serialnumber"))
ipaddress = Trim(Request.Form("ipaddress"))
' Handle new model creation
If modelid = "new" Then
Dim newmodelnumber, newvendorid, newmodelnotes, newmodeldocpath, newvendorname
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelnotes = Trim(Request.Form("newmodelnotes"))
newmodeldocpath = Trim(Request.Form("newmodeldocpath"))
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields for new model
If newmodelnumber = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Model number is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
If newvendorid = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Vendor is required for new model</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If newvendorname = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Vendor name is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Escape and insert new vendor
Dim escapedVendorName, sqlNewVendor
escapedVendorName = Replace(newvendorname, "'", "''")
sqlNewVendor = "INSERT INTO vendors (vendor, isactive) VALUES ('" & escapedVendorName & "', 1)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error creating vendor: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Get newly created vendor ID
Dim rsNewVendor
Set rsNewVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newvendorid = rsNewVendor("newid")
rsNewVendor.Close
Set rsNewVendor = Nothing
On Error Goto 0
End If
' Escape and insert new model
Dim escapedModelNumber, escapedModelNotes, escapedModelDocPath, sqlNewModel
escapedModelNumber = Replace(newmodelnumber, "'", "''")
escapedModelNotes = Replace(newmodelnotes, "'", "''")
escapedModelDocPath = Replace(newmodeldocpath, "'", "''")
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) " & _
"VALUES ('" & escapedModelNumber & "', " & newvendorid & ", '" & escapedModelNotes & "', '" & escapedModelDocPath & "', 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error creating model: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Get newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelid = rsNewModel("newid")
rsNewModel.Close
Set rsNewModel = Nothing
On Error Goto 0
' Handle NULL/empty modelid
ElseIf modelid = "" Or Not IsNumeric(modelid) Then
modelid = "NULL"
Else
modelid = CLng(modelid)
End If
' Escape strings
serialnumber = Replace(serialnumber, "'", "''")
ipaddress = Replace(ipaddress, "'", "''")
' Validate lengths
If Len(serialnumber) > 100 Or Len(ipaddress) > 45 Then
Response.Write("<html><body><div style='color:red;'>Error: Field length exceeded</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
If deviceId = "0" Then
' INSERT
strSQL = "INSERT INTO " & tableName & " (" & nameField & ", modelid, serialnumber, ipaddress, description, maptop, mapleft, isactive) " & _
"VALUES ('" & deviceName & "', " & modelid & ", '" & serialnumber & "', '" & ipaddress & "', '" & description & "', " & maptop & ", " & mapleft & ", " & isactiveForm & ")"
Else
' UPDATE
strSQL = "UPDATE " & tableName & " SET " & _
nameField & " = '" & deviceName & "', " & _
"modelid = " & modelid & ", " & _
"serialnumber = '" & serialnumber & "', " & _
"ipaddress = '" & ipaddress & "', " & _
"description = '" & description & "', " & _
"maptop = " & maptop & ", " & _
"mapleft = " & mapleft & ", " & _
"isactive = " & isactiveForm & " " & _
"WHERE " & idField & " = " & deviceId
End If
ElseIf deviceType = "camera" Then
' Camera - has modelid, idfid, AND macaddress
Dim cameraModelid, cameraIdfid, cameraSerial, cameraMac, cameraIP
cameraModelid = Trim(Request.Form("modelid"))
cameraIdfid = Trim(Request.Form("idfid"))
cameraSerial = Trim(Request.Form("serialnumber"))
cameraMac = Trim(Request.Form("macaddress"))
cameraIP = Trim(Request.Form("ipaddress"))
' Handle new IDF creation for camera
If cameraIdfid = "new" Then
Dim cameraNewidfname, cameraNewidfdescription
cameraNewidfname = Trim(Request.Form("newidfname"))
cameraNewidfdescription = Trim(Request.Form("newidfdescription"))
' Validate required fields for new IDF
If cameraNewidfname = "" Then
Response.Write("<html><body><div style='color:red;'>Error: IDF name is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Escape and insert new IDF
Dim cameraEscapedIdfName, cameraEscapedIdfDesc, cameraSqlNewIdf
cameraEscapedIdfName = Replace(cameraNewidfname, "'", "''")
cameraEscapedIdfDesc = Replace(cameraNewidfdescription, "'", "''")
cameraSqlNewIdf = "INSERT INTO idfs (idfname, description, isactive) VALUES ('" & cameraEscapedIdfName & "', '" & cameraEscapedIdfDesc & "', 1)"
On Error Resume Next
objConn.Execute cameraSqlNewIdf
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error creating IDF: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Get newly created IDF ID
Dim rsNewIdfCamera
Set rsNewIdfCamera = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
cameraIdfid = CLng(rsNewIdfCamera("newid"))
rsNewIdfCamera.Close
Set rsNewIdfCamera = Nothing
On Error Goto 0
End If
' Validate required idfid for cameras
If cameraIdfid = "" Or Not IsNumeric(cameraIdfid) Or CLng(cameraIdfid) < 1 Then
Response.Write("<html><body><div style='color:red;'>Error: IDF location is required for cameras</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Handle new model creation for camera
If cameraModelid = "new" Then
Dim cameraNewmodelnumber, cameraNewvendorid, cameraNewmodelnotes, cameraNewmodeldocpath, cameraNewvendorname
cameraNewmodelnumber = Trim(Request.Form("newmodelnumber"))
cameraNewvendorid = Trim(Request.Form("newvendorid"))
cameraNewmodelnotes = Trim(Request.Form("newmodelnotes"))
cameraNewmodeldocpath = Trim(Request.Form("newmodeldocpath"))
cameraNewvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields for new model
If cameraNewmodelnumber = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Model number is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
If cameraNewvendorid = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Vendor is required for new model</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If cameraNewvendorid = "new" Then
If cameraNewvendorname = "" Then
Response.Write("<html><body><div style='color:red;'>Error: Vendor name is required</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Escape and insert new vendor
Dim cameraEscapedVendorName, cameraSqlNewVendor
cameraEscapedVendorName = Replace(cameraNewvendorname, "'", "''")
cameraSqlNewVendor = "INSERT INTO vendors (vendor, isactive) VALUES ('" & cameraEscapedVendorName & "', 1)"
On Error Resume Next
objConn.Execute cameraSqlNewVendor
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error creating vendor: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Get newly created vendor ID
Dim rsNewVendorCamera
Set rsNewVendorCamera = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
cameraNewvendorid = rsNewVendorCamera("newid")
rsNewVendorCamera.Close
Set rsNewVendorCamera = Nothing
On Error Goto 0
End If
' Escape and insert new model
Dim cameraEscapedModelNumber, cameraEscapedModelNotes, cameraEscapedModelDocPath, cameraSqlNewModel
cameraEscapedModelNumber = Replace(cameraNewmodelnumber, "'", "''")
cameraEscapedModelNotes = Replace(cameraNewmodelnotes, "'", "''")
cameraEscapedModelDocPath = Replace(cameraNewmodeldocpath, "'", "''")
cameraSqlNewModel = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) " & _
"VALUES ('" & cameraEscapedModelNumber & "', " & cameraNewvendorid & ", '" & cameraEscapedModelNotes & "', '" & cameraEscapedModelDocPath & "', 1)"
On Error Resume Next
objConn.Execute cameraSqlNewModel
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error creating model: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
' Get newly created model ID
Dim rsNewModelCamera
Set rsNewModelCamera = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
cameraModelid = rsNewModelCamera("newid")
rsNewModelCamera.Close
Set rsNewModelCamera = Nothing
On Error Goto 0
' Handle NULL modelid
ElseIf cameraModelid = "" Or Not IsNumeric(cameraModelid) Then
cameraModelid = "NULL"
Else
cameraModelid = CLng(cameraModelid)
End If
' Escape strings
cameraSerial = Replace(cameraSerial, "'", "''")
cameraMac = Replace(cameraMac, "'", "''")
cameraIP = Replace(cameraIP, "'", "''")
' Validate lengths
If Len(cameraSerial) > 100 Or Len(cameraMac) > 17 Or Len(cameraIP) > 45 Then
Response.Write("<html><body><div style='color:red;'>Error: Field length exceeded</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
If deviceId = "0" Then
' INSERT
strSQL = "INSERT INTO cameras (cameraname, modelid, idfid, serialnumber, macaddress, ipaddress, description, maptop, mapleft, isactive) " & _
"VALUES ('" & deviceName & "', " & cameraModelid & ", " & cameraIdfid & ", '" & cameraSerial & "', '" & cameraMac & "', '" & cameraIP & "', '" & description & "', " & maptop & ", " & mapleft & ", " & isactiveForm & ")"
Else
' UPDATE
strSQL = "UPDATE cameras SET " & _
"cameraname = '" & deviceName & "', " & _
"modelid = " & cameraModelid & ", " & _
"idfid = " & cameraIdfid & ", " & _
"serialnumber = '" & cameraSerial & "', " & _
"macaddress = '" & cameraMac & "', " & _
"ipaddress = '" & cameraIP & "', " & _
"description = '" & description & "', " & _
"maptop = " & maptop & ", " & _
"mapleft = " & mapleft & ", " & _
"isactive = " & isactiveForm & " " & _
"WHERE cameraid = " & deviceId
End If
End If
' Execute SQL
On Error Resume Next
objConn.Execute(strSQL)
If Err.Number <> 0 Then
Response.Write("<html><body><div style='color:red;'>Error saving device: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='javascript:history.back()'>Go back</a></body></html>")
objConn.Close
Response.End
End If
On Error Goto 0
' Success - redirect to list
objConn.Close
Response.Redirect(redirectUrl)
%>

View File

@@ -1,248 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get all form data
Dim appname, appdescription, supportteamid
Dim applicationnotes, installpath, applicationlink, documentationpath, image
Dim isinstallable, isactive, ishidden, isprinter, islicenced
Dim newsupportteamname, newsupportteamurl, newappownerid
appname = Trim(Request.Form("appname"))
appdescription = Trim(Request.Form("appdescription"))
supportteamid = Trim(Request.Form("supportteamid"))
applicationnotes = Trim(Request.Form("applicationnotes"))
installpath = Trim(Request.Form("installpath"))
applicationlink = Trim(Request.Form("applicationlink"))
documentationpath = Trim(Request.Form("documentationpath"))
image = Trim(Request.Form("image"))
' New support team fields
newsupportteamname = Trim(Request.Form("newsupportteamname"))
newsupportteamurl = Trim(Request.Form("newsupportteamurl"))
newappownerid = Trim(Request.Form("newappownerid"))
' Checkboxes
If Request.Form("isinstallable") = "1" Then isinstallable = 1 Else isinstallable = 0
If Request.Form("isactive") = "1" Then isactive = 1 Else isactive = 0
If Request.Form("ishidden") = "1" Then ishidden = 1 Else ishidden = 0
If Request.Form("isprinter") = "1" Then isprinter = 1 Else isprinter = 0
If Request.Form("islicenced") = "1" Then islicenced = 1 Else islicenced = 0
' Basic validation
If Len(appname) < 1 Or Len(appname) > 50 Then
Response.Write("Error: Application name must be 1-50 characters")
objConn.Close
Response.End
End If
' Validate support team is selected
If supportteamid = "" Then
Response.Write("<div class='alert alert-danger'>Error: Please select a support team.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Check if we need to create a new support team first
If supportteamid = "new" Then
If newsupportteamname = "" Then
Response.Write("<div class='alert alert-danger'>Error: Support team name is required.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newsupportteamname) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Support team name too long.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes for support team name and URL
Dim escapedTeamName, escapedTeamUrl
escapedTeamName = Replace(newsupportteamname, "'", "''")
escapedTeamUrl = Replace(newsupportteamurl, "'", "''")
' Check if support team already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM supportteams WHERE LOWER(teamname) = LOWER('" & escapedTeamName & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck.EOF Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Database query failed.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Support team '" & Server.HTMLEncode(newsupportteamname) & "' already exists.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Check if we need to create a new app owner first (nested creation)
If newappownerid = "new" Then
Dim newappownername, newappownersso
newappownername = Trim(Request.Form("newappownername"))
newappownersso = Trim(Request.Form("newappownersso"))
If newappownername = "" Or newappownersso = "" Then
Response.Write("<div class='alert alert-danger'>Error: App owner name and SSO are required.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newappownername) > 50 Or Len(newappownersso) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: App owner name or SSO too long.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes
Dim escapedOwnerName, escapedSSO
escapedOwnerName = Replace(newappownername, "'", "''")
escapedSSO = Replace(newappownersso, "'", "''")
' Check if app owner already exists
checkSQL = "SELECT COUNT(*) as cnt FROM appowners WHERE LOWER(appowner) = LOWER('" & escapedOwnerName & "') OR LOWER(sso) = LOWER('" & escapedSSO & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck.EOF Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Database query failed (app owner check).</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: App owner with this name or SSO already exists.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Insert new app owner
Dim ownerSQL
ownerSQL = "INSERT INTO appowners (appowner, sso, isactive) VALUES ('" & escapedOwnerName & "', '" & escapedSSO & "', 1)"
On Error Resume Next
objConn.Execute ownerSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating app owner: " & Err.Description & "</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new app owner ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newappownerid = rsCheck("newid")
rsCheck.Close
Else
' Validate existing app owner ID
If Not IsNumeric(newappownerid) Or CLng(newappownerid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid app owner.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
End If
' Insert new support team
Dim teamSQL
teamSQL = "INSERT INTO supportteams (teamname, teamurl, appownerid, isactive) VALUES ('" & escapedTeamName & "', '" & escapedTeamUrl & "', " & newappownerid & ", 1)"
On Error Resume Next
objConn.Execute teamSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating support team: " & Err.Description & "</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new support team ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
supportteamid = rsCheck("newid")
rsCheck.Close
Else
' Validate existing support team ID
If Not IsNumeric(supportteamid) Or CLng(supportteamid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid support team ID.</div>")
Response.Write("<a href='addapplication.asp'>Go back</a>")
objConn.Close
Response.End
End If
End If
' Escape backslashes and single quotes for SQL
' Must escape backslashes FIRST, then quotes
appname = Replace(appname, "\", "\\")
appname = Replace(appname, "'", "''")
appdescription = Replace(appdescription, "\", "\\")
appdescription = Replace(appdescription, "'", "''")
applicationnotes = Replace(applicationnotes, "\", "\\")
applicationnotes = Replace(applicationnotes, "'", "''")
installpath = Replace(installpath, "\", "\\")
installpath = Replace(installpath, "'", "''")
applicationlink = Replace(applicationlink, "\", "\\")
applicationlink = Replace(applicationlink, "'", "''")
documentationpath = Replace(documentationpath, "\", "\\")
documentationpath = Replace(documentationpath, "'", "''")
image = Replace(image, "\", "\\")
image = Replace(image, "'", "''")
' Build INSERT statement
Dim strSQL
strSQL = "INSERT INTO applications (" & _
"appname, appdescription, supportteamid, applicationnotes, " & _
"installpath, applicationlink, documentationpath, image, " & _
"isinstallable, isactive, ishidden, isprinter, islicenced" & _
") VALUES (" & _
"'" & appname & "', " & _
"'" & appdescription & "', " & _
supportteamid & ", " & _
"'" & applicationnotes & "', " & _
"'" & installpath & "', " & _
"'" & applicationlink & "', " & _
"'" & documentationpath & "', " & _
"'" & image & "', " & _
isinstallable & ", " & _
isactive & ", " & _
ishidden & ", " & _
isprinter & ", " & _
islicenced & ")"
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Write("Error: " & Err.Description)
objConn.Close
Response.End
End If
' Get the new application ID
Dim rsNew
Set rsNew = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
Dim newAppId
newAppId = rsNew("newid")
rsNew.Close
Set rsNew = Nothing
objConn.Close
If newAppId > 0 Then
Response.Redirect("displayapplication.asp?appid=" & newAppId)
Else
Response.Write("Error: Could not retrieve new application ID")
End If
%>

View File

@@ -1,55 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get the serial number from the form
Dim serialnumber
serialnumber = Trim(Request.Form("serialnumber"))
' Basic validation - serial number should not be empty and should be alphanumeric-ish
If serialnumber = "" Or Len(serialnumber) < 3 Or Len(serialnumber) > 100 Then
objConn.Close
Response.Redirect("./adddevice.asp?error=INVALID_SERIAL")
Response.End
End If
' Escape quotes
serialnumber = Replace(serialnumber, "'", "''")
' Check if serial number already exists
Dim checkSQL, rsCheck, existingPCID
checkSQL = "SELECT pcid FROM pc WHERE serialnumber = '" & serialnumber & "'"
Set rsCheck = objConn.Execute(checkSQL)
If Not rsCheck.EOF Then
' Serial number already exists - redirect to edit page
existingPCID = rsCheck("pcid")
rsCheck.Close
objConn.Close
Response.Redirect("./editdevice.asp?pcid=" & existingPCID & "&scanned=1")
Response.End
End If
rsCheck.Close
' Insert new device with minimal required fields and defaults
' pcstatusid = 2 (Inventory)
' isactive = 1
' modelnumberid = 1 (default model)
' requires_manual_machine_config = 0 (no manual config needed)
' osid = 1 (default OS)
' machinenumber = 'IT Closet' (default location for new devices)
Dim insertSQL
insertSQL = "INSERT INTO pc (serialnumber, pcstatusid, isactive, modelnumberid, requires_manual_machine_config, osid, machinenumber, dateadded) " & _
"VALUES ('" & serialnumber & "', 2, 1, 1, 0, 1, 'IT Closet', NOW())"
On Error Resume Next
objConn.Execute insertSQL
If Err.Number = 0 Then
objConn.Close
' Success - redirect back with success message
Response.Redirect("./adddevice.asp?added=" & Server.URLEncode(Request.Form("serialnumber")))
Else
objConn.Close
Response.Redirect("./adddevice.asp?error=db")
End If
%>

View File

@@ -1,180 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/encoding.asp"-->
<!--#include file="./includes/error_handler.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
</head>
<body>
<div class="page">
<%
' Initialize error handling
Call InitializeErrorHandling("savemachine.asp")
' Get and validate all inputs
Dim machinenumber, modelid, machinetypeid, businessunitid, alias, machinenotes, mapleft, maptop
machinenumber = Trim(Request.Form("machinenumber"))
modelid = Trim(Request.Form("modelid"))
machinetypeid = Trim(Request.Form("machinetypeid"))
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"))
' Validate required fields
If machinenumber = "" Then
Call HandleValidationError("addmachine.asp", "INVALID_INPUT")
End If
If Not ValidateID(modelid) Then
Call HandleValidationError("addmachine.asp", "INVALID_ID")
End If
If Not ValidateID(machinetypeid) Then
Call HandleValidationError("addmachine.asp", "INVALID_ID")
End If
If Not ValidateID(businessunitid) Then
Call HandleValidationError("addmachine.asp", "INVALID_ID")
End If
' Validate field lengths
If Len(machinenumber) > 50 Then
Call HandleValidationError("addmachine.asp", "INVALID_INPUT")
End If
If Len(alias) > 50 Then
Call HandleValidationError("addmachine.asp", "INVALID_INPUT")
End If
' machinenotes is TEXT field, no length validation needed
' Check if machine number already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinenumber = ?"
Set rsCheck = ExecuteParameterizedQuery(objConn, checkSQL, Array(machinenumber))
If Not rsCheck.EOF Then
If Not IsNull(rsCheck("cnt")) Then
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Response.Write("<div class='alert alert-danger'>Error: Machine number '" & Server.HTMLEncode(machinenumber) & "' already exists.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Call CleanupResources()
Response.End
End If
End If
End If
rsCheck.Close
Set rsCheck = Nothing
' Build INSERT statement with parameterized query
Dim params, paramList
strSQL = "INSERT INTO machines (machinenumber, modelnumberid, machinetypeid, businessunitid"
' Add optional fields to SQL
If alias <> "" Then
strSQL = strSQL & ", alias"
End If
If machinenotes <> "" Then
strSQL = strSQL & ", machinenotes"
End If
If mapleft <> "" And maptop <> "" Then
If IsNumeric(mapleft) And IsNumeric(maptop) Then
strSQL = strSQL & ", mapleft, maptop"
End If
End If
strSQL = strSQL & ", isactive, islocationonly) VALUES (?, ?, ?, ?"
' Build param list dynamically
Dim paramCount
paramCount = 4 ' Start with 4 required params
' Count optional params
If alias <> "" Then paramCount = paramCount + 1
If machinenotes <> "" Then paramCount = paramCount + 1
If mapleft <> "" And maptop <> "" Then
If IsNumeric(mapleft) And IsNumeric(maptop) Then
paramCount = paramCount + 2
End If
End If
paramCount = paramCount + 2 ' For isactive and islocationonly
' Initialize array with correct size
ReDim paramList(paramCount - 1)
Dim paramIndex
paramIndex = 0
' Add required fields
paramList(paramIndex) = machinenumber
paramIndex = paramIndex + 1
paramList(paramIndex) = modelid
paramIndex = paramIndex + 1
paramList(paramIndex) = machinetypeid
paramIndex = paramIndex + 1
paramList(paramIndex) = businessunitid
paramIndex = paramIndex + 1
' Add optional fields to param list
If alias <> "" Then
strSQL = strSQL & ", ?"
paramList(paramIndex) = alias
paramIndex = paramIndex + 1
End If
If machinenotes <> "" Then
strSQL = strSQL & ", ?"
paramList(paramIndex) = machinenotes
paramIndex = paramIndex + 1
End If
If mapleft <> "" And maptop <> "" Then
If IsNumeric(mapleft) And IsNumeric(maptop) Then
strSQL = strSQL & ", ?, ?"
paramList(paramIndex) = mapleft
paramIndex = paramIndex + 1
paramList(paramIndex) = maptop
paramIndex = paramIndex + 1
End If
End If
' Add isactive and islocationonly values
strSQL = strSQL & ", ?, ?)"
paramList(paramIndex) = 1 ' isactive = 1
paramIndex = paramIndex + 1
paramList(paramIndex) = 0 ' islocationonly = 0
' Execute parameterized insert
Dim recordsAffected
recordsAffected = ExecuteParameterizedInsert(objConn, strSQL, paramList)
' Get the new machine ID
Dim newMachineId
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newMachineId = 0
If Not rsCheck.EOF Then
If Not IsNull(rsCheck("newid")) Then
newMachineId = CLng(rsCheck("newid"))
End If
End If
rsCheck.Close
Set rsCheck = Nothing
' Cleanup resources
Call CleanupResources()
' Redirect to display page
If recordsAffected > 0 And newMachineId > 0 Then
%>
<meta http-equiv="refresh" content="0; url=./displaymachine.asp?machineid=<%=Server.HTMLEncode(newMachineId)%>">
<%
Else
Response.Write("Error: Machine was not added successfully.")
End If
%>
</div>
</body>
</html>

View File

@@ -1,409 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim machinenumber, modelid, machinetypeid, businessunitid, alias, machinenotes, mapleft, maptop
machinenumber = Trim(Request.Form("machinenumber"))
modelid = Trim(Request.Form("modelid"))
machinetypeid = Trim(Request.Form("machinetypeid"))
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 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
newfunctionalaccount = Trim(Request.Form("newfunctionalaccount"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelimage
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelimage = Trim(Request.Form("newmodelimage"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields
If machinenumber = "" Then
Response.Write("<div class='alert alert-danger'>Error: Machine number is required.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate ID fields - allow "new" as a valid value
If modelid <> "new" And Not IsNumeric(modelid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If machinetypeid <> "new" And Not IsNumeric(machinetypeid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine type ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If businessunitid <> "new" And Not IsNumeric(businessunitid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid business unit ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(machinenumber) > 50 Or Len(alias) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Field length exceeded.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Check if machine number already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM machines WHERE machinenumber = '" & Replace(machinenumber, "'", "''") & "'"
Set rsCheck = objConn.Execute(checkSQL)
If Not rsCheck.EOF Then
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Response.Write("<div class='alert alert-danger'>Error: Machine number '" & Server.HTMLEncode(machinenumber) & "' already exists.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
End If
rsCheck.Close
Set rsCheck = Nothing
' Handle new business unit creation
If businessunitid = "new" Then
If Len(newbusinessunit) = 0 Then
Response.Write("<div class='alert alert-danger'>New business unit name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newbusinessunit) > 50 Then
Response.Write("<div class='alert alert-danger'>Business unit name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedBUName
escapedBUName = Replace(newbusinessunit, "'", "''")
' Insert new business unit
Dim sqlNewBU
sqlNewBU = "INSERT INTO businessunits (businessunit, isactive) VALUES ('" & escapedBUName & "', 1)"
On Error Resume Next
objConn.Execute sqlNewBU
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new business unit: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Handle new machine type creation
If machinetypeid = "new" Then
If Len(newmachinetype) = 0 Then
Response.Write("<div class='alert alert-danger'>New machine type name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccountid) = 0 Then
Response.Write("<div class='alert alert-danger'>Functional account is required for new machine type</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmachinetype) > 50 Or Len(newmachinedescription) > 255 Then
Response.Write("<div class='alert alert-danger'>Machine type field length exceeded</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new functional account creation (nested)
If newfunctionalaccountid = "new" Then
If Len(newfunctionalaccount) = 0 Then
Response.Write("<div class='alert alert-danger'>New functional account name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccount) > 50 Then
Response.Write("<div class='alert alert-danger'>Functional account name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedFAName
escapedFAName = Replace(newfunctionalaccount, "'", "''")
' Insert new functional account
Dim sqlNewFA
sqlNewFA = "INSERT INTO functionalaccounts (functionalaccount, isactive) VALUES ('" & escapedFAName & "', 1)"
On Error Resume Next
objConn.Execute sqlNewFA
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new functional account: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes
Dim escapedMTName, escapedMTDesc
escapedMTName = Replace(newmachinetype, "'", "''")
escapedMTDesc = Replace(newmachinedescription, "'", "''")
' Insert new machine type
Dim sqlNewMT
sqlNewMT = "INSERT INTO machinetypes (machinetype, machinedescription, functionalaccountid, isactive) " & _
"VALUES ('" & escapedMTName & "', '" & escapedMTDesc & "', " & newfunctionalaccountid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewMT
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new machine type: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created machine type ID
Dim rsNewMT
Set rsNewMT = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
machinetypeid = CLng(rsNewMT("newid"))
rsNewMT.Close
Set rsNewMT = Nothing
On Error Goto 0
End If
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Or Len(newmodelimage) > 100 Then
Response.Write("<div class='alert alert-danger'>Model field length exceeded</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Vendor name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with ismachine=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & escapedVendorName & "', 1, 0, 0, 1)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes for model
Dim escapedModelNumber, escapedModelImage
escapedModelNumber = Replace(newmodelnumber, "'", "''")
escapedModelImage = Replace(newmodelimage, "'", "''")
' Set default image if not specified
If escapedModelImage = "" Then
escapedModelImage = "default.png"
End If
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, image, isactive) " & _
"VALUES ('" & escapedModelNumber & "', " & newvendorid & ", '" & escapedModelImage & "', 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes
machinenumber = Replace(machinenumber, "'", "''")
alias = Replace(alias, "'", "''")
machinenotes = Replace(machinenotes, "'", "''")
' Build INSERT statement
Dim strSQL, fields, values
fields = "machinenumber, modelnumberid, machinetypeid, businessunitid"
values = "'" & machinenumber & "', " & modelid & ", " & machinetypeid & ", " & businessunitid
If alias <> "" Then
fields = fields & ", alias"
values = values & ", '" & alias & "'"
End If
If machinenotes <> "" Then
fields = fields & ", machinenotes"
values = values & ", '" & machinenotes & "'"
End If
If mapleft <> "" And maptop <> "" And IsNumeric(mapleft) And IsNumeric(maptop) Then
fields = fields & ", mapleft, maptop"
values = values & ", " & mapleft & ", " & maptop
End If
fields = fields & ", isactive, islocationonly"
values = values & ", 1, 0"
strSQL = "INSERT INTO machines (" & fields & ") VALUES (" & values & ")"
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' 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, updatePCSQL
pcid = Trim(Request.Form("pcid"))
If pcid <> "" And IsNumeric(pcid) And CLng(pcid) > 0 Then
updatePCSQL = "UPDATE pc SET machinenumber = '" & machinenumber & "' WHERE pcid = " & CLng(pcid)
On Error Resume Next
objConn.Execute updatePCSQL
On Error Goto 0
End If
objConn.Close
If CLng(newMachineId) > 0 Then
%>
<meta http-equiv="refresh" content="0; url=./displaymachine.asp?machineid=<%=Server.HTMLEncode(newMachineId)%>">
<%
Else
Response.Write("Error: Machine was not added successfully.")
End If
%>
</div>
</body>
</html>

View File

@@ -1,459 +0,0 @@
<%
'=============================================================================
' FILE: savemachine_direct.asp
' PURPOSE: Create new machine with nested entity creation (vendor, model, machine type, functional account, business unit)
' SECURITY: Parameterized queries, HTML encoding, input validation
' UPDATED: 2025-10-27 - Migrated to secure patterns
'=============================================================================
%>
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim machinenumber, modelid, machinetypeid, businessunitid, alias, machinenotes, mapleft, maptop
machinenumber = Trim(Request.Form("machinenumber"))
modelid = Trim(Request.Form("modelid"))
machinetypeid = Trim(Request.Form("machinetypeid"))
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 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
newfunctionalaccount = Trim(Request.Form("newfunctionalaccount"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelimage
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelimage = Trim(Request.Form("newmodelimage"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields
If machinenumber = "" Then
Response.Write("<div class='alert alert-danger'>Error: Machine number is required.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate ID fields - allow "new" as a valid value
If modelid <> "new" And Not IsNumeric(modelid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If machinetypeid <> "new" And Not IsNumeric(machinetypeid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine type ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If businessunitid <> "new" And Not IsNumeric(businessunitid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid business unit ID.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(machinenumber) > 50 Or Len(alias) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Field length exceeded.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
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
Response.Write("<div class='alert alert-danger'>Error: Machine number '" & Server.HTMLEncode(machinenumber) & "' already exists.</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
Response.Write("<div class='alert alert-danger'>New business unit name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newbusinessunit) > 50 Then
Response.Write("<div class='alert alert-danger'>Business unit name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
Response.Write("<div class='alert alert-danger'>Error creating new business unit: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdNewBU = Nothing
objConn.Close
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 machine type creation
If machinetypeid = "new" Then
If Len(newmachinetype) = 0 Then
Response.Write("<div class='alert alert-danger'>New machine type name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccountid) = 0 Then
Response.Write("<div class='alert alert-danger'>Functional account is required for new machine type</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmachinetype) > 50 Or Len(newmachinedescription) > 255 Then
Response.Write("<div class='alert alert-danger'>Machine type field length exceeded</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new functional account creation (nested)
If newfunctionalaccountid = "new" Then
If Len(newfunctionalaccount) = 0 Then
Response.Write("<div class='alert alert-danger'>New functional account name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newfunctionalaccount) > 50 Then
Response.Write("<div class='alert alert-danger'>Functional account name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Insert new functional account using parameterized query
Dim sqlNewFA, cmdNewFA
sqlNewFA = "INSERT INTO functionalaccounts (functionalaccount, 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)
On Error Resume Next
cmdNewFA.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new functional account: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdNewFA = Nothing
objConn.Close
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)
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@machinedescription", 200, 1, 255, newmachinedescription)
cmdNewMT.Parameters.Append cmdNewMT.CreateParameter("@functionalaccountid", 3, 1, , CLng(newfunctionalaccountid))
On Error Resume Next
cmdNewMT.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new machine type: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdNewMT = Nothing
objConn.Close
Response.End
End If
' Get the newly created machine type ID
Dim rsNewMT
Set rsNewMT = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
machinetypeid = CLng(rsNewMT("newid"))
rsNewMT.Close
Set rsNewMT = Nothing
Set cmdNewMT = Nothing
On Error Goto 0
End If
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Or Len(newmodelimage) > 100 Then
Response.Write("<div class='alert alert-danger'>Model field length exceeded</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Vendor name too long</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
objConn.Close
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
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdNewVendor = Nothing
objConn.Close
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
Dim sqlNewModel, cmdNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, 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("@image", 200, 1, 100, modelImageValue)
On Error Resume Next
cmdNewModel.Execute
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdNewModel = Nothing
objConn.Close
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
' Build INSERT statement with parameterized query
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, , CLng(machinetypeid))
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
Response.Write("<div class='alert alert-danger'>Error: " & Server.HTMLEncode(Err.Description) & "</div>")
Response.Write("<a href='addmachine.asp'>Go back</a>")
Set cmdMachine = Nothing
objConn.Close
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
pcid = Trim(Request.Form("pcid"))
If pcid <> "" And IsNumeric(pcid) And CLng(pcid) > 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, , CLng(pcid))
On Error Resume Next
cmdUpdatePC.Execute
Set cmdUpdatePC = Nothing
On Error Goto 0
End If
objConn.Close
If CLng(newMachineId) > 0 Then
%>
<meta http-equiv="refresh" content="0; url=./displaymachine.asp?machineid=<%=Server.HTMLEncode(newMachineId)%>">
<%
Else
Response.Write("Error: Machine was not added successfully.")
End If
%>
</div>
</body>
</html>

View File

@@ -1,181 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/validation.asp"-->
<!--#include file="./includes/encoding.asp"-->
<!--#include file="./includes/error_handler.asp"-->
<!--#include file="./includes/db_helpers.asp"-->
</head>
<body>
<div class="page">
<%
' Initialize error handling
Call InitializeErrorHandling("savemodel.asp")
' Get and validate all inputs
Dim modelnumber, vendorid, notes, documentationpath
Dim newvendorname, isprinter, ispc, ismachine
Dim modelisprinter, modelispc, modelismachine
modelnumber = Trim(Request.Form("modelnumber"))
vendorid = Trim(Request.Form("vendorid"))
notes = Trim(Request.Form("notes"))
documentationpath = Trim(Request.Form("documentationpath"))
' New vendor fields
newvendorname = Trim(Request.Form("newvendorname"))
isprinter = Request.Form("isprinter")
ispc = Request.Form("ispc")
ismachine = Request.Form("ismachine")
' Model type checkboxes (NOTE: these are different from vendor checkboxes above)
modelisprinter = Request.Form("modelisprinter")
modelispc = Request.Form("modelispc")
modelismachine = Request.Form("modelismachine")
' Validate required fields
If modelnumber = "" Then
Call HandleValidationError("addmodel.asp", "INVALID_INPUT")
End If
' Validate field lengths
If Len(modelnumber) > 255 Then
Call HandleValidationError("addmodel.asp", "INVALID_INPUT")
End If
If Len(notes) > 255 Then
Call HandleValidationError("addmodel.asp", "INVALID_INPUT")
End If
If Len(documentationpath) > 255 Then
Call HandleValidationError("addmodel.asp", "INVALID_INPUT")
End If
' Check if we need to create a new vendor first
If vendorid = "new" Then
If newvendorname = "" Then
Response.Write("<div class='alert alert-danger'>Error: Manufacturer name is required when adding a new manufacturer.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
Call CleanupResources()
Response.End
End If
If Len(newvendorname) > 50 Then
Call HandleValidationError("addmodel.asp", "INVALID_INPUT")
End If
' Check if vendor already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM vendors WHERE LOWER(vendor) = LOWER(?)"
Set rsCheck = ExecuteParameterizedQuery(objConn, checkSQL, Array(newvendorname))
If rsCheck("cnt") > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Response.Write("<div class='alert alert-danger'>Error: Manufacturer '" & Server.HTMLEncode(newvendorname) & "' already exists.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
Call CleanupResources()
Response.End
End If
rsCheck.Close
Set rsCheck = Nothing
' Insert new vendor
Dim vendorSQL
vendorSQL = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES (?, 1, ?, ?, ?)"
Dim vendorParams
vendorParams = Array(newvendorname, _
IIf(isprinter = "1", 1, 0), _
IIf(ispc = "1", 1, 0), _
IIf(ismachine = "1", 1, 0))
Call ExecuteParameterizedUpdate(objConn, vendorSQL, vendorParams)
' Get the new vendor ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
vendorid = rsCheck("newid")
rsCheck.Close
Set rsCheck = Nothing
Else
' Validate existing vendor ID
If Not ValidateID(vendorid) Then
Call HandleValidationError("addmodel.asp", "INVALID_ID")
End If
End If
' Now we need to update the vendor's type flags based on model type selection
' If model is for printer, ensure vendor.isprinter = 1, etc.
If modelisprinter = "1" OR modelispc = "1" OR modelismachine = "1" Then
Dim updateVendorSQL
updateVendorSQL = "UPDATE vendors SET "
Dim updateParts()
ReDim updateParts(-1)
If modelisprinter = "1" Then
ReDim Preserve updateParts(UBound(updateParts) + 1)
updateParts(UBound(updateParts)) = "isprinter = 1"
End If
If modelispc = "1" Then
ReDim Preserve updateParts(UBound(updateParts) + 1)
updateParts(UBound(updateParts)) = "ispc = 1"
End If
If modelismachine = "1" Then
ReDim Preserve updateParts(UBound(updateParts) + 1)
updateParts(UBound(updateParts)) = "ismachine = 1"
End If
If UBound(updateParts) >= 0 Then
updateVendorSQL = updateVendorSQL & Join(updateParts, ", ") & " WHERE vendorid = ?"
Call ExecuteParameterizedUpdate(objConn, updateVendorSQL, Array(vendorid))
End If
End If
' Check if model already exists for this vendor
checkSQL = "SELECT COUNT(*) as cnt FROM models WHERE LOWER(modelnumber) = LOWER(?) AND vendorid = ?"
Set rsCheck = ExecuteParameterizedQuery(objConn, checkSQL, Array(modelnumber, vendorid))
If rsCheck("cnt") > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Response.Write("<div class='alert alert-danger'>Error: Model '" & Server.HTMLEncode(modelnumber) & "' already exists for this manufacturer.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
Call CleanupResources()
Response.End
End If
rsCheck.Close
Set rsCheck = Nothing
' Insert the new model
Dim modelSQL, modelParams
modelSQL = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) VALUES (?, ?, ?, ?, 1)"
modelParams = Array(modelnumber, vendorid, notes, documentationpath)
Dim recordsAffected
recordsAffected = ExecuteParameterizedUpdate(objConn, modelSQL, modelParams)
' Get the new model ID
Dim newModelId
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newModelId = rsCheck("newid")
rsCheck.Close
Set rsCheck = Nothing
' Cleanup resources
Call CleanupResources()
' Redirect back to where they came from or to a success page
If recordsAffected > 0 And newModelId > 0 Then
Response.Write("<div class='alert alert-success'><i class='zmdi zmdi-check'></i> Model added successfully!</div>")
Response.Write("<p>Model '" & Server.HTMLEncode(modelnumber) & "' has been added.</p>")
Response.Write("<p><a href='addmodel.asp' class='btn btn-primary'>Add Another Model</a> ")
Response.Write("<a href='addprinter.asp' class='btn btn-secondary'>Add Printer</a> ")
Response.Write("<a href='addmachine.asp' class='btn btn-secondary'>Add Machine</a></p>")
Else
Response.Write("<div class='alert alert-danger'>Error: Model was not added successfully.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
End If
%>
</div>
</body>
</html>

View File

@@ -1,203 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim modelnumber, vendorid, notes, documentationpath
Dim newvendorname, isprinter, ispc, ismachine
Dim modelisprinter, modelispc, modelismachine
modelnumber = Trim(Request.Form("modelnumber"))
vendorid = Trim(Request.Form("vendorid"))
notes = Trim(Request.Form("notes"))
documentationpath = Trim(Request.Form("documentationpath"))
' New vendor fields
newvendorname = Trim(Request.Form("newvendorname"))
isprinter = Request.Form("isprinter")
ispc = Request.Form("ispc")
ismachine = Request.Form("ismachine")
' Model type checkboxes
modelisprinter = Request.Form("modelisprinter")
modelispc = Request.Form("modelispc")
modelismachine = Request.Form("modelismachine")
' Validate required fields
If modelnumber = "" Then
Response.Write("<div class='alert alert-danger'>Error: Model number is required.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(modelnumber) > 255 Then
Response.Write("<div class='alert alert-danger'>Error: Model number too long.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(notes) > 255 Then
Response.Write("<div class='alert alert-danger'>Error: Notes too long.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(documentationpath) > 255 Then
Response.Write("<div class='alert alert-danger'>Error: Documentation path too long.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape quotes
modelnumber = Replace(modelnumber, "'", "''")
notes = Replace(notes, "'", "''")
documentationpath = Replace(documentationpath, "'", "''")
newvendorname = Replace(newvendorname, "'", "''")
' Check if we need to create a new vendor first
If vendorid = "new" Then
If newvendorname = "" Then
Response.Write("<div class='alert alert-danger'>Error: Manufacturer name is required when adding a new manufacturer.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Manufacturer name too long.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Check if vendor already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM vendors WHERE LOWER(vendor) = LOWER('" & newvendorname & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck("cnt") > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Manufacturer '" & Server.HTMLEncode(Request.Form("newvendorname")) & "' already exists.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Convert vendor checkboxes
Dim iPrint, iPC, iMach
If isprinter = "1" Then iPrint = 1 Else iPrint = 0
If ispc = "1" Then iPC = 1 Else iPC = 0
If ismachine = "1" Then iMach = 1 Else iMach = 0
' Insert new vendor
Dim vendorSQL
vendorSQL = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & newvendorname & "', 1, " & iPrint & ", " & iPC & ", " & iMach & ")"
On Error Resume Next
objConn.Execute vendorSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating manufacturer: " & Err.Description & "</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new vendor ID
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
vendorid = rsCheck("newid")
rsCheck.Close
Else
' Validate existing vendor ID
If Not IsNumeric(vendorid) Or CLng(vendorid) < 1 Then
Response.Write("<div class='alert alert-danger'>Error: Invalid manufacturer ID.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
End If
' Update vendor's type flags based on model type selection
If modelisprinter = "1" OR modelispc = "1" OR modelismachine = "1" Then
Dim updateVendorSQL, updateParts
updateParts = ""
If modelisprinter = "1" Then
If updateParts <> "" Then updateParts = updateParts & ", "
updateParts = updateParts & "isprinter = 1"
End If
If modelispc = "1" Then
If updateParts <> "" Then updateParts = updateParts & ", "
updateParts = updateParts & "ispc = 1"
End If
If modelismachine = "1" Then
If updateParts <> "" Then updateParts = updateParts & ", "
updateParts = updateParts & "ismachine = 1"
End If
If updateParts <> "" Then
updateVendorSQL = "UPDATE vendors SET " & updateParts & " WHERE vendorid = " & vendorid
objConn.Execute updateVendorSQL
End If
End If
' Check if model already exists for this vendor
checkSQL = "SELECT COUNT(*) as cnt FROM models WHERE LOWER(modelnumber) = LOWER('" & modelnumber & "') AND vendorid = " & vendorid
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck("cnt") > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Model '" & Server.HTMLEncode(Request.Form("modelnumber")) & "' already exists for this manufacturer.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Insert the new model
Dim modelSQL
modelSQL = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) " & _
"VALUES ('" & modelnumber & "', " & vendorid & ", '" & notes & "', '" & documentationpath & "', 1)"
On Error Resume Next
objConn.Execute modelSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the new model ID
Dim newModelId
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newModelId = rsCheck("newid")
rsCheck.Close
objConn.Close
If newModelId > 0 Then
Response.Write("<div class='alert alert-success'><i class='zmdi zmdi-check'></i> Model added successfully!</div>")
Response.Write("<p>Model '" & Server.HTMLEncode(Request.Form("modelnumber")) & "' has been added.</p>")
Response.Write("<p><a href='addmodel.asp' class='btn btn-primary'>Add Another Model</a> ")
Response.Write("<a href='addprinter.asp' class='btn btn-secondary'>Add Printer</a> ")
Response.Write("<a href='addmachine.asp' class='btn btn-secondary'>Add Machine</a></p>")
Else
Response.Write("<div class='alert alert-danger'>Error: Model was not added successfully.</div>")
Response.Write("<a href='addmodel.asp'>Go back</a>")
End If
%>
</div>
</body>
</html>

View File

@@ -1,74 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form inputs
Dim notification, ticketnumber, starttime, endtime, isactive, isshopfloor, notificationtypeid, businessunitid
notification = Trim(Request.Form("notification"))
ticketnumber = Trim(Request.Form("ticketnumber"))
starttime = Trim(Request.Form("starttime"))
endtime = Trim(Request.Form("endtime"))
isactive = Request.Form("isactive")
isshopfloor = Request.Form("isshopfloor")
notificationtypeid = Trim(Request.Form("notificationtypeid"))
businessunitid = Trim(Request.Form("businessunitid"))
If isactive = "" Then isactive = 0 Else isactive = 1
If isshopfloor = "" Then isshopfloor = 0 Else isshopfloor = 1
' Default to TBD if no type selected
If notificationtypeid = "" Or Not IsNumeric(notificationtypeid) Then
notificationtypeid = "1"
End If
' Validate required fields (endtime is now optional)
If Len(notification) = 0 Or Len(starttime) = 0 Then
Response.Write("Required fields missing")
objConn.Close
Response.End
End If
If Len(notification) > 500 Or Len(ticketnumber) > 50 Then
Response.Write("Field length exceeded")
objConn.Close
Response.End
End If
' Escape quotes
notification = Replace(notification, "'", "''")
ticketnumber = Replace(ticketnumber, "'", "''")
' Convert datetime format for starttime
starttime = Replace(starttime, "T", " ") & ":00"
' Handle optional endtime - leave as NULL if blank (indefinite)
Dim strSQL, endtimeSQL, businessunitSQL
If Len(endtime) = 0 Then
' No end date - store as NULL for indefinite notifications
endtimeSQL = "NULL"
Else
' End date specified - convert format and wrap in quotes
endtime = Replace(endtime, "T", " ") & ":00"
endtimeSQL = "'" & endtime & "'"
End If
' Handle optional businessunitid - NULL means applies to all business units
If businessunitid = "" Or Not IsNumeric(businessunitid) Then
businessunitSQL = "NULL"
Else
businessunitSQL = businessunitid
End If
' INSERT
strSQL = "INSERT INTO notifications (notificationtypeid, businessunitid, notification, ticketnumber, starttime, endtime, isactive, isshopfloor) " & _
"VALUES (" & notificationtypeid & ", " & businessunitSQL & ", '" & notification & "', '" & ticketnumber & "', '" & starttime & "', " & endtimeSQL & ", " & isactive & ", " & isshopfloor & ")"
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("displaynotifications.asp")
Else
Response.Write("Error: " & Err.Description)
objConn.Close
End If
%>

View File

@@ -1,241 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get and validate all inputs
Dim modelid, serialnumber, ipaddress, fqdn, printercsfname, printerwindowsname, machineid, maptop, mapleft
modelid = Trim(Request.Form("modelid"))
serialnumber = Trim(Request.Form("serialnumber"))
ipaddress = Trim(Request.Form("ipaddress"))
fqdn = Trim(Request.Form("fqdn"))
printercsfname = Trim(Request.Form("printercsfname"))
printerwindowsname = Trim(Request.Form("printerwindowsname"))
machineid = Trim(Request.Form("machineid"))
maptop = Trim(Request.Form("maptop"))
mapleft = Trim(Request.Form("mapleft"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid, newmodelnotes, newmodeldocpath
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
newmodelnotes = Trim(Request.Form("newmodelnotes"))
newmodeldocpath = Trim(Request.Form("newmodeldocpath"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required fields
If modelid = "" Then
Response.Write("<div class='alert alert-danger'>Error: Model is required.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If modelid <> "new" And Not IsNumeric(modelid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid model ID.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Not IsNumeric(machineid) Then
Response.Write("<div class='alert alert-danger'>Error: Invalid machine ID.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If serialnumber = "" Or ipaddress = "" Or printerwindowsname = "" Then
Response.Write("<div class='alert alert-danger'>Error: Required fields missing.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Validate field lengths
If Len(serialnumber) > 100 Or Len(fqdn) > 255 Or Len(printercsfname) > 50 Or Len(printerwindowsname) > 255 Then
Response.Write("<div class='alert alert-danger'>Error: Field length exceeded.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Check if printer with same IP already exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM printers WHERE ipaddress = '" & Replace(ipaddress, "'", "''") & "' AND isactive = 1"
Set rsCheck = objConn.Execute(checkSQL)
If Not rsCheck.EOF Then
If CLng(rsCheck("cnt")) > 0 Then
rsCheck.Close
Set rsCheck = Nothing
Response.Write("<div class='alert alert-danger'>Error: A printer with IP address '" & Server.HTMLEncode(ipaddress) & "' already exists.</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
End If
rsCheck.Close
Set rsCheck = Nothing
' Handle new model creation
If modelid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Write("<div class='alert alert-danger'>New model number is required</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Write("<div class='alert alert-danger'>Vendor is required for new model</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 255 Or Len(newmodelnotes) > 255 Or Len(newmodeldocpath) > 255 Then
Response.Write("<div class='alert alert-danger'>Model field length exceeded</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Write("<div class='alert alert-danger'>New vendor name is required</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Write("<div class='alert alert-danger'>Vendor name too long</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with isprinter=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & escapedVendorName & "', 1, 1, 0, 0)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new vendor: " & Err.Description & "</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created vendor ID
Dim rsNewVendor
Set rsNewVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newvendorid = rsNewVendor("newid")
rsNewVendor.Close
Set rsNewVendor = Nothing
On Error Goto 0
End If
' Escape single quotes for model
Dim escapedModelNumber, escapedModelNotes, escapedModelDocPath
escapedModelNumber = Replace(newmodelnumber, "'", "''")
escapedModelNotes = Replace(newmodelnotes, "'", "''")
escapedModelDocPath = Replace(newmodeldocpath, "'", "''")
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, notes, documentationpath, isactive) " & _
"VALUES ('" & escapedModelNumber & "', " & newvendorid & ", '" & escapedModelNotes & "', '" & escapedModelDocPath & "', 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error creating new model: " & Err.Description & "</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelid = rsNewModel("newid")
rsNewModel.Close
Set rsNewModel = Nothing
On Error Goto 0
End If
' Escape single quotes
serialnumber = Replace(serialnumber, "'", "''")
ipaddress = Replace(ipaddress, "'", "''")
fqdn = Replace(fqdn, "'", "''")
printercsfname = Replace(printercsfname, "'", "''")
printerwindowsname = Replace(printerwindowsname, "'", "''")
' Build INSERT statement with map coordinates (default to 50,50 if not provided)
Dim strSQL, maptopSQL, mapleftSQL
' Handle map coordinates - default to 50 if not provided
If maptop <> "" And IsNumeric(maptop) Then
maptopSQL = maptop
Else
maptopSQL = "50"
End If
If mapleft <> "" And IsNumeric(mapleft) Then
mapleftSQL = mapleft
Else
mapleftSQL = "50"
End If
strSQL = "INSERT INTO printers (modelid, serialnumber, ipaddress, fqdn, printercsfname, printerwindowsname, machineid, maptop, mapleft, isactive) " & _
"VALUES (" & modelid & ", '" & serialnumber & "', '" & ipaddress & "', '" & fqdn & "', '" & printercsfname & "', '" & printerwindowsname & "', " & machineid & ", " & maptopSQL & ", " & mapleftSQL & ", 1)"
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error inserting printer: " & Err.Description & "</div>")
Response.Write("<div>SQL: " & Server.HTMLEncode(strSQL) & "</div>")
Response.Write("<a href='addprinter.asp'>Go back</a>")
objConn.Close
Response.End
End If
On Error Goto 0
' Get the new printer ID
Dim newPrinterId
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
newPrinterId = CLng(rsCheck("newid"))
rsCheck.Close
Set rsCheck = Nothing
objConn.Close
If CLng(newPrinterId) > 0 Then
%>
<meta http-equiv="refresh" content="0; url=./displayprinter.asp?printerid=<%=Server.HTMLEncode(newPrinterId)%>">
<%
Else
Response.Write("Error: Printer was not added successfully.")
End If
%>
</div>
</body>
</html>

View File

@@ -1,94 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
Dim vendor, isprinter, ispc, ismachine
vendor = Trim(Request.Form("vendor"))
isprinter = Request.Form("isprinter")
ispc = Request.Form("ispc")
ismachine = Request.Form("ismachine")
' Validate
If vendor = "" Then
Response.Write("<div class='alert alert-danger'>Error: Manufacturer name is required.</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
objConn.Close
Response.End
End If
If Len(vendor) > 50 Then
Response.Write("<div class='alert alert-danger'>Error: Manufacturer name too long.</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
objConn.Close
Response.End
End If
If isprinter <> "1" AND ispc <> "1" AND ismachine <> "1" Then
Response.Write("<div class='alert alert-danger'>Error: Please select at least one category.</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
objConn.Close
Response.End
End If
' Check if exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM vendors WHERE LOWER(vendor) = LOWER('" & Replace(vendor, "'", "''") & "')"
Set rsCheck = objConn.Execute(checkSQL)
If rsCheck("cnt") > 0 Then
rsCheck.Close
Response.Write("<div class='alert alert-danger'>Error: Manufacturer '" & Server.HTMLEncode(vendor) & "' already exists.</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
objConn.Close
Response.End
End If
rsCheck.Close
' Escape quotes
vendor = Replace(vendor, "'", "''")
' Convert checkboxes
Dim iPrint, iPC, iMach
If isprinter = "1" Then iPrint = 1 Else iPrint = 0
If ispc = "1" Then iPC = 1 Else iPC = 0
If ismachine = "1" Then iMach = 1 Else iMach = 0
' INSERT
Dim vendorSQL
vendorSQL = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) " & _
"VALUES ('" & vendor & "', 1, " & iPrint & ", " & iPC & ", " & iMach & ")"
On Error Resume Next
objConn.Execute vendorSQL
If Err.Number <> 0 Then
Response.Write("<div class='alert alert-danger'>Error: " & Err.Description & "</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
objConn.Close
Response.End
End If
Set rsCheck = objConn.Execute("SELECT LAST_INSERT_ID() as newid")
Dim newVendorId
newVendorId = rsCheck("newid")
rsCheck.Close
objConn.Close
If newVendorId > 0 Then
Response.Write("<div class='alert alert-success'><i class='zmdi zmdi-check'></i> Manufacturer added successfully!</div>")
Response.Write("<p>Manufacturer '" & Server.HTMLEncode(Request.Form("vendor")) & "' has been added.</p>")
Response.Write("<p><a href='addvendor.asp' class='btn btn-primary'>Add Another Manufacturer</a> ")
Response.Write("<a href='addmodel.asp' class='btn btn-secondary'>Add Model</a></p>")
Else
Response.Write("<div class='alert alert-danger'>Error: Manufacturer was not added.</div>")
Response.Write("<a href='addvendor.asp'>Go back</a>")
End If
%>
</div>
</body>
</html>

View File

@@ -1,951 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/zabbix_all_supplies_cached.asp"-->
</head>
<%
' ============================================================================
' FUNCTION: SafeGetZabbixData
' PURPOSE: Safely call Zabbix function with error handling
' ============================================================================
Function SafeGetZabbixData(ipaddress)
On Error Resume Next
Dim result
result = GetAllPrinterSuppliesCached(ipaddress)
If Err.Number <> 0 Then
result = Empty
Err.Clear
End If
On Error Goto 0
SafeGetZabbixData = result
End Function
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
' ============================================================================
' FUNCTION: GetMarketingName
' PURPOSE: Convert OEM part numbers to marketing names for easier supply closet matching
' ============================================================================
Function GetMarketingName(oemPartNumber)
Dim oem, marketing
oem = UCase(Trim(oemPartNumber))
' HP M454dw / M454dn / M479fdw (414A/414X series)
If oem = "W2020A" Or oem = "W2020X" Then marketing = "414A/414X Black"
ElseIf oem = "W2021A" Or oem = "W2021X" Then marketing = "414A/414X Cyan"
ElseIf oem = "W2022A" Or oem = "W2022X" Then marketing = "414A/414X Yellow"
ElseIf oem = "W2023A" Or oem = "W2023X" Then marketing = "414A/414X Magenta"
' HP M254dw / M255dw (202A/202X series)
ElseIf oem = "CF500A" Or oem = "CF500X" Then marketing = "202A/202X Black"
ElseIf oem = "CF501A" Or oem = "CF501X" Then marketing = "202A/202X Cyan"
ElseIf oem = "CF502A" Or oem = "CF502X" Then marketing = "202A/202X Yellow"
ElseIf oem = "CF503A" Or oem = "CF503X" Then marketing = "202A/202X Magenta"
' HP M251nw / M252dw (201A/201X series)
ElseIf oem = "CF400A" Or oem = "CF400X" Then marketing = "201A/201X Black"
ElseIf oem = "CF401A" Or oem = "CF401X" Then marketing = "201A/201X Cyan"
ElseIf oem = "CF402A" Or oem = "CF402X" Then marketing = "201A/201X Yellow"
ElseIf oem = "CF403A" Or oem = "CF403X" Then marketing = "201A/201X Magenta"
' HP LaserJet 200 color M251nw (131A/131X series)
ElseIf oem = "CF210A" Or oem = "CF210X" Then marketing = "131A/131X Black"
ElseIf oem = "CF211A" Then marketing = "131A Cyan"
ElseIf oem = "CF212A" Then marketing = "131A Yellow"
ElseIf oem = "CF213A" Then marketing = "131A Magenta"
' HP M404n / M406 (58A/58X series)
ElseIf oem = "CF258A" Or oem = "CF258X" Then marketing = "58A/58X Black"
' HP M506 / M607 (87A/87X series)
ElseIf oem = "CF287A" Or oem = "CF287X" Then marketing = "87A/87X Black"
' HP M602 (90A/90X series)
ElseIf oem = "CE390A" Or oem = "CE390X" Then marketing = "90A/90X Black"
' HP P3015dn (55A/55X series)
ElseIf oem = "CE255A" Or oem = "CE255X" Then marketing = "55A/55X Black"
' HP LaserJet 4250tn (42A/42X series)
ElseIf oem = "Q5942A" Or oem = "Q5942X" Then marketing = "42A/42X Black"
' HP LaserJet Pro 4001n (147A/147X series)
ElseIf oem = "W1470A" Or oem = "W1470X" Then marketing = "147A/147X Black"
' HP Imaging Drums
ElseIf oem = "CF234A" Then marketing = "34A Drum"
ElseIf oem = "CF219A" Then marketing = "19A Drum"
ElseIf oem = "W2030A" Or oem = "W2030X" Then marketing = "415A/415X Drum"
' HP Maintenance Kits
ElseIf oem = "CF254A" Then marketing = "54A Maintenance Kit"
ElseIf oem = "CF247A" Then marketing = "47A Maintenance Kit"
' Xerox (note: many use numeric part numbers)
ElseIf oem = "006R01697" Then marketing = "Xerox Black Toner"
ElseIf oem = "006R01698" Then marketing = "Xerox Cyan Toner"
ElseIf oem = "006R01699" Then marketing = "Xerox Yellow Toner"
ElseIf oem = "006R01700" Then marketing = "Xerox Magenta Toner"
Else
marketing = "" ' No mapping found - will display OEM number only
End If
GetMarketingName = marketing
End Function
%>
<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="row">
<div class="col-xl-auto">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div>
<h5 class="card-title"><i class='zmdi zmdi-collection-image text-yellow'></i>&nbsp;&nbsp;Supplies Alert Report</h5>
<p class="text-muted" style="font-size:13px; margin-top:5px; margin-bottom:0;">
Monitors: Toner/Ink &lt;20%, Drums &lt;20%, Maintenance Kits &lt;20%, Waste Cartridges &gt;80%
</p>
</div>
<div style="display:flex; gap:10px; align-items:center;">
<select id="vendorFilter" class="form-control form-control-sm" style="width:150px;">
<option value="all">All Models</option>
<option value="HP">HP Models</option>
<option value="Xerox">Xerox Models</option>
</select>
<button type="button" class="btn btn-sm btn-secondary" id="refreshBtn" title="Clear Zabbix cache and refresh data">
<i class="zmdi zmdi-refresh"></i> Refresh Data
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">Printer</th>
<th scope="col">Location</th>
<th scope="col">Model</th>
<th scope="col">Level</th>
<th scope="col">Part Number</th>
</tr>
</thead>
<tbody>
<%
' Declare all variables at top level to avoid scope issues
Dim strSQL, rs, printerid, printerwindowsname, printercsfname, ipaddress, machinenumber, modelnumber, machineid, vendor
Dim printerData, zabbixConnected, pingStatus, suppliesJSON
Dim lowSuppliesFound
Dim alertItems()
Dim alertCount
Dim itemStart, itemEnd, currentPos, itemBlock
Dim itemName, itemValue, itemStatus, itemState
Dim namePos, nameStart, nameEnd
Dim valuePos, valueStart, valueEnd
Dim statusPos, statusStart, statusEnd
Dim statePos, stateStart, stateEnd
Dim baseName, numericValue
Dim statusIcon, statusColor, statusText
Dim partNumber, lookupName
Dim partNumbers
Dim debugPartNumbers, debugAllItems, debugItemCount
Dim isSupplyItem, isWasteItem, showItem
Dim marketingName, displayPartNumber
Dim urgencyScore, alertItem
Dim i, j, tempAlert, outputItem, k
Dim partKeyName, tryName, partKey, foundMatch
Dim primaryWord, supplyType, colorPos
Dim typeMatches, colorMatches
alertCount = 0
ReDim alertItems(500) ' Pre-allocate space for up to 500 alerts
lowSuppliesFound = False
strSQL = "SELECT printers.printerid, printers.printerwindowsname, printers.printercsfname, printers.ipaddress, " &_
"machines.machinenumber, machines.machineid, models.modelnumber, machines.alias, vendors.vendor " &_
"FROM printers " &_
"INNER JOIN models ON printers.modelid = models.modelnumberid " &_
"INNER JOIN machines ON printers.machineid = machines.machineid " &_
"INNER JOIN vendors ON models.vendorid = vendors.vendorid " &_
"WHERE printers.isactive = 1 AND printers.ipaddress IS NOT NULL AND printers.ipaddress != '' " &_
"ORDER BY machines.machinenumber ASC"
set rs = objconn.Execute(strSQL)
While Not rs.EOF
printerid = rs("printerid")
printerwindowsname = rs("printerwindowsname")
printercsfname = rs("printercsfname")
ipaddress = rs("ipaddress")
modelnumber = rs("modelnumber")
machineid = rs("machineid")
vendor = rs("vendor")
' Use alias if available, otherwise machinenumber
If NOT IsNull(rs("alias")) AND rs("alias") <> "" Then
machinenumber = rs("alias")
Else
machinenumber = rs("machinenumber")
End If
' Get cached Zabbix data for this printer (all supplies including maintenance)
printerData = SafeGetZabbixData(ipaddress)
If Not IsEmpty(printerData) And IsArray(printerData) Then
zabbixConnected = printerData(0)
pingStatus = printerData(1)
suppliesJSON = printerData(2)
' Parse supplies JSON to find items below 20%
If zabbixConnected = "1" And suppliesJSON <> "" And InStr(suppliesJSON, """result"":[") > 0 Then
' Check if result array is not empty
If InStr(suppliesJSON, """result"":[]") = 0 Then
' First pass: Build lookup of part numbers (type:info items)
' Use Dictionary object for more reliable storage
Set partNumbers = Server.CreateObject("Scripting.Dictionary")
debugPartNumbers = ""
debugAllItems = ""
debugItemCount = 0
currentPos = InStr(suppliesJSON, """result"":[") + 11
' Scan for part number items (containing "Part Number" in name)
Do While currentPos > 11 And currentPos < Len(suppliesJSON)
itemStart = InStr(currentPos, suppliesJSON, "{""itemid"":")
If itemStart = 0 Then Exit Do
itemEnd = InStr(itemStart, suppliesJSON, "},{")
If itemEnd = 0 Then itemEnd = InStr(itemStart, suppliesJSON, "}]")
If itemEnd = 0 Then Exit Do
itemBlock = Mid(suppliesJSON, itemStart, itemEnd - itemStart + 1)
' Extract name
namePos = InStr(itemBlock, """name"":""")
If namePos > 0 Then
nameStart = namePos + 8
nameEnd = InStr(nameStart, itemBlock, """")
itemName = Mid(itemBlock, nameStart, nameEnd - nameStart)
Else
itemName = ""
End If
' DEBUG: Track all items scanned
debugItemCount = debugItemCount + 1
If debugItemCount <= 10 Then
debugAllItems = debugAllItems & itemName & " | "
End If
' If this is a part number item, store it
' Look for various part number patterns (case-insensitive)
If InStr(1, itemName, "Part Number", 1) > 0 Or InStr(1, itemName, "Part number", 1) > 0 Or InStr(1, itemName, "OEM", 1) > 0 Or InStr(1, itemName, "SKU", 1) > 0 Then
valuePos = InStr(itemBlock, """lastvalue"":""")
If valuePos > 0 Then
valueStart = valuePos + 13
valueEnd = InStr(valueStart, itemBlock, """")
itemValue = Mid(itemBlock, valueStart, valueEnd - valueStart)
' Store in dictionary with full item name as key (e.g., "Black Toner Part Number")
If Not partNumbers.Exists(itemName) Then
partNumbers.Add itemName, itemValue
debugPartNumbers = debugPartNumbers & "[" & itemName & "=" & itemValue & "] "
End If
End If
End If
currentPos = itemEnd + 1
Loop
' Debug disabled - uncomment to show part number matching debug info
' Response.Write("<tr style='background:#1e3a5f;'><td colspan='7'><small>")
' Response.Write("<strong>DEBUG (" & ipaddress & "):</strong> Scanned " & debugItemCount & " items | ")
' Response.Write("<strong>First 10:</strong> " & Server.HTMLEncode(debugAllItems) & "<br>")
' If debugPartNumbers <> "" Then
' Response.Write("<strong>Part Numbers Found:</strong> " & Server.HTMLEncode(debugPartNumbers))
' Else
' Response.Write("<strong style='color:#ff6666;'>No part numbers found!</strong>")
' End If
' Response.Write("</small></td></tr>")
' Second pass: Find level items below 20%
currentPos = InStr(suppliesJSON, """result"":[") + 11
Do While currentPos > 11 And currentPos < Len(suppliesJSON)
' Find next item
itemStart = InStr(currentPos, suppliesJSON, "{""itemid"":")
If itemStart = 0 Then Exit Do
' Find end of this item
itemEnd = InStr(itemStart, suppliesJSON, "},{")
If itemEnd = 0 Then
' Last item in array
itemEnd = InStr(itemStart, suppliesJSON, "}]")
End If
If itemEnd = 0 Then Exit Do
itemBlock = Mid(suppliesJSON, itemStart, itemEnd - itemStart + 1)
' Extract item name - "name":" is 8 characters
namePos = InStr(itemBlock, """name"":""")
If namePos > 0 Then
nameStart = namePos + 8
nameEnd = InStr(nameStart, itemBlock, """")
itemName = Mid(itemBlock, nameStart, nameEnd - nameStart)
Else
itemName = "Unknown"
End If
' Extract lastvalue - "lastvalue":" is 13 characters
valuePos = InStr(itemBlock, """lastvalue"":""")
If valuePos > 0 Then
valueStart = valuePos + 13
valueEnd = InStr(valueStart, itemBlock, """")
itemValue = Mid(itemBlock, valueStart, valueEnd - valueStart)
Else
itemValue = "0"
End If
' Extract status (0 = enabled, 1 = disabled) - "status":" is 10 characters
statusPos = InStr(itemBlock, """status"":""")
If statusPos > 0 Then
statusStart = statusPos + 10
statusEnd = InStr(statusStart, itemBlock, """")
itemStatus = Mid(itemBlock, statusStart, statusEnd - statusStart)
Else
itemStatus = "0"
End If
' Extract state (0 = normal, 1 = not supported) - "state":" is 9 characters
statePos = InStr(itemBlock, """state"":""")
If statePos > 0 Then
stateStart = statePos + 9
stateEnd = InStr(stateStart, itemBlock, """")
itemState = Mid(itemBlock, stateStart, stateEnd - stateStart)
Else
itemState = "0"
End If
' Convert value to number and check if below 20%
On Error Resume Next
numericValue = CDbl(itemValue)
On Error Goto 0
' Filter: Only show actual supply level items (must have "Level" in name)
isSupplyItem = False
If InStr(1, itemName, "Level", 1) > 0 Then
' Exclude non-supply items
If InStr(1, itemName, "Part Number", 1) = 0 And _
InStr(1, itemName, "ICMP", 1) = 0 And _
InStr(1, itemName, "ping", 1) = 0 And _
InStr(1, itemName, "loss", 1) = 0 And _
InStr(1, itemName, "response", 1) = 0 And _
InStr(1, itemName, "Hostname", 1) = 0 And _
InStr(1, itemName, "Model", 1) = 0 And _
InStr(1, itemName, "Serial", 1) = 0 And _
InStr(1, itemName, "Location", 1) = 0 And _
InStr(1, itemName, "Firmware", 1) = 0 And _
InStr(1, itemName, "Current", 1) = 0 And _
InStr(1, itemName, " Max", 1) = 0 Then
isSupplyItem = True
End If
End If
' Detect if this is a waste cartridge (works backwards - high % is bad)
isWasteItem = (InStr(1, itemName, "Waste", 1) > 0)
' Check if item should be shown based on type
showItem = False
If isSupplyItem And itemStatus = "0" And itemState = "0" Then
If isWasteItem Then
' Waste cartridges: alert when ABOVE 80% (nearly full)
If numericValue > 80 And numericValue <= 100 Then
showItem = True
End If
Else
' Regular supplies: alert when BELOW 20% (running low)
If numericValue < 20 And numericValue >= 0 Then
showItem = True
End If
End If
End If
If showItem Then
lowSuppliesFound = True
' Determine status indicator
If isWasteItem Then
' Waste cartridge status (high % = bad)
If numericValue >= 95 Then
statusIcon = "zmdi-alert-circle"
statusColor = "#ff0000"
statusText = "Critical - Nearly Full"
ElseIf numericValue >= 90 Then
statusIcon = "zmdi-alert-triangle"
statusColor = "#ff6600"
statusText = "Very High"
Else
statusIcon = "zmdi-info"
statusColor = "#ffaa00"
statusText = "High"
End If
Else
' Regular supply status (low % = bad)
If numericValue <= 5 Then
statusIcon = "zmdi-alert-circle"
statusColor = "#ff0000"
statusText = "Critical"
ElseIf numericValue <= 10 Then
statusIcon = "zmdi-alert-triangle"
statusColor = "#ff6600"
statusText = "Very Low"
Else
statusIcon = "zmdi-info"
statusColor = "#ffaa00"
statusText = "Low"
End If
End If
' Look up part number for this item
partNumber = "-"
If partNumbers.Count > 0 Then
' Extract base name for lookup - remove " Level" suffix
lookupName = Replace(itemName, " Level", "")
lookupName = Trim(lookupName)
' Comprehensive matching strategy for all template versions
foundMatch = False
' Strategy 1: EXACT match - NEW template format (preferred)
' "Black Toner Level" → "Black Toner Part Number"
' "Cyan Ink Level" → "Cyan Ink Part Number"
' "Black Drum Level" → "Black Drum Part Number"
partKeyName = lookupName & " Part Number"
If partNumbers.Exists(partKeyName) Then
partNumber = partNumbers(partKeyName)
foundMatch = True
End If
' Strategy 2: Add " Cartridge" - OLD Xerox template format
' "Black Drum Level" → "Black Drum Cartridge Part Number"
' "Black Toner Level" → "Black Toner Cartridge Part Number"
If Not foundMatch Then
tryName = lookupName & " Cartridge Part Number"
If partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 3: Replace supply type with "Cartridge" - OLD HP template format
' "Black Toner Level" → "Black Cartridge Part Number"
' "Cyan Ink Level" → "Cyan Cartridge Part Number"
If Not foundMatch Then
' Replace common supply types with "Cartridge"
If InStr(1, lookupName, "Toner", 1) > 0 Then
tryName = Replace(lookupName, "Toner", "Cartridge", 1, -1, 1) & " Part Number"
ElseIf InStr(1, lookupName, "Ink", 1) > 0 Then
tryName = Replace(lookupName, "Ink", "Cartridge", 1, -1, 1) & " Part Number"
ElseIf InStr(1, lookupName, "Drum", 1) > 0 Then
tryName = Replace(lookupName, "Drum", "Cartridge", 1, -1, 1) & " Part Number"
Else
tryName = ""
End If
If tryName <> "" And partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 4: Check for "Standard MIB" suffix variation
' "Maintenance Kit Level" → "Maintenance Kit Part Number (Standard MIB)"
If Not foundMatch Then
tryName = lookupName & " Part Number (Standard MIB)"
If partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 5: Intelligent fuzzy match by type and color
If Not foundMatch Then
' Extract primary identifier (first significant word)
primaryWord = ""
supplyType = ""
' Determine supply type
If InStr(1, lookupName, "Toner", 1) > 0 Then
supplyType = "Toner"
ElseIf InStr(1, lookupName, "Ink", 1) > 0 Then
supplyType = "Ink"
ElseIf InStr(1, lookupName, "Drum", 1) > 0 Then
supplyType = "Drum"
ElseIf InStr(1, lookupName, "Waste", 1) > 0 Then
supplyType = "Waste"
ElseIf InStr(1, lookupName, "Fuser", 1) > 0 Then
supplyType = "Fuser"
ElseIf InStr(1, lookupName, "Maintenance", 1) > 0 Then
supplyType = "Maintenance"
End If
' Extract color/identifier (first word before supply type)
If supplyType <> "" Then
colorPos = InStr(1, lookupName, supplyType, 1)
If colorPos > 1 Then
primaryWord = Trim(Left(lookupName, colorPos - 1))
End If
End If
' Search all keys for matching type and color
For Each partKey In partNumbers.Keys
If InStr(1, partKey, "Part Number", 1) > 0 Then
' Must match supply type
typeMatches = False
If supplyType <> "" Then
typeMatches = (InStr(1, partKey, supplyType, 1) > 0) Or (InStr(1, partKey, "Cartridge", 1) > 0)
Else
' For items without obvious type, just look for any match
typeMatches = True
End If
' Must match color/identifier if present
colorMatches = True
If primaryWord <> "" Then
colorMatches = (InStr(1, partKey, primaryWord, 1) > 0)
End If
If typeMatches And colorMatches Then
partNumber = partNumbers(partKey)
foundMatch = True
Exit For
End If
End If
Next
End If
End If
' Get marketing name for this part number
marketingName = GetMarketingName(partNumber)
If marketingName <> "" Then
' Show marketing name prominently with OEM number in smaller text
displayPartNumber = "<strong>" & Server.HTMLEncode(marketingName) & "</strong><br><small style='color:#999;'>" & Server.HTMLEncode(partNumber) & "</small>"
Else
' No mapping found, just show OEM number
displayPartNumber = Server.HTMLEncode(partNumber)
End If
' Calculate urgency score for sorting
' For regular supplies: lower % = higher urgency (5% = 95 urgency)
' For waste: higher % = higher urgency (95% = 95 urgency)
If isWasteItem Then
urgencyScore = numericValue
Else
urgencyScore = 100 - numericValue
End If
' Store alert data for later sorting
alertItem = Array( _
urgencyScore, _
vendor, _
printerid, _
printerwindowsname, _
machineid, _
machinenumber, _
modelnumber, _
numericValue, _
statusColor, _
displayPartNumber, _
itemName _
)
alertItems(alertCount) = alertItem
alertCount = alertCount + 1
End If
' Move to next item
currentPos = itemEnd + 1
Loop
End If
End If
End If
rs.MoveNext
Wend
' Sort alerts by urgency (highest urgency first = most critical)
' Simple bubble sort with error handling
On Error Resume Next
If alertCount > 1 Then
For i = 0 To alertCount - 2
For j = 0 To alertCount - i - 2
' alertItems(j)(0) is the urgency score
If Not IsEmpty(alertItems(j)) And Not IsEmpty(alertItems(j + 1)) Then
If CDbl(alertItems(j)(0)) < CDbl(alertItems(j + 1)(0)) Then
' Swap items
tempAlert = alertItems(j)
alertItems(j) = alertItems(j + 1)
alertItems(j + 1) = tempAlert
End If
End If
Next
Next
End If
' Output sorted alerts
If alertCount > 0 Then
lowSuppliesFound = True
For k = 0 To alertCount - 1
If Not IsEmpty(alertItems(k)) And IsArray(alertItems(k)) Then
outputItem = alertItems(k)
' Array indices: 0=urgencyScore, 1=vendor, 2=printerid, 3=printerwindowsname,
' 4=machineid, 5=machinenumber, 6=modelnumber, 7=numericValue,
' 8=statusColor, 9=displayPartNumber, 10=itemName
Response.Write("<tr data-vendor='" & Server.HTMLEncode(outputItem(1)) & "'>")
Response.Write("<td><a href='./displayprinter.asp?printerid=" & outputItem(2) & "'>" & Server.HTMLEncode(outputItem(3)) & "</a></td>")
Response.Write("<td><span class='location-link' data-machineid='" & outputItem(4) & "' style='cursor:pointer; color:#007bff;'><i class='zmdi zmdi-pin' style='margin-right:4px;'></i>" & Server.HTMLEncode(outputItem(5)) & "</span></td>")
Response.Write("<td>" & Server.HTMLEncode(outputItem(6)) & "</td>")
Response.Write("<td><strong style='color:" & outputItem(8) & ";'>" & Round(CDbl(outputItem(7)), 1) & "%</strong></td>")
Response.Write("<td>" & outputItem(9) & "</td>")
Response.Write("</tr>")
End If
Next
End If
On Error Goto 0
If Not lowSuppliesFound Then
Response.Write("<tr><td colspan='6' style='text-align:center; padding:20px;'>")
Response.Write("<i class='zmdi zmdi-check-circle' style='color:#00aa00; font-size:24px;'></i><br>")
Response.Write("No supply issues found - All printers have adequate supplies")
Response.Write("</td></tr>")
End If
objConn.Close
%>
</tbody>
</table>
</div>
<div class="card-footer">
<small class="text-muted">
<i class="zmdi zmdi-info-outline"></i> This report shows printers with low supplies (&lt;20%) or waste cartridges near full (&gt;80%).
Data refreshed from Zabbix every 5 minutes.
</small>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<script>
$(document).ready(function() {
$('#refreshBtn').click(function() {
if (confirm('Clear all Zabbix cache and refresh? This will fetch fresh data from Zabbix for all printers.')) {
var btn = $(this);
var originalHtml = btn.html();
// Show loading state
btn.prop('disabled', true);
btn.html('<i class="zmdi zmdi-refresh zmdi-hc-spin"></i> Refreshing...');
// Call clear cache endpoint
$.ajax({
url: './admin_clear_cache.asp?confirm=yes&type=zabbix&ajax=1',
method: 'GET',
success: function() {
// Reload page after cache cleared
location.reload();
},
error: function() {
// Still reload on error
location.reload();
}
});
}
});
});
</script>
<!-- Location map popup modal -->
<style>
/* Theme-specific styling for location links */
body.bg-theme .location-link {
color: #fff !important;
}
.location-popup-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9998;
display: none;
}
.location-popup {
position: fixed;
background: #1f1f1f;
border: 2px solid #667eea;
border-radius: 8px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
max-width: 90vw;
max-height: 90vh;
}
.location-popup-header {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 15px;
border-radius: 6px 6px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.location-popup-close {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
}
.location-popup-close:hover {
background: rgba(255, 255, 255, 0.2);
}
.location-popup-body {
padding: 0;
background: #2a2a2a;
}
.location-popup iframe {
display: block;
border: none;
border-radius: 0 0 6px 6px;
}
.location-link:hover {
text-decoration: underline;
}
</style>
<script>
$(document).ready(function() {
// Create popup elements
var $overlay = $('<div class="location-popup-overlay"></div>').appendTo('body');
var $popup = $('<div class="location-popup"></div>').appendTo('body');
$popup.html(
'<div class="location-popup-header">' +
'<h6 style="margin:0; font-size:16px;"><i class="zmdi zmdi-pin"></i> <span class="location-title">Loading...</span></h6>' +
'<button class="location-popup-close" title="Close (Esc)">&times;</button>' +
'</div>' +
'<div class="location-popup-body">' +
'<iframe src="" width="440" height="340"></iframe>' +
'</div>'
);
var $iframe = $popup.find('iframe');
var $title = $popup.find('.location-title');
var currentMachineId = null;
// Function to show popup with smart positioning
function showLocationPopup(machineId, locationName, mouseEvent) {
// Don't reload if same location
if (currentMachineId === machineId && $popup.is(':visible')) {
return;
}
currentMachineId = machineId;
$title.text(locationName);
// Load iframe
$iframe.attr('src', './displaylocation.asp?machineid=' + machineId);
// Position popup
var popupWidth = 440;
var popupHeight = 400;
var mouseX = mouseEvent.clientX;
var mouseY = mouseEvent.clientY;
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var left, top;
// Horizontal positioning
left = mouseX + 10;
if (left + popupWidth > windowWidth - 10) {
left = mouseX - popupWidth - 10;
}
if (left < 10) {
left = 10;
}
// Vertical positioning
var spaceBelow = windowHeight - mouseY;
var spaceAbove = mouseY;
if (spaceBelow >= popupHeight + 20) {
top = mouseY + 10;
} else if (spaceAbove >= popupHeight + 20) {
top = mouseY - popupHeight - 10;
} else {
top = Math.max(10, (windowHeight - popupHeight) / 2);
}
if (top < 10) {
top = 10;
}
if (top + popupHeight > windowHeight - 10) {
top = windowHeight - popupHeight - 10;
}
$popup.css({
left: left + 'px',
top: top + 'px',
display: 'block'
});
$overlay.fadeIn(200);
$popup.fadeIn(200);
}
// Function to hide popup
function hideLocationPopup() {
$overlay.fadeOut(200);
$popup.fadeOut(200);
setTimeout(function() {
$iframe.attr('src', '');
currentMachineId = null;
}, 200);
}
var hoverTimer = null;
// Hover handler for location links
$(document).on('mouseenter', '.location-link', function(e) {
var $link = $(this);
var machineId = $link.data('machineid');
var locationName = $link.text().trim();
var mouseEvent = e;
if (hoverTimer) {
clearTimeout(hoverTimer);
}
hoverTimer = setTimeout(function() {
showLocationPopup(machineId, locationName, mouseEvent);
}, 300);
});
// Cancel popup if mouse leaves before delay
$(document).on('mouseleave', '.location-link', function() {
if (hoverTimer) {
clearTimeout(hoverTimer);
hoverTimer = null;
}
});
// Keep popup open when hovering over it
$popup.on('mouseenter', function() {
// Keep open
});
// Close popup when mouse leaves popup
$popup.on('mouseleave', function() {
hideLocationPopup();
});
// Close on overlay click
$overlay.on('click', function() {
hideLocationPopup();
});
// Close on X button
$popup.find('.location-popup-close').on('click', function() {
hideLocationPopup();
});
// Close on Escape key
$(document).on('keydown', function(e) {
if (e.key === 'Escape' && $popup.is(':visible')) {
hideLocationPopup();
}
});
});
// Vendor filter functionality
$(document).ready(function() {
$('#vendorFilter').on('change', function() {
var selectedVendor = $(this).val();
if (selectedVendor === 'all') {
// Show all rows
$('tbody tr[data-vendor]').show();
} else {
// Hide all rows first
$('tbody tr[data-vendor]').hide();
// Show only matching vendor rows
$('tbody tr[data-vendor="' + selectedVendor + '"]').show();
}
});
});
</script>
</body>
</html>

View File

@@ -1,951 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!--#include file="./includes/header.asp"-->
<!--#include file="./includes/sql.asp"-->
<!--#include file="./includes/zabbix_all_supplies_cached.asp"-->
</head>
<%
' ============================================================================
' FUNCTION: SafeGetZabbixData
' PURPOSE: Safely call Zabbix function with error handling
' ============================================================================
Function SafeGetZabbixData(ipaddress)
On Error Resume Next
Dim result
result = GetAllPrinterSuppliesCached(ipaddress)
If Err.Number <> 0 Then
result = Empty
Err.Clear
End If
On Error Goto 0
SafeGetZabbixData = result
End Function
theme = Request.Cookies("theme")
IF theme = "" THEN
theme="bg-theme1"
END IF
' ============================================================================
' FUNCTION: GetMarketingName
' PURPOSE: Convert OEM part numbers to marketing names for easier supply closet matching
' ============================================================================
Function GetMarketingName(oemPartNumber)
Dim oem, marketing
oem = UCase(Trim(oemPartNumber))
' HP M454dw / M454dn / M479fdw (414A/414X series)
If oem = "W2020A" Or oem = "W2020X" Then marketing = "414A/414X Black"
ElseIf oem = "W2021A" Or oem = "W2021X" Then marketing = "414A/414X Cyan"
ElseIf oem = "W2022A" Or oem = "W2022X" Then marketing = "414A/414X Yellow"
ElseIf oem = "W2023A" Or oem = "W2023X" Then marketing = "414A/414X Magenta"
' HP M254dw / M255dw (202A/202X series)
ElseIf oem = "CF500A" Or oem = "CF500X" Then marketing = "202A/202X Black"
ElseIf oem = "CF501A" Or oem = "CF501X" Then marketing = "202A/202X Cyan"
ElseIf oem = "CF502A" Or oem = "CF502X" Then marketing = "202A/202X Yellow"
ElseIf oem = "CF503A" Or oem = "CF503X" Then marketing = "202A/202X Magenta"
' HP M251nw / M252dw (201A/201X series)
ElseIf oem = "CF400A" Or oem = "CF400X" Then marketing = "201A/201X Black"
ElseIf oem = "CF401A" Or oem = "CF401X" Then marketing = "201A/201X Cyan"
ElseIf oem = "CF402A" Or oem = "CF402X" Then marketing = "201A/201X Yellow"
ElseIf oem = "CF403A" Or oem = "CF403X" Then marketing = "201A/201X Magenta"
' HP LaserJet 200 color M251nw (131A/131X series)
ElseIf oem = "CF210A" Or oem = "CF210X" Then marketing = "131A/131X Black"
ElseIf oem = "CF211A" Then marketing = "131A Cyan"
ElseIf oem = "CF212A" Then marketing = "131A Yellow"
ElseIf oem = "CF213A" Then marketing = "131A Magenta"
' HP M404n / M406 (58A/58X series)
ElseIf oem = "CF258A" Or oem = "CF258X" Then marketing = "58A/58X Black"
' HP M506 / M607 (87A/87X series)
ElseIf oem = "CF287A" Or oem = "CF287X" Then marketing = "87A/87X Black"
' HP M602 (90A/90X series)
ElseIf oem = "CE390A" Or oem = "CE390X" Then marketing = "90A/90X Black"
' HP P3015dn (55A/55X series)
ElseIf oem = "CE255A" Or oem = "CE255X" Then marketing = "55A/55X Black"
' HP LaserJet 4250tn (42A/42X series)
ElseIf oem = "Q5942A" Or oem = "Q5942X" Then marketing = "42A/42X Black"
' HP LaserJet Pro 4001n (147A/147X series)
ElseIf oem = "W1470A" Or oem = "W1470X" Then marketing = "147A/147X Black"
' HP Imaging Drums
ElseIf oem = "CF234A" Then marketing = "34A Drum"
ElseIf oem = "CF219A" Then marketing = "19A Drum"
ElseIf oem = "W2030A" Or oem = "W2030X" Then marketing = "415A/415X Drum"
' HP Maintenance Kits
ElseIf oem = "CF254A" Then marketing = "54A Maintenance Kit"
ElseIf oem = "CF247A" Then marketing = "47A Maintenance Kit"
' Xerox (note: many use numeric part numbers)
ElseIf oem = "006R01697" Then marketing = "Xerox Black Toner"
ElseIf oem = "006R01698" Then marketing = "Xerox Cyan Toner"
ElseIf oem = "006R01699" Then marketing = "Xerox Yellow Toner"
ElseIf oem = "006R01700" Then marketing = "Xerox Magenta Toner"
Else
marketing = "" ' No mapping found - will display OEM number only
End If
GetMarketingName = marketing
End Function
%>
<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="row">
<div class="col-xl-auto">
<div class="card">
<div class="card-body">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div>
<h5 class="card-title"><i class='zmdi zmdi-collection-image text-yellow'></i>&nbsp;&nbsp;Supplies Alert Report</h5>
<p class="text-muted" style="font-size:13px; margin-top:5px; margin-bottom:0;">
Monitors: Toner/Ink &lt;20%, Drums &lt;20%, Maintenance Kits &lt;20%, Waste Cartridges &gt;80%
</p>
</div>
<div style="display:flex; gap:10px; align-items:center;">
<select id="vendorFilter" class="form-control form-control-sm" style="width:150px;">
<option value="all">All Models</option>
<option value="HP">HP Models</option>
<option value="Xerox">Xerox Models</option>
</select>
<button type="button" class="btn btn-sm btn-secondary" id="refreshBtn" title="Clear Zabbix cache and refresh data">
<i class="zmdi zmdi-refresh"></i> Refresh Data
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">Printer</th>
<th scope="col">Location</th>
<th scope="col">Model</th>
<th scope="col">Level</th>
<th scope="col">Part Number</th>
</tr>
</thead>
<tbody>
<%
' Declare all variables at top level to avoid scope issues
Dim strSQL, rs, printerid, printerwindowsname, printercsfname, ipaddress, machinenumber, modelnumber, machineid, vendor
Dim printerData, zabbixConnected, pingStatus, suppliesJSON
Dim lowSuppliesFound
Dim alertItems()
Dim alertCount
Dim itemStart, itemEnd, currentPos, itemBlock
Dim itemName, itemValue, itemStatus, itemState
Dim namePos, nameStart, nameEnd
Dim valuePos, valueStart, valueEnd
Dim statusPos, statusStart, statusEnd
Dim statePos, stateStart, stateEnd
Dim baseName, numericValue
Dim statusIcon, statusColor, statusText
Dim partNumber, lookupName
Dim partNumbers
Dim debugPartNumbers, debugAllItems, debugItemCount
Dim isSupplyItem, isWasteItem, showItem
Dim marketingName, displayPartNumber
Dim urgencyScore, alertItem
Dim i, j, tempAlert, outputItem, k
Dim partKeyName, tryName, partKey, foundMatch
Dim primaryWord, supplyType, colorPos
Dim typeMatches, colorMatches
alertCount = 0
ReDim alertItems(500) ' Pre-allocate space for up to 500 alerts
lowSuppliesFound = False
strSQL = "SELECT printers.printerid, printers.printerwindowsname, printers.printercsfname, printers.ipaddress, " &_
"machines.machinenumber, machines.machineid, models.modelnumber, machines.alias, vendors.vendor " &_
"FROM printers " &_
"INNER JOIN models ON printers.modelid = models.modelnumberid " &_
"INNER JOIN machines ON printers.machineid = machines.machineid " &_
"INNER JOIN vendors ON models.vendorid = vendors.vendorid " &_
"WHERE printers.isactive = 1 AND printers.ipaddress IS NOT NULL AND printers.ipaddress != '' " &_
"ORDER BY machines.machinenumber ASC"
set rs = objconn.Execute(strSQL)
While Not rs.EOF
printerid = rs("printerid")
printerwindowsname = rs("printerwindowsname")
printercsfname = rs("printercsfname")
ipaddress = rs("ipaddress")
modelnumber = rs("modelnumber")
machineid = rs("machineid")
vendor = rs("vendor")
' Use alias if available, otherwise machinenumber
If NOT IsNull(rs("alias")) AND rs("alias") <> "" Then
machinenumber = rs("alias")
Else
machinenumber = rs("machinenumber")
End If
' Get cached Zabbix data for this printer (all supplies including maintenance)
printerData = SafeGetZabbixData(ipaddress)
If Not IsEmpty(printerData) And IsArray(printerData) Then
zabbixConnected = printerData(0)
pingStatus = printerData(1)
suppliesJSON = printerData(2)
' Parse supplies JSON to find items below 20%
If zabbixConnected = "1" And suppliesJSON <> "" And InStr(suppliesJSON, """result"":[") > 0 Then
' Check if result array is not empty
If InStr(suppliesJSON, """result"":[]") = 0 Then
' First pass: Build lookup of part numbers (type:info items)
' Use Dictionary object for more reliable storage
Set partNumbers = Server.CreateObject("Scripting.Dictionary")
debugPartNumbers = ""
debugAllItems = ""
debugItemCount = 0
currentPos = InStr(suppliesJSON, """result"":[") + 11
' Scan for part number items (containing "Part Number" in name)
Do While currentPos > 11 And currentPos < Len(suppliesJSON)
itemStart = InStr(currentPos, suppliesJSON, "{""itemid"":")
If itemStart = 0 Then Exit Do
itemEnd = InStr(itemStart, suppliesJSON, "},{")
If itemEnd = 0 Then itemEnd = InStr(itemStart, suppliesJSON, "}]")
If itemEnd = 0 Then Exit Do
itemBlock = Mid(suppliesJSON, itemStart, itemEnd - itemStart + 1)
' Extract name
namePos = InStr(itemBlock, """name"":""")
If namePos > 0 Then
nameStart = namePos + 8
nameEnd = InStr(nameStart, itemBlock, """")
itemName = Mid(itemBlock, nameStart, nameEnd - nameStart)
Else
itemName = ""
End If
' DEBUG: Track all items scanned
debugItemCount = debugItemCount + 1
If debugItemCount <= 10 Then
debugAllItems = debugAllItems & itemName & " | "
End If
' If this is a part number item, store it
' Look for various part number patterns (case-insensitive)
If InStr(1, itemName, "Part Number", 1) > 0 Or InStr(1, itemName, "Part number", 1) > 0 Or InStr(1, itemName, "OEM", 1) > 0 Or InStr(1, itemName, "SKU", 1) > 0 Then
valuePos = InStr(itemBlock, """lastvalue"":""")
If valuePos > 0 Then
valueStart = valuePos + 13
valueEnd = InStr(valueStart, itemBlock, """")
itemValue = Mid(itemBlock, valueStart, valueEnd - valueStart)
' Store in dictionary with full item name as key (e.g., "Black Toner Part Number")
If Not partNumbers.Exists(itemName) Then
partNumbers.Add itemName, itemValue
debugPartNumbers = debugPartNumbers & "[" & itemName & "=" & itemValue & "] "
End If
End If
End If
currentPos = itemEnd + 1
Loop
' Debug disabled - uncomment to show part number matching debug info
' Response.Write("<tr style='background:#1e3a5f;'><td colspan='7'><small>")
' Response.Write("<strong>DEBUG (" & ipaddress & "):</strong> Scanned " & debugItemCount & " items | ")
' Response.Write("<strong>First 10:</strong> " & Server.HTMLEncode(debugAllItems) & "<br>")
' If debugPartNumbers <> "" Then
' Response.Write("<strong>Part Numbers Found:</strong> " & Server.HTMLEncode(debugPartNumbers))
' Else
' Response.Write("<strong style='color:#ff6666;'>No part numbers found!</strong>")
' End If
' Response.Write("</small></td></tr>")
' Second pass: Find level items below 20%
currentPos = InStr(suppliesJSON, """result"":[") + 11
Do While currentPos > 11 And currentPos < Len(suppliesJSON)
' Find next item
itemStart = InStr(currentPos, suppliesJSON, "{""itemid"":")
If itemStart = 0 Then Exit Do
' Find end of this item
itemEnd = InStr(itemStart, suppliesJSON, "},{")
If itemEnd = 0 Then
' Last item in array
itemEnd = InStr(itemStart, suppliesJSON, "}]")
End If
If itemEnd = 0 Then Exit Do
itemBlock = Mid(suppliesJSON, itemStart, itemEnd - itemStart + 1)
' Extract item name - "name":" is 8 characters
namePos = InStr(itemBlock, """name"":""")
If namePos > 0 Then
nameStart = namePos + 8
nameEnd = InStr(nameStart, itemBlock, """")
itemName = Mid(itemBlock, nameStart, nameEnd - nameStart)
Else
itemName = "Unknown"
End If
' Extract lastvalue - "lastvalue":" is 13 characters
valuePos = InStr(itemBlock, """lastvalue"":""")
If valuePos > 0 Then
valueStart = valuePos + 13
valueEnd = InStr(valueStart, itemBlock, """")
itemValue = Mid(itemBlock, valueStart, valueEnd - valueStart)
Else
itemValue = "0"
End If
' Extract status (0 = enabled, 1 = disabled) - "status":" is 10 characters
statusPos = InStr(itemBlock, """status"":""")
If statusPos > 0 Then
statusStart = statusPos + 10
statusEnd = InStr(statusStart, itemBlock, """")
itemStatus = Mid(itemBlock, statusStart, statusEnd - statusStart)
Else
itemStatus = "0"
End If
' Extract state (0 = normal, 1 = not supported) - "state":" is 9 characters
statePos = InStr(itemBlock, """state"":""")
If statePos > 0 Then
stateStart = statePos + 9
stateEnd = InStr(stateStart, itemBlock, """")
itemState = Mid(itemBlock, stateStart, stateEnd - stateStart)
Else
itemState = "0"
End If
' Convert value to number and check if below 20%
On Error Resume Next
numericValue = CDbl(itemValue)
On Error Goto 0
' Filter: Only show actual supply level items (must have "Level" in name)
isSupplyItem = False
If InStr(1, itemName, "Level", 1) > 0 Then
' Exclude non-supply items
If InStr(1, itemName, "Part Number", 1) = 0 And _
InStr(1, itemName, "ICMP", 1) = 0 And _
InStr(1, itemName, "ping", 1) = 0 And _
InStr(1, itemName, "loss", 1) = 0 And _
InStr(1, itemName, "response", 1) = 0 And _
InStr(1, itemName, "Hostname", 1) = 0 And _
InStr(1, itemName, "Model", 1) = 0 And _
InStr(1, itemName, "Serial", 1) = 0 And _
InStr(1, itemName, "Location", 1) = 0 And _
InStr(1, itemName, "Firmware", 1) = 0 And _
InStr(1, itemName, "Current", 1) = 0 And _
InStr(1, itemName, " Max", 1) = 0 Then
isSupplyItem = True
End If
End If
' Detect if this is a waste cartridge (works backwards - high % is bad)
isWasteItem = (InStr(1, itemName, "Waste", 1) > 0)
' Check if item should be shown based on type
showItem = False
If isSupplyItem And itemStatus = "0" And itemState = "0" Then
If isWasteItem Then
' Waste cartridges: alert when ABOVE 80% (nearly full)
If numericValue > 80 And numericValue <= 100 Then
showItem = True
End If
Else
' Regular supplies: alert when BELOW 20% (running low)
If numericValue < 20 And numericValue >= 0 Then
showItem = True
End If
End If
End If
If showItem Then
lowSuppliesFound = True
' Determine status indicator
If isWasteItem Then
' Waste cartridge status (high % = bad)
If numericValue >= 95 Then
statusIcon = "zmdi-alert-circle"
statusColor = "#ff0000"
statusText = "Critical - Nearly Full"
ElseIf numericValue >= 90 Then
statusIcon = "zmdi-alert-triangle"
statusColor = "#ff6600"
statusText = "Very High"
Else
statusIcon = "zmdi-info"
statusColor = "#ffaa00"
statusText = "High"
End If
Else
' Regular supply status (low % = bad)
If numericValue <= 5 Then
statusIcon = "zmdi-alert-circle"
statusColor = "#ff0000"
statusText = "Critical"
ElseIf numericValue <= 10 Then
statusIcon = "zmdi-alert-triangle"
statusColor = "#ff6600"
statusText = "Very Low"
Else
statusIcon = "zmdi-info"
statusColor = "#ffaa00"
statusText = "Low"
End If
End If
' Look up part number for this item
partNumber = "-"
If partNumbers.Count > 0 Then
' Extract base name for lookup - remove " Level" suffix
lookupName = Replace(itemName, " Level", "")
lookupName = Trim(lookupName)
' Comprehensive matching strategy for all template versions
foundMatch = False
' Strategy 1: EXACT match - NEW template format (preferred)
' "Black Toner Level" → "Black Toner Part Number"
' "Cyan Ink Level" → "Cyan Ink Part Number"
' "Black Drum Level" → "Black Drum Part Number"
partKeyName = lookupName & " Part Number"
If partNumbers.Exists(partKeyName) Then
partNumber = partNumbers(partKeyName)
foundMatch = True
End If
' Strategy 2: Add " Cartridge" - OLD Xerox template format
' "Black Drum Level" → "Black Drum Cartridge Part Number"
' "Black Toner Level" → "Black Toner Cartridge Part Number"
If Not foundMatch Then
tryName = lookupName & " Cartridge Part Number"
If partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 3: Replace supply type with "Cartridge" - OLD HP template format
' "Black Toner Level" → "Black Cartridge Part Number"
' "Cyan Ink Level" → "Cyan Cartridge Part Number"
If Not foundMatch Then
' Replace common supply types with "Cartridge"
If InStr(1, lookupName, "Toner", 1) > 0 Then
tryName = Replace(lookupName, "Toner", "Cartridge", 1, -1, 1) & " Part Number"
ElseIf InStr(1, lookupName, "Ink", 1) > 0 Then
tryName = Replace(lookupName, "Ink", "Cartridge", 1, -1, 1) & " Part Number"
ElseIf InStr(1, lookupName, "Drum", 1) > 0 Then
tryName = Replace(lookupName, "Drum", "Cartridge", 1, -1, 1) & " Part Number"
Else
tryName = ""
End If
If tryName <> "" And partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 4: Check for "Standard MIB" suffix variation
' "Maintenance Kit Level" → "Maintenance Kit Part Number (Standard MIB)"
If Not foundMatch Then
tryName = lookupName & " Part Number (Standard MIB)"
If partNumbers.Exists(tryName) Then
partNumber = partNumbers(tryName)
foundMatch = True
End If
End If
' Strategy 5: Intelligent fuzzy match by type and color
If Not foundMatch Then
' Extract primary identifier (first significant word)
primaryWord = ""
supplyType = ""
' Determine supply type
If InStr(1, lookupName, "Toner", 1) > 0 Then
supplyType = "Toner"
ElseIf InStr(1, lookupName, "Ink", 1) > 0 Then
supplyType = "Ink"
ElseIf InStr(1, lookupName, "Drum", 1) > 0 Then
supplyType = "Drum"
ElseIf InStr(1, lookupName, "Waste", 1) > 0 Then
supplyType = "Waste"
ElseIf InStr(1, lookupName, "Fuser", 1) > 0 Then
supplyType = "Fuser"
ElseIf InStr(1, lookupName, "Maintenance", 1) > 0 Then
supplyType = "Maintenance"
End If
' Extract color/identifier (first word before supply type)
If supplyType <> "" Then
colorPos = InStr(1, lookupName, supplyType, 1)
If colorPos > 1 Then
primaryWord = Trim(Left(lookupName, colorPos - 1))
End If
End If
' Search all keys for matching type and color
For Each partKey In partNumbers.Keys
If InStr(1, partKey, "Part Number", 1) > 0 Then
' Must match supply type
typeMatches = False
If supplyType <> "" Then
typeMatches = (InStr(1, partKey, supplyType, 1) > 0) Or (InStr(1, partKey, "Cartridge", 1) > 0)
Else
' For items without obvious type, just look for any match
typeMatches = True
End If
' Must match color/identifier if present
colorMatches = True
If primaryWord <> "" Then
colorMatches = (InStr(1, partKey, primaryWord, 1) > 0)
End If
If typeMatches And colorMatches Then
partNumber = partNumbers(partKey)
foundMatch = True
Exit For
End If
End If
Next
End If
End If
' Get marketing name for this part number
marketingName = GetMarketingName(partNumber)
If marketingName <> "" Then
' Show marketing name prominently with OEM number in smaller text
displayPartNumber = "<strong>" & Server.HTMLEncode(marketingName) & "</strong><br><small style='color:#999;'>" & Server.HTMLEncode(partNumber) & "</small>"
Else
' No mapping found, just show OEM number
displayPartNumber = Server.HTMLEncode(partNumber)
End If
' Calculate urgency score for sorting
' For regular supplies: lower % = higher urgency (5% = 95 urgency)
' For waste: higher % = higher urgency (95% = 95 urgency)
If isWasteItem Then
urgencyScore = numericValue
Else
urgencyScore = 100 - numericValue
End If
' Store alert data for later sorting
alertItem = Array( _
urgencyScore, _
vendor, _
printerid, _
printerwindowsname, _
machineid, _
machinenumber, _
modelnumber, _
numericValue, _
statusColor, _
displayPartNumber, _
itemName _
)
alertItems(alertCount) = alertItem
alertCount = alertCount + 1
End If
' Move to next item
currentPos = itemEnd + 1
Loop
End If
End If
End If
rs.MoveNext
Wend
' Sort alerts by urgency (highest urgency first = most critical)
' Simple bubble sort with error handling
On Error Resume Next
If alertCount > 1 Then
For i = 0 To alertCount - 2
For j = 0 To alertCount - i - 2
' alertItems(j)(0) is the urgency score
If Not IsEmpty(alertItems(j)) And Not IsEmpty(alertItems(j + 1)) Then
If CDbl(alertItems(j)(0)) < CDbl(alertItems(j + 1)(0)) Then
' Swap items
tempAlert = alertItems(j)
alertItems(j) = alertItems(j + 1)
alertItems(j + 1) = tempAlert
End If
End If
Next
Next
End If
' Output sorted alerts
If alertCount > 0 Then
lowSuppliesFound = True
For k = 0 To alertCount - 1
If Not IsEmpty(alertItems(k)) And IsArray(alertItems(k)) Then
outputItem = alertItems(k)
' Array indices: 0=urgencyScore, 1=vendor, 2=printerid, 3=printerwindowsname,
' 4=machineid, 5=machinenumber, 6=modelnumber, 7=numericValue,
' 8=statusColor, 9=displayPartNumber, 10=itemName
Response.Write("<tr data-vendor='" & Server.HTMLEncode(outputItem(1)) & "'>")
Response.Write("<td><a href='./displayprinter.asp?printerid=" & outputItem(2) & "'>" & Server.HTMLEncode(outputItem(3)) & "</a></td>")
Response.Write("<td><span class='location-link' data-machineid='" & outputItem(4) & "' style='cursor:pointer; color:#007bff;'><i class='zmdi zmdi-pin' style='margin-right:4px;'></i>" & Server.HTMLEncode(outputItem(5)) & "</span></td>")
Response.Write("<td>" & Server.HTMLEncode(outputItem(6)) & "</td>")
Response.Write("<td><strong style='color:" & outputItem(8) & ";'>" & Round(CDbl(outputItem(7)), 1) & "%</strong></td>")
Response.Write("<td>" & outputItem(9) & "</td>")
Response.Write("</tr>")
End If
Next
End If
On Error Goto 0
If Not lowSuppliesFound Then
Response.Write("<tr><td colspan='6' style='text-align:center; padding:20px;'>")
Response.Write("<i class='zmdi zmdi-check-circle' style='color:#00aa00; font-size:24px;'></i><br>")
Response.Write("No supply issues found - All printers have adequate supplies")
Response.Write("</td></tr>")
End If
objConn.Close
%>
</tbody>
</table>
</div>
<div class="card-footer">
<small class="text-muted">
<i class="zmdi zmdi-info-outline"></i> This report shows printers with low supplies (&lt;20%) or waste cartridges near full (&gt;80%).
Data refreshed from Zabbix every 5 minutes.
</small>
</div>
</div>
</div>
</div>
</div><!--End Row-->
<!-- 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">
</div>
</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>
<!-- simplebar js -->
<script src="assets/plugins/simplebar/js/simplebar.js"></script>
<!-- sidebar-menu js -->
<script src="assets/js/sidebar-menu.js"></script>
<!-- Custom scripts -->
<script src="assets/js/app-script.js"></script>
<script>
$(document).ready(function() {
$('#refreshBtn').click(function() {
if (confirm('Clear all Zabbix cache and refresh? This will fetch fresh data from Zabbix for all printers.')) {
var btn = $(this);
var originalHtml = btn.html();
// Show loading state
btn.prop('disabled', true);
btn.html('<i class="zmdi zmdi-refresh zmdi-hc-spin"></i> Refreshing...');
// Call clear cache endpoint
$.ajax({
url: './admin_clear_cache.asp?confirm=yes&type=zabbix&ajax=1',
method: 'GET',
success: function() {
// Reload page after cache cleared
location.reload();
},
error: function() {
// Still reload on error
location.reload();
}
});
}
});
});
</script>
<!-- Location map popup modal -->
<style>
/* Theme-specific styling for location links */
body.bg-theme .location-link {
color: #fff !important;
}
.location-popup-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9998;
display: none;
}
.location-popup {
position: fixed;
background: #1f1f1f;
border: 2px solid #667eea;
border-radius: 8px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
max-width: 90vw;
max-height: 90vh;
}
.location-popup-header {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 15px;
border-radius: 6px 6px 0 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.location-popup-close {
background: none;
border: none;
color: white;
font-size: 24px;
cursor: pointer;
padding: 0;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
}
.location-popup-close:hover {
background: rgba(255, 255, 255, 0.2);
}
.location-popup-body {
padding: 0;
background: #2a2a2a;
}
.location-popup iframe {
display: block;
border: none;
border-radius: 0 0 6px 6px;
}
.location-link:hover {
text-decoration: underline;
}
</style>
<script>
$(document).ready(function() {
// Create popup elements
var $overlay = $('<div class="location-popup-overlay"></div>').appendTo('body');
var $popup = $('<div class="location-popup"></div>').appendTo('body');
$popup.html(
'<div class="location-popup-header">' +
'<h6 style="margin:0; font-size:16px;"><i class="zmdi zmdi-pin"></i> <span class="location-title">Loading...</span></h6>' +
'<button class="location-popup-close" title="Close (Esc)">&times;</button>' +
'</div>' +
'<div class="location-popup-body">' +
'<iframe src="" width="440" height="340"></iframe>' +
'</div>'
);
var $iframe = $popup.find('iframe');
var $title = $popup.find('.location-title');
var currentMachineId = null;
// Function to show popup with smart positioning
function showLocationPopup(machineId, locationName, mouseEvent) {
// Don't reload if same location
if (currentMachineId === machineId && $popup.is(':visible')) {
return;
}
currentMachineId = machineId;
$title.text(locationName);
// Load iframe
$iframe.attr('src', './displaylocation.asp?machineid=' + machineId);
// Position popup
var popupWidth = 440;
var popupHeight = 400;
var mouseX = mouseEvent.clientX;
var mouseY = mouseEvent.clientY;
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var left, top;
// Horizontal positioning
left = mouseX + 10;
if (left + popupWidth > windowWidth - 10) {
left = mouseX - popupWidth - 10;
}
if (left < 10) {
left = 10;
}
// Vertical positioning
var spaceBelow = windowHeight - mouseY;
var spaceAbove = mouseY;
if (spaceBelow >= popupHeight + 20) {
top = mouseY + 10;
} else if (spaceAbove >= popupHeight + 20) {
top = mouseY - popupHeight - 10;
} else {
top = Math.max(10, (windowHeight - popupHeight) / 2);
}
if (top < 10) {
top = 10;
}
if (top + popupHeight > windowHeight - 10) {
top = windowHeight - popupHeight - 10;
}
$popup.css({
left: left + 'px',
top: top + 'px',
display: 'block'
});
$overlay.fadeIn(200);
$popup.fadeIn(200);
}
// Function to hide popup
function hideLocationPopup() {
$overlay.fadeOut(200);
$popup.fadeOut(200);
setTimeout(function() {
$iframe.attr('src', '');
currentMachineId = null;
}, 200);
}
var hoverTimer = null;
// Hover handler for location links
$(document).on('mouseenter', '.location-link', function(e) {
var $link = $(this);
var machineId = $link.data('machineid');
var locationName = $link.text().trim();
var mouseEvent = e;
if (hoverTimer) {
clearTimeout(hoverTimer);
}
hoverTimer = setTimeout(function() {
showLocationPopup(machineId, locationName, mouseEvent);
}, 300);
});
// Cancel popup if mouse leaves before delay
$(document).on('mouseleave', '.location-link', function() {
if (hoverTimer) {
clearTimeout(hoverTimer);
hoverTimer = null;
}
});
// Keep popup open when hovering over it
$popup.on('mouseenter', function() {
// Keep open
});
// Close popup when mouse leaves popup
$popup.on('mouseleave', function() {
hideLocationPopup();
});
// Close on overlay click
$overlay.on('click', function() {
hideLocationPopup();
});
// Close on X button
$popup.find('.location-popup-close').on('click', function() {
hideLocationPopup();
});
// Close on Escape key
$(document).on('keydown', function(e) {
if (e.key === 'Escape' && $popup.is(':visible')) {
hideLocationPopup();
}
});
});
// Vendor filter functionality
$(document).ready(function() {
$('#vendorFilter').on('change', function() {
var selectedVendor = $(this).val();
if (selectedVendor === 'all') {
// Show all rows
$('tbody tr[data-vendor]').show();
} else {
// Hide all rows first
$('tbody tr[data-vendor]').hide();
// Show only matching vendor rows
$('tbody tr[data-vendor="' + selectedVendor + '"]').show();
}
});
});
</script>
</body>
</html>

View File

@@ -1,223 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form data
Dim pcid, pcstatusid, pctypeid, hostname, modelnumberid, machinenumber, isactive
pcid = Trim(Request.Form("pcid"))
pcstatusid = Trim(Request.Form("pcstatusid"))
pctypeid = Trim(Request.Form("pctypeid"))
hostname = Trim(Request.Form("hostname"))
modelnumberid = Trim(Request.Form("modelnumberid"))
machinenumber = Trim(Request.Form("machinenumber"))
isactive = Trim(Request.Form("isactive"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required ID fields
If Not IsNumeric(pcid) Or CLng(pcid) < 1 Then
Response.Write("Invalid PC ID")
objConn.Close
Response.End
End If
If Not IsNumeric(pcstatusid) Or CLng(pcstatusid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
' Verify the PC exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM pc WHERE pcid = " & CLng(pcid)
Set rsCheck = objConn.Execute(checkSQL)
If Not rsCheck.EOF Then
If CLng(rsCheck("cnt")) = 0 Then
rsCheck.Close
objConn.Close
Response.Redirect("default.asp")
Response.End
End If
End If
rsCheck.Close
' Set isactive: if checkbox not checked, it won't be in form data
If isactive = "1" Then
isactive = 1
Else
isactive = 0
End If
' Validate optional ID fields - allow "new" as a valid value for model
If pctypeid <> "" Then
If Not IsNumeric(pctypeid) Or CLng(pctypeid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
If modelnumberid <> "" And modelnumberid <> "new" Then
If Not IsNumeric(modelnumberid) Or CLng(modelnumberid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
' Handle new model creation
If modelnumberid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with ispc=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES ('" & escapedVendorName & "', 1, 0, 1, 0)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Err.Description))
objConn.Close
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
On Error Goto 0
End If
' Escape single quotes for model
Dim escapedModelNumber
escapedModelNumber = Replace(newmodelnumber, "'", "''")
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, isactive) VALUES ('" & escapedModelNumber & "', " & newvendorid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Err.Description))
objConn.Close
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelnumberid = CLng(rsNewModel("newid"))
rsNewModel.Close
Set rsNewModel = Nothing
On Error Goto 0
End If
' Validate field lengths
If hostname <> "" And Len(hostname) > 255 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
If machinenumber <> "" And Len(machinenumber) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Escape quotes
hostname = Replace(hostname, "'", "''")
machinenumber = Replace(machinenumber, "'", "''")
' Build UPDATE query dynamically
Dim updateSQL
updateSQL = "UPDATE pc SET pcstatusid = " & pcstatusid & ", isactive = " & isactive & ", "
' Add optional fields
If pctypeid <> "" Then
updateSQL = updateSQL & "pctypeid = " & pctypeid & ", "
Else
updateSQL = updateSQL & "pctypeid = NULL, "
End If
If hostname <> "" Then
updateSQL = updateSQL & "hostname = '" & hostname & "', "
Else
updateSQL = updateSQL & "hostname = NULL, "
End If
If modelnumberid <> "" Then
updateSQL = updateSQL & "modelnumberid = " & modelnumberid & ", "
Else
updateSQL = updateSQL & "modelnumberid = NULL, "
End If
If machinenumber <> "" Then
updateSQL = updateSQL & "machinenumber = '" & machinenumber & "', "
Else
updateSQL = updateSQL & "machinenumber = NULL, "
End If
' Add lastupdated timestamp and WHERE clause
updateSQL = updateSQL & "lastupdated = NOW() WHERE pcid = " & pcid
' Execute update
On Error Resume Next
objConn.Execute updateSQL
If Err.Number = 0 Then
objConn.Close
' Success - redirect back to scan page ready for next scan
Response.Redirect("./adddevice.asp")
Else
Dim errMsg
errMsg = Err.Description
objConn.Close
Response.Redirect("./editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(errMsg))
End If
%>

View File

@@ -1,230 +0,0 @@
<%
'=============================================================================
' FILE: updatedevice_direct.asp
' PURPOSE: Update PC/device with optional vendor and model creation
' SECURITY: Parameterized queries, HTML encoding, input validation
' UPDATED: 2025-10-27 - Migrated to secure patterns
'=============================================================================
%>
<!--#include file="./includes/sql.asp"-->
<%
' Get form data
Dim pcid, machinestatusid, pctypeid, hostname, modelnumberid, machinenumber, isactive
pcid = Trim(Request.Form("pcid"))
machinestatusid = Trim(Request.Form("machinestatusid"))
pctypeid = Trim(Request.Form("pctypeid"))
hostname = Trim(Request.Form("hostname"))
modelnumberid = Trim(Request.Form("modelnumberid"))
machinenumber = Trim(Request.Form("machinenumber"))
isactive = Trim(Request.Form("isactive"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid
newmodelnumber = Trim(Request.Form("newmodelnumber"))
newvendorid = Trim(Request.Form("newvendorid"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newvendorname"))
' Validate required ID fields
If Not IsNumeric(pcid) Or CLng(pcid) < 1 Then
Response.Write("Invalid PC ID")
objConn.Close
Response.End
End If
If Not IsNumeric(machinestatusid) Or CLng(machinestatusid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
' Set isactive: if checkbox not checked, it won't be in form data
If isactive = "1" Then
isactive = 1
Else
isactive = 0
End If
' Validate optional ID fields - allow "new" as a valid value for model
If pctypeid <> "" Then
If Not IsNumeric(pctypeid) Or CLng(pctypeid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
If modelnumberid <> "" And modelnumberid <> "new" Then
If Not IsNumeric(modelnumberid) Or CLng(modelnumberid) < 1 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
' Handle new model creation
If modelnumberid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Handle new vendor creation (nested)
If newvendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Insert new vendor using parameterized query (with ispc=1)
Dim sqlNewVendor, cmdNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES (?, 1, 0, 1, 0)"
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
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Server.HTMLEncode(Err.Description)))
Set cmdNewVendor = Nothing
objConn.Close
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
' Insert new model using parameterized query
Dim sqlNewModel, cmdNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, 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))
On Error Resume Next
cmdNewModel.Execute
If Err.Number <> 0 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Server.HTMLEncode(Err.Description)))
Set cmdNewModel = Nothing
objConn.Close
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelnumberid = CLng(rsNewModel("newid"))
rsNewModel.Close
Set rsNewModel = Nothing
Set cmdNewModel = Nothing
On Error Goto 0
End If
' Validate field lengths
If hostname <> "" And Len(hostname) > 255 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
If machinenumber <> "" And Len(machinenumber) > 50 Then
Response.Redirect("editdevice.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Build UPDATE query using parameterized query
Dim updateSQL, cmdUpdate
updateSQL = "UPDATE machines SET machinestatusid = ?, isactive = ?, pctypeid = ?, hostname = ?, modelnumberid = ?, machinenumber = ?, lastupdated = NOW() WHERE machineid = ? AND pctypeid IS NOT NULL"
Set cmdUpdate = Server.CreateObject("ADODB.Command")
cmdUpdate.ActiveConnection = objConn
cmdUpdate.CommandText = updateSQL
cmdUpdate.CommandType = 1
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machinestatusid", 3, 1, , CLng(machinestatusid))
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@isactive", 3, 1, , isactive)
' Handle optional pctypeid
If pctypeid <> "" Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@pctypeid", 3, 1, , CLng(pctypeid))
Else
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@pctypeid", 3, 1, , Null)
End If
' Handle optional hostname
If hostname <> "" Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@hostname", 200, 1, 255, hostname)
Else
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@hostname", 200, 1, 255, Null)
End If
' Handle optional modelnumberid
If modelnumberid <> "" Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@modelnumberid", 3, 1, , CLng(modelnumberid))
Else
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@modelnumberid", 3, 1, , Null)
End If
' Handle optional machinenumber
If machinenumber <> "" Then
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machinenumber", 200, 1, 50, machinenumber)
Else
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machinenumber", 200, 1, 50, Null)
End If
cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@machineid", 3, 1, , CLng(pcid))
' Execute update
On Error Resume Next
cmdUpdate.Execute
If Err.Number = 0 Then
Set cmdUpdate = Nothing
objConn.Close
' Success - redirect back to scan page ready for next scan
Response.Redirect("./adddevice.asp")
Else
Dim errMsg
errMsg = Server.HTMLEncode(Err.Description)
Set cmdUpdate = Nothing
objConn.Close
Response.Redirect("./editdevice.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(errMsg))
End If
%>

View File

@@ -1,227 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form inputs for KB article
Dim linkid, linkurl, shortdescription, keywords, appid
linkid = Trim(Request.Form("linkid"))
linkurl = Trim(Request.Form("linkurl"))
shortdescription = Trim(Request.Form("shortdescription"))
keywords = Trim(Request.Form("keywords"))
appid = Trim(Request.Form("appid"))
' Get form inputs for new topic
Dim newappname, newappdescription, newsupportteamid
Dim newapplicationnotes, newinstallpath, newdocumentationpath, newisactive
newappname = Trim(Request.Form("newappname"))
newappdescription = Trim(Request.Form("newappdescription"))
newsupportteamid = Trim(Request.Form("newsupportteamid"))
newapplicationnotes = Trim(Request.Form("newapplicationnotes"))
newinstallpath = Trim(Request.Form("newinstallpath"))
newdocumentationpath = Trim(Request.Form("newdocumentationpath"))
newisactive = Request.Form("newisactive")
' Get form inputs for new support team
Dim newsupportteamname, newsupportteamurl, newappownerid
newsupportteamname = Trim(Request.Form("newsupportteamname"))
newsupportteamurl = Trim(Request.Form("newsupportteamurl"))
newappownerid = Trim(Request.Form("newappownerid"))
' Get form inputs for new app owner
Dim newappownername, newappownersso
newappownername = Trim(Request.Form("newappownername"))
newappownersso = Trim(Request.Form("newappownersso"))
' Basic validation
If Not IsNumeric(linkid) Or CLng(linkid) < 1 Then
Response.Write("Invalid link ID")
objConn.Close
Response.End
End If
If Len(linkurl) = 0 Or Len(shortdescription) = 0 Or Len(appid) = 0 Then
Response.Write("Required fields missing")
objConn.Close
Response.End
End If
If Len(linkurl) > 2000 Or Len(shortdescription) > 500 Or Len(keywords) > 500 Then
Response.Write("Field length exceeded")
objConn.Close
Response.End
End If
' Handle new topic creation
If appid = "new" Then
If Len(newappname) = 0 Then
Response.Write("New topic name is required")
objConn.Close
Response.End
End If
If Len(newsupportteamid) = 0 Then
Response.Write("Support team is required for new topic")
objConn.Close
Response.End
End If
' Validate field lengths for new topic
If Len(newappname) > 50 Or Len(newappdescription) > 255 Or Len(newapplicationnotes) > 512 Or Len(newinstallpath) > 255 Or Len(newdocumentationpath) > 512 Then
Response.Write("New topic field length exceeded")
objConn.Close
Response.End
End If
' Handle new support team creation (nested)
If newsupportteamid = "new" Then
If Len(newsupportteamname) = 0 Then
Response.Write("New support team name is required")
objConn.Close
Response.End
End If
If Len(newappownerid) = 0 Then
Response.Write("App owner is required for new support team")
objConn.Close
Response.End
End If
If Len(newsupportteamname) > 50 Or Len(newsupportteamurl) > 512 Then
Response.Write("New support team field length exceeded")
objConn.Close
Response.End
End If
' Handle new app owner creation (doubly nested)
If newappownerid = "new" Then
If Len(newappownername) = 0 Or Len(newappownersso) = 0 Then
Response.Write("App owner name and SSO are required")
objConn.Close
Response.End
End If
If Len(newappownername) > 50 Or Len(newappownersso) > 255 Then
Response.Write("App owner field length exceeded")
objConn.Close
Response.End
End If
' Escape single quotes for new app owner
Dim escapedOwnerName, escapedOwnerSSO
escapedOwnerName = Replace(newappownername, "'", "''")
escapedOwnerSSO = Replace(newappownersso, "'", "''")
' Insert new app owner
Dim sqlNewOwner
sqlNewOwner = "INSERT INTO appowners (appowner, sso, isactive) " & _
"VALUES ('" & escapedOwnerName & "', '" & escapedOwnerSSO & "', 1)"
On Error Resume Next
objConn.Execute sqlNewOwner
If Err.Number <> 0 Then
Response.Write("Error creating new app owner: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created app owner ID
Dim rsNewOwner
Set rsNewOwner = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newappownerid = rsNewOwner("newid")
rsNewOwner.Close
Set rsNewOwner = Nothing
On Error Goto 0
End If
' Escape single quotes for new support team
Dim escapedTeamName, escapedTeamURL
escapedTeamName = Replace(newsupportteamname, "'", "''")
escapedTeamURL = Replace(newsupportteamurl, "'", "''")
' Insert new support team with selected or newly created app owner
Dim sqlNewTeam
sqlNewTeam = "INSERT INTO supportteams (teamname, teamurl, appownerid, isactive) " & _
"VALUES ('" & escapedTeamName & "', '" & escapedTeamURL & "', " & newappownerid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewTeam
If Err.Number <> 0 Then
Response.Write("Error creating new support team: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created support team ID
Dim rsNewTeam
Set rsNewTeam = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
newsupportteamid = rsNewTeam("newid")
rsNewTeam.Close
Set rsNewTeam = Nothing
On Error Goto 0
End If
' Escape single quotes for new topic
Dim escapedAppName, escapedAppDesc, escapedAppNotes, escapedInstallPath, escapedDocPath
escapedAppName = Replace(newappname, "'", "''")
escapedAppDesc = Replace(newappdescription, "'", "''")
escapedAppNotes = Replace(newapplicationnotes, "'", "''")
escapedInstallPath = Replace(newinstallpath, "'", "''")
escapedDocPath = Replace(newdocumentationpath, "'", "''")
' Convert isactive checkbox
Dim isActiveValue
If newisactive = "1" Then
isActiveValue = 1
Else
isActiveValue = 0
End If
' Insert new application/topic
Dim sqlNewApp
sqlNewApp = "INSERT INTO applications (appname, appdescription, supportteamid, applicationnotes, installpath, documentationpath, isactive, isinstallable, ishidden, isprinter, islicenced) " & _
"VALUES ('" & escapedAppName & "', '" & escapedAppDesc & "', " & newsupportteamid & ", '" & escapedAppNotes & "', '" & escapedInstallPath & "', '" & escapedDocPath & "', " & isActiveValue & ", 0, 0, 0, 0)"
On Error Resume Next
objConn.Execute sqlNewApp
If Err.Number <> 0 Then
Response.Write("Error creating new topic: " & Err.Description)
objConn.Close
Response.End
End If
' Get the newly created topic ID
Dim rsNewApp
Set rsNewApp = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
appid = rsNewApp("newid")
rsNewApp.Close
Set rsNewApp = Nothing
On Error Goto 0
End If
' Escape single quotes for KB article
linkurl = Replace(linkurl, "'", "''")
shortdescription = Replace(shortdescription, "'", "''")
keywords = Replace(keywords, "'", "''")
' Build UPDATE statement
Dim strSQL
strSQL = "UPDATE knowledgebase SET " & _
"linkurl = '" & linkurl & "', " & _
"shortdescription = '" & shortdescription & "', " & _
"keywords = '" & keywords & "', " & _
"appid = " & appid & ", " & _
"lastupdated = NOW() " & _
"WHERE linkid = " & linkid
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("displayknowledgearticle.asp?linkid=" & linkid & "&status=updated")
Else
objConn.Close
Response.Redirect("displayknowledgearticle.asp?linkid=" & linkid & "&status=error&msg=" & Server.URLEncode("Error: " & Err.Description))
End If
%>

View File

@@ -1,117 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form inputs
Dim notificationid, notification, ticketnumber, starttime, endtime, isactive, isshopfloor, notificationtypeid, businessunitid
notificationid = Trim(Request.Form("notificationid"))
notification = Trim(Request.Form("notification"))
ticketnumber = Trim(Request.Form("ticketnumber"))
starttime = Trim(Request.Form("starttime"))
endtime = Trim(Request.Form("endtime"))
notificationtypeid = Trim(Request.Form("notificationtypeid"))
businessunitid = Trim(Request.Form("businessunitid"))
' Handle checkbox - if the hidden field is submitted but checkbox isn't, it means unchecked
If Request.Form("isactive_submitted") = "1" Then
If Request.Form("isactive") = "1" Then
isactive = 1
Else
isactive = 0
End If
Else
' Fallback for backward compatibility
If Request.Form("isactive") = "" Then
isactive = 0
Else
isactive = 1
End If
End If
' Handle isshopfloor checkbox - same pattern as isactive
If Request.Form("isshopfloor_submitted") = "1" Then
If Request.Form("isshopfloor") = "1" Then
isshopfloor = 1
Else
isshopfloor = 0
End If
Else
' Fallback for backward compatibility
If Request.Form("isshopfloor") = "" Then
isshopfloor = 0
Else
isshopfloor = 1
End If
End If
' Validate
If Not IsNumeric(notificationid) Or CLng(notificationid) < 1 Then
Response.Write("Invalid notification ID")
objConn.Close
Response.End
End If
' Default to TBD if no type selected
If notificationtypeid = "" Or Not IsNumeric(notificationtypeid) Then
notificationtypeid = "1"
End If
' Validate required fields (endtime is now optional)
If Len(notification) = 0 Or Len(starttime) = 0 Then
Response.Write("Required fields missing")
objConn.Close
Response.End
End If
If Len(notification) > 500 Or Len(ticketnumber) > 50 Then
Response.Write("Field length exceeded")
objConn.Close
Response.End
End If
' Escape quotes
notification = Replace(notification, "'", "''")
ticketnumber = Replace(ticketnumber, "'", "''")
' Convert datetime format for starttime
starttime = Replace(starttime, "T", " ") & ":00"
' Handle optional endtime - leave as NULL if blank (indefinite)
Dim strSQL, endtimeSQL, businessunitSQL
If Len(endtime) = 0 Then
' No end date - store as NULL for indefinite notifications
endtimeSQL = "NULL"
Else
' End date specified - convert format and wrap in quotes
endtime = Replace(endtime, "T", " ") & ":00"
endtimeSQL = "'" & endtime & "'"
End If
' Handle optional businessunitid - NULL means applies to all business units
If businessunitid = "" Or Not IsNumeric(businessunitid) Then
businessunitSQL = "NULL"
Else
businessunitSQL = businessunitid
End If
' UPDATE
strSQL = "UPDATE notifications SET " & _
"notificationtypeid = " & notificationtypeid & ", " & _
"businessunitid = " & businessunitSQL & ", " & _
"notification = '" & notification & "', " & _
"ticketnumber = '" & ticketnumber & "', " & _
"starttime = '" & starttime & "', " & _
"endtime = " & endtimeSQL & ", " & _
"isactive = " & isactive & ", " & _
"isshopfloor = " & isshopfloor & " " & _
"WHERE notificationid = " & notificationid
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("displaynotifications.asp")
Else
Response.Write("Error: " & Err.Description)
objConn.Close
End If
%>

View File

@@ -1,193 +0,0 @@
<!--#include file="./includes/sql.asp"-->
<%
' Get form data
Dim pcid, vendorid, modelnumberid, machinenumber
pcid = Trim(Request.Form("pcid"))
vendorid = Trim(Request.Form("vendorid"))
modelnumberid = Trim(Request.Form("modelid"))
machinenumber = Trim(Request.Form("machinenumber"))
' Get form inputs for new model
Dim newmodelnumber, newvendorid
newmodelnumber = Trim(Request.Form("newpcmodelnumber"))
newvendorid = Trim(Request.Form("newpcmodelvendorid"))
' Get form inputs for new vendor
Dim newvendorname
newvendorname = Trim(Request.Form("newpcvendorname"))
' Validate required ID fields
If Not IsNumeric(pcid) Or CLng(pcid) < 1 Then
Response.Write("Invalid PC ID")
objConn.Close
Response.End
End If
' Verify the PC exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM pc WHERE pcid = " & CLng(pcid)
Set rsCheck = objConn.Execute(checkSQL)
If Not rsCheck.EOF Then
If CLng(rsCheck("cnt")) = 0 Then
rsCheck.Close
objConn.Close
Response.Redirect("displaypcs.asp")
Response.End
End If
End If
rsCheck.Close
' Validate optional ID fields - allow "new" as a valid value for model and vendor
If vendorid <> "" And vendorid <> "new" Then
If Not IsNumeric(vendorid) Or CLng(vendorid) < 1 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
If modelnumberid <> "" And modelnumberid <> "new" Then
If Not IsNumeric(modelnumberid) Or CLng(modelnumberid) < 1 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
End If
' Handle new vendor creation
If vendorid = "new" Then
If Len(newvendorname) = 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorname) > 50 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Escape single quotes
Dim escapedVendorName
escapedVendorName = Replace(newvendorname, "'", "''")
' Insert new vendor (with ispc=1)
Dim sqlNewVendor
sqlNewVendor = "INSERT INTO vendors (vendor, isactive, isprinter, ispc, ismachine) VALUES ('" & escapedVendorName & "', 1, 0, 1, 0)"
On Error Resume Next
objConn.Execute sqlNewVendor
If Err.Number <> 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Err.Description))
objConn.Close
Response.End
End If
' Get the newly created vendor ID
Dim rsNewVendor
Set rsNewVendor = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
vendorid = CLng(rsNewVendor("newid"))
rsNewVendor.Close
Set rsNewVendor = Nothing
On Error Goto 0
End If
' Handle new model creation
If modelnumberid = "new" Then
If Len(newmodelnumber) = 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newvendorid) = 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
If Len(newmodelnumber) > 50 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' If vendor was also created new, use that vendor ID
If vendorid <> "" And IsNumeric(vendorid) Then
newvendorid = vendorid
End If
' Escape single quotes for model
Dim escapedModelNumber
escapedModelNumber = Replace(newmodelnumber, "'", "''")
' Insert new model
Dim sqlNewModel
sqlNewModel = "INSERT INTO models (modelnumber, vendorid, isactive) VALUES ('" & escapedModelNumber & "', " & newvendorid & ", 1)"
On Error Resume Next
objConn.Execute sqlNewModel
If Err.Number <> 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=db&msg=" & Server.URLEncode(Err.Description))
objConn.Close
Response.End
End If
' Get the newly created model ID
Dim rsNewModel
Set rsNewModel = objConn.Execute("SELECT LAST_INSERT_ID() AS newid")
modelnumberid = CLng(rsNewModel("newid"))
rsNewModel.Close
Set rsNewModel = Nothing
On Error Goto 0
End If
' Validate machine number length
If machinenumber <> "" And Len(machinenumber) > 50 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Escape single quotes for machine number
If machinenumber <> "" Then
machinenumber = Replace(machinenumber, "'", "''")
End If
' Build UPDATE statement for PC
Dim strSQL
strSQL = "UPDATE pc SET "
' Update model if provided
If modelnumberid <> "" And IsNumeric(modelnumberid) Then
strSQL = strSQL & "modelnumberid = " & modelnumberid & ", "
End If
' Update machine number
If machinenumber <> "" Then
strSQL = strSQL & "machinenumber = '" & machinenumber & "', "
Else
strSQL = strSQL & "machinenumber = NULL, "
End If
' Add lastupdated timestamp
strSQL = strSQL & "lastupdated = NOW() WHERE pcid = " & pcid
On Error Resume Next
objConn.Execute strSQL
If Err.Number <> 0 Then
Response.Redirect("displaypc.asp?pcid=" & pcid & "&error=db")
objConn.Close
Response.End
End If
objConn.Close
' Success - redirect back to displaypc
Response.Redirect("./displaypc.asp?pcid=" & pcid)
%>

View File

@@ -1,167 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="./style.css" type="text/css">
<!--#include file="./includes/sql.asp"-->
</head>
<body>
<div class="page">
<%
' Get form inputs
Dim subnetid, vlan, ipstart, cidr, description, subnettypeid, cidrarray, ipend
subnetid = Trim(Request.Querystring("subnetid"))
vlan = Trim(Request.Form("vlan"))
ipstart = Trim(Request.Form("ipstart"))
cidr = Trim(Request.Form("cidr"))
description = Trim(Request.Form("description"))
subnettypeid = Trim(Request.Form("subnettypeid"))
' Validate required ID fields
If Not IsNumeric(subnetid) Or CLng(subnetid) < 1 Then
Response.Write("Invalid subnet ID")
objConn.Close
Response.End
End If
' Verify the subnet exists
Dim checkSQL, rsCheck
checkSQL = "SELECT COUNT(*) as cnt FROM subnets WHERE subnetid = " & subnetid
Set rsCheck = objConn.Execute(checkSQL)
Dim subnetExists
subnetExists = False
If Not rsCheck.EOF Then
If Not IsNull(rsCheck("cnt")) Then
If CLng(rsCheck("cnt")) > 0 Then
subnetExists = True
End If
End If
End If
rsCheck.Close
Set rsCheck = Nothing
If Not subnetExists Then
Response.Redirect("displaysubnets.asp")
objConn.Close
Response.End
End If
' Validate required fields
If vlan = "" Or ipstart = "" Or cidr = "" Or subnettypeid = "" Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=REQUIRED_FIELD")
objConn.Close
Response.End
End If
' Validate VLAN is numeric
If Not IsNumeric(vlan) Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Basic IP address validation
If Len(ipstart) < 7 Or Len(ipstart) > 15 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_IP")
objConn.Close
Response.End
End If
' Validate subnet type ID
If Not IsNumeric(subnettypeid) Or CLng(subnettypeid) < 1 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_ID")
objConn.Close
Response.End
End If
' Parse CIDR value (expected format: "cidr,ipend")
If InStr(cidr, ",") = 0 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
cidrarray = Split(cidr, ",")
If UBound(cidrarray) < 1 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
ipend = Trim(cidrarray(1))
cidr = Trim(cidrarray(0))
' Remove leading slash if present (CIDR comes as "/24" format)
If Left(cidr, 1) = "/" Then
cidr = Mid(cidr, 2)
End If
' Validate CIDR is numeric (0-32)
If Not IsNumeric(cidr) Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
If CInt(cidr) < 0 Or CInt(cidr) > 32 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Validate ipend is numeric
If Not IsNumeric(ipend) Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Validate description length
If Len(description) > 500 Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=INVALID_INPUT")
objConn.Close
Response.End
End If
' Escape quotes
description = Replace(description, "'", "''")
ipstart = Replace(ipstart, "'", "''")
' Verify subnet type exists
checkSQL = "SELECT COUNT(*) as cnt FROM subnettypes WHERE subnettypeid = " & subnettypeid
Set rsCheck = objConn.Execute(checkSQL)
Dim typeExists
typeExists = False
If Not rsCheck.EOF Then
If Not IsNull(rsCheck("cnt")) Then
If CLng(rsCheck("cnt")) > 0 Then
typeExists = True
End If
End If
End If
rsCheck.Close
Set rsCheck = Nothing
If Not typeExists Then
Response.Redirect("displaysubnet.asp?subnetid=" & subnetid & "&error=NOT_FOUND")
objConn.Close
Response.End
End If
' Update
Dim strSQL
strSQL = "UPDATE subnets SET vlan = " & vlan & ", ipstart = INET_ATON('" & ipstart & "'), ipend = (INET_ATON('" & ipstart & "') + " & ipend & "), cidr = '" & cidr & "', subnettypeid = " & subnettypeid & ", description = '" & description & "' WHERE subnetid = " & subnetid
On Error Resume Next
objConn.Execute strSQL
If Err.Number = 0 Then
objConn.Close
Response.Redirect("./displaysubnet.asp?subnetid=" & subnetid)
Else
Response.Write("Error: " & Err.Description)
objConn.Close
End If
%>