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