diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 1456b95b45f..69da6d7fbb7 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -75,14 +75,27 @@ if ($search_version) $param.='&search_version='.urlencode($search_version); * Actions */ + +if (GETPOST('buttonreset')) +{ + $search_keyword=''; + $search_status=''; + $search_nature=''; + $search_version=''; +} + if ($action == 'set' && $user->admin) { - $result=activateModule($value); - if ($result) setEventMessages($result, null, 'errors'); + $resarray = activateModule($value); + if (! empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors'); else { - $msg = $langs->trans('ModuleEnabledAdminMustCheckRights'); - setEventMessages($msg, null, 'warnings'); + //var_dump($resarray);exit; + if ($resarray['nbperms'] > 0) + { + $msg = $langs->trans('ModuleEnabledAdminMustCheckRights'); + setEventMessages($msg, null, 'warnings'); + } } header("Location: modules.php?mode=".$mode.$param.($page_y?'&page_y='.$page_y:'')); exit; @@ -96,14 +109,6 @@ if ($action == 'reset' && $user->admin) exit; } -if (GETPOST('buttonreset')) -{ - $search_keyword=''; - $search_status=''; - $search_nature=''; - $search_version=''; -} - /* diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 4bcd34baa8a..134de6018a5 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -708,7 +708,7 @@ function purgeSessions($mysessionid) * * @param string $value Name of module to activate * @param int $withdeps Activate/Disable also all dependencies - * @return string Error message or ''; + * @return array array('nbmodules'=>nb modules activated with success, 'errors=>array of error messages, 'nbperms'=>Nb permission added); */ function activateModule($value,$withdeps=1) { @@ -717,7 +717,7 @@ function activateModule($value,$withdeps=1) // Check parameters if (empty($value)) return 'ErrorBadParameter'; - $ret=''; + $ret=array('nbmodules'=>0, 'errors'=>array(), 'nbperms'=>0); $modName = $value; $modFile = $modName . ".class.php"; @@ -761,50 +761,67 @@ function activateModule($value,$withdeps=1) } $result=$objMod->init(); - if ($result <= 0) $ret=$objMod->error; - - if (! $ret && $withdeps) + if ($result <= 0) { - if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends)) + $ret['errors'][]=$objMod->error; + } + else + { + if ($withdeps) { - // Activation des modules dont le module depend - $TError=array(); - $num = count($objMod->depends); - for ($i = 0; $i < $num; $i++) + if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends)) { - $activate = false; - foreach ($modulesdir as $dir) - { - if (file_exists($dir.$objMod->depends[$i].".class.php")) - { - activateModule($objMod->depends[$i]); - $activate = true; - } - } - - if (!$activate) $TError[] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $objMod->depends[$i]); + // Activation des modules dont le module depend + $num = count($objMod->depends); + for ($i = 0; $i < $num; $i++) + { + $activate = false; + foreach ($modulesdir as $dir) + { + if (file_exists($dir.$objMod->depends[$i].".class.php")) + { + $resarray = activateModule($objMod->depends[$i]); + if (empty($resarray['errors'])) $activate = true; + break; + } + } + + if ($activate) + { + $ret['nbmodules']+=$resarray['nbmodules']; + $ret['nbperms']+=$resarray['nbperms']; + } + else + { + $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $objMod->depends[$i]); + } + } } - - setEventMessages('', $TError, 'errors'); - } - - if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith)) - { - // Desactivation des modules qui entrent en conflit - $num = count($objMod->conflictwith); - for ($i = 0; $i < $num; $i++) + + if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith)) { - foreach ($modulesdir as $dir) - { - if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) - { - unActivateModule($objMod->conflictwith[$i],0); - } - } + // Desactivation des modules qui entrent en conflit + $num = count($objMod->conflictwith); + for ($i = 0; $i < $num; $i++) + { + foreach ($modulesdir as $dir) + { + if (file_exists($dir.$objMod->conflictwith[$i].".class.php")) + { + unActivateModule($objMod->conflictwith[$i],0); + } + } + } } } } + if (! count($ret['errors'])) + { + $ret['nbmodules']++; + $ret['nbperms']+=count($objMod->rights); + } + return $ret; } diff --git a/htdocs/install/step5.php b/htdocs/install/step5.php index 4b45dfae3e3..96cc1c4fdcf 100644 --- a/htdocs/install/step5.php +++ b/htdocs/install/step5.php @@ -249,7 +249,7 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i',$action)) $res=dol_include_once("/core/modules/".$file); $res=activateModule($modtoactivatenew,1); - if (! $result) print 'ERROR in activating module file='.$file; + if (! empty($res['errors'])) print 'ERROR in activating module file='.$file; } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index dcd2764c7dc..54cda62d35b 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1625,5 +1625,5 @@ activateModuleDependNotSatisfied=Module "%s" depends on module "%s" that is miss CommandIsNotInsideAllowedCommands=The command you try to run is not inside list of allowed commands defined into parameter $dolibarr_main_restrict_os_commands into conf.php file. LandingPage=Landing page SamePriceAlsoForSharedCompanies=If you use the multicompany module, with the choice "Single price", price will be also the same for all companies if products are shared between environments -ModuleEnabledAdminMustCheckRights=Module has been activated. All permissions were given to admin users only. +ModuleEnabledAdminMustCheckRights=Module has been activated. Permissions for activated module(s) were given to admin users only. You may need to grant permissions to other users manually if necessary. UserHasNoPermissions=This user has no permission defined