Skip to content

Commit

Permalink
NEW add property to show warnings when activating modules
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 9, 2017
1 parent d241adc commit c962daa
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 25 deletions.
55 changes: 47 additions & 8 deletions htdocs/admin/modules.php
Expand Up @@ -235,6 +235,8 @@
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();
Expand Down Expand Up @@ -266,7 +268,7 @@

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.<br>";
setEventMessages($mesg, null, 'warnings');
Expand Down Expand Up @@ -297,7 +299,7 @@
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)
Expand All @@ -321,8 +323,8 @@
// 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;

Expand All @@ -342,6 +344,16 @@

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].'<br>';
Expand Down Expand Up @@ -484,7 +496,7 @@
$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;
Expand Down Expand Up @@ -633,7 +645,7 @@
print "</td>\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;

Expand Down Expand Up @@ -699,20 +711,47 @@
}

}
else // Module not activated
else // Module not yet activated
{
print '<td align="center" valign="middle">';
if (! empty($objMod->always_enabled))
{
// Ne devrait pas arriver.
// Should never happened
}
else if (! empty($objMod->disabled))
{
print $langs->trans("Disabled");
}
else
{
// Module non actif
// Module qualified for activation
$warningmessage='';
if (! empty($arrayofwarnings[$modName]))
{
print '<!-- This module has a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\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 '<!-- This module is an external module and it may have a warning to show (note: your country is '.$mysoc->country_code.') -->'."\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 '<!-- Message to show: '.$warningmessage.' -->'."\n";
print '<a class="reposition" href="modules.php?id='.$objMod->numero.'&amp;module_position='.$module_position.'&amp;action=set&amp;value=' . $modName . '&amp;mode=' . $mode . $param . '">';
print img_picto($langs->trans("Disabled"),'switch_off');
print "</a>\n";
Expand Down
17 changes: 11 additions & 6 deletions htdocs/core/lib/admin.lib.php
Expand Up @@ -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{
Expand All @@ -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);
}
}
}
Expand Down
27 changes: 22 additions & 5 deletions htdocs/core/modules/DolibarrModules.class.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand All @@ -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)
Expand All @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/modCron.class.php
Expand Up @@ -67,7 +67,7 @@ function __construct($db)

// 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
Expand Down
9 changes: 6 additions & 3 deletions htdocs/core/modules/modFacture.class.php
Expand Up @@ -64,11 +64,13 @@ function __construct($db)
$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");

Expand Down Expand Up @@ -96,7 +98,8 @@ function __construct($db)
$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(
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/modSkype.class.php
Expand Up @@ -65,7 +65,7 @@ function __construct($db)

// 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
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/modWebsites.class.php
Expand Up @@ -67,7 +67,7 @@ function __construct($db)

// 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
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/admin.lang
Expand Up @@ -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")<br>Use "At end of month", if, after delta, the date must be increased to reach the end of month (+ an optional "Offset" in days)<br>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 <strong>%s</strong> 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).
Expand Down

0 comments on commit c962daa

Please sign in to comment.