From f55510a02ec165a49985c1eb34916369c6d19da0 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Mon, 12 Jun 2023 14:16:09 +0200 Subject: [PATCH] add script for complet label field --- htdocs/core/lib/modulebuilder.lib.php | 23 +-- htdocs/modulebuilder/index.php | 212 +++++++++++++------------- 2 files changed, 112 insertions(+), 123 deletions(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 2f416e2e296..fce9702d6c9 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -537,9 +537,9 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $ } else { $permsToadd = array(); $perms = array( - 'read' => 'Read objects of '.ucfirst($module), - 'write' => 'Create/Update objects of '.ucfirst($module), - 'delete' => 'Delete objects of '.ucfirst($module) + 'read' => 'Read '.$objectname.' object of '.ucfirst($module), + 'write' => 'Create/Update '.$objectname.' object of '.ucfirst($module), + 'delete' => 'Delete '.$objectname.' object of '.ucfirst($module) ); $i = 0; foreach ($perms as $index => $value) { @@ -681,8 +681,8 @@ function writePropsInAsciiDoc($file, $objectname, $destfile) $table .= implode("|", $values) . "\n"; } // end table - $table .= "|==="; - $table .= "__ end table for object $objectname"; + $table .= "|===\n"; + $table .= "__ end table for object $objectname\n"; //write in file $writeInFile = dolReplaceInFile($destfile, array('== DATA SPECIFICATIONS'=> $table)); if ($writeInFile<0) { @@ -925,16 +925,6 @@ function removeObjectFromApiFile($file, $objectname, $modulename) return 1; } -/** - * Compare menus by their object - * @param mixed $a first value - * @param mixed $b seconde value - * @return int 1 if OK, -1 if KO - */ -function compareMenus($a, $b) -{ - return strcmp($a['fk_menu'], $b['fk_menu']); -} /** * @param string $file path of filename @@ -995,9 +985,6 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) $allMenus = getFromFile($file, $beginMenu, $endMenu); dolReplaceInFile($file, array($allMenus => '')); - // orders menu with other menus that have the same object - usort($menus, 'compareMenus'); - //prepare each menu and stock them in string $str_menu = ""; foreach ($menus as $index =>$menu) { diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index d6527adc0a8..9056b129d6d 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2019,20 +2019,6 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha')); $crud = GETPOST('crud', 'alpha'); - // check coherence between crud and label - if ($label == "Read objects of $module" && $crud != "read") { - $crud = "read"; - $label == "Read objects of $module"; - } - if ($label == "Create/Update objects of $module" && $crud != "write") { - $crud = "write"; - $label == "Create/Update objects of $module"; - } - if ($label == "Delete objects of $module" && $crud != "delete") { - $crud = "delete"; - $label == "Delete objects of $module"; - } - //check existing object permission $counter = 0; $permsForObject =array(); @@ -2054,9 +2040,9 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { // check if label of object already exists $countPermsObj = count($permsForObject); for ($j = 0; $j<$countPermsObj; $j++) { - if (in_array($label, $permsForObject[$j])) { + if (in_array($crud, $permsForObject[$j])) { $error++; - setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); + setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($crud), $langs->transnoentities($objectForPerms)), null, 'errors'); } } @@ -4688,24 +4674,24 @@ if ($module == 'initmodule') { print ''; print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); - print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); print "\n"; //form for add new right print ''; - print ''; - print ''; - print ''; + print ''; - print ''; + print ''; + foreach ($crud as $key => $val) { + print ''; + } + print ''; + + print ''; - print ''; print ''; print ''; @@ -4730,85 +4713,78 @@ if ($module == 'initmodule') { $i = 0; foreach ($perms as $perm) { $i++; - 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 ''; + + // 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 ''; + foreach ($crud as $i=> $x) { + if ($perm[5] != $i) { + print ''; } - print ''; - - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print '
'; - print ''; - print ''; - - print '
'; - print ''; - } else { - print ''; - - print ''; - print dol_escape_htmltag($perm[0]); - print ''; - - print ''; - print $langs->trans($perm[1]); - print ''; - - print ''; - print dol_escape_htmltag($perm[4]); - print ''; - - print ''; - print $perm[5]; - print ''; - - print ''; - print ''.img_edit().''; - print ''.img_delete().''; - - print ''; - - print ''; } + print ''; + print ''; + + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'; + print ''; + print ''; + + print ''; + print ''; + } else { + print ''; + + print ''; + print dol_escape_htmltag($perm[0]); + print ''; + + print ''; + print ($perm[5] == 'write' ? $langs->trans($crud['write']): ucfirst($langs->trans($perm[5]))); + print ''; + + print ''; + print dol_escape_htmltag(ucfirst($perm[4])); + print ''; + + print ''; + print $langs->trans($perm[1]); + print ''; + + print ''; + print ''.img_edit().''; + print ''.img_delete().''; + + print ''; + + print ''; } } } else { @@ -4819,6 +4795,32 @@ if ($module == 'initmodule') { print ''; print ''; + print ''; } else { $fullpathoffile = dol_buildpath($file, 0);