diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 582fddd83df..d386fda721c 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); @@ -1262,7 +1274,10 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { \$this->rights[\$r][5] = 'delete'; \$r++; "; - dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); + $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php'; + if (!$existRight) { + dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); + } } } @@ -1429,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.'>' : '') @@ -2036,7 +2051,7 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { // if not found permission for the object if (!in_array($objectForPerms, array_unique($allObject))) { $firstRight++; - $existRight = 0; + $existRight++; } if (!$error) { if (isModEnabled(strtolower($module))) { @@ -2058,11 +2073,10 @@ 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); } - if ($firstRight) { + if ($firstRight>0) { dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null); } @@ -4720,8 +4734,8 @@ if ($module == 'initmodule') { print '
'; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; @@ -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 ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + if ($perm[4] != 'myobject') { + // section for editing right + if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + for ($i = 0; $i<3; $i++) { + if ($perm[1] != $labels[$i]) { + print ''; + } } - } - print ''; + print ''; - print ''; + print ''; - print ''; - print ''; + print ''; + for ($i = 0; $i<3; $i++) { + if ($perm[5] != $crud[$i]) { + print ''; + } } - } - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - print '
'; - print ''; - print ''; + print ''; + print ''; + print '
'; + print ''; + print ''; - print '
'; - print ''; - } else { - print ''; + print ''; + print ''; + } else { + print ''; - print ''; - print $perm[0]; - print ''; + print ''; + print $perm[0]; + print ''; - print ''; - print $langs->trans($perm[1]); - print ''; + print ''; + print $langs->trans($perm[1]); + print ''; - print ''; - print $perm[4]; - print ''; + print ''; + print $perm[4]; + print ''; - print ''; - print $perm[5]; - print ''; + print ''; + print $perm[5]; + print ''; - print ''; - if ($perm[4] != 'myobject') { + print ''; print ''.img_edit().''; print ''.img_delete().''; - } - print ''; - print ''; + print ''; + + print ''; + } } } } else {