Files
itflow/agent/modals/link/link.php
johnnyq ade9d5aac3 Services modernization: new services list with Needs attention, Review due, High importance, No review set, Starred and Archived views, dependency chips, in-place importance, bulk importance/category/review schedule, mark reviewed, star, archive/restore/delete and CSV/PDF export; new service page with service facts, backup and recovery, who to call (vendor and client contact details), auto-saving notes and tabs for the assets it runs on, logins, domains and certificates, documents, tickets and history; compact quick look; shared add/edit form with importance, category suggestions, a review schedule and dependency pickers on add; review modal with checklist and history note; attention flags for expiring or expired domains and certificates, certificate check problems, infrastructure out of warranty or out of action, and archived records still linked; Report a problem opens a prefilled ticket linked to the service, plus a service_tickets table, ticket page services list and link/unlink from both sides; services, domains and certificates added to the generic link system, legacy service link actions routed through it with same-client checks; services shown on the asset, contact and vendor pages, the asset/domain/certificate/credential quick looks, the document Linked card, the client overview (card, attention items, upcoming reviews), the dashboard, calendar, global search, client PDF pack and nightly review notifications; archived services left out of nav counts and lookups; services read endpoint in the API; demo data review schedules; database update 2.8.7 (archive and review columns, wider category and backup, link table dedupe with primary keys, service_domains foreign keys, service_tickets)
2026-10-15 17:32:09 -04:00

141 lines
6.5 KiB
PHP

<?php
/*
* Link things to a document or a file - or a document or file to an asset or
* contact, devices, users and credentials to a license, what a service
* depends on to the service. One modal for every
* pair in LINK_RELATIONS (functions/links.php):
* ?from=document&id=81&to=asset opens on Assets; the pills along the top
* switch to anything else this record can be linked to. Pick as many as you
* like; only the client's own, unarchived, not-yet-linked records are offered.
*
* The old one-pair modals (document_link_asset.php, asset_link_file.php...)
* are thin wrappers that set from/id/to and include this.
*/
require_once '../../../includes/modal_header.php';
$link_from = (string) ($_GET['from'] ?? '');
$link_id = intval($_GET['id'] ?? 0);
$link_source = linkRecord($link_from, $link_id);
if (!$link_source) {
echo json_encode(['error' => 'That record no longer exists.']);
exit;
}
$client_id = intval($link_source['client_id']);
enforceClientAccess();
// Only the kinds this agent may change
$link_types = array_values(array_filter(linkTypesFor($link_from), function ($to) use ($link_from) {
return linkCanEdit($link_from, $to);
}));
if (!$link_types) {
echo json_encode(['error' => 'You do not have permission to change these links.']);
exit;
}
$link_to = in_array($_GET['to'] ?? '', $link_types, true) ? $_GET['to'] : $link_types[0];
$from_entity = LINK_ENTITIES[$link_from];
$link_name = escapeHtml($link_source['name']);
$panes = [];
foreach ($link_types as $to) {
$panes[$to] = [
'entity' => LINK_ENTITIES[$to],
'linked' => count(linkedRecords($link_from, $link_id, $to)),
'candidates' => linkCandidates($link_from, $link_id, $to, $client_id),
];
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-link me-2"></i>Link to <strong><?= $link_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off" data-link-form>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="from" value="<?= escapeHtml($link_from) ?>">
<input type="hidden" name="id" value="<?= $link_id ?>">
<input type="hidden" name="to" value="<?= escapeHtml($link_to) ?>" data-link-to>
<div class="modal-body">
<?php if (count($panes) > 1) { ?>
<nav class="nav nav-pills itflow-asset-pills itflow-link-types mb-3" role="tablist">
<?php foreach ($panes as $to => $pane) { ?>
<button type="button" class="nav-link <?= $to === $link_to ? 'active' : '' ?>" data-bs-toggle="pill" data-bs-target="#linkPane-<?= $to ?>" data-link-type="<?= $to ?>" role="tab">
<i class="fas fa-fw <?= $pane['entity']['icon'] ?> me-1"></i><?= $pane['entity']['plural'] ?>
<?php if ($pane['linked']) { ?><span class="badge rounded-pill ms-1" title="Already linked"><?= $pane['linked'] ?></span><?php } ?>
</button>
<?php } ?>
</nav>
<?php } ?>
<div class="tab-content">
<?php foreach ($panes as $to => $pane) {
$entity = $pane['entity']; ?>
<div class="tab-pane fade <?= $to === $link_to ? 'show active' : '' ?>" id="linkPane-<?= $to ?>" role="tabpanel">
<?php if ($pane['candidates']) { ?>
<label class="form-label">Which <?= strtolower($entity['plural']) ?>?</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw <?= $entity['icon'] ?>"></i></span>
<select class="form-select select2" name="ids[]" multiple data-placeholder="Pick one or more <?= strtolower($entity['plural']) ?>" <?= $to === $link_to ? '' : 'disabled' ?> data-link-select="<?= $to ?>">
<?php foreach ($pane['candidates'] as $row) { ?>
<option value="<?= intval($row['id']) ?>"<?= linkOptionData($to, $row, $client_id) ?>><?= escapeHtml($row['name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text"><?= count($pane['candidates']) ?> <?= count($pane['candidates']) === 1 ? $entity['label'] : strtolower($entity['plural']) ?> not linked yet<?= $pane['linked'] ? ', ' . $pane['linked'] . ' already linked' : '' ?>.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas <?= $entity['icon'] ?> fa-2x mb-2"></i>
<div><?= $pane['linked'] ? 'Every ' . $entity['label'] . ' this client has is already linked.' : 'This client has no ' . strtolower($entity['plural']) . ' to link.' ?></div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_items" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<script>
(function () {
// Only the pane on show posts its picks
var form = document.querySelector('form[data-link-form]:not([data-wired])');
if (!form) {
return;
}
form.dataset.wired = '1';
var to = form.querySelector('[data-link-to]');
form.querySelectorAll('[data-link-type]').forEach(function (pill) {
pill.addEventListener('shown.bs.tab', function () {
to.value = pill.dataset.linkType;
form.querySelectorAll('[data-link-select]').forEach(function (select) {
select.disabled = select.dataset.linkSelect !== to.value;
});
});
});
form.addEventListener('submit', function (e) {
var select = form.querySelector('[data-link-select="' + to.value + '"]');
if (!select || !select.selectedOptions.length) {
e.preventDefault();
if (select && select.itflowSelect) {
select.itflowSelect.open();
}
}
});
})();
</script>
<?php
require_once '../../../includes/modal_footer.php';