['asset_ids', 'assets'], 'contact' => ['contact_ids', 'contacts']] as $kind => [$field, $list]) { if (array_key_exists($field, $_POST)) { $ids = array_values(array_unique(array_filter(array_map('intval', (array) $_POST[$field])))); $owned = softwareClientIds($kind, $ids, $client_id); if (count($owned) !== count($ids)) { http_response_code(400); $return_arr['success'] = "False"; $return_arr['message'] = "$field are the client's own {$kind}s, not archived - these aren't: " . implode(', ', array_diff($ids, $owned)) . '.'; echo json_encode($return_arr); exit(); } $wanted[$kind] = $owned; } else { $wanted[$kind] = array_map(function ($row) use ($kind) { return intval($row[$kind . '_id']); }, $holders[$list]); } } $changes = softwareSyncSeats($software_id, $client_id, $wanted['asset'], $wanted['contact']); $update_count = 1; $return_arr['added'] = array_values($changes['added']); $return_arr['removed'] = array_values($changes['removed']); $return_arr['warning'] = $software_seat_warning($software_id); if ($changes['added'] || $changes['removed']) { $label = escapeSql($software['software_name'] . softwareSeatChangeText($changes)); logAudit("Software", "Seats", "Changed seats on license $label via API ($api_key_name)", $client_id, $software_id); logAudit("API", "Success", "Changed seats on license " . escapeSql($software['software_name']) . " via API ($api_key_name)", $client_id); } } // Output require_once '../update_output.php';