';
/*
diff --git a/htdocs/index.php b/htdocs/index.php
index f1ce8248921..dd1e36d04f8 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -42,12 +42,17 @@ $hookmanager->initHooks(array('index'));
* Actions
*/
+$nbmodulesnotautoenabled = count($conf->modules);
+if (in_array('fckeditor', $conf->modules)) $nbmodulesnotautoenabled--;
+if (in_array('export', $conf->modules)) $nbmodulesnotautoenabled--;
+if (in_array('import', $conf->modules)) $nbmodulesnotautoenabled--;
+
// Check if company name is defined (first install)
if (!isset($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_NOM)) {
header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete");
exit;
}
-if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only user module enabled
+if ($nbmodulesnotautoenabled <= getDolGlobalString('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only user module enabled
header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete");
exit;
}
diff --git a/htdocs/install/mysql/data/llx_c_availability.sql b/htdocs/install/mysql/data/llx_c_availability.sql
index b98db76b48e..7768477c5d1 100644
--- a/htdocs/install/mysql/data/llx_c_availability.sql
+++ b/htdocs/install/mysql/data/llx_c_availability.sql
@@ -33,6 +33,11 @@
--
INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_NOW', 'Immediate', null, 0, 1, 10);
+INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_1D', '1 day', 'd', 1, 1, 11);
+INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_2D', '2 days', 'd', 2, 1, 12);
+INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_3D', '3 days', 'd', 3, 1, 13);
+INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_4D', '4 days', 'd', 4, 1, 14);
+INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_5D', '5 days', 'd', 5, 1, 15);
INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_1W', '1 week', 'w', 1, 1, 20);
INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_2W', '2 weeks', 'w', 2, 1, 30);
INSERT INTO llx_c_availability (code, label, type_duration, qty, active, position) VALUES ('AV_3W', '3 weeks', 'w', 3, 1, 40);
diff --git a/htdocs/install/step5.php b/htdocs/install/step5.php
index fc0dcf37799..6598843b882 100644
--- a/htdocs/install/step5.php
+++ b/htdocs/install/step5.php
@@ -29,6 +29,7 @@
* For installation:
* It creates the login admin and set the MAIN_SECURITY_SALT to a random value.
* It set the value for MAIN_VERSION_LAST_INSTALL
+ * It activates some modules
* It creates the install.lock and shows the final message.
* For upgrade:
* It updates the value for MAIN_VERSION_LAST_UPGRADE.
@@ -42,6 +43,7 @@ if (file_exists($conffile)) {
}
require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash
+require_once $dolibarr_main_document_root.'/core/lib/functions2.lib.php';
global $langs;
@@ -287,6 +289,9 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
*/
}
+ // List of modules to enable
+ $tmparray = array();
+
// If we ask to force some modules to be enabled
if (!empty($force_install_module)) {
if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
@@ -294,9 +299,53 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
}
$tmparray = explode(',', $force_install_module);
+ }
+
+ $modNameLoaded = array();
+
+ // Search modules dirs
+ $modulesdir[] = $dolibarr_main_document_root.'/core/modules/';
+
+ foreach ($modulesdir as $dir) {
+ // Load modules attributes in arrays (name, numero, orders) from dir directory
+ //print $dir."\n
";
+ dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
+ $handle = @opendir($dir);
+ if (is_resource($handle)) {
+ while (($file = readdir($handle)) !== false) {
+ if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
+ $modName = substr($file, 0, dol_strlen($file) - 10);
+ if ($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');
+ dol_syslog($mesg, LOG_ERR);
+ continue;
+ }
+
+ try {
+ $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
+ if (class_exists($modName)) {
+ $objMod = new $modName($db);
+ $modNameLoaded[$modName] = $dir;
+ if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
+ $tmparray[] = $file;
+ }
+ }
+ } catch (Exception $e) {
+ dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Loop on each modules to activate it
+ if (!empty($tmparray)) {
foreach ($tmparray as $modtoactivate) {
$modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate);
- print $langs->trans("ActivateModule", $modtoactivatenew).'
';
+ //print $langs->trans("ActivateModule", $modtoactivatenew).'
';
$file = $modtoactivatenew.'.class.php';
dolibarr_install_syslog('step5: activate module file='.$file);
@@ -307,8 +356,10 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
print 'ERROR: failed to activateModule() file='.$file;
}
}
+ //print '
';
}
+ // Now delete the flag to say install is complete
dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const');
$resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
if (!$resql) {
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 9706ffedb76..90e520cea25 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1234,7 +1234,7 @@ SetupDescription4=
%s -> %sThis software is a suite of m
SetupDescription5=Other Setup menu entries manage optional parameters.
SetupDescriptionLink=
%s - %s
SetupDescription3b=Basic parameters used to customize the default behavior of your application (e.g for country-related features).
-SetupDescription4b=This software is a suite of many modules/applications. The modules related to your needs must be enabled and configured. Menu entries will appears with the activation of these modules.
+SetupDescription4b=This software is a suite of many modules/applications. The modules related to your needs must be activated. Menu entries will appears with the activation of these modules.
AuditedSecurityEvents=Security events that are audited
NoSecurityEventsAreAduited=No security events are audited. You can enable them from menu %s
Audit=Security events
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 4c4d79398b2..a4457363d70 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -1223,5 +1223,5 @@ AddToContacts=Add address to my contacts
LastAccess=Last access
UploadAnImageToSeeAPhotoHere=Upload an image from the tab %s to see a photo here
LastPasswordChangeDate=Last password change date
-PublicVirtualCardUrl=Public virtual user card
+PublicVirtualCardUrl=Virtual business card page
TreeView=Tree view
diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang
index 600dfba7227..3c442fcc84a 100644
--- a/htdocs/langs/en_US/modulebuilder.lang
+++ b/htdocs/langs/en_US/modulebuilder.lang
@@ -169,4 +169,7 @@ GeneratePermissions=I want to add the rights for this object
GeneratePermissionsHelp=generate default rights for this object
PermissionDeletedSuccesfuly=Permission has been successfully removed
PermissionUpdatedSuccesfuly=Permission has been successfully updated
-PermissionAddedSuccesfuly=Permission has been successfully added
\ No newline at end of file
+PermissionAddedSuccesfuly=Permission has been successfully added
+MenuDeletedSuccessfuly=Menu has been successfully deleted
+MenuAddedSuccessfuly=Menu has been successfully added
+MenuUpdatedSuccessfuly=Menu has been successfully updated
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/modulebuilder.lang b/htdocs/langs/fr_FR/modulebuilder.lang
index 3c4161941e8..c9c0b9ef1bc 100644
--- a/htdocs/langs/fr_FR/modulebuilder.lang
+++ b/htdocs/langs/fr_FR/modulebuilder.lang
@@ -169,4 +169,7 @@ GeneratePermissions=Je souhaite ajouter les droits pour cet objet
GeneratePermissionsHelp=générer les droits par défault pour cet objet
PermissionDeletedSuccesfuly=La permission a été supprimée avec succès
PermissionUpdatedSuccesfuly=La permission a été mise à jour avec succès
-PermissionAddedSuccesfuly= La permission a été ajoutée avec succès
\ No newline at end of file
+PermissionAddedSuccesfuly= La permission a été ajoutée avec succès
+MenuDeletedSuccessfuly=Menu a été supprimé avec succès
+MenuAddedSuccessfuly=Menu a été ajouté avec succès
+MenuUpdatedSuccessfuly=Menu a été mise à jour avec succès
\ No newline at end of file
diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php
index 93f3e34bf2b..e52985e8c50 100644
--- a/htdocs/modulebuilder/index.php
+++ b/htdocs/modulebuilder/index.php
@@ -896,6 +896,17 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
// Init an object
if ($dirins && $action == 'initobject' && $module && $objectname) {
+ // check if module is enabled
+ if (isModEnabled(strtolower($module))) {
+ $result = unActivateModule(strtolower($module));
+ dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
+ if ($result) {
+ setEventMessages($result, null, 'errors');
+ }
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
+ setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
+ }
+
$objectname = ucfirst($objectname);
$dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
@@ -1341,43 +1352,31 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
// Regenerate left menu entry in descriptor for $objectname
$stringtoadd = "
\$this->menu[\$r++]=array(
- // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'fk_menu'=>'fk_mainmenu=mymodule',
- // This is a Left menu entry
'type'=>'left',
'titre'=>'List MyObject',
'mainmenu'=>'mymodule',
'leftmenu'=>'mymodule_myobject',
'url'=>'/mymodule/myobject_list.php',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'langs'=>'mymodule@mymodule',
'position'=>1100+\$r,
- // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
'enabled'=>'\$conf->mymodule->enabled',
- // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'perms'=>'1',
'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
'user'=>2,
);
\$this->menu[\$r++]=array(
- // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject',
- // This is a Left menu entry
'type'=>'left',
'titre'=>'New MyObject',
'mainmenu'=>'mymodule',
'leftmenu'=>'mymodule_myobject',
'url'=>'/mymodule/myobject_card.php?action=create',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'langs'=>'mymodule@mymodule',
'position'=>1100+\$r,
- // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
'enabled'=>'\$conf->mymodule->enabled',
- // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'perms'=>'1',
'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
'user'=>2
);\n";
$stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
@@ -1389,8 +1388,28 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
// TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
// TODO Avoid duplicate addition
- dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
-
+ // load class and check if menu exist with same object name
+ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
+ dol_include_once($pathtofile);
+ $class = 'mod'.$module;
+ if (class_exists($class)) {
+ try {
+ $moduleobj = new $class($db);
+ } catch (Exception $e) {
+ $error++;
+ dol_print_error($db, $e->getMessage());
+ }
+ }
+ $menus = $moduleobj->menu;
+ $counter = 0 ;
+ foreach ($menus as $menu) {
+ if ($menu['leftmenu'] == strtolower($module).'_'.strtolower($objectname)) {
+ $counter++;
+ }
+ }
+ if (!$counter) {
+ dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */'));
+ }
// Add module descriptor to list of files to replace "MyObject' string with real name of object.
$filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
}
@@ -1728,6 +1747,16 @@ if ($dirins && $action == 'confirm_deletemodule') {
}
if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
+ // check if module is enabled (if it's disabled and send msg event)
+ if (isModEnabled(strtolower($module))) {
+ $result = unActivateModule(strtolower($module));
+ dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
+ if ($result) {
+ setEventMessages($result, null, 'errors');
+ }
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
+ setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
+ }
if (preg_match('/[^a-z0-9_]/i', $objectname)) {
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
@@ -1766,53 +1795,43 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
);
//menu for the object selected
- $stringtoedit = "\$this->menu[\$r++]=array(
- // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
- 'fk_menu'=>'fk_mainmenu=".strtolower($module)."',
- // This is a Left menu entry
- 'type'=>'left',
- 'titre'=>'List ".ucfirst($objectname)."',
- 'mainmenu'=>'".strtolower($module)."',
- 'leftmenu'=>'".strtolower($module)."_".strtolower($objectname)."',
- 'url'=>'/".strtolower($module)."/".strtolower($objectname)."_list.php',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
- 'langs'=>'".strtolower($module)."@".strtolower($module)."',
- 'position'=>1100+\$r,
- // Define condition to show or hide menu entry. Use '\$conf->".strtolower($module)."->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
- 'enabled'=>'\$conf->".strtolower($module)."->enabled',
- // Use 'perms'=>'\$user->rights->".strtolower($module)."->level1->level2' if you want your menu with a permission rules
- 'perms'=>'1',
- 'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
- 'user'=>2,
- );
- \$this->menu[\$r++]=array(
- // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
- 'fk_menu'=>'fk_mainmenu=".strtolower($module).",fk_leftmenu=".strtolower($module)."_".strtolower($objectname)."',
- // This is a Left menu entry
- 'type'=>'left',
- 'titre'=>'New ".ucfirst($objectname)."',
- 'mainmenu'=>'".strtolower($module)."',
- 'leftmenu'=>'".strtolower($module)."_".strtolower($objectname)."',
- 'url'=>'/".strtolower($module)."/".strtolower($objectname)."_card.php?action=create',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
- 'langs'=>'".strtolower($module)."@".strtolower($module)."',
- 'position'=>1100+\$r,
- // Define condition to show or hide menu entry. Use '\$conf->".strtolower($module)."->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
- 'enabled'=>'\$conf->".strtolower($module)."->enabled',
- // Use 'perms'=>'\$user->rights->".strtolower($module)."->level1->level2' if you want your menu with a permission rules
- 'perms'=>'1',
- 'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
- 'user'=>2
- );";
+ // load class and check if menu exist for this object
+ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
+ dol_include_once($pathtofile);
+ $class = 'mod'.$module;
+ if (class_exists($class)) {
+ try {
+ $moduleobj = new $class($db);
+ } catch (Exception $e) {
+ $error++;
+ dol_print_error($db, $e->getMessage());
+ }
+ }
+ $menus = $moduleobj->menu;
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
- $check = dolReplaceInFile($moduledescriptorfile, array($stringtoedit => ''));
- if ($check > 0) {
- dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($objectname).'*/' => ''));
+ foreach ($menus as $menu) {
+ if ($menu['type'] == 'left' && $menu['leftmenu'] == strtolower($module).'_'.strtolower($objectname)) {
+ $left="\$this->menu[\$r++]=array(
+ 'fk_menu'=>'".$menu['fk_menu']."',
+ 'type'=>'".$menu['type']."',
+ 'titre'=>'".$menu['titre']."',
+ 'mainmenu'=>'".$menu['mainmenu']."',
+ 'leftmenu'=>'".$menu['leftmenu']."',
+ 'url'=>'".$menu['url']."',
+ 'langs'=>'".$menu['langs']."',
+ 'position'=>1100+\$r,
+ 'enabled'=>'".$menu['enabled']."',
+ 'perms'=>'".$menu['perms']."',
+ 'target'=>'".$menu['target']."',
+ 'user'=>".$menu['user'].",
+ );";
+ dolReplaceInFile($moduledescriptorfile, array($left => ''));
+ }
}
+ // Remarque : "\n" not handling yet
+ $check = dolReplaceInFile($moduledescriptorfile, array('/*LEFTMENU '.strtoupper($objectname).'*/'."\n" => '',"\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n" => ''));
// regenerate permissions and delete them
$rights = "
@@ -1994,8 +2013,9 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
$existRight = 0;
$allObject = array();
- $nbOfPermissions = count($permissions);
- for ($i =0; $i<$nbOfPermissions; $i++) {
+ $countPerms = count($permissions);
+
+ for ($i =0; $i<$countPerms; $i++) {
if ($permissions[$i][4] == $objectForPerms) {
$counter++;
if (count($permsForObject) < 3) {
@@ -2004,9 +2024,10 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
}
$allObject[] = $permissions[$i][4];
}
- $nbOfpermsInObj = count($permsForObject);
+
// check if label of object already exists
- for ($j = 0; $j<$nbOfpermsInObj; $j++) {
+ $countPermsObj = count($permsForObject);
+ for ($j = 0; $j<$countPermsObj; $j++) {
if (in_array($label, $permsForObject[$j])) {
$existRight++;
setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
@@ -2037,6 +2058,7 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
";
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
if (!$existRight) {
+ //var_dump(1);exit;
dolReplaceInFile($moduledescriptorfile, array('/*END '.strtoupper($objectForPerms).'*/' => $rightToAdd.'/*END '.strtoupper($objectForPerms).'*/'));
setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
}
@@ -2099,13 +2121,18 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
$x1 = $permissions[$r-1][1];
$x2 = $permissions[$r-1][4];
$x3 = $permissions[$r-1][5];
- //check existing object permission
- $permsForObject =array();
+ //check existing object permission
+ $counter = 0;
+ $permsForObject =array();
+ $permissions = $moduleobj->rights;
+ $firstRight = 0;
+ $existRight = 0;
+ $allObject = array();
- $allObject = array();
- $nbOfPermissions = count($permissions);
- for ($i =0; $i<$nbOfPermissions; $i++) {
+ $countPerms = count($permissions);
+ for ($i =0; $i<$countPerms; $i++) {
if ($permissions[$i][4] == $objectForPerms) {
+ $counter++;
if (count($permsForObject) < 3) {
$permsForObject[] = $permissions[$i];
}
@@ -2114,8 +2141,8 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
}
if ($label != $x1 && $crud != $x3) {
- $x = count($permsForObject);
- for ($j = 0; $j<$x; $j++) {
+ $countPermsObj = count($permsForObject);
+ for ($j = 0; $j<$countPermsObj; $j++) {
if (in_array($label, $permsForObject[$j])) {
$error++;
setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
@@ -2158,6 +2185,70 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
exit;
}
}
+// Delete permission
+if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) {
+ $error = 0;
+ // load class and check if right exist
+ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
+ dol_include_once($pathtofile);
+ $class = 'mod'.$module;
+ if (class_exists($class)) {
+ try {
+ $moduleobj = new $class($db);
+ } catch (Exception $e) {
+ $error++;
+ dol_print_error($db, $e->getMessage());
+ }
+ }
+
+ $permissions = $moduleobj->rights;
+ $key = (int) GETPOST('permskey', 'int')-1;
+ //get permission want to delete from permissions array
+ $x1 = $permissions[$key][1];
+ $x2 = $permissions[$key][4];
+ $x3 = $permissions[$key][5];
+ //prepare right want to delete
+ $rightTodelete = "
+ \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
+ \$this->rights[\$r][1] = '$x1';
+ \$this->rights[\$r][4] = '$x2';
+ \$this->rights[\$r][5] = '$x3';
+ \$r++;
+ ";
+
+
+ $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
+ $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n\t\t"));
+ if ($check > 0) {
+ //check if all permissions of object was deleted
+ $permsForObj = array();
+ foreach ($permissions as $perms) {
+ $permsForObj[] = $perms[4];
+ }
+ $permsForObj = array_count_values($permsForObj);
+ if ($permsForObj[$permissions[$key][4]] == 1) {
+ $delObjStart = dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($permissions[$key][4].'*/') => '','/*END '.strtoupper($permissions[$key][4].'*/') => ''));
+ }
+ }
+ if (!$error) {
+ // check if module is enabled
+ if (isModEnabled(strtolower($module))) {
+ $result = unActivateModule(strtolower($module));
+ dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
+ if ($result) {
+ setEventMessages($result, null, 'errors');
+ }
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
+ setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
+ setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
+ exit;
+ } else {
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
+ setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
+ exit;
+ }
+ }
+}
// Save file
if ($action == 'savefile' && empty($cancel)) {
$relofcustom = basename($dirins);
@@ -2269,6 +2360,91 @@ if ($action == 'reset' && $user->admin) {
exit;
}
+// delete menu
+if ($dirins && $action == 'confirm_deletemenu' && GETPOST('menukey', 'int')) {
+ // check if module is enabled
+ if (isModEnabled(strtolower($module))) {
+ $result = unActivateModule(strtolower($module));
+ dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
+ if ($result) {
+ setEventMessages($result, null, 'errors');
+ }
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
+ setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
+ }
+ // load class and check if menu exist
+ $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
+ dol_include_once($pathtofile);
+ $class = 'mod'.$module;
+ if (class_exists($class)) {
+ try {
+ $moduleobj = new $class($db);
+ } catch (Exception $e) {
+ $error++;
+ dol_print_error($db, $e->getMessage());
+ }
+ }
+
+ $menus = $moduleobj->menu;
+
+ $key = (int) GETPOST('menukey', 'int');
+ $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
+
+
+ if ($menus[$key]['type'] == 'top') {
+ $menuTop = "
+ \$this->menu[\$r++] = array(
+ 'fk_menu'=>'".$menus[$key]['fk_menu']."',
+ 'type'=>'".$menus[$key]['type']."',
+ 'titre'=>'".$menus[$key]['titre']."',
+ 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
+ 'mainmenu'=>'".$menus[$key]['mainmenu']."',
+ 'leftmenu'=> '',
+ 'url'=>'".$menus[$key]['url']."',
+ 'langs'=>'".$menus[$key]['langs']."',
+ 'position'=>1000 + \$r,
+ 'enabled'=>'isModEnabled(\"".strtolower($module)."\")',
+ 'perms' =>'".$menus[$key]['perms']."',
+ 'target'=>'".$menus[$key]['target']."',
+ 'user'=>".$menus[$key]['user'].",
+ );";
+ $check = dolReplaceInFile($moduledescriptorfile, array($menuTop => '',"\t\t".'/*TOPMENU '.strtolower($menus[$key]['titre']).'*/'."\n" => '', '/*END TOPMENU '.strtolower($menus[$key]['titre']).'*/'."\n\t\t" => ''));
+ }
+ if ($menus[$key]['type'] == 'left') {
+ $left="\$this->menu[\$r++]=array(
+ 'fk_menu'=>'".$menus[$key]['fk_menu']."',
+ 'type'=>'".$menus[$key]['type']."',
+ 'titre'=>'".$menus[$key]['titre']."',
+ 'mainmenu'=>'".$menus[$key]['mainmenu']."',
+ 'leftmenu'=>'".$menus[$key]['leftmenu']."',
+ 'url'=>'".$menus[$key]['url']."',
+ 'langs'=>'".$menus[$key]['langs']."',
+ 'position'=>1100+\$r,
+ 'enabled'=>'".$menus[$key]['enabled']."',
+ 'perms'=>'".$menus[$key]['perms']."',
+ 'target'=>'".$menus[$key]['target']."',
+ 'user'=>".$menus[$key]['user'].",
+ );";
+ $check = dolReplaceInFile($moduledescriptorfile, array($left => ''));
+
+ // check if still had menu created when initial object
+ // if not we delete the comments from file
+ $menuForObj = 0;
+ foreach ($menus as $menu) {
+ if ($menu['leftmenu'] == $menus[$key]['leftmenu']) {
+ $menuForObj++;
+ }
+ }
+ if ($menuForObj == 1) {
+ $extractObjName = explode("_", $menus[$key]['leftmenu']);
+ dolReplaceInFile($moduledescriptorfile, array('/*LEFTMENU '.strtoupper($extractObjName[1]).'*/'."\n" => '','/*END LEFTMENU '.strtoupper($extractObjName[1]).'*/' => ''));
+ }
+ }
+
+ setEventMessages($langs->trans('MenuDeletedSuccessfuly'), null);
+ header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
+ exit;
+}
/*
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index ba1bc47046f..5f58678985a 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1854,7 +1854,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
if ($object->isService()) {
$type = $langs->trans('Service');
}
- //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
+ // print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
// Main official, simple, and not duplicated code
print '