Merge pull request #25081 from lamrani002/updatePermissionSectionInMB
New script for complet label field inn permissions form
This commit is contained in:
commit
29c509d783
2 changed files with 112 additions and 123 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 '<tr class="liste_titre">';
|
||||
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 "</tr>\n";
|
||||
|
||||
//form for add new right
|
||||
print '<tr class="small">';
|
||||
print '<td><input type="text" readonly name="id" class="width75" value="0"></td>';
|
||||
print '<td>';
|
||||
print '<select name="label" >';
|
||||
print '<option value=""></option>';
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
print '<option value="'.dol_escape_htmltag($labels[$i]).'">'.$labels[$i].'</option>';
|
||||
}
|
||||
print '</select></td>';
|
||||
print '<td><input type="hidden" readonly name="id" class="width75" value="0"></td>';
|
||||
|
||||
print '<td ><select name="permissionObj">';
|
||||
print '<td><select class="maxwidth" name="crud" id="crud">';
|
||||
print '<option value=""></option>';
|
||||
foreach ($crud as $key => $val) {
|
||||
print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td><select name="permissionObj" id="permissionObj">';
|
||||
print '<option value=""></option>';
|
||||
foreach ($objects as $obj) {
|
||||
if ($obj != 'myobject') {
|
||||
|
|
@ -4714,11 +4700,8 @@ if ($module == 'initmodule') {
|
|||
}
|
||||
print '</select></td>';
|
||||
|
||||
print '<td><select class="maxwidth" name="crud">';
|
||||
print '<option value=""></option>';
|
||||
foreach ($crud as $key => $val) {
|
||||
print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
|
||||
}
|
||||
print '<td >';
|
||||
print '<input type="text" name="label" id="label">';
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
|
|
@ -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 '<tr class="oddeven">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="tab" value="permissions">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
|
||||
print '<input type="hidden" name="action" value="update_right">';
|
||||
print '<input type="hidden" name="counter" value="'.$i.'">';
|
||||
|
||||
// section for editing right
|
||||
if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="tab" value="permissions">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
|
||||
print '<input type="hidden" name="action" value="update_right">';
|
||||
print '<input type="hidden" name="counter" value="'.$i.'">';
|
||||
|
||||
|
||||
print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
|
||||
print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
|
||||
|
||||
print '<td class="tdsticky tdstickygray">';
|
||||
print '<input type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
|
||||
print '</td>';
|
||||
print '<td class="tdsticky tdstickygray">';
|
||||
print '<input class="width75" type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<select name="label" >';
|
||||
print '<option value="'.dol_escape_htmltag($perm[1]).'">'.dol_escape_htmltag($perm[1]).'</option>';
|
||||
for ($i = 0; $i<3; $i++) {
|
||||
if ($perm[1] != $labels[$i]) {
|
||||
print '<option value="'.dol_escape_htmltag($labels[$i]).'">'.$labels[$i].'</option>';
|
||||
}
|
||||
print '<td>';
|
||||
print '<select name="crud">';
|
||||
print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
|
||||
foreach ($crud as $i=> $x) {
|
||||
if ($perm[5] != $i) {
|
||||
print '<option value="'.$i.'">'.$langs->trans(ucfirst($x)).'</option>';
|
||||
}
|
||||
print '</select></td>';
|
||||
|
||||
print '<td ><select name="permissionObj">';
|
||||
print '<option value="'.dol_escape_htmltag($perm[4]).'">'.$perm[4].'</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>';
|
||||
print '<select name="crud">';
|
||||
print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
|
||||
for ($i = 0; $i<3; $i++) {
|
||||
if ($perm[5] != $crud[$i]) {
|
||||
print '<option value="'.$crud[$i].'">'.$langs->trans($crud[$i]).'</option>';
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<input class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
|
||||
print '<br>';
|
||||
print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
|
||||
print '</td>';
|
||||
|
||||
print '</form>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
print '<td>';
|
||||
print dol_escape_htmltag($perm[0]);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $langs->trans($perm[1]);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print dol_escape_htmltag($perm[4]);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $perm[5];
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_right&token='.newToken().'&permskey='.urlencode($perm[0]).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
|
||||
print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteright&token='.newToken().'&permskey='.urlencode($i).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
|
||||
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
print '</select>';
|
||||
print '</td>';
|
||||
|
||||
print '<td><select name="permissionObj" >';
|
||||
print '<option value="'.dol_escape_htmltag($perm[4]).'">'.ucfirst($perm[4]).'</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>';
|
||||
print '<input type="text" name="label" value="'.dol_escape_htmltag($perm[1]).'">';
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<input id ="modifyPerm" class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
|
||||
print '<br>';
|
||||
print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
|
||||
print '</td>';
|
||||
|
||||
print '</form>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
print '<td>';
|
||||
print dol_escape_htmltag($perm[0]);
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print ($perm[5] == 'write' ? $langs->trans($crud['write']): ucfirst($langs->trans($perm[5])));
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print dol_escape_htmltag(ucfirst($perm[4]));
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $langs->trans($perm[1]);
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center tdstickyright tdstickyghostwhite">';
|
||||
print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_right&token='.newToken().'&permskey='.urlencode($perm[0]).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
|
||||
print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteright&token='.newToken().'&permskey='.urlencode($i).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
|
||||
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -4819,6 +4795,32 @@ if ($module == 'initmodule') {
|
|||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
print '<script>
|
||||
function updateInputField() {
|
||||
value1 = $("#crud").val();
|
||||
value2 = $("#permissionObj").val();
|
||||
|
||||
// Vérifie si les deux sélections sont faites
|
||||
if ($("#label").val() == "" && value1 && value2) {
|
||||
switch(value1.toLowerCase()){
|
||||
case "read":
|
||||
$("#label").val("Read "+value2+" object of '.ucfirst($module).'")
|
||||
break;
|
||||
case "write":
|
||||
$("#label").val("Create/Update "+value2+" object of '.ucfirst($module).'")
|
||||
break;
|
||||
case "delete":
|
||||
$("#label").val("Delete "+value2+" object of '.ucfirst($module).'")
|
||||
break;
|
||||
default:
|
||||
$("#label").val("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$("#crud, #permissionObj").change(updateInputField);
|
||||
updateInputField();
|
||||
</script>';
|
||||
} else {
|
||||
$fullpathoffile = dol_buildpath($file, 0);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue