diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 93550e2c928..28183dfd571 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1942,6 +1942,70 @@ if ($dirins && $action == 'generatepackage') { } +// 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")); + 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); + //var_dump($permsForObj[$permissions[$key][4]]);exit; + 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'); + } 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);