diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index 559600b41..2d4f5d16a 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -734,10 +734,11 @@ EOF $sRestrictions = Dict::S('UI:AccessRO-Users'); } + $sApplicationBanner = ''; if (strlen($sRestrictions) > 0) { $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); - $sApplicationBanner = '
'; + $sApplicationBanner .= '
'; $sApplicationBanner .= ''; $sApplicationBanner .= ' '.$sRestrictions.''; if (strlen($sAdminMessage) > 0) @@ -746,13 +747,21 @@ EOF } $sApplicationBanner .= '
'; } - else if(strlen($this->m_sMessage)) + + if(strlen($this->m_sMessage)) { - $sApplicationBanner = '
'.$this->m_sMessage.'
'; + $sApplicationBanner .= '
'.$this->m_sMessage.'
'; } - else + + $sEnvironment = utils::GetCurrentEnvironment(); + if($sEnvironment != 'production') { - $sApplicationBanner = ''; + $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label')); + if (strlen($sEnvLabel) == 0) + { + $sEnvLabel = $sEnvironment; + } + $sApplicationBanner .= '
'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).'
'; } $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help'); diff --git a/core/config.class.inc.php b/core/config.class.inc.php index bf0786d8f..befcd0f16 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -84,6 +84,14 @@ class Config // New way to store the settings ! // protected $m_aSettings = array( + 'app_env_label' => array( + 'type' => 'string', + 'description' => 'Label displayed to describe the current application environnment, defaults to the environment name (e.g. "production")', + 'default' => '', + 'value' => '', + 'source_of_value' => '', + 'show_in_conf_sample' => true, + ), 'app_root_url' => array( '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)', @@ -1334,5 +1342,107 @@ class Config } return $aResult; } + + /** + * Helper function to initialize a configuration from the page arguments + */ + public function UpdateFromParams($aParamValues, $sModulesDir = null) + { + if (isset($aParamValues['application_path'])) + { + $this->Set('app_root_url', $aParamValues['application_path']); + } + if (isset($aParamValues['mode']) && isset($aParamValues['language'])) + { + if (($aParamValues['mode'] == 'install') || $this->GetDefaultLanguage() == '') + { + $this->SetDefaultLanguage($aParamValues['language']); + } + } + if (isset($aParamValues['db_server'])) + { + $this->SetDBHost($aParamValues['db_server']); + $this->SetDBUser($aParamValues['db_user']); + $this->SetDBPwd($aParamValues['db_pwd']); + $sDBName = $aParamValues['db_name']; + if ($sDBName == '') + { + $sDBName = $aParamValues['new_db_name']; + } + $this->SetDBName($sDBName); + $this->SetDBSubname($aParamValues['db_prefix']); + } + + if (!is_null($sModulesDir)) + { + if (isset($aParamValues['selected_modules'])) + { + $aSelectedModules = explode(',', $aParamValues['selected_modules']); + } + else + { + $aSelectedModules = null; + } + + // Initialize the arrays below with default values for the application... + $oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values + $aAddOns = $oEmptyConfig->GetAddOns(); + $aAppModules = $oEmptyConfig->GetAppModules(); + $aDataModels = $oEmptyConfig->GetDataModels(); + $aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories(); + $aDictionaries = $oEmptyConfig->GetDictionaries(); + // Merge the values with the ones provided by the modules + // Make sure when don't load the same file twice... + + $aModules = ModuleDiscovery::GetAvailableModules(APPROOT, $sModulesDir); + foreach($aModules as $sModuleId => $aModuleInfo) + { + list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId); + if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules)) + { + if (isset($aModuleInfo['datamodel'])) + { + $aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel'])); + } + if (isset($aModuleInfo['webservice'])) + { + $aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice'])); + } + if (isset($aModuleInfo['dictionary'])) + { + $aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary'])); + } + if (isset($aModuleInfo['settings'])) + { + foreach($aModuleInfo['settings'] as $sProperty => $value) + { + list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId); + $this->SetModuleSetting($sName, $sProperty, $value); + } + } + if (isset($aModuleInfo['installer'])) + { + $sModuleInstallerClass = $aModuleInfo['installer']; + if (!class_exists($sModuleInstallerClass)) + { + throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']); + } + if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI')) + { + throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']); + } + $aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig'); + call_user_func_array($aCallSpec, array($this)); + } + } + } + $this->SetAddOns($aAddOns); + $this->SetAppModules($aAppModules); + $this->SetDataModels($aDataModels); + $this->SetWebServiceCategories($aWebServiceCategories); + $this->SetDictionaries($aDictionaries); + } + } + } ?> diff --git a/dictionaries/dictionary.itop.ui.php b/dictionaries/dictionary.itop.ui.php index 12f2568be..59f2041c9 100644 --- a/dictionaries/dictionary.itop.ui.php +++ b/dictionaries/dictionary.itop.ui.php @@ -480,6 +480,7 @@ Dict::Add('EN US', 'English', 'English', array( 'UI:Login:PasswordChanged' => 'Password successfully set !', 'UI:AccessRO-All' => 'iTop is read-only', 'UI:AccessRO-Users' => 'iTop is read-only for end-users', + 'UI:ApplicationEnvironment' => 'Application environment: %1$s', 'UI:Login:RetypePwdDoesNotMatch' => 'New password and retyped new password do not match !', 'UI:Button:Login' => 'Enter iTop', 'UI:Login:Error:AccessRestricted' => 'iTop access is restricted. Please, contact an iTop administrator.', diff --git a/dictionaries/fr.dictionary.itop.ui.php b/dictionaries/fr.dictionary.itop.ui.php index 94833f0d5..881e0b213 100644 --- a/dictionaries/fr.dictionary.itop.ui.php +++ b/dictionaries/fr.dictionary.itop.ui.php @@ -358,6 +358,7 @@ Dict::Add('FR FR', 'French', 'Français', array( 'UI:Login:PasswordChanged' => 'Mot de passe mis à jour !', 'UI:AccessRO-All' => 'iTop est en lecture seule', 'UI:AccessRO-Users' => 'iTop est en lecture seule pour les utilisateurs finaux', + 'UI:ApplicationEnvironment' => 'Environnement applicatif: %1$s', 'UI:Login:RetypePwdDoesNotMatch' => 'Les deux saisies du nouveau mot de passe ne sont pas identiques !', 'UI:Button:Login' => 'Entrer dans iTop', 'UI:Login:Error:AccessRestricted' => 'L\'accès à iTop est soumis à autorisation. Merci de contacter votre administrateur iTop.', diff --git a/setup/ajax.dataloader.php b/setup/ajax.dataloader.php index 87a35ac8f..27419b7eb 100644 --- a/setup/ajax.dataloader.php +++ b/setup/ajax.dataloader.php @@ -211,7 +211,7 @@ try 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') ); $sModuleDir = Utils::ReadParam('modules_dir', ''); - UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); + $oConfig->UpdateFromParams($aParamValues, $sModuleDir); InitDataModel($oConfig, true); // load data model only @@ -240,7 +240,7 @@ try 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') ); $sModuleDir = Utils::ReadParam('modules_dir', ''); - UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); + $oConfig->UpdateFromParams($aParamValues, $sModuleDir); InitDataModel($oConfig, false); // load data model and connect to the database @@ -310,7 +310,7 @@ try 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') ); $sModuleDir = Utils::ReadParam('modules_dir', ''); - UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); + $oConfig->UpdateFromParams($aParamValues, $sModuleDir); InitDataModel($oConfig, false); // load data model and connect to the database diff --git a/setup/index.php b/setup/index.php index 0fdff45f6..174a24cfb 100644 --- a/setup/index.php +++ b/setup/index.php @@ -1369,7 +1369,7 @@ function SetupFinished(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oCon $oConfig->SetDBCollation('utf8_unicode_ci'); // Final config update: add the modules - UpdateConfigSettings($oConfig, $aParamValues, $aParamValues['target_dir']); + $oConfig->UpdateFromParams($aParamValues, $aParamValues['target_dir']); // Make sure the root configuration directory exists if (!file_exists(APPCONF)) @@ -1532,7 +1532,7 @@ else } $oConfig = new Config(); -UpdateConfigSettings($oConfig, $aParamValues); +$oConfig->UpdateFromParams($aParamValues); try { diff --git a/setup/setuppage.class.inc.php b/setup/setuppage.class.inc.php index 127ad1387..c78a12996 100644 --- a/setup/setuppage.class.inc.php +++ b/setup/setuppage.class.inc.php @@ -285,108 +285,6 @@ h3.clickable.open { } // End of class -/** - * Helper function to initialize a configuration from the page arguments - */ -function UpdateConfigSettings(&$oConfig, $aParamValues, $sModulesDir = null) -{ - if (isset($aParamValues['application_path'])) - { - $oConfig->Set('app_root_url', $aParamValues['application_path']); - } - if (isset($aParamValues['mode']) && isset($aParamValues['language'])) - { - if (($aParamValues['mode'] == 'install') || $oConfig->GetDefaultLanguage() == '') - { - $oConfig->SetDefaultLanguage($aParamValues['language']); - } - } - if (isset($aParamValues['db_server'])) - { - $oConfig->SetDBHost($aParamValues['db_server']); - $oConfig->SetDBUser($aParamValues['db_user']); - $oConfig->SetDBPwd($aParamValues['db_pwd']); - $sDBName = $aParamValues['db_name']; - if ($sDBName == '') - { - $sDBName = $aParamValues['new_db_name']; - } - $oConfig->SetDBName($sDBName); - $oConfig->SetDBSubname($aParamValues['db_prefix']); - } - - if (!is_null($sModulesDir)) - { - if (isset($aParamValues['selected_modules'])) - { - $aSelectedModules = explode(',', $aParamValues['selected_modules']); - } - else - { - $aSelectedModules = null; - } - - // Initialize the arrays below with default values for the application... - $oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values - $aAddOns = $oEmptyConfig->GetAddOns(); - $aAppModules = $oEmptyConfig->GetAppModules(); - $aDataModels = $oEmptyConfig->GetDataModels(); - $aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories(); - $aDictionaries = $oEmptyConfig->GetDictionaries(); - // Merge the values with the ones provided by the modules - // Make sure when don't load the same file twice... - - $aModules = ModuleDiscovery::GetAvailableModules(APPROOT, $sModulesDir); - foreach($aModules as $sModuleId => $aModuleInfo) - { - list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId); - if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules)) - { - if (isset($aModuleInfo['datamodel'])) - { - $aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel'])); - } - if (isset($aModuleInfo['webservice'])) - { - $aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice'])); - } - if (isset($aModuleInfo['dictionary'])) - { - $aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary'])); - } - if (isset($aModuleInfo['settings'])) - { - foreach($aModuleInfo['settings'] as $sProperty => $value) - { - list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId); - $oConfig->SetModuleSetting($sName, $sProperty, $value); - } - } - if (isset($aModuleInfo['installer'])) - { - $sModuleInstallerClass = $aModuleInfo['installer']; - if (!class_exists($sModuleInstallerClass)) - { - throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']); - } - if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI')) - { - throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']); - } - $aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig'); - $oConfig = call_user_func_array($aCallSpec, array($oConfig)); - } - } - } - $oConfig->SetAddOns($aAddOns); - $oConfig->SetAppModules($aAppModules); - $oConfig->SetDataModels($aDataModels); - $oConfig->SetWebServiceCategories($aWebServiceCategories); - $oConfig->SetDictionaries($aDictionaries); - } -} - - /** * Helper function to initialize the ORM and load the data model