diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 89dfc8694e3..ec9f05db1bc 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1230,6 +1230,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { ); } if (GETPOST('generatepermissions', 'aZ09')) { + $firstobjectname = 'myobject'; $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; dol_include_once($pathtofile); $class = 'mod'.$module; @@ -1241,9 +1242,20 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { dol_print_error($db, $e->getMessage()); } } - if (empty($firstobjectname)) { + $rights = $moduleobj->rights; + $obj = array(); + $existRight = 0; + foreach ($rights as $right) { + $obj[]= $right[4]; + } + + if (in_array(strtolower($firstobjectname), $obj)) { $rightToadd = preg_replace('/myobject/', $objectname, $rightToadd); } + if (in_array(strtolower($objectname), $obj)) { + $existRight++; + setEventMessages($langs->trans("PermissionAlreadyExist", $langs->transnoentities($objectname)), null, 'errors'); + } if ($objectname != $firstobjectname) { $rightToadd = " \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); @@ -1263,7 +1275,9 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { \$r++; "; $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php'; - dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); + if (!$existRight) { + dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); + } } } @@ -1430,7 +1444,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { 'mon module'=>$module, 'Mon module'=>$module, 'htdocs/modulebuilder/template/'=>strtolower($modulename), - 'myobject'=>strtolower($objectname), + //'myobject'=>strtolower($objectname), 'MyObject'=>$objectname, //'MYOBJECT'=>strtoupper($objectname), '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '') @@ -4772,84 +4786,85 @@ if ($module == 'initmodule') { $i = 0; foreach ($perms as $perm) { $i++; - // section for editing right - if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) { - print '