diff --git a/application/themehandler.class.inc.php b/application/themehandler.class.inc.php index a9d0887ead..ed012c72a3 100644 --- a/application/themehandler.class.inc.php +++ b/application/themehandler.class.inc.php @@ -73,15 +73,42 @@ public static function GetCurrentThemeId() */ public static function GetApplicationThemeId(): string { + $sThemeId = null; try { - $sThemeId = utils::GetConfig()->Get('backoffice_default_theme'); + //environment type from config.php + $sEnvType = MetaModel::GetConfig()->Get('local_branding'); + //environment type from config.php + if (utils::IsNotNullOrEmptyString($sEnvType)) { + $sWorkingPath = APPROOT.'env-'.utils::GetCurrentEnvironment().'/'; + $aThemeParameters = json_decode(@file_get_contents($sWorkingPath.'branding/themes.json'), true); + if ( isset($aThemeParameters[$sEnvType]) ) { + if (isset($aThemeParameters[$sEnvType]['allowed_theme'])) { + $aThemeId = $aThemeParameters[$sEnvType]['allowed_theme']; + if (in_array($sThemeId, $aThemeId) == false) { + $sThemeId = null; + } + } + if (is_null($sThemeId)) { + //environment type from config.php + if (isset($aThemeParameters[$sEnvType]['default_theme'])) { + $sThemeId = $aThemeParameters[$sEnvType]['default_theme']; + } else { + $aDefaultTheme = ThemeHandler::GetDefaultThemeInformation(); + $sThemeId = $aDefaultTheme['name']; + } + } + } + } + if (is_null($sThemeId)) { + $sThemeId = utils::GetConfig()->Get('backoffice_default_theme'); + } } catch (CoreException $oCompileException) { // Fallback on our default theme in case the config. is not available yet $aDefaultTheme = ThemeHandler::GetDefaultThemeInformation(); $sThemeId = $aDefaultTheme['name']; } - + IssueLog::Error("GetApplicationThemeId: ".$sThemeId); return $sThemeId; } @@ -101,11 +128,24 @@ public static function GetCurrentUserThemeId(): string catch (Exception $oException) { // Do nothing, already handled by $sThemeId null by default } + $sEnvType = MetaModel::GetConfig()->Get('local_branding'); + //environment type from config.php + if (utils::IsNotNullOrEmptyString($sEnvType)) { + $sWorkingPath = APPROOT.'env-'.utils::GetCurrentEnvironment().'/'; + $aThemeParameters = json_decode(@file_get_contents($sWorkingPath.'branding/themes.json'), true); + if (isset($aThemeParameters[$sEnvType]) && isset($aThemeParameters[$sEnvType]['allowed_theme'])) { + $aThemeId = $aThemeParameters[$sEnvType]['allowed_theme']; + if ( in_array($sThemeId,$aThemeId) == false) { + $sThemeId = null; + } + } + } // Fallback on the app. theme if (is_null($sThemeId)) { $sThemeId = static::GetApplicationThemeId(); } + IssueLog::Error("GetCurrentUserThemeId: ".$sThemeId); return $sThemeId; } @@ -142,6 +182,25 @@ public static function GetAvailableThemes(): array } asort($aThemes); + $sEnvType = MetaModel::GetConfig()->Get('local_branding'); + if (!utils::IsNullOrEmptyString($sEnvType)) { + $sWorkingPath = APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/'; + $aThemeParameters = json_decode(@file_get_contents($sWorkingPath . 'branding/themes.json'), true); + //environment type from config.php + if (isset($aThemeParameters[$sEnvType])) { + $aThemeId = $aThemeParameters[$sEnvType]['allowed_theme']; + $aAvailableThemes = []; + foreach ($aThemeId as $sThemeId) { + if (isset($aThemes[$sThemeId])) { + $aAvailableThemes[$sThemeId] = $aThemes[$sThemeId]; + } + } + if (count($aAvailableThemes) > 0) { + $aThemes = $aAvailableThemes; + } + } + } + return $aThemes; } diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 8380a3fdc9..542bb4d43e 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -185,7 +185,7 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'temporary_object.garbage_interval' => [ + 'temporary_object.garbage_interval' => [ 'type' => 'integer', 'description' => 'Seconds between garbage collections', 'default' => 60, @@ -193,7 +193,7 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'app_env_label' => [ + 'app_env_label' => [ 'type' => 'string', 'description' => 'Label displayed to describe the current application environment, defaults to the environment name (e.g. "production")', 'default' => '', @@ -201,7 +201,7 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'app_root_url' => [ + 'app_root_url' => [ 'type' => 'string', 'description' => 'Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server\'s name)', 'default' => '', @@ -209,7 +209,15 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'app_icon_url' => [ + 'local_branding' => [ + 'type' => 'string', + 'description' => 'type of branding. useful for put different logo depending environment', + 'default' => null, + 'value' => null, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ], + 'app_icon_url' => [ 'type' => 'string', 'description' => 'Hyperlink to redirect the user when clicking on the application icon (in the main window, or login/logoff pages)', 'default' => 'http://www.combodo.com/itop', @@ -217,50 +225,50 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'db_host' => [ + 'db_host' => [ 'type' => 'string', 'default' => null, 'value' => '', 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'db_user' => [ - 'type' => 'string', - 'default' => null, - 'value' => '', - 'source_of_value' => '', + 'db_user' => [ + 'type' => 'string', + 'default' => null, + 'value' => '', + 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'db_pwd' => [ - 'type' => 'string', - 'default' => null, - 'value' => '', - 'source_of_value' => '', + 'db_pwd' => [ + 'type' => 'string', + 'default' => null, + 'value' => '', + 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'db_name' => [ - 'type' => 'string', - 'default' => null, - 'value' => '', - 'source_of_value' => '', + 'db_name' => [ + 'type' => 'string', + 'default' => null, + 'value' => '', + 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'db_subname' => [ - 'type' => 'string', - 'default' => null, - 'value' => '', - 'source_of_value' => '', + 'db_subname' => [ + 'type' => 'string', + 'default' => null, + 'value' => '', + 'source_of_value' => '', 'show_in_conf_sample' => true, ], - 'db_tls.enabled' => [ - 'type' => 'bool', - 'description' => 'If true then the connection to the DB will be encrypted', - 'default' => false, - 'value' => false, - 'source_of_value' => '', + 'db_tls.enabled' => [ + 'type' => 'bool', + 'description' => 'If true then the connection to the DB will be encrypted', + 'default' => false, + 'value' => false, + 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'db_tls.ca' => [ + 'db_tls.ca' => [ 'type' => 'string', 'description' => 'Path to certificate authority file for SSL', 'default' => null, @@ -268,7 +276,7 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ], - 'db_core_transactions_enabled' => [ + 'db_core_transactions_enabled' => [ 'type' => 'bool', 'description' => 'If true, CRUD transactions in iTop core will be enabled', 'default' => true, @@ -1888,6 +1896,7 @@ public function Set($sPropCode, $value, $sSourceDesc = 'unknown', $bCanOverride */ public function Get($sPropCode) { + return $this->m_aSettings[$sPropCode]['value']; } diff --git a/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php b/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php index 2c8f40a788..7fcf31ecdd 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php +++ b/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php @@ -72,6 +72,7 @@ public function Process(Container $oContainer) */ private function GetInitialPortalConf() { + $aPortalConf = array( 'properties' => array( 'id' => $_ENV['PORTAL_ID'], @@ -81,15 +82,15 @@ private function GetInitialPortalConf() 'favicon' => Branding::GetPortalFavIconAbsoluteUrl(), 'themes' => array( 'bootstrap' => 'itop-portal-base/portal/public/css/bootstrap-theme-combodo.scss', - 'portal' => 'itop-portal-base/portal/public/css/portal.scss', - 'others' => array(), + 'portal' => 'itop-portal-base/portal/public/css/portal.scss', + 'others' => array(), ), - 'templates' => array( + 'templates' => array( 'layout' => 'itop-portal-base/portal/templates/layout.html.twig', - 'home' => 'itop-portal-base/portal/templates/home/layout.html.twig', + 'home' => 'itop-portal-base/portal/templates/home/layout.html.twig', ), - 'urlmaker_class' => null, - 'triggers_query' => null, + 'urlmaker_class' => null, + 'triggers_query' => null, 'attachments' => array( 'allow_delete' => true, ), diff --git a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig index 25f1c37415..8f9578c6c4 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig @@ -25,7 +25,7 @@ {% block pPageExtraMetas %} {% endblock %}