Fixing style errors.

This commit is contained in:
stickler-ci 2023-02-07 13:58:29 +00:00
parent b67a676c89
commit 23d212d9dc

View File

@ -1950,31 +1950,31 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
dol_include_once($pathtofile); dol_include_once($pathtofile);
$class = 'mod'.$module; $class = 'mod'.$module;
if (class_exists($class)) { if (class_exists($class)) {
try { try {
$moduleobj = new $class($db); $moduleobj = new $class($db);
} catch (Exception $e) { } catch (Exception $e) {
$error++; $error++;
dol_print_error($db, $e->getMessage()); dol_print_error($db, $e->getMessage());
} }
} }
// verify informations entred // verify informations entred
if (!GETPOST('label','alpha')) { if (!GETPOST('label', 'alpha')) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
} }
if (!GETPOST('permissionObj','alpha')) { if (!GETPOST('permissionObj', 'alpha')) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
} }
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
$objectForPerms = strtolower(GETPOST('permissionObj','alpha')); $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
$crud = GETPOST('crud', 'alpha'); $crud = GETPOST('crud', 'alpha');
// check coherence between crud and label // check coherence between crud and label
if ($label == "Read objects of $module" && $crud != "read"){ if ($label == "Read objects of $module" && $crud != "read") {
$crud = "read"; $crud = "read";
$label == "Read objects of $module"; $label == "Read objects of $module";
} }
if ($label == "Create/Update objects of $module" && $crud != "write") { if ($label == "Create/Update objects of $module" && $crud != "write") {
@ -1994,39 +1994,39 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
$existRight = 0; $existRight = 0;
$allObject = array(); $allObject = array();
for ($i =0; $i<count($permissions); $i++) { for ($i =0; $i<count($permissions); $i++) {
if ($permissions[$i][4] == $objectForPerms){ if ($permissions[$i][4] == $objectForPerms) {
$counter++; $counter++;
if (count($permsForObject) < 3){ if (count($permsForObject) < 3) {
$permsForObject[] = $permissions[$i]; $permsForObject[] = $permissions[$i];
} }
} }
$allObject[] = $permissions[$i][4]; $allObject[] = $permissions[$i][4];
} }
// check if label of object already exists // check if label of object already exists
for ($j = 0; $j<count($permsForObject); $j++){ for ($j = 0; $j<count($permsForObject); $j++) {
if (in_array($label,$permsForObject[$j])){ if (in_array($label, $permsForObject[$j])) {
$existRight++; $existRight++;
setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
} }
} }
// if not found permission for the object // if not found permission for the object
if (!in_array($objectForPerms,array_unique($allObject))){ if (!in_array($objectForPerms, array_unique($allObject))) {
$firstRight++; $firstRight++;
$existRight = 0; $existRight = 0;
} }
if (!$error) { if (!$error) {
if (isModEnabled(strtolower($module))){ if (isModEnabled(strtolower($module))) {
$result = unActivateModule(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); dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
if ($result) { if ($result) {
setEventMessages($result, null, 'errors'); setEventMessages($result, null, 'errors');
} }
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null,'warnings'); setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
} }
//prepare stirng to add //prepare stirng to add
$rightToAdd = " $rightToAdd = "
@ -2037,24 +2037,22 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
\$r++; \$r++;
"; ";
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
if (!$existRight){ if (!$existRight) {
//var_dump(1);exit; //var_dump(1);exit;
dolReplaceInFile($moduledescriptorfile, array('/*END '.strtoupper($objectForPerms).'*/' => $rightToAdd.'/*END '.strtoupper($objectForPerms).'*/')); dolReplaceInFile($moduledescriptorfile, array('/*END '.strtoupper($objectForPerms).'*/' => $rightToAdd.'/*END '.strtoupper($objectForPerms).'*/'));
setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null); setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
} }
if ($firstRight){ if ($firstRight) {
//var_dump(array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */"));exit; //var_dump(array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */"));exit;
dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */")); dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */"));
setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null); setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
} }
} }
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
exit; exit;
} }
// Delete permission // Delete permission
if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) { if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) {
$error = 0; $error = 0;
// load class and check if right exist // load class and check if right exist
@ -2062,16 +2060,16 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
dol_include_once($pathtofile); dol_include_once($pathtofile);
$class = 'mod'.$module; $class = 'mod'.$module;
if (class_exists($class)) { if (class_exists($class)) {
try { try {
$moduleobj = new $class($db); $moduleobj = new $class($db);
} catch (Exception $e) { } catch (Exception $e) {
$error++; $error++;
dol_print_error($db, $e->getMessage()); dol_print_error($db, $e->getMessage());
} }
} }
$permissions = $moduleobj->rights; $permissions = $moduleobj->rights;
$key = (int)GETPOST('permskey','int')-1; $key = (int) GETPOST('permskey', 'int')-1;
//get permission want to delete from permissions array //get permission want to delete from permissions array
$x1 = $permissions[$key][1]; $x1 = $permissions[$key][1];
$x2 = $permissions[$key][4]; $x2 = $permissions[$key][4];
@ -2084,41 +2082,40 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
\$this->rights[\$r][5] = '$x3'; \$this->rights[\$r][5] = '$x3';
\$r++; \$r++;
"; ";
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
$check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n\t\t")); $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n\t\t"));
if ($check > 0) { if ($check > 0) {
//check if all permissions of object was deleted //check if all permissions of object was deleted
$permsForObj = array(); $permsForObj = array();
foreach($permissions as $perms){ foreach ($permissions as $perms) {
$permsForObj[] = $perms[4]; $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');
exit;
}
else{
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
exit;
}
} }
$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');
exit;
} else {
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
exit;
}
}
} }
// Update permission // Update permission
@ -2129,30 +2126,30 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
dol_include_once($pathtofile); dol_include_once($pathtofile);
$class = 'mod'.$module; $class = 'mod'.$module;
if (class_exists($class)) { if (class_exists($class)) {
try { try {
$moduleobj = new $class($db); $moduleobj = new $class($db);
} catch (Exception $e) { } catch (Exception $e) {
$error++; $error++;
dol_print_error($db, $e->getMessage()); dol_print_error($db, $e->getMessage());
} }
} }
// verify informations entred // verify informations entred
if (!GETPOST('label','alpha')) { if (!GETPOST('label', 'alpha')) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
} }
if (!GETPOST('permissionObj','alpha')) { if (!GETPOST('permissionObj', 'alpha')) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
} }
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
$objectForPerms = strtolower(GETPOST('permissionObj','alpha')); $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
$crud = GETPOST('crud', 'alpha'); $crud = GETPOST('crud', 'alpha');
if ($label == "Read objects of $module" && $crud != "read"){ if ($label == "Read objects of $module" && $crud != "read") {
$crud = "read"; $crud = "read";
$label == "Read objects of $module"; $label == "Read objects of $module";
} }
if ($label == "Create/Update objects of $module" && $crud != "write") { if ($label == "Create/Update objects of $module" && $crud != "write") {
@ -2165,7 +2162,7 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
} }
$permissions = $moduleobj->rights; $permissions = $moduleobj->rights;
$r =(int)GETPOST('counter'); $r =(int) GETPOST('counter');
//get permission want to delete from permissions array //get permission want to delete from permissions array
$x1 = $permissions[$r-1][1]; $x1 = $permissions[$r-1][1];
$x2 = $permissions[$r-1][4]; $x2 = $permissions[$r-1][4];
@ -2177,26 +2174,26 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
$firstRight = 0; $firstRight = 0;
$existRight = 0; $existRight = 0;
$allObject = array(); $allObject = array();
for ($i =0; $i<count($permissions); $i++) { for ($i =0; $i<count($permissions); $i++) {
if ($permissions[$i][4] == $objectForPerms){ if ($permissions[$i][4] == $objectForPerms) {
$counter++; $counter++;
if (count($permsForObject) < 3){ if (count($permsForObject) < 3) {
$permsForObject[] = $permissions[$i]; $permsForObject[] = $permissions[$i];
}
}
$allObject[] = $permissions[$i][4];
}
if ($label != $x1 && $crud != $x3){
for ($j = 0; $j<count($permsForObject); $j++){
if (in_array($label,$permsForObject[$j])){
$error++;
setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
}
} }
} }
$allObject[] = $permissions[$i][4];
}
if ($label != $x1 && $crud != $x3) {
for ($j = 0; $j<count($permsForObject); $j++) {
if (in_array($label, $permsForObject[$j])) {
$error++;
setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
}
}
}
//prepare right want to delete //prepare right want to delete
$right = " $right = "
\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
@ -2205,7 +2202,7 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
\$this->rights[\$r][5] = '$x3'; \$this->rights[\$r][5] = '$x3';
\$r++; \$r++;
"; ";
$rightUpdated = " $rightUpdated = "
\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
\$this->rights[\$r][1] = '$label'; \$this->rights[\$r][1] = '$label';
@ -2213,26 +2210,24 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
\$this->rights[\$r][5] = '$crud'; \$this->rights[\$r][5] = '$crud';
\$r++; \$r++;
"; ";
if(!$error){ if (!$error) {
if (isModEnabled(strtolower($module))) {
if (isModEnabled(strtolower($module))){ $result = unActivateModule(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);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); if ($result) {
if ($result) { setEventMessages($result, null, 'errors');
setEventMessages($result, null, 'errors');
}
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null,'warnings');
} }
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
$check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated));
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null); setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
exit;
} }
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
$check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated));
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
exit;
}
} }
// Save file // Save file
if ($action == 'savefile' && empty($cancel)) { if ($action == 'savefile' && empty($cancel)) {