From c962daabacac1c832045663f6284b7f9e6c476b6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Mar 2017 15:16:16 +0100 Subject: [PATCH] NEW add property to show warnings when activating modules --- htdocs/admin/modules.php | 55 ++++++++++++++++--- htdocs/core/lib/admin.lib.php | 17 ++++-- htdocs/core/modules/DolibarrModules.class.php | 27 +++++++-- htdocs/core/modules/modCron.class.php | 2 +- htdocs/core/modules/modFacture.class.php | 9 ++- htdocs/core/modules/modSkype.class.php | 2 +- htdocs/core/modules/modWebsites.class.php | 2 +- htdocs/langs/en_US/admin.lang | 1 + 8 files changed, 90 insertions(+), 25 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 596aefa803e..6d9df62e979 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -235,6 +235,8 @@ $help_url='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones' llxHeader('',$langs->trans("Setup"),$help_url); $arrayofnatures=array('core'=>$langs->transnoentitiesnoconv("Core"), 'external'=>$langs->transnoentitiesnoconv("External").' - '.$langs->trans("AllPublishers")); +$arrayofwarnings=array(); // Array of warning each module want to show when activated +$arrayofwarningsext=array(); // Array of warning each module want to show when we activate an external module // Search modules dirs $modulesdir = dolGetModulesDirs(); @@ -266,7 +268,7 @@ foreach ($modulesdir as $dir) if ($modName) { - if (! empty($modNameLoaded[$modName])) + if (! empty($modNameLoaded[$modName])) // In cache of already loaded modules ? { $mesg="Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.
"; setEventMessages($mesg, null, 'warnings'); @@ -297,7 +299,7 @@ foreach ($modulesdir as $dir) if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) $modulequalified=0; if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) $modulequalified=0; - // We discard modules according to property disabled + // We discard modules according to property ->hidden if (! empty($objMod->hidden)) $modulequalified=0; if ($modulequalified > 0) @@ -321,8 +323,8 @@ foreach ($modulesdir as $dir) // Define array $categ with categ with at least one qualified module if ($modulequalified > 0) { - $modules[$i] = $objMod; $filename[$i]= $modName; + $modules[$modName] = $objMod; $special = $objMod->special; @@ -342,6 +344,16 @@ foreach ($modulesdir as $dir) if ($special == 1) $familykey='interface'; + // Add list of warnings to show into arrayofwarnings and arrayofwarningsext + if (! empty($objMod->warnings_activation)) + { + $arrayofwarnings[$modName]=$objMod->warnings_activation; + } + if (! empty($objMod->warnings_activation_ext)) + { + $arrayofwarningsext[$modName]=$objMod->warnings_activation_ext; + } + $orders[$i] = $familyinfo[$familykey]['position']."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number $dirmod[$i] = $dir; //print $i.'-'.$dirmod[$i].'
'; @@ -484,7 +496,7 @@ if ($mode == 'common') $familyposition=$tab[0]; $familykey=$tab[1]; $module_position=$tab[2]; $numero=$tab[3]; $modName = $filename[$key]; - $objMod = $modules[$key]; + $objMod = $modules[$modName]; $dirofmodule = $dirmod[$key]; $special = $objMod->special; @@ -633,7 +645,7 @@ if ($mode == 'common') print "\n"; // Activate/Disable and Setup (2 columns) - if (! empty($conf->global->$const_name)) // If module is activated + if (! empty($conf->global->$const_name)) // If module is already activated { $disableSetup = 0; @@ -699,12 +711,12 @@ if ($mode == 'common') } } - else // Module not activated + else // Module not yet activated { print ''; if (! empty($objMod->always_enabled)) { - // Ne devrait pas arriver. + // Should never happened } else if (! empty($objMod->disabled)) { @@ -712,7 +724,34 @@ if ($mode == 'common') } else { - // Module non actif + // Module qualified for activation + $warningmessage=''; + if (! empty($arrayofwarnings[$modName])) + { + print ''."\n"; + foreach ($arrayofwarnings[$modName] as $keycountry => $cursorwarningmessage) + { + $warningmessage .= ($warningmessage?"\n":"").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code); + } + } + if ($objMod->isCoreOrExternalModule() == 'external' && ! empty($arrayofwarningsext)) + { + print ''."\n"; + foreach ($arrayofwarningsext as $keymodule => $arrayofwarningsextbycountry) + { + if (! empty($modules[$keymodule]->const_name)) // If module that request warning is on + { + foreach ($arrayofwarningsextbycountry as $keycountry => $cursorwarningmessage) + { + if ($keycountry == 'always' || $keycountry == $mysoc->country_code) + { + $warningmessage .= ($warningmessage?"\n":"").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code, $modules[$keymodule]->getName()); + } + } + } + } + } + print ''."\n"; print ''; print img_picto($langs->trans("Disabled"),'switch_off'); print "\n"; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 288082296f3..7de948ddfba 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -779,16 +779,21 @@ function activateModule($value,$withdeps=1) { if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends)) { - // Activation des modules dont le module depend - $num = count($objMod->depends); - for ($i = 0; $i < $num; $i++) + // Activation of modules this module depends on + // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>"modModule1", 'FR'=>'modModule2') + foreach ($objMod->depend as $key => $modulestring) { + if ((! is_numeric($key)) && $key != 'always' && $key != $mysoc->country_code) + { + dol_syslog("We are not concerned by dependency with key=".$key." because our country is ".$mysoc->country_code); + continue; + } $activate = false; foreach ($modulesdir as $dir) { - if (file_exists($dir.$objMod->depends[$i].".class.php")) + if (file_exists($dir.$modulestring.".class.php")) { - $resarray = activateModule($objMod->depends[$i]); + $resarray = activateModule($modulestring); if (empty($resarray['errors'])){ $activate = true; }else{ @@ -807,7 +812,7 @@ function activateModule($value,$withdeps=1) } else { - $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $objMod->depends[$i]); + $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring); } } } diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 8e526baa241..84538801add 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -215,11 +215,6 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $descriptionlong; - /** - * @var string[] Module language files - */ - public $langfiles; - /** * @var string Module export code */ @@ -291,6 +286,7 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $config_page_url; + /** * @var string[] List of module class names that must be enabled if this module is enabled. * @@ -309,6 +305,26 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $conflictwith; + /** + * @var string[] Module language files + */ + public $langfiles; + + /** + * @var string[] Array of warnings to show when we activate the module + * + * array('always'='text') or array('FR'='text') + */ + public $warnings_activation; + + /** + * @var string[] Array of warnings to show when we activate an external module + * + * array('always'='text') or array('FR'='text') + */ + public $warnings_activation_ext; + + /** * @var array() Minimum version of PHP required by module. * e.g.: PHP ≥ 5.3 = array(5, 3) @@ -326,6 +342,7 @@ class DolibarrModules // Can not be abstract, because we need to insta */ public $hidden = false; + /** * Constructor. Define names, constants, directories, boxes, permissions * diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index bd5f193c568..88b154f891e 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -67,7 +67,7 @@ class modCron extends DolibarrModules // Dependancies //------------- - $this->hidden = ! empty($conf->global->CRON_MODULE_DISABLED); // A condition to disable module + $this->hidden = ! empty($conf->global->MODULE_CRON_DISABLED); // A condition to disable module $this->depends = array(); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 4bc8590d5b4..a88082ba6fc 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -64,11 +64,13 @@ class modFacture extends DolibarrModules $this->dirs = array("/facture/temp"); // Dependencies - $this->depends = array("modSociete"); + $this->depends = array('always'=>"modSociete", 'FR'=>'modBlockChainLog'); $this->requiredby = array("modComptabilite","modAccounting"); $this->conflictwith = array(); $this->langfiles = array("bills","companies","compta","products"); - + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='text') + $this->warnings_activation_ext = array('CA'=>'WarningInstallationMayBecomeNotCompliantWithLaw'); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text') + // Config pages $this->config_page_url = array("facture.php"); @@ -96,7 +98,8 @@ class modFacture extends DolibarrModules $this->const[$r][3] = ""; $this->const[$r][4] = 0; $r++; - + + // Boxes //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php')); $this->boxes = array( diff --git a/htdocs/core/modules/modSkype.class.php b/htdocs/core/modules/modSkype.class.php index d6017b06c16..ca9179d5fa3 100644 --- a/htdocs/core/modules/modSkype.class.php +++ b/htdocs/core/modules/modSkype.class.php @@ -65,7 +65,7 @@ class modSkype extends DolibarrModules // Dependancies //------------- - $this->hidden = ! empty($conf->global->SKYPE_MODULE_DISABLED); // A condition to disable module + $this->hidden = ! empty($conf->global->MODULE_SKYPE_DISABLED); // A condition to disable module $this->depends = array('modSociete'); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with diff --git a/htdocs/core/modules/modWebsites.class.php b/htdocs/core/modules/modWebsites.class.php index 97dfbd6dd12..877c78b85eb 100644 --- a/htdocs/core/modules/modWebsites.class.php +++ b/htdocs/core/modules/modWebsites.class.php @@ -67,7 +67,7 @@ class modWebsites extends DolibarrModules // Dependancies //------------- - $this->hidden = ! empty($conf->global->WEBSITE_MODULE_DISABLED); // A condition to disable module + $this->hidden = ! empty($conf->global->MODULE_WEBSITE_DISABLED); // A condition to disable module $this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index a5fb93a4665..f5aa35f0c35 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1661,6 +1661,7 @@ ModuleEnabledAdminMustCheckRights=Module has been activated. Permissions for act UserHasNoPermissions=This user has no permission defined TypeCdr=Use "None" if the date of payment term is date of invoice plus a delta in days (delta is field "Nb of days")
Use "At end of month", if, after delta, the date must be increased to reach the end of month (+ an optional "Offset" in days)
Use "Current/Next" to have payment term date being the first Nth of the month (N is stored into field "Nb of days") BaseCurrency=Reference currency of the company (go into setup of company to change this) +WarningInstallationMayBecomeNotCompliantWithLaw=You try to install the module %s that is an external module. Activate an external module only if it does not alterate negatively the behavior required by your country laws (%s). If the module bring a non legal feature, you are the only responsible for the use of a non-compliant software. ##### Resource #### ResourceSetup=Configuration du module Resource UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list).