= 2; $can_delete = lookupUserPermission('module_support') >= 3; // Asset type tabs (functions/asset_type.php) $asset_type_tabs = assetTypeTabs(); $type_filter = (isset($_GET['type']) && isset($asset_type_tabs[$_GET['type']])) ? $_GET['type'] : ''; $_GET['type'] = $type_filter; $type_query = $type_filter ? $asset_type_tabs[$type_filter]['query'] : "1 = 1"; $client = ''; if (!$client_url) { // Client Filter if (!empty($_GET['client'])) { $client = intval($_GET['client']); $client_query = "AND asset_client_id = $client"; } } // Location Filter if ($client_url && !empty($_GET['location'])) { $location_filter = intval($_GET['location']); $location_query = "AND asset_location_id = $location_filter"; } else { // Default - any $location_query = ''; $location_filter = 0; } // Status Filter - the asset statuses (Admin > Categories), held by name $status_filter = trim(strip_tags((string) ($_GET['status'] ?? ''))); $status_query = $status_filter !== '' ? "AND asset_status = '" . escapeSql($status_filter) . "'" : ''; // Tags Filter if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) { $tag_filter = implode(",", array_map('intval', $_GET['tags'])); $tag_query = "AND asset_id IN (SELECT asset_tag_asset_id FROM asset_tags WHERE asset_tag_tag_id IN ($tag_filter))"; } else { $tag_filter = 0; $tag_query = ''; } // Expiring In Filter if (!empty($_GET['expire_days'])) { if ($_GET['expire_days'] == "expired") { $expire_days = "expired"; $expire_query = "AND (asset_warranty_expire IS NOT NULL AND asset_warranty_expire != '0000-00-00' AND asset_warranty_expire < CURDATE())"; } else { $expire_days = intval($_GET['expire_days']); $expire_query = "AND (asset_warranty_expire IS NOT NULL AND asset_warranty_expire != '0000-00-00' AND asset_warranty_expire BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL $expire_days DAY))"; } } else { // Default - any $expire_days = ''; $expire_query = ''; } // Extra columns, picked from the filter bar $extra_column_options = [ 'Mac_Address' => 'MAC address', 'Purchase_Date' => 'Purchase date', 'Install_Date' => 'Install date', 'Warranty_Expire' => 'Warranty', 'Details' => 'Details', ]; $extra_columns = array_values(array_intersect(array_keys($extra_column_options), (array) ($_GET['show_column'] ?? []))); $show_mac = in_array('Mac_Address', $extra_columns, true); $show_purchase = in_array('Purchase_Date', $extra_columns, true); $show_install = in_array('Install_Date', $extra_columns, true); $show_warranty = in_array('Warranty_Expire', $extra_columns, true); $show_details = in_array('Details', $extra_columns, true); // Assigned To only means something for workstations and the like - printers are shared $show_contact = !in_array($type_filter, ['network', 'server', 'virtual', 'power', 'printer', 'other'], true); $show_model = $type_filter !== 'virtual'; // Only these sort - filter_header.php will hand through any lowercase word, and // an unknown column takes the page down with a mysqli exception $sortable_columns = [ 'asset_name', 'asset_type', 'asset_make', 'interface_ip', 'interface_mac', 'asset_purchase_date', 'asset_install_date', 'asset_warranty_expire', 'contact_name', 'location_name', 'asset_status', 'client_name', 'asset_created_at' ]; if (!in_array($sort, $sortable_columns, true)) { $sort = 'asset_name'; } // Addresses sort by value - .9 before .10 - and this works for IPv4 and IPv6 alike $order_by = $sort === 'interface_ip' ? "INET6_ATON(interface_ip) $order, interface_ip $order" : "$sort $order"; // Tab counts - within the client, status, tag and archive scope, before the search narrows it $row = mysqli_fetch_assoc(mysqli_query($mysqli, " SELECT COUNT(*) AS all_count" . implode('', array_map(function ($tab_key, $tab) { return ",\n SUM({$tab['query']}) AS {$tab_key}_count"; }, array_keys($asset_type_tabs), $asset_type_tabs)) . " FROM assets LEFT JOIN clients ON client_id = asset_client_id WHERE $archive_query $status_query $tag_query " . clientScopeSql('asset_client_id') . " $client_query ")); $tab_counts = ['' => intval($row['all_count'])]; foreach ($asset_type_tabs as $tab_key => $tab) { $tab_counts[$tab_key] = intval($row[$tab_key . '_count']); } $sql = mysqli_query( $mysqli, "SELECT SQL_CALC_FOUND_ROWS asset_archived_at, asset_client_id, asset_contact_id, asset_description, asset_favorite, asset_id, asset_install_date, asset_location_id, asset_make, asset_model, asset_name, asset_os, asset_physical_location, asset_purchase_date, asset_serial, asset_status, asset_type, asset_uri, asset_uri_2, asset_uri_client, asset_warranty_expire, client_id, client_name, contact_archived_at, contact_name, contact_photo, interface_ip, interface_ipv6, interface_mac, location_archived_at, location_name FROM assets LEFT JOIN clients ON asset_client_id = client_id LEFT JOIN contacts ON asset_contact_id = contact_id LEFT JOIN locations ON asset_location_id = location_id LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE $archive_query $tag_query AND (asset_name LIKE '%$q%' OR asset_description LIKE '%$q%' OR asset_type LIKE '%$q%' OR interface_ip LIKE '%$q%' OR interface_ipv6 LIKE '%$q%' OR interface_mac LIKE '%$q%' OR asset_make LIKE '%$q%' OR asset_model LIKE '%$q%' OR asset_serial LIKE '%$q%' OR asset_os LIKE '%$q%' OR contact_name LIKE '%$q%' OR location_name LIKE '%$q%' OR client_name LIKE '%$q%' OR asset_id IN (SELECT asset_tag_asset_id FROM asset_tags JOIN tags ON tag_id = asset_tag_tag_id WHERE tag_name LIKE '%$q%')) AND ($type_query) " . clientScopeSql('asset_client_id') . " $status_query $location_query $expire_query $client_query GROUP BY asset_id ORDER BY $order_by LIMIT $record_from, $record_to" ); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $assets = []; while ($row = mysqli_fetch_assoc($sql)) { $assets[intval($row['asset_id'])] = $row; } // Each one's details - its type's (functions/asset_type.php): a UPS battery due is flagged like a warranty, and Details lists them $asset_list_specs = assetSpecsFor(array_keys($assets)); // Tags and rack positions for the whole page in two queries, not two per row $assets_tags = tagsForRecords('asset', array_keys($assets)); $assets_racked = []; if ($assets) { $sql_racked = mysqli_query($mysqli, "SELECT unit_asset_id, unit_start_number, unit_end_number, rack_id, rack_name FROM rack_units JOIN racks ON rack_id = unit_rack_id WHERE unit_asset_id IN (" . implode(',', array_keys($assets)) . ")"); while ($row = mysqli_fetch_assoc($sql_racked)) { $assets_racked[intval($row['unit_asset_id'])] = $row; } } $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'; ?>

Assets

text-nowrap table-light"> $row) { $client_id = intval($row['client_id']); $client_name = escapeHtml($row['client_name']); $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_ip = escapeHtml($row['interface_ip']); $asset_ipv6 = escapeHtml($row['interface_ipv6']); $asset_mac = escapeHtml($row['interface_mac']); $asset_links = assetLinks($row['asset_uri'], $row['asset_uri_2'], $row['asset_uri_client']); $asset_status_pill = assetStatusPill($row['asset_status']); $asset_purchase_date = escapeHtml($row['asset_purchase_date']); $asset_install_date = escapeHtml($row['asset_install_date']); $asset_warranty = assetWarranty($row['asset_warranty_expire']); $asset_physical_location = escapeHtml($row['asset_physical_location']); $asset_favorite = intval($row['asset_favorite']); $asset_archived_at = escapeHtml($row['asset_archived_at']); $asset_contact_id = intval($row['asset_contact_id']); $asset_tone = assetTypeTone($row['asset_type']); $device_icon = getAssetIcon($row['asset_type']); $asset_spec_rows = assetSpecRows($row['asset_type'], $asset_list_specs[$asset_id] ?? [], $client_id); $asset_battery = $asset_spec_rows['battery_replace']['flag'] ?? null; $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']); $asset_rack = $assets_racked[$asset_id] ?? null; $asset_tags = $assets_tags[$asset_id] ?? []; ?>
Name Type / OS Model / Serial IP MAC Purchased Details Installed Warranty Assigned To Location Status Client
Archived
= 2) { ?>
-' ?>
Warranty Battery
-
- -' ?>
old
' . escapeHtml($spec_row['label']) . ' ' . escapeHtml($spec_row['flag']['date']) . '' : $spec_row['brief'] ?>
-
-' ?>
-
$contact_archived]) ?> -
>
-
·
-' ?>
$type_filter ? strtolower($asset_type_tabs[$type_filter]['label']) : 'assets', 'icon' => $type_filter ? $asset_type_tabs[$type_filter]['icon'] : 'fa-desktop', 'views' => ['type'], 'text' => $type_filter ? '' : 'Their computers, servers, network gear and phones - what each is, where it is and who uses it.', 'actions' => $can_edit ? array_merge( [['label' => 'New ' . ($type_filter ? rtrim($asset_type_tabs[$type_filter]['label'], 's') : 'Asset'), 'modal' => "modals/asset/asset_add.php?$client_url&type=$type_filter", 'size' => 'lg']], $client_url ? [['label' => 'Import', 'modal' => "modals/asset/asset_import.php?$client_url", 'icon' => 'fa-upload']] : [] ) : [], ]; ?>