{$source['name']}.", 'warning'); } elseif (count($added) === 1) { flashAlert(ucfirst($to_entity['label']) . " {$added[0]} linked to {$source['name']}$seat_warning", $seat_warning ? 'warning' : 'success'); } else { flashAlert("Linked " . count($added) . " " . strtolower($to_entity['plural']) . " to {$source['name']}$seat_warning", $seat_warning ? 'warning' : 'success'); } } else { $removed = linkRemove($from, $source['id'], $to, intval($ids[0] ?? 0)); if ($removed !== '') { flashAlert(ucfirst($to_entity['label']) . " $removed unlinked from {$source['name']}", 'error'); } } redirect(); } if (isset($_POST['link_items'])) { $ids = $_POST['ids'] ?? []; linkHandle('link', (string) ($_POST['from'] ?? ''), intval($_POST['id'] ?? 0), (string) ($_POST['to'] ?? ''), is_array($ids) ? $ids : [$ids]); } if (isset($_GET['unlink_item'])) { linkHandle('unlink', (string) ($_GET['from'] ?? ''), intval($_GET['id'] ?? 0), (string) ($_GET['to'] ?? ''), [intval($_GET['other'] ?? 0)]); } // The older names: [from, its id field, to, its id field] $legacy_links = [ 'asset_to_document' => ['document', 'document_id', 'asset', 'asset_id'], 'contact_to_document' => ['document', 'document_id', 'contact', 'contact_id'], 'file_to_document' => ['document', 'document_id', 'file', 'file_id'], 'software_to_document' => ['document', 'document_id', 'software', 'software_id'], 'vendor_to_document' => ['document', 'document_id', 'vendor', 'vendor_id'], 'asset_to_file' => ['file', 'file_id', 'asset', 'asset_id'], 'contact_to_file' => ['file', 'file_id', 'contact', 'contact_id'], 'software_to_asset' => ['asset', 'asset_id', 'software', 'software_id'], 'software_to_contact' => ['contact', 'contact_id', 'software', 'software_id'], 'service_to_asset' => ['asset', 'asset_id', 'service', 'service_id'], 'service_to_contact' => ['contact', 'contact_id', 'service', 'service_id'], ]; foreach ($legacy_links as $legacy => [$from, $from_field, $to, $to_field]) { if (isset($_POST["link_$legacy"])) { linkHandle('link', $from, intval($_POST[$from_field] ?? 0), $to, [intval($_POST[$to_field] ?? 0)]); } $unlink = 'unlink_' . str_replace('_to_', '_from_', $legacy); if (isset($_GET[$unlink])) { linkHandle('unlink', $from, intval($_GET[$from_field] ?? 0), $to, [intval($_GET[$to_field] ?? 0)]); } }