Files
shopdb/pcmachinerelationships.asp
cproudlock 8945fe2a0a Add PC-machine relationships API and report, fix shopfloor dashboard
- Add getPCMachineRelationships API endpoint for PC-to-machine mappings
- Add pcmachinerelationships.asp report page with copy table/CSV/JSON export
- Fix shopfloor dashboard to immediately hide deactivated notifications
- Add Firewall (machinetypeid 46) support to network device pages
- Add model migration warning banner to networkdevices.asp
- Create SQL script for hybrid model/machine type view

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 16:06:33 -05:00

159 lines
5.5 KiB
Plaintext

<%@ Language=VBScript %>
<!--#include file="includes/sql.asp"-->
<!DOCTYPE html>
<html>
<head>
<title>PC-Machine Relationships</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.6.0/css/bootstrap.min.css">
<style>
body { padding: 20px; }
table { font-size: 14px; }
.copy-btn { margin-bottom: 15px; }
pre { background: #f8f9fa; padding: 15px; border-radius: 4px; max-height: 400px; overflow: auto; }
</style>
</head>
<body>
<div class="container-fluid">
<h2>PC-Machine Relationships</h2>
<p class="text-muted">PCs with relationships to shop floor machines</p>
<button class="btn btn-primary copy-btn" onclick="copyTable()">Copy Table to Clipboard</button>
<button class="btn btn-secondary copy-btn" onclick="copyCSV()">Copy as CSV</button>
<button class="btn btn-info copy-btn" onclick="copyJSON()">Copy as JSON</button>
<table class="table table-striped table-bordered table-sm" id="dataTable">
<thead class="thead-dark">
<tr>
<th>Machine #</th>
<th>Vendor</th>
<th>Model</th>
<th>PC Hostname</th>
<th>PC IP</th>
</tr>
</thead>
<tbody>
<%
Dim strSQL, rs
strSQL = "SELECT " & _
"pc.machineid AS pc_id, " & _
"pc.machinenumber AS hostname, " & _
"c.address AS ip, " & _
"eq.machineid AS machine_id, " & _
"eq.machinenumber AS machine_number, " & _
"v.vendor AS vendor, " & _
"m.modelnumber AS model " & _
"FROM machinerelationships mr " & _
"JOIN machines eq ON mr.machineid = eq.machineid " & _
"JOIN machines pc ON mr.related_machineid = pc.machineid " & _
"LEFT JOIN communications c ON pc.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
"LEFT JOIN models m ON eq.modelnumberid = m.modelnumberid " & _
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
"WHERE mr.isactive = 1 " & _
"AND pc.pctypeid IS NOT NULL " & _
"AND eq.machinenumber IS NOT NULL AND eq.machinenumber != '' " & _
"AND eq.machinenumber REGEXP '^[0-9]{4}$' " & _
"AND eq.machinenumber NOT IN ('0612', '0613', '0614', '0615') " & _
"AND (v.vendor IS NULL OR v.vendor != 'WJDT') " & _
"AND (m.modelnumber IS NULL OR m.modelnumber != 'TBD') " & _
"ORDER BY eq.machinenumber"
Set rs = objConn.Execute(strSQL)
Dim rowCount
rowCount = 0
Do While Not rs.EOF
rowCount = rowCount + 1
%>
<tr>
<td><%= Server.HTMLEncode(rs("machine_number") & "") %></td>
<td><%= Server.HTMLEncode(rs("vendor") & "") %></td>
<td><%= Server.HTMLEncode(rs("model") & "") %></td>
<td><%= Server.HTMLEncode(rs("hostname") & "") %></td>
<td><%= Server.HTMLEncode(rs("ip") & "") %></td>
</tr>
<%
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
%>
</tbody>
</table>
<p class="text-muted"><%= rowCount %> records found</p>
</div>
<script>
function copyTable() {
var table = document.getElementById('dataTable');
var text = '';
// Get headers
var headers = table.querySelectorAll('thead th');
headers.forEach(function(th, i) {
text += th.innerText + (i < headers.length - 1 ? '\t' : '\n');
});
// Get rows
var rows = table.querySelectorAll('tbody tr');
rows.forEach(function(row) {
var cells = row.querySelectorAll('td');
cells.forEach(function(td, i) {
text += td.innerText + (i < cells.length - 1 ? '\t' : '\n');
});
});
navigator.clipboard.writeText(text).then(function() {
alert('Table copied to clipboard!');
});
}
function copyCSV() {
var table = document.getElementById('dataTable');
var csv = '';
// Get headers
var headers = table.querySelectorAll('thead th');
headers.forEach(function(th, i) {
csv += '"' + th.innerText + '"' + (i < headers.length - 1 ? ',' : '\n');
});
// Get rows
var rows = table.querySelectorAll('tbody tr');
rows.forEach(function(row) {
var cells = row.querySelectorAll('td');
cells.forEach(function(td, i) {
csv += '"' + td.innerText + '"' + (i < cells.length - 1 ? ',' : '\n');
});
});
navigator.clipboard.writeText(csv).then(function() {
alert('CSV copied to clipboard!');
});
}
function copyJSON() {
var table = document.getElementById('dataTable');
var data = [];
var rows = table.querySelectorAll('tbody tr');
rows.forEach(function(row) {
var cells = row.querySelectorAll('td');
data.push({
"Name": cells[0].innerText,
"IpAddress": cells[4].innerText,
"Group": null
});
});
var json = JSON.stringify(data, null, 2);
navigator.clipboard.writeText(json).then(function() {
alert('JSON copied to clipboard!');
});
}
</script>
</body>
</html>