'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']); /** The option extras for one candidate - its icon or avatar, and a line under it. */ function linkOptionData($to, $row, $client_id) { switch ($to) { case 'asset': return selectOptionAsset($row['asset_type'], trim($row['asset_make'] . ' ' . $row['asset_model'])); case 'contact': return selectOptionContact($row['contact_client_id'], $row['name'], $row['contact_photo'], $row['contact_title'], $row['id']); case 'file': $info = fileTypeInfo($row['file_ext']); return selectOptionData(['icon' => 'fas fa-' . $info['icon'], 'description' => ($row['folder_name'] ?: 'Top level') . ' ยท ' . formatBytes(intval($row['file_size'])), 'keywords' => $row['file_description']]); case 'document': return selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row['document_description'] ?: 'Updated ' . timeAgo($row['document_updated_at'] ?: $row['document_created_at'])]); case 'software': return selectOptionData(['icon' => 'fas fa-cube', 'description' => trim($row['software_type'] . ' ' . $row['software_version'])]); case 'vendor': return selectOptionData(['icon' => 'fas fa-building', 'description' => $row['vendor_description']]); } return ''; } $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(); ?>