'That location no longer exists.']); exit; } $client_id = intval($location['location_client_id']); enforceClientAccess(); // Only the kinds this agent may move $kinds = array_filter(LOCATION_KINDS, function ($k) { return lookupUserPermission($k['module']) >= 2; }); if (!$kinds) { echo json_encode(['error' => 'You do not have permission to move things to a location.']); exit; } $kind = isset($kinds[$_GET['kind'] ?? '']) ? $_GET['kind'] : array_key_first($kinds); /** The client's records of one kind that are not at this location, with where they are now. */ function locationAssignCandidates($kind, $client_id, $location_id) { global $mysqli; $k = LOCATION_KINDS[$kind]; $extra = [ 'contact' => 'contact_title AS detail, contact_photo, contact_client_id', 'asset' => "asset_type, TRIM(CONCAT(IFNULL(asset_make, ''), ' ', IFNULL(asset_model, ''))) AS detail", 'network' => "CONCAT(network, IF(network_vlan > 0, CONCAT(' · VLAN ', network_vlan), '')) AS detail", 'rack' => "CONCAT(rack_units, 'U') AS detail", ][$kind]; $sql = mysqli_query($mysqli, "SELECT t.{$k['id']} AS id, t.{$k['name']} AS name, $extra, l.location_name AS current_location FROM {$k['table']} AS t LEFT JOIN locations AS l ON l.location_id = t.{$k['location']} WHERE t.{$k['client']} = $client_id AND t.{$k['archived']} IS NULL AND (t.{$k['location']} IS NULL OR t.{$k['location']} != $location_id) ORDER BY t.{$k['name']} ASC"); $rows = []; while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } return $rows; } $location_name = escapeHtml($location['location_name']); ob_start(); ?>