['min_range' => 1]]); if (!$id || !class_exists('WHMCS\\Authentication\\CurrentUser')) return null; $current = new \WHMCS\Authentication\CurrentUser(); $client = $current->client(); if (!$client || !$current->isAuthenticatedUser() || !$client->hasPermission('products')) return null; $service = \WHMCS\Database\Capsule::table('tblhosting')->where('id', $id)->where('userid', $client->id)->first(); if (!$service) return null; try { $keys = BackupOption::applicable($service->packageid); } catch (\Throwable $e) { Backups::diagnostic('OPTION_DEFINITION', $id); return null; } $fields = \WHMCS\Database\Capsule::table('tblcustomfields') ->where('type', 'product')->where('relid', $service->packageid) ->where('fieldname', 'backuppc_host')->get(); if (count($fields) !== 1) return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null]; $field = $fields[0]; if ($field->fieldtype !== 'text' || $field->adminonly !== 'on' || $field->showorder !== '' || $field->showinvoice !== '') return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null]; $values = \WHMCS\Database\Capsule::table('tblcustomfieldsvalues')->where('fieldid', $field->id)->where('relid', $id)->get(); return ['serviceid' => $id, 'option_keys' => $keys, 'host' => count($values) === 1 ? $values[0]->value : null]; } catch (\Throwable $e) { return null; // Unsupported WHMCS authentication/schema fails closed. } } }