mirror of
https://github.com/itflow-org/itflow
synced 2026-12-05 18:49:01 +00:00
Link assets to each other: a Linked assets card on the asset page with the link picker for any of the client's other assets, links kept both ways in asset_links (database 4.4.7) and written to both assets' History and the audit log, a menu on a linked asset at another site to move either one to the other's site, linked names on the assets list and quick look, links in the client export, and links kept between assets transferred to another client together; 26.12.6 changelog
This commit is contained in:
@@ -120,6 +120,8 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
|
||||
$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;
|
||||
|
||||
@@ -804,6 +806,23 @@ if (mysqli_num_rows($sql) == 0) {
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (assetLinksReady() && ($asset_linked || ($can_edit && !$asset_archived_at))) { ?>
|
||||
<!-- Linked assets - a printer and the knife unit on it; each shows the other -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center gap-2">
|
||||
<h3 class="card-title mb-0 me-auto"><i class="fas fa-fw fa-link text-secondary me-2"></i>Linked assets<?php if ($asset_linked) { ?> <span class="text-body-secondary fw-normal">(<?= count($asset_linked) ?>)</span><?php } ?></h3>
|
||||
<?php if ($can_edit && !$asset_archived_at) { ?>
|
||||
<?= 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') ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($asset_linked) { ?>
|
||||
<?= assetLinkedListHtml($asset_row, $asset_linked, $can_edit && !$asset_archived_at) ?>
|
||||
<?php } else { ?>
|
||||
<div class="card-body small text-body-secondary">An asset that goes with this one - a part on it, or what it's fitted to. Each shows the other, and swaps go in both histories.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-pen text-secondary me-2"></i>Quick notes</h3>
|
||||
|
||||
@@ -209,6 +209,7 @@ $asset_list_specs = assetSpecsFor(array_keys($assets));
|
||||
|
||||
// Tags, rack positions and what its RMM says of each for the whole page in three queries, not three per row
|
||||
$assets_tags = tagsForRecords('asset', array_keys($assets));
|
||||
$assets_linked = assetLinkedNames(array_keys($assets)); // what each is linked to - a printer's knife unit
|
||||
$assets_rmm = $rmm_set_up ? rmmDevicesForAssets(array_keys($assets)) : [];
|
||||
$assets_racked = [];
|
||||
if ($assets) {
|
||||
@@ -623,6 +624,9 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'
|
||||
<?php if ($asset_description) { ?>
|
||||
<div class="small text-body-secondary text-truncate itflow-asset-desc" title="<?= $asset_description ?>"><?= $asset_description ?></div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($assets_linked[$asset_id])) { $linked_names = $assets_linked[$asset_id]; ?>
|
||||
<div class="small text-body-secondary text-truncate" title="Linked to <?= escapeHtml(implode(', ', $linked_names)) ?>"><i class="fas fa-fw fa-link me-1"></i><?= escapeHtml(implode(', ', array_slice($linked_names, 0, 2))) ?><?= count($linked_names) > 2 ? ' +' . (count($linked_names) - 2) : '' ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($asset_tags || lookupUserPermission('module_client') >= 2) { ?>
|
||||
<div class="itflow-tags-row mt-1 itflow-above-stretch"><?= tagPills('asset', $asset_id, $asset_tags, "assets.php?$client_url") ?></div>
|
||||
<?php } ?>
|
||||
|
||||
@@ -167,7 +167,9 @@ $asset_spec_rows = assetSpecRows($asset_row['asset_type'], assetSpecs($asset_id)
|
||||
$asset_has_contact = assetTypeHasField($asset_row['asset_type'], 'contact') || $asset_row['contact_name'];
|
||||
|
||||
$has_left = $asset_ip || $asset_mac || $asset_serial || $asset_warranty || $asset_spec_rows;
|
||||
$has_right = $can_edit || $asset_row['location_name'] || $asset_row['contact_name'] || $asset_rack;
|
||||
// The assets it's linked to - a part on it, or what it's fitted to (functions/asset_link.php)
|
||||
$asset_linked = assetLinked($asset_id);
|
||||
$has_right = $can_edit || $asset_row['location_name'] || $asset_row['contact_name'] || $asset_rack || $asset_linked;
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -302,6 +304,17 @@ ob_start();
|
||||
<span><a href="rack.php?client_id=<?= $client_id ?>&rack_id=<?= intval($asset_rack['rack_id']) ?>"><?= escapeHtml($asset_rack['rack_name']) ?></a> <span class="text-body-secondary">· <?= rackPositionLabel($asset_rack['unit_start_number'], $asset_rack['unit_end_number']) ?>, <?= $asset_rack['unit_face'] === 'rear' ? 'rear' : 'front' ?><?= rackSlotHtml($asset_rack, $client_id) ?><?= intval($asset_rack['unit_slots']) && !$asset_rack['holder_id'] ? ' · holds ' . rackDeviceCount(rackChildCount($asset_rack['unit_id'])) : '' ?></span></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($asset_linked || ($can_edit && assetLinksReady() && empty($asset_row['asset_archived_at']))) { ?>
|
||||
<div class="itflow-glance-item" title="Linked assets">
|
||||
<i class="fas fa-fw fa-link"></i>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<?php foreach ($asset_linked as $n => $linked_asset) { ?><?= $n ? ', ' : '' ?><a href="asset.php?client_id=<?= $client_id ?>&asset_id=<?= intval($linked_asset['asset_id']) ?>"><?= escapeHtml($linked_asset['asset_name']) ?></a><?php } ?>
|
||||
<?php if ($can_edit && empty($asset_row['asset_archived_at'])) { ?>
|
||||
<?= linkPickerButton('asset', $asset_id, 'asset', $asset_linked ? 'Change' : 'Link an asset', 'small' . ($asset_linked ? ' ms-1' : ''), '', 'Link it to another of this client\'s assets') ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
@@ -655,6 +655,7 @@ if (isset($_POST['bulk_transfer_client_asset'])) {
|
||||
|
||||
// Get Count
|
||||
$asset_count = count($_POST['asset_ids']);
|
||||
$transferred = []; // old asset ID => new
|
||||
|
||||
foreach($_POST['asset_ids'] as $current_asset_id) {
|
||||
$current_asset_id = intval($current_asset_id);
|
||||
@@ -683,6 +684,7 @@ if (isset($_POST['bulk_transfer_client_asset'])) {
|
||||
WHERE asset_id = $current_asset_id
|
||||
");
|
||||
$new_asset_id = mysqli_insert_id($mysqli);
|
||||
$transferred[$current_asset_id] = $new_asset_id;
|
||||
|
||||
// Transfer all Interfaces over too - with their type, so a port stays a port and an SFP cage a cage
|
||||
$sql_interfaces = mysqli_query($mysqli, "SELECT interface_mac, interface_name, interface_type, interface_primary FROM asset_interfaces WHERE interface_asset_id = $current_asset_id");
|
||||
@@ -730,6 +732,17 @@ if (isset($_POST['bulk_transfer_client_asset'])) {
|
||||
|
||||
} // End Transfer to Client Loop
|
||||
|
||||
// Assets moved together stay linked to each other (functions/asset_link.php) - a link to one
|
||||
// left behind stays with the old, archived asset
|
||||
if (count($transferred) > 1 && assetLinksReady()) {
|
||||
$old_ids = implode(',', array_keys($transferred));
|
||||
$sql_links = mysqli_query($mysqli, "SELECT asset_id, linked_asset_id FROM asset_links WHERE asset_id IN ($old_ids) AND linked_asset_id IN ($old_ids)");
|
||||
while ($row = mysqli_fetch_row($sql_links)) {
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO asset_links (asset_id, linked_asset_id, asset_link_created_by)
|
||||
VALUES (" . $transferred[intval($row[0])] . ", " . $transferred[intval($row[1])] . ", " . intval($session_user_id) . ")");
|
||||
}
|
||||
}
|
||||
|
||||
logAudit("Asset", "Bulk Transfer", "$session_name transferred $asset_count assets to $new_client_name", $new_client_id);
|
||||
|
||||
flashAlert("Transferred <strong>$asset_count</strong> asset" . ($asset_count === 1 ? '' : 's') . " to <strong>" . stripslashes($new_client_name) . "</strong>");
|
||||
@@ -1042,6 +1055,60 @@ if (isset($_POST['bulk_delete_assets'])) {
|
||||
|
||||
// Licenses are linked in post/link.php (link_software_to_asset)
|
||||
|
||||
/*
|
||||
* Linked assets (functions/asset_link.php) - unlinking one from the asset's page, and moving one
|
||||
* of two linked assets to the other's site: what the Move menu beside it offers, never done on
|
||||
* its own.
|
||||
*/
|
||||
if (isset($_GET['unlink_asset_link'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
$other_id = intval($_GET['other'] ?? 0);
|
||||
$row = linkRecord('asset', $asset_id);
|
||||
if (!$row) {
|
||||
flashAlert('That asset no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($row['client_id']);
|
||||
enforceClientAccess();
|
||||
|
||||
$name = assetLinkRemove($asset_id, $other_id);
|
||||
flashAlert($name !== '' ? 'Unlinked <strong>' . escapeHtml($name) . '</strong> from <strong>' . escapeHtml($row['name']) . '</strong>' : 'They weren\'t linked.', $name !== '' ? 'error' : 'info');
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['move_linked_asset'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$move_id = intval($_GET['move'] ?? 0);
|
||||
$with_id = intval($_GET['with'] ?? 0);
|
||||
$move = assetQuickRow($move_id);
|
||||
$with = assetQuickRow($with_id);
|
||||
if (!$move || !$with) {
|
||||
flashAlert('That asset no longer exists.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$client_id = intval($move['asset_client_id']);
|
||||
enforceClientAccess();
|
||||
if (intval($with['asset_client_id']) !== $client_id || !assetLinkedTo($move_id, $with_id)) {
|
||||
flashAlert('Those two aren\'t linked.', 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
[$ok, $message] = assetQuickSet($move_id, 'asset_location', intval($with['asset_location_id']));
|
||||
flashAlert($ok ? '<strong>' . escapeHtml($move['asset_name']) . '</strong>: ' . escapeHtml($message ?: 'already there') : escapeHtml($message), $ok ? 'success' : 'error');
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['unlink_credential_from_asset'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
Reference in New Issue
Block a user