From 9979d62a2a55ce1f995eff6aa281d38cdb62b996 Mon Sep 17 00:00:00 2001 From: mariano Date: Thu, 21 May 2026 09:26:03 +0200 Subject: [PATCH] sistemazione finale - server .php --- MEMORY.md | 48 +++++++++++++++++ front/server.form.php | 64 ++++++++++++++++++++++- front/server.php | 20 ++------ src/Server.php | 116 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 217 insertions(+), 31 deletions(-) diff --git a/MEMORY.md b/MEMORY.md index 43018fc..cf1c61c 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -267,3 +267,51 @@ Il test del pulsante "Test API" continua a restituire 403 Forbidden quando acces - `src/AssetTab.php`: Aggiunti metodi `startBackup()`, `saveInternetMode()`, `saveDefaultDirs()` - `src/UrbackupApiClient.php`: Aggiunti metodi `updateClientSettings()`, `saveInternetMode()` - `front/asset.form.php`: Gestione azioni per salvataggio impostazioni e backup + +### Refactoring server.form.php e nuove tab (v0.4.7) + +**Data**: 2026-05-21 + +**Descrizione**: Restrutturazione completa della pagina server con tab laterali e nuove funzionalità: + +**Refactoring Server::showForm()**: +- Estratto `showFormFields(?int $ID)` da `showForm()` per permettere layout custom +- `showForm()` ora chiama header + fields + buttons in sequenza + +**Tab laterali (server.form.php)**: +- Side tabs a sinistra (col-2) con `nav-pills flex-column` +- 4 tab: Server, Linked clients, Unlinked clients, Missing clients +- Tab persistence via URL hash (JS su `shown.bs.tab`) + +**Missing clients tab**: +- Mostra asset GLPI con root location matching, non ancora collegati a ServerAsset e non presenti su UrBackup +- Colonne: Name (link all'asset), Entity, Location (completename), Inventory number, IP, State, User, Group +- Ricerca testuale client-side +- Ordinamento colonne click-to-sort vanilla JS +- Navigazione server spostata in server.form.php (sopra i tab, indipendente dalle sezioni) + +**Bug fix namespace risolto**: +- `getCachedName()` usava `new $classname()` con stringa → PHP cercava `GlpiPlugin\Urbackup\Group` invece di `\Group` +- Fix: `$fqcn = '\\' . ltrim($classname, '\\')` per forzare global namespace + +**Gruppo asset corretto**: +- Gruppo non in `glpi_computers.groups_id` (colonna inesistente) +- Letto da `glpi_groups_items` WHERE `type = 1` (GROUP_TYPE_NORMAL) +- Usa `completename` per gerarchia (es. "Helpdesk > Livello 1") + +**Indirizzo IP asset**: +- Query JOIN: `glpi_ipaddresses → glpi_networknames → glpi_networkports` +- Primo IP valido per l'item + +**Breadcrumb**: +- Cambiato da `'Assets'` a `'admin'` in `Html::header()` di server.php e server.form.php +- Mostra: Pagina principale > Amministrazione > UrBackup servers + +**Fix port default per nuovi server**: +- `prepareInputForAdd()` ora setta default 55414 per `port`, 'http' per `protocol`, 1 per `is_active`, ecc. +- `prepareInputForUpdate()` normalizza anche valori vuoti + +**File modificati**: +- `src/Server.php`: `showFormFields()`, `showMissingClientsTab()`, `getCachedName()` fix, `getAssetGroupName()`, `getAssetIp()`, `getCachedLocationName()`, `prepareInputForAdd/Update` default fix +- `front/server.form.php`: Tab laterali, tab hash JS, breadcrumb admin +- `front/server.php`: Breadcrumb admin, rimosso pulsante "Add" manuale (GLPI lo genera) diff --git a/front/server.form.php b/front/server.form.php index b8cade9..22e2037 100644 --- a/front/server.form.php +++ b/front/server.form.php @@ -47,13 +47,62 @@ $ID = $_GET['id'] ?? null; Html::header( $ID ? __('Edit UrBackup server', 'urbackup') : __('Add UrBackup server', 'urbackup'), '', - 'Assets', + 'admin', 'GlpiPlugin\Urbackup\Server' ); if ($ID > 0) { + global $DB; + $server->getFromDB($ID); + + $serverIterator = $DB->request([ + 'FROM' => Server::getTable(), + 'ORDER' => 'name', + ]); + $serverIds = []; + foreach ($serverIterator as $row) { + $serverIds[(int) $row['id']] = (string) $row['name']; + } + $serverIdKeys = array_keys($serverIds); + $currentIndex = array_search((int) $ID, $serverIdKeys, true); + $totalServers = count($serverIds); + $prevId = ($currentIndex !== false && $currentIndex > 0) ? $serverIdKeys[$currentIndex - 1] : null; + $nextId = ($currentIndex !== false && $currentIndex < $totalServers - 1) ? $serverIdKeys[$currentIndex + 1] : null; + + $baseUrl = PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php'; ?> +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+
"; - echo "
"; -} - Search::show('GlpiPlugin\Urbackup\Server', [ 'is_deleted' => 0, 'massiveaction' => true, @@ -45,4 +31,4 @@ Search::show('GlpiPlugin\Urbackup\Server', [ ], ]); -Html::footer(); \ No newline at end of file +Html::footer(); diff --git a/src/Server.php b/src/Server.php index cf41231..675212b 100644 --- a/src/Server.php +++ b/src/Server.php @@ -333,7 +333,7 @@ class Server extends CommonDBTM return true; } - public function showFormFields(int $ID): void + public function showFormFields(?int $ID): void { echo ""; echo "" . htmlspecialchars(__('Name')) . ""; @@ -548,6 +548,26 @@ class Server extends CommonDBTM public function prepareInputForAdd(mixed $input): mixed { + if (!is_array($input)) { + return $input; + } + + if (!isset($input['port']) || $input['port'] === '' || $input['port'] === null) { + $input['port'] = 55414; + } + if (!isset($input['protocol']) || $input['protocol'] === '') { + $input['protocol'] = 'http'; + } + if (!isset($input['is_active']) || $input['is_active'] === '' || $input['is_active'] === null) { + $input['is_active'] = 1; + } + if (!isset($input['is_recursive']) || $input['is_recursive'] === '' || $input['is_recursive'] === null) { + $input['is_recursive'] = 0; + } + if (!isset($input['ignore_ssl']) || $input['ignore_ssl'] === '' || $input['ignore_ssl'] === null) { + $input['ignore_ssl'] = 0; + } + return $this->prepareInputForUpdate($input); } @@ -557,6 +577,16 @@ class Server extends CommonDBTM return $input; } + if (isset($input['port']) && ($input['port'] === '' || $input['port'] === null)) { + $input['port'] = 55414; + } + if (isset($input['protocol']) && $input['protocol'] === '') { + $input['protocol'] = 'http'; + } + if (isset($input['ignore_ssl']) && ($input['ignore_ssl'] === '' || $input['ignore_ssl'] === null)) { + $input['ignore_ssl'] = 0; + } + if (!empty($input['id']) && (int) $input['id'] > 0) { $server = new self(); if ($server->getFromDB((int) $input['id'])) { @@ -1148,25 +1178,41 @@ class Server extends CommonDBTM return; } + echo '
'; + echo ''; + echo '
'; + $formAction = PLUGIN_URBACKUP_WEB_DIR . '/front/server.form.php'; - echo ''; + echo '
'; echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; echo ''; foreach ($missingAssets as $asset) { + $item = new $asset['itemtype'](); + $itemLink = ''; + if ($item instanceof CommonDBTM && $item->getFromDB($asset['items_id'])) { + $itemLink = $item->getLinkURL(); + } + echo ''; - echo ''; + echo ''; echo ''; echo ''; echo ''; @@ -1190,6 +1236,50 @@ class Server extends CommonDBTM echo ''; echo '
' . htmlspecialchars(__('Name')) . '' . htmlspecialchars(Entity::getTypeName(1)) . '' . htmlspecialchars(Location::getTypeName(1)) . '' . htmlspecialchars(__('Inventory number')) . '' . htmlspecialchars(__('IP address', 'urbackup')) . '' . htmlspecialchars(State::getTypeName(1)) . '' . htmlspecialchars(User::getTypeName(1)) . '' . htmlspecialchars(Group::getTypeName(1)) . '' . htmlspecialchars(__('Actions', 'urbackup')) . '' . htmlspecialchars(__('Name')) . ' ' . htmlspecialchars(Entity::getTypeName(1)) . ' ' . htmlspecialchars(Location::getTypeName(1)) . ' ' . htmlspecialchars(__('Inventory number')) . ' ' . htmlspecialchars(__('IP address', 'urbackup')) . ' ' . htmlspecialchars(State::getTypeName(1)) . ' ' . htmlspecialchars(User::getTypeName(1)) . ' ' . htmlspecialchars(Group::getTypeName(1)) . ' ' . htmlspecialchars(__('Actions', 'urbackup')) . '
' . htmlspecialchars($asset['name']) . ''; + if ($itemLink !== '') { + echo '' . htmlspecialchars($asset['name']) . ''; + } else { + echo htmlspecialchars($asset['name']); + } + echo '' . htmlspecialchars($asset['entity']) . '' . htmlspecialchars($asset['location']) . '' . htmlspecialchars($asset['otherserial']) . '
'; + + echo <<<'JAVASCRIPT' + +JAVASCRIPT; } private static function getCachedName(string $classname, int $id, array &$cache): string @@ -1201,7 +1291,7 @@ class Server extends CommonDBTM $fqcn = '\\' . ltrim($classname, '\\'); $obj = new $fqcn(); if ($obj->getFromDB($id)) { - $cache[$id] = (string) ($obj->fields['name'] ?? ''); + $cache[$id] = (string) ($obj->fields['completename'] ?? $obj->fields['name'] ?? ''); } else { $cache[$id] = ''; }