";
} else {
$row = mysqli_fetch_assoc($sql);
$asset_row = $row; // raw, for the quick pickers - $row gets reused below
$client_id = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']);
$asset_id = intval($row['asset_id']);
$asset_type = escapeHtml($row['asset_type']);
$asset_name = escapeHtml($row['asset_name']);
$asset_description = escapeHtml($row['asset_description']);
$asset_make_model = escapeHtml(trim($row['asset_make'] . ' ' . $row['asset_model']));
$asset_serial = escapeHtml($row['asset_serial']);
$asset_os = escapeHtml($row['asset_os']);
$asset_os_icon = assetOsIcon($row['asset_os']);
$asset_links = assetLinks($row['asset_uri'], $row['asset_uri_2'], $row['asset_uri_client']);
$asset_status_pill = assetStatusPill($row['asset_status']);
$asset_purchase_reference = escapeHtml($row['asset_purchase_reference']);
$asset_purchase_date = escapeHtml($row['asset_purchase_date']);
$asset_purchase_age = assetAge($row['asset_purchase_date']);
$asset_install_date = escapeHtml($row['asset_install_date']);
$asset_install_age = assetAge($row['asset_install_date']);
$asset_warranty = assetWarranty($row['asset_warranty_expire']);
$asset_photo = escapeHtml($row['asset_photo']);
$asset_physical_location = escapeHtml($row['asset_physical_location']);
$asset_notes = escapeHtml($row['asset_notes']);
$asset_favorite = intval($row['asset_favorite']);
$asset_created_at = escapeHtml($row['asset_created_at']);
$asset_archived_at = escapeHtml($row['asset_archived_at']);
$asset_vendor_id = intval($row['asset_vendor_id']);
$asset_contact_id = intval($row['asset_contact_id']);
$asset_tone = assetTypeTone($row['asset_type']);
// Its type's details, what its OS field is called on it, and the fields it has (functions/asset_type.php)
$asset_spec_rows = assetSpecRows($row['asset_type'], assetSpecs($asset_id), intval($row['asset_client_id']));
$asset_os_label = assetTypeOsLabel($row['asset_type']) === 'Firmware' ? 'Firmware' : 'OS';
$asset_has_contact = assetTypeHasField($row['asset_type'], 'contact');
$asset_has_warranty = assetTypeHasField($row['asset_type'], 'warranty');
// The virtual machines that run on it
$asset_guests = assetGuests($asset_id, intval($row['asset_client_id']));
// Sold to the client on one of our invoices, from a catalog product
$can_sales = lookupUserPermission('module_sales') >= 1;
$asset_invoice_id = intval($row['asset_invoice_id']);
$asset_sold_number = $row['invoice_number'] !== null ? escapeHtml($row['invoice_prefix'] . $row['invoice_number']) : '';
$asset_sold_date = escapeHtml((string) $row['invoice_date']);
$asset_product_id = intval($row['asset_product_id']);
$asset_product_name = escapeHtml((string) $row['product_name']);
$device_icon = getAssetIcon($row['asset_type']);
$asset_ip = escapeHtml($row['interface_ip']);
$asset_ipv6 = escapeHtml($row['interface_ipv6']);
$asset_nat_ip = escapeHtml($row['interface_nat_ip']);
$asset_mac = escapeHtml($row['interface_mac']);
$asset_network_id = intval($row['interface_network_id']);
$asset_network_type = networkType($row);
$network_name = escapeHtml($row['network_name']);
$vendor_name = escapeHtml($row['vendor_name']);
$contact_name = escapeHtml($row['contact_name']);
$contact_archived = !empty($row['contact_archived_at']);
$location_name = escapeHtml($row['location_name']);
$location_archived = !empty($row['location_archived_at']);
$can_edit = lookupUserPermission('module_support') >= 2;
$can_delete = lookupUserPermission('module_support') >= 3;
// The assets it's linked to - a part on it, or what it sits on (functions/asset_link.php)
$asset_linked = assetLinked($asset_id);
$can_credentials = lookupUserPermission('module_credential') >= 1;
$can_credentials_edit = lookupUserPermission('module_credential') >= 2;
// Its devices in an RMM, if it came from one (functions/rmm.php) - the one that matters most first; its links go up top
$rmm_devices = rmmDevicesForAsset($asset_id);
$rmm_device = $rmm_devices[0] ?? null;
$rmm_urls = $rmm_device && $rmm_device['rmm_device_removed_at'] === null ? rmmDeviceUrls($rmm_device) : [];
$rmm_links = $rmm_device ? (rmmKind($rmm_device)['links'] ?? []) : [];
$rmm_first = $rmm_urls ? (isset($rmm_urls['control']) ? 'control' : (string) array_key_first($rmm_urls)) : '';
$rmm_icons = ['open' => 'fa-external-link-alt', 'control' => 'fa-desktop', 'background' => 'fa-terminal'];
// Its alerts that are open, with their tickets
$rmm_open_alerts = rmmOpenAlertsForDevices(array_column($rmm_devices, 'rmm_device_id'));
// The rack it sits in, if any - in a holder, its slot there and the holder; a holder (a chassis), what is in it
$asset_rack = rackPositionForAsset($asset_id);
$asset_holds = null;
if ($asset_rack) {
$asset_rack_id = intval($asset_rack['rack_id']);
$asset_rack_name = escapeHtml($asset_rack['rack_name']);
$asset_rack_position = rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) . ', ' . ($asset_rack['unit_face'] === 'rear' ? 'rear' : 'front')
. rackSlotHtml($asset_rack, $client_id);
if (intval($asset_rack['unit_slots']) && !$asset_rack['holder_id']) {
$asset_holds = rackHolderChildren($asset_rack['unit_id']);
}
}
// Override Tab Title // No Sanitizing needed as this var will opnly be used in the tab title
$page_title = $row['asset_name'];
// Tags - functions/tags.php
$asset_tags_display = tagPills('asset', $asset_id, tagsForRecord('asset', $asset_id), "assets.php?client_id=$client_id&");
// Tickets - linked as the ticket's asset or as one of its other assets (functions/ticket.php)
$related_tickets = ticketRows(ticketAssetSql($asset_id));
$ticket_count = count($related_tickets);
$ticket_open_count = count(array_filter(array_column($related_tickets, 'is_open')));
// Recurring tickets
$sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT recurring_tickets.recurring_ticket_id, recurring_ticket_subject,
recurring_ticket_priority, recurring_ticket_frequency, recurring_ticket_next_run, recurring_ticket_paused_at
FROM recurring_tickets
LEFT JOIN recurring_ticket_assets ON recurring_tickets.recurring_ticket_id = recurring_ticket_assets.recurring_ticket_id
WHERE recurring_ticket_asset_id = $asset_id OR recurring_ticket_assets.asset_id = $asset_id
GROUP BY recurring_tickets.recurring_ticket_id
ORDER BY recurring_ticket_next_run ASC"
);
$recurring_ticket_count = mysqli_num_rows($sql_related_recurring_tickets);
// Network interfaces, in port order, and what each one is plugged into (functions/asset_interface.php)
$interfaces = [];
$sql_related_interfaces = mysqli_query($mysqli, "SELECT asset_interfaces.*, network_name, network, network_type, network_description, network_archived_at
FROM asset_interfaces
LEFT JOIN networks ON network_id = interface_network_id AND interface_network_id > 0
WHERE interface_asset_id = $asset_id AND interface_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql_related_interfaces)) {
$interfaces[intval($row['interface_id'])] = $row;
}
$interface_links = interfaceLinks(array_keys($interfaces));
interfaceSort($interfaces);
$interface_count = count($interfaces);
// A switch, firewall or access point with a few ports is drawn as its ports too
$interface_port_map = assetTypeHasPortMap(html_entity_decode($asset_type, ENT_QUOTES, 'UTF-8')) && $interface_count >= 4;
// Files
$sql_related_files = mysqli_query($mysqli, "SELECT file_created_at, file_description, file_ext, files.file_id, file_name FROM asset_files
LEFT JOIN files ON asset_files.file_id = files.file_id
WHERE asset_files.asset_id = $asset_id
AND file_archived_at IS NULL
ORDER BY file_name ASC"
);
$files_count = mysqli_num_rows($sql_related_files);
// Documents
$sql_related_documents = mysqli_query($mysqli, "SELECT document_created_at, document_description, documents.document_id, document_name,
document_updated_at, user_name FROM asset_documents, documents
LEFT JOIN users ON document_created_by = user_id
WHERE asset_documents.asset_id = $asset_id
AND asset_documents.document_id = documents.document_id
AND document_archived_at IS NULL
ORDER BY document_name ASC"
);
$document_count = mysqli_num_rows($sql_related_documents);
// Credentials
$related_credentials = $can_credentials ? credentialRows("credential_asset_id = $asset_id AND credential_client_id = $client_id") : [];
$credential_count = count($related_credentials);
// Licenses it holds a seat on, with each one's seats in use and the key it was given
$held_software = softwareHeldBy('asset', $asset_id);
$software_count = count($held_software);
// The services it is part of - most important first
$linked_services = servicesFor('asset', $asset_id);
$service_count = count($linked_services);
// Notes - 1 to many relationship
$sql_related_notes = mysqli_query($mysqli, "SELECT asset_note, asset_note_created_at, asset_note_id, asset_note_type, user_name FROM asset_notes
LEFT JOIN users ON asset_note_created_by = user_id
WHERE asset_note_asset_id = $asset_id
AND asset_note_archived_at IS NULL
ORDER BY asset_note_created_at DESC"
);
$note_count = mysqli_num_rows($sql_related_notes);
// Note type icons, read from the categories list so the seeded icons
// stay the single source of truth
$note_type_icons = array();
$sql_note_type_icons = mysqli_query($mysqli, "SELECT category_name, category_icon FROM categories WHERE category_type = 'asset_note_type'");
while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
$note_type_icons[escapeHtml($row['category_name'])] = escapeHtml($row['category_icon']);
}
// The tabs, in the order a tech reaches for them
// Its history, from the audit log
$history = auditLogHistory('Asset', $asset_id);
$asset_tabs = [
'interfaces' => ['label' => 'Interfaces', 'icon' => 'fa-ethernet', 'count' => $interface_count],
'credentials' => ['label' => 'Credentials', 'icon' => 'fa-key', 'count' => $credential_count],
'tickets' => ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'count' => $ticket_count, 'badge' => $ticket_open_count],
'recurring' => ['label' => 'Recurring', 'icon' => 'fa-redo-alt', 'count' => $recurring_ticket_count],
'licenses' => ['label' => 'Licenses', 'icon' => 'fa-cube', 'count' => $software_count],
'documents' => ['label' => 'Documents', 'icon' => 'fa-file-alt', 'count' => $document_count],
'files' => ['label' => 'Files', 'icon' => 'fa-paperclip', 'count' => $files_count],
'services' => ['label' => 'Services', 'icon' => 'fa-stream', 'count' => $service_count],
'notes' => ['label' => 'Notes', 'icon' => 'fa-sticky-note', 'count' => $note_count],
'history' => ['label' => 'History', 'icon' => 'fa-history', 'count' => $history['count']],
];
if (!$can_credentials) {
unset($asset_tabs['credentials']);
}
// Ticketing switched off (Admin > Settings > Modules) - its tabs and New items go
$asset_ticketing = moduleOn('ticketing');
if (!$asset_ticketing) {
unset($asset_tabs['tickets'], $asset_tabs['recurring']);
}
?>
= escapeHtml($rmm_each_name) ?> stopped listing it = escapeHtml(timeAgo($rmm_each['rmm_device_removed_at'])) ?> - its agent was removed, or it moved to a client that isn't linked. = escapeHtml(preg_replace('/^[^:]*: /', '', $rmm_state['title'])) ?> there.
Status
= escapeHtml($rmm_state['label']) ?>- last seen = escapeHtml(timeAgo($rmm_each['rmm_device_last_seen_at'])) ?>
= intval($seen['now']) ? 'Connected now - as ' . escapeHtml(rmmProviderName($seen)) . ' said ' . escapeHtml(timeAgo($seen['rmm_seen_at'])) : 'Last seen there ' . escapeHtml(timeAgo($seen['rmm_seen_at'])) . ', by ' . escapeHtml(rmmProviderName($seen)) ?>.
= escapeHtml(phoneSystemName($phone_device)) ?>
Status
= escapeHtml($phone_status[0]) ?>- since = escapeHtml(timeAgo($phone_device['phone_device_status_at'])) ?>
Line
= escapeHtml(phoneNumberText($phone_device['phone_device_line']) ?: $phone_device['phone_device_line']) ?> on = escapeHtml($phone_device['phone_domain_name']) ?>
As the phone said = escapeHtml(timeAgo($phone_device['phone_device_heard_at'])) ?> - a phone only says something when it starts up, registers or has a call, so this can be out of date.
= linkPickerButton('asset', $asset_id, 'asset', 'Link', 'btn btn-sm btn-outline-secondary', 'fas fa-link me-2', 'Link it to another of this client\'s assets') ?>
Services that run on it - when it is down, so are they.
= linkPickerButton('asset', $asset_id, 'service', 'Link Service', 'btn btn-sm btn-outline-secondary', 'fas fa-link me-2') ?>