tableExists($table)) { self::$enable_computer_cache = true; return self::$enable_computer_cache; } try { $iterator = $DB->request([ 'FROM' => $table, 'WHERE' => ['name' => self::CONFIG_ENABLE_COMPUTER], 'LIMIT' => 1, ]); $row = $iterator->current(); self::$enable_computer_cache = $row === false || (string) ($row['value'] ?? '') === '1'; } catch (\Throwable) { self::$enable_computer_cache = true; } return self::$enable_computer_cache; } /** * Check whether itemtype is enabled for UrBackup. * * @param string $itemtype Itemtype * * @return bool */ public static function isItemtypeEnabled(string $itemtype): bool { if ($itemtype === '') { return false; } if ($itemtype === 'Computer') { return self::getEnableComputer(); } // All Asset subclasses are enabled by default. // The UrBackupCapacity is still registered for cleanup (onCapacityDisabled) // and usage tracking in the Capacities UI, but visibility is always on // so the tab appears out of the box on any Asset Definition. if (is_a($itemtype, Asset::class, true)) { return true; } return false; } /** * Get enabled itemtypes. * * @return array */ public static function getEnabledItemtypes(): array { $itemtypes = []; if (self::getEnableComputer()) { $itemtypes[] = 'Computer'; } if (class_exists(AssetDefinitionManager::class)) { $manager = AssetDefinitionManager::getInstance(); foreach ($manager->getDefinitions() as $definition) { $classname = $definition->getAssetClassName(); if (!in_array($classname, $itemtypes, true)) { $itemtypes[] = $classname; } } } return $itemtypes; } /** * Get the Asset Definitions that have the UrBackup capacity enabled. * * @return array */ public static function getEnabledAssetDefinitions(): array { if (!class_exists(AssetDefinitionManager::class)) { return []; } $manager = AssetDefinitionManager::getInstance(); $capacities = $manager->getAvailableCapacities(); $urbackup_capacity = $capacities[UrBackupCapacity::class] ?? null; $definitions = []; foreach ($manager->getDefinitions() as $definition) { if ($urbackup_capacity !== null) { if ($definition->hasCapacityEnabled($urbackup_capacity)) { $definitions[] = $definition; } } else { // Fallback: decode the raw capacities JSON. $decoded = json_decode((string) ($definition->fields['capacities'] ?? '[]'), true); if ( is_array($decoded) && in_array(UrBackupCapacity::class, array_column($decoded, 'name'), true) ) { $definitions[] = $definition; } } } return $definitions; } /** * Show config form. * * @param int $ID ID * @param array $options Options * * @return bool */ public function showForm($ID, array $options = []): bool { Session::checkRight('config', UPDATE); $enable_computer = self::getEnableComputer(); echo "
"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . htmlspecialchars(__('UrBackup configuration', 'urbackup')) . "
"; echo "" . htmlspecialchars(__('Enable UrBackup on Computer', 'urbackup')) . "
"; echo "" . htmlspecialchars( __( 'Show the UrBackup tab on Computer items. When disabled, Computer is ignored everywhere (tabs, massive actions, links).', 'urbackup' ) ) . ""; echo "
"; Dropdown::showYesNo(self::CONFIG_ENABLE_COMPUTER, (int) $enable_computer); echo "
"; echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]); echo Html::submit(__('Save'), ['name' => 'update', 'class' => 'btn btn-primary']); echo "
"; echo "
"; echo "
"; echo ""; echo ""; $definitions = self::getEnabledAssetDefinitions(); if (count($definitions) === 0) { echo ""; echo ""; echo ""; } else { echo ""; echo ""; echo ""; echo ""; echo ""; foreach ($definitions as $definition) { $is_active = (bool) ($definition->fields['is_active'] ?? 0); echo ""; echo ""; echo ""; echo ""; echo ""; } } echo "
"; echo htmlspecialchars(__('Custom assets with "Urbackup" capacity enabled', 'urbackup')); echo "
"; echo ""; echo htmlspecialchars( __('No custom asset with the "Urbackup" capacity enabled.', 'urbackup') ); echo ""; echo "
" . htmlspecialchars(__('Name')) . "" . htmlspecialchars(__('System name')) . "" . htmlspecialchars(__('Active')) . "
" . htmlspecialchars((string) ($definition->fields['label'] ?? '')) . "" . htmlspecialchars((string) ($definition->fields['system_name'] ?? '')) . ""; if ($is_active) { echo "" . htmlspecialchars(__('Yes')) . ""; } else { echo "" . htmlspecialchars(__('No')) . ""; } echo "
"; echo "
"; echo "
"; echo htmlspecialchars( __( 'For Asset Definition types, enable/disable UrBackup via Config > Asset definitions > Capacities.', 'urbackup' ) ); echo "
"; echo "
"; return true; } }