'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(); ?>