pulsanti e create client

This commit is contained in:
mariano
2026-05-20 11:46:28 +02:00
parent 7143d721fb
commit a1c3a5a07e
5 changed files with 112 additions and 21 deletions
-12
View File
@@ -116,8 +116,6 @@ class AssetTab extends CommonDBTM
*/
private static function showNoServerLinkedBlock(CommonDBTM $item): void
{
$asset_location_id = LocationHelper::getAssetLocationId($item);
$root_location_id = LocationHelper::getRootLocationIdForAsset($item);
$is_sub_location = LocationHelper::assetIsInSubLocation($item);
$servers = LocationHelper::getAvailableServersForAsset($item);
@@ -128,16 +126,6 @@ class AssetTab extends CommonDBTM
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='2'>" . htmlspecialchars(__('UrBackup server selection', 'urbackup')) . "</th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . htmlspecialchars(__('Asset location ID', 'urbackup')) . "</td>";
echo "<td>" . htmlspecialchars((string) $asset_location_id) . "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . htmlspecialchars(__('Root location ID', 'urbackup')) . "</td>";
echo "<td>" . htmlspecialchars((string) $root_location_id) . "</td>";
echo "</tr>";
if ($is_sub_location) {
echo "<tr class='tab_bg_1'>";
echo "<td colspan='2'><em>";
+67 -1
View File
@@ -904,6 +904,51 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
return;
}
$serverLocationId = (int) ($server->fields['locations_id'] ?? 0);
$linkableAssets = [];
if ($serverLocationId > 0) {
$itemtypes = Config::getEnabledItemtypes();
foreach ($unlinkedClients as $uc) {
$clientName = (string) ($uc['name'] ?? '');
if ($clientName === '') {
continue;
}
$clientNameLower = strtolower($clientName);
foreach ($itemtypes as $itemtype) {
if (!class_exists($itemtype)) {
continue;
}
$assetItem = new $itemtype();
if (!$assetItem instanceof CommonDBTM) {
continue;
}
$table = $assetItem->getTable();
if (!$DB->tableExists($table)) {
continue;
}
$assetIterator = $DB->request([
'FROM' => $table,
'WHERE' => [
'name' => $clientName,
'is_deleted' => 0,
],
'LIMIT' => 1,
]);
foreach ($assetIterator as $assetRow) {
$assetLocationId = (int) ($assetRow['locations_id'] ?? 0);
$rootLocationId = LocationHelper::getRootLocationId($assetLocationId);
if ($rootLocationId > 0 && $rootLocationId === $serverLocationId) {
$linkableAssets[$clientNameLower] = [
'itemtype' => $itemtype,
'items_id' => (int) $assetRow['id'],
];
}
break;
}
}
}
}
echo '<table class="table table-striped table-hover">';
echo '<thead>';
echo '<tr>';
@@ -912,11 +957,15 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
echo '<th>' . htmlspecialchars(__('Status', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('Last backup', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('IP address', 'urbackup')) . '</th>';
echo '<th>' . htmlspecialchars(__('Actions', 'urbackup')) . '</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($unlinkedClients as $uc) {
$clientName = (string) ($uc['name'] ?? 'Unknown');
$clientNameLower = strtolower($clientName);
$online = $uc['online'] ?? null;
$apiStatusString = $uc['status'] ?? '';
$statusHtml = self::renderOnlineBadge($online, $apiStatusString);
@@ -928,11 +977,28 @@ $apiStatus = (int) ($this->fields['last_api_status'] ?? 0);
$clientVersion = $uc['client_version_string'] ?? $uc['client_version'] ?? '-';
echo '<tr>';
echo '<td>' . htmlspecialchars((string) ($uc['name'] ?? 'Unknown')) . '</td>';
echo '<td>' . htmlspecialchars($clientName) . '</td>';
echo '<td>' . htmlspecialchars($clientVersion) . '</td>';
echo '<td>' . $statusHtml . '</td>';
echo '<td>' . htmlspecialchars($lastBackup ?: '-') . '</td>';
echo '<td>' . htmlspecialchars($clientIp ?: '-') . '</td>';
echo '<td>';
if (isset($linkableAssets[$clientNameLower])) {
$match = $linkableAssets[$clientNameLower];
$formAction = PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php';
echo '<form method="post" action="' . htmlspecialchars($formAction) . '" class="d-inline">';
echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]);
echo Html::hidden('itemtype', ['value' => $match['itemtype']]);
echo Html::hidden('items_id', ['value' => $match['items_id']]);
echo Html::hidden('id', ['value' => (int) $server->fields['id']]);
echo '<button type="submit" name="link_asset" value="1" class="btn btn-primary btn-sm">';
echo htmlspecialchars(__('Connect'));
echo '</button>';
Html::closeForm();
} else {
echo '<span class="text-muted">—</span>';
}
echo '</td>';
echo '</tr>';
}