Debug modulebuilder
This commit is contained in:
parent
009288ad4d
commit
bd066b3211
@ -432,7 +432,7 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" box
|
|||||||
while (($file = readdir($handle)) !== false) {
|
while (($file = readdir($handle)) !== false) {
|
||||||
$reg = array();
|
$reg = array();
|
||||||
if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $file, $reg)) {
|
if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $file, $reg)) {
|
||||||
if (preg_match('/\.back$/', $file)) {
|
if (preg_match('/\.back$/', $file) || preg_match('/^(.+)\.disabled\.php/', $file)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1788,7 +1788,9 @@ function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $di
|
|||||||
if (empty($conf->use_javascript_ajax)) {
|
if (empty($conf->use_javascript_ajax)) {
|
||||||
$out .= ' href="'.DOL_URL_ROOT.$url.'" target="_blank"';
|
$out .= ' href="'.DOL_URL_ROOT.$url.'" target="_blank"';
|
||||||
} elseif ($jsonopen) {
|
} elseif ($jsonopen) {
|
||||||
$out .= ' onclick="javascript:'.$jsonopen.'"';
|
$out .= ' href="#" onclick="javascript:'.$jsonopen.'"';
|
||||||
|
} else {
|
||||||
|
$out .= ' href="#"';
|
||||||
}
|
}
|
||||||
$out .= '>'.$buttonstring.'</a>';
|
$out .= '>'.$buttonstring.'</a>';
|
||||||
|
|
||||||
|
|||||||
@ -174,3 +174,6 @@ MenuDeletedSuccessfuly=Menu has been successfully deleted
|
|||||||
MenuAddedSuccessfuly=Menu has been successfully added
|
MenuAddedSuccessfuly=Menu has been successfully added
|
||||||
MenuUpdatedSuccessfuly=Menu has been successfully updated
|
MenuUpdatedSuccessfuly=Menu has been successfully updated
|
||||||
ApiObjectDeleted=API for object %s has been successfully deleted
|
ApiObjectDeleted=API for object %s has been successfully deleted
|
||||||
|
CRUDRead=Read
|
||||||
|
CRUDCreateWrite=Create or Update
|
||||||
|
FailedToAddCodeIntoDescriptor=Failed to add code into descriptor. Check that the string comment "%s" is still present into the file.
|
||||||
@ -924,19 +924,17 @@ if ($dirins && $action == 'addlanguage' && !empty($module)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove/delete File
|
// Remove/delete File
|
||||||
if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
|
if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
|
||||||
$objectname = $tabobj;
|
$objectname = $tabobj;
|
||||||
|
|
||||||
$relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
|
$relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
|
||||||
$file_api = $dirins."/".$relativefilename;
|
|
||||||
|
|
||||||
//check if have more than one object
|
// Scan dir class to detect all classes of module $module and save them into $objects[]
|
||||||
$dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
|
$dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
|
||||||
$destdir = $dirins.'/'.strtolower($module);
|
$destdir = $dirins.'/'.strtolower($module);
|
||||||
$listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
|
$listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
|
||||||
$objects = array();
|
$objects = array();
|
||||||
|
|
||||||
foreach ($listofobject as $fileobj) {
|
foreach ($listofobject as $fileobj) {
|
||||||
if (preg_match('/^api_/', $fileobj['name'])) {
|
if (preg_match('/^api_/', $fileobj['name'])) {
|
||||||
continue;
|
continue;
|
||||||
@ -952,115 +950,57 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$existObj = 0;
|
// Now we delete the file
|
||||||
$file = file_get_contents($file_api);
|
if ($relativefilename) {
|
||||||
$objs = array();
|
$dirnametodelete = dirname($relativefilename);
|
||||||
if (str_contains($file, $objectname)) {
|
$filetodelete = $dirins.'/'.$relativefilename;
|
||||||
$existObj++;
|
$dirtodelete = $dirins.'/'.$dirnametodelete;
|
||||||
}
|
|
||||||
if ($existObj && count($objects) > 1) {
|
$result = dol_delete_file($filetodelete);
|
||||||
$begin = '/*CRUD FOR '.strtoupper($objectname).'*/';
|
if (!$result) {
|
||||||
$end = '/*END CRUD FOR '.strtoupper($objectname).'*/';
|
setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
|
||||||
$varcomentedDel = "\t * @var ".$objectname." \$".strtolower($objectname)." {@type ".$objectname."}";
|
} else {
|
||||||
$propsDel .= "\tpublic \$".strtolower($objectname).";";
|
// If we delete a .sql file, we delete also the other .sql file
|
||||||
$constructObjDel .= "\t\t\$this->".strtolower($objectname)."= new ".$objectname."(\$this->db);";
|
if (preg_match('/\.sql$/', $relativefilename)) {
|
||||||
$content = file($file_api);
|
if (preg_match('/\.key\.sql$/', $relativefilename)) {
|
||||||
// for delete property and the initialization from the construct
|
$relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
|
||||||
foreach ($content as $lineNumber => &$lineContent) {
|
$filetodelete = $dirins.'/'.$relativefilename;
|
||||||
if (strpos($lineContent, $varcomentedDel) !== false) {
|
$result = dol_delete_file($filetodelete);
|
||||||
$lineContent = '';
|
} elseif (preg_match('/\.sql$/', $relativefilename)) {
|
||||||
|
$relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
|
||||||
|
$filetodelete = $dirins.'/'.$relativefilename;
|
||||||
|
$result = dol_delete_file($filetodelete);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (strpos($lineContent, $propsDel) !== false) {
|
|
||||||
$lineContent = '';
|
if (dol_is_dir_empty($dirtodelete)) {
|
||||||
|
dol_delete_dir($dirtodelete);
|
||||||
}
|
}
|
||||||
if (strpos($lineContent, $constructObjDel) !== false) {
|
|
||||||
$lineContent = '';
|
// Update descriptor file to comment file
|
||||||
|
if (in_array($tab, array('css', 'js'))) {
|
||||||
|
$srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
||||||
|
$arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
|
||||||
|
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$allContent = implode("", $content);
|
if (preg_match('/_extrafields/', $relativefilename)) {
|
||||||
file_put_contents($file_api, $allContent);
|
// Now we update the object file to set $isextrafieldmanaged to 0
|
||||||
// for delete methods of object
|
$srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
|
||||||
$handle = fopen($file_api, "r");
|
$arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
|
||||||
$i = 1;
|
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
||||||
$lines = array();
|
|
||||||
while (($line = fgets($handle)) !== false) {
|
|
||||||
//search line begin
|
|
||||||
if (strpos($line, $begin) !== false) {
|
|
||||||
$start_line = $i;
|
|
||||||
// Copy lines until the end on array
|
|
||||||
while (($line = fgets($handle)) !== false) {
|
|
||||||
if (strpos($line, $end) !== false) {
|
|
||||||
$end_line = $i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$lines[] = $line;
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
$allContent = implode("", $lines);
|
|
||||||
//var_dump($allContent);exit;
|
|
||||||
$check = dolReplaceInFile($file_api, array($allContent => ''));
|
|
||||||
if ($check) {
|
|
||||||
dolReplaceInFile($file_api, array($begin => '', $end => ''));
|
|
||||||
setEventMessages($langs->trans("ApiObjectDeleted", $langs->transnoentities($objectname)), null);
|
|
||||||
}
|
|
||||||
fclose($handle);
|
|
||||||
}
|
|
||||||
if (count($objects) == 1 && $existObj) {
|
|
||||||
if ($relativefilename) {
|
|
||||||
$dirnametodelete = dirname($relativefilename);
|
|
||||||
$filetodelete = $dirins.'/'.$relativefilename;
|
|
||||||
$dirtodelete = $dirins.'/'.$dirnametodelete;
|
|
||||||
|
|
||||||
$result = dol_delete_file($filetodelete);
|
// Now we update the lib file to set $showtabofpagexxx to 0
|
||||||
if (!$result) {
|
$varnametoupdate = '';
|
||||||
setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
|
$reg = array();
|
||||||
} else {
|
if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
|
||||||
// If we delete a .sql file, we delete also the other .sql file
|
$varnametoupdate = 'showtabofpage'.$reg[1];
|
||||||
if (preg_match('/\.sql$/', $relativefilename)) {
|
}
|
||||||
if (preg_match('/\.key\.sql$/', $relativefilename)) {
|
if ($varnametoupdate) {
|
||||||
$relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
|
$srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
|
||||||
$filetodelete = $dirins.'/'.$relativefilename;
|
$arrayreplacement = array('/\$'.$varnametoupdate.' = 1;/' => '$'.$varnametoupdate.' = 0;');
|
||||||
$result = dol_delete_file($filetodelete);
|
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
||||||
} elseif (preg_match('/\.sql$/', $relativefilename)) {
|
|
||||||
$relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
|
|
||||||
$filetodelete = $dirins.'/'.$relativefilename;
|
|
||||||
$result = dol_delete_file($filetodelete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dol_is_dir_empty($dirtodelete)) {
|
|
||||||
dol_delete_dir($dirtodelete);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update descriptor file to comment file
|
|
||||||
if (in_array($tab, array('css', 'js'))) {
|
|
||||||
$srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
|
||||||
$arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
|
|
||||||
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preg_match('/_extrafields/', $relativefilename)) {
|
|
||||||
// Now we update the object file to set $isextrafieldmanaged to 0
|
|
||||||
$srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
|
|
||||||
$arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
|
|
||||||
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we update the lib file to set $showtabofpagexxx to 0
|
|
||||||
$varnametoupdate = '';
|
|
||||||
$reg = array();
|
|
||||||
if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
|
|
||||||
$varnametoupdate = 'showtabofpage'.$reg[1];
|
|
||||||
}
|
|
||||||
if ($varnametoupdate) {
|
|
||||||
$srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
|
|
||||||
$arrayreplacement = array('/\$'.$varnametoupdate.' = 1;/' => '$'.$varnametoupdate.' = 0;');
|
|
||||||
dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1074,9 +1014,12 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
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');
|
||||||
|
} else {
|
||||||
|
/* FIX ALI header must be after action. Always add an exit after a header.
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
||||||
|
*/
|
||||||
|
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
||||||
}
|
}
|
||||||
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
|
||||||
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$objectname = ucfirst($objectname);
|
$objectname = ucfirst($objectname);
|
||||||
@ -1539,31 +1482,43 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
// Regenerate left menu entry in descriptor for $objectname
|
// Regenerate left menu entry in descriptor for $objectname
|
||||||
$stringtoadd = "
|
$stringtoadd = "
|
||||||
\$this->menu[\$r++]=array(
|
\$this->menu[\$r++]=array(
|
||||||
|
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||||
'fk_menu'=>'fk_mainmenu=mymodule',
|
'fk_menu'=>'fk_mainmenu=mymodule',
|
||||||
|
// This is a Left menu entry
|
||||||
'type'=>'left',
|
'type'=>'left',
|
||||||
'titre'=>'List MyObject',
|
'titre'=>'List MyObject',
|
||||||
'mainmenu'=>'mymodule',
|
'mainmenu'=>'mymodule',
|
||||||
'leftmenu'=>'myobject',
|
'leftmenu'=>'mymodule_myobject',
|
||||||
'url'=>'/mymodule/myobject_list.php',
|
'url'=>'/mymodule/myobject_list.php',
|
||||||
|
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||||
'langs'=>'mymodule@mymodule',
|
'langs'=>'mymodule@mymodule',
|
||||||
'position'=>1100+\$r,
|
'position'=>1100+\$r,
|
||||||
|
// Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
|
||||||
'enabled'=>'\$conf->mymodule->enabled',
|
'enabled'=>'\$conf->mymodule->enabled',
|
||||||
|
// Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||||
'perms'=>'1',
|
'perms'=>'1',
|
||||||
'target'=>'',
|
'target'=>'',
|
||||||
|
// 0=Menu for internal users, 1=external users, 2=both
|
||||||
'user'=>2,
|
'user'=>2,
|
||||||
);
|
);
|
||||||
\$this->menu[\$r++]=array(
|
\$this->menu[\$r++]=array(
|
||||||
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
|
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
|
||||||
|
'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject',
|
||||||
|
// This is a Left menu entry
|
||||||
'type'=>'left',
|
'type'=>'left',
|
||||||
'titre'=>'New MyObject',
|
'titre'=>'New MyObject',
|
||||||
'mainmenu'=>'mymodule',
|
'mainmenu'=>'mymodule',
|
||||||
'leftmenu'=>'myobject',
|
'leftmenu'=>'mymodule_myobject',
|
||||||
'url'=>'/mymodule/myobject_card.php?action=create',
|
'url'=>'/mymodule/myobject_card.php?action=create',
|
||||||
|
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
||||||
'langs'=>'mymodule@mymodule',
|
'langs'=>'mymodule@mymodule',
|
||||||
'position'=>1100+\$r,
|
'position'=>1100+\$r,
|
||||||
|
// Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
|
||||||
'enabled'=>'\$conf->mymodule->enabled',
|
'enabled'=>'\$conf->mymodule->enabled',
|
||||||
|
// Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||||
'perms'=>'1',
|
'perms'=>'1',
|
||||||
'target'=>'',
|
'target'=>'',
|
||||||
|
// 0=Menu for internal users, 1=external users, 2=both
|
||||||
'user'=>2
|
'user'=>2
|
||||||
);\n";
|
);\n";
|
||||||
$stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
|
$stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
|
||||||
@ -1572,13 +1527,14 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
|
|
||||||
$moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
|
$moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
|
||||||
}
|
}
|
||||||
// TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
|
|
||||||
// TODO Avoid duplicate addition
|
|
||||||
|
|
||||||
// load class and check if menu exist with same object name
|
// TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
|
||||||
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
// TODO Avoid duplicate addition
|
||||||
dol_include_once($pathtofile);
|
|
||||||
$class = 'mod'.$module;
|
// load class and check if menu exist with same object name
|
||||||
|
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
||||||
|
dol_include_once($pathtofile);
|
||||||
|
$class = 'mod'.$module;
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
try {
|
try {
|
||||||
$moduleobj = new $class($db);
|
$moduleobj = new $class($db);
|
||||||
@ -1587,8 +1543,8 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
dol_print_error($db, $e->getMessage());
|
dol_print_error($db, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$menus = $moduleobj->menu;
|
$menus = $moduleobj->menu;
|
||||||
$counter = 0 ;
|
$counter = 0 ;
|
||||||
foreach ($menus as $menu) {
|
foreach ($menus as $menu) {
|
||||||
if ($menu['leftmenu'] == strtolower($objectname)) {
|
if ($menu['leftmenu'] == strtolower($objectname)) {
|
||||||
$counter++;
|
$counter++;
|
||||||
@ -1597,8 +1553,9 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
if (!$counter) {
|
if (!$counter) {
|
||||||
dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */'));
|
dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */'));
|
||||||
}
|
}
|
||||||
// Add module descriptor to list of files to replace "MyObject' string with real name of object.
|
|
||||||
$filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
|
// Add module descriptor to list of files to replace "MyObject' string with real name of object.
|
||||||
|
$filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
@ -1940,9 +1897,13 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
|
|||||||
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');
|
||||||
|
$error++;
|
||||||
|
} else {
|
||||||
|
/* TODO ALI Header reidrect must be at end after actions. Also tab=pemrissions looks strange
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
||||||
|
*/
|
||||||
|
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
||||||
}
|
}
|
||||||
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
|
||||||
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
|
||||||
}
|
}
|
||||||
if (preg_match('/[^a-z0-9_]/i', $objectname)) {
|
if (preg_match('/[^a-z0-9_]/i', $objectname)) {
|
||||||
$error++;
|
$error++;
|
||||||
@ -2244,15 +2205,32 @@ 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';
|
||||||
|
|
||||||
|
//var_dump($existRight.' '.$firstRight);exit;
|
||||||
if (!$existRight) {
|
if (!$existRight) {
|
||||||
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>0) {
|
if ($firstRight > 0) {
|
||||||
dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */'));
|
$filecontentbefore = file_get_contents($moduledescriptorfile);
|
||||||
setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
|
|
||||||
|
$result = dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */'));
|
||||||
|
|
||||||
|
$filecontentafter = file_get_contents($moduledescriptorfile);
|
||||||
|
|
||||||
|
if ($filecontentbefore != $filecontentafter) {
|
||||||
|
setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
|
||||||
|
} else {
|
||||||
|
setEventMessages($langs->trans('FailedToAddCodeIntoDescriptor', 'END MODULEBUILDER PERMISSIONS'), null, 'warnings');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearstatcache(true);
|
||||||
|
if (function_exists('opcache_invalidate')) {
|
||||||
|
opcache_reset(); // remove the include cache hell !
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -2336,6 +2314,7 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO ALI Update of permission must be done by rewriting completely the permission section
|
||||||
//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);
|
||||||
@ -2352,6 +2331,7 @@ 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));
|
||||||
@ -2366,8 +2346,14 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e
|
|||||||
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
||||||
$check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated));
|
$check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated));
|
||||||
|
|
||||||
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
|
||||||
setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
|
setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
|
||||||
|
|
||||||
|
clearstatcache(true);
|
||||||
|
if (function_exists('opcache_invalidate')) {
|
||||||
|
opcache_reset(); // remove the include cache hell !
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2377,7 +2363,7 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
|
|||||||
// load class and check if right exist
|
// load class and check if right exist
|
||||||
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
||||||
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);
|
||||||
@ -2387,14 +2373,14 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$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];
|
||||||
$x3 = $permissions[$key][5];
|
$x3 = $permissions[$key][5];
|
||||||
//prepare right want to delete
|
//prepare right want to delete
|
||||||
$rightTodelete = "
|
$rightTodelete = "
|
||||||
\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
|
\$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1);
|
||||||
\$this->rights[\$r][1] = '$x1';
|
\$this->rights[\$r][1] = '$x1';
|
||||||
\$this->rights[\$r][4] = '$x2';
|
\$this->rights[\$r][4] = '$x2';
|
||||||
@ -2402,9 +2388,11 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
|
|||||||
\$r++;
|
\$r++;
|
||||||
";
|
";
|
||||||
|
|
||||||
|
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
||||||
|
|
||||||
|
// TODO ALI The delete must be done by rewriting all content between /* BEGIN MODULEBUILDER PERMISSIONS */ and /* END MODULEBUILDER PERMISSIONS */
|
||||||
|
$check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => "\n\t\t"));
|
||||||
|
|
||||||
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
|
||||||
$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();
|
||||||
@ -2424,13 +2412,20 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p
|
|||||||
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('PermissionDeletedSuccesfuly'), null);
|
setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
|
||||||
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
||||||
|
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
|
||||||
setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
|
setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
|
||||||
|
|
||||||
|
clearstatcache(true);
|
||||||
|
if (function_exists('opcache_invalidate')) {
|
||||||
|
opcache_reset(); // remove the include cache hell !
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3401,7 +3396,8 @@ if ($module == 'initmodule') {
|
|||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
print $moduleobj->numero;
|
print $moduleobj->numero;
|
||||||
print '<span class="opacitymedium">';
|
print '<span class="opacitymedium">';
|
||||||
print ' (<a href="'.DOL_URL_ROOT.'/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeIDsInUse").'</a>';
|
print ' (';
|
||||||
|
print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
|
||||||
print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
|
print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
|
||||||
print '</span>';
|
print '</span>';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
@ -4873,8 +4869,8 @@ if ($module == 'initmodule') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// declared select list for actions and labels permissions
|
// declared select list for actions and labels permissions
|
||||||
$crud = array('Read','Write','Delete');
|
$crud = array('read'=>'CRUDRead', 'write'=>'CRUDCreateWrite', 'delete'=>'Delete');
|
||||||
$labels = array("Read objects of $module","Create/Update objects of $module","Delete objects of $module");
|
$labels = array("Read objects of ".$module, "Create/Update objects of ".$module, "Delete objects of ".$module);
|
||||||
|
|
||||||
$action = GETPOST('action', 'alpha');
|
$action = GETPOST('action', 'alpha');
|
||||||
|
|
||||||
@ -4919,18 +4915,18 @@ if ($module == 'initmodule') {
|
|||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
|
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("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
|
||||||
print_liste_field_titre("Permission", $_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("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
|
||||||
print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
|
print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
//form for add new right
|
//form for add new right
|
||||||
print '<tr>';
|
print '<tr class="small">';
|
||||||
print '<td><input type="text" readonly name="id" value="'.dol_escape_htmltag($moduleobj->numero.sprintf('%02d', $i + count($perms))).'"></td>';
|
print '<td><input type="text" readonly name="id" class="width75" value="'.dol_escape_htmltag($moduleobj->numero.sprintf('%02d', $i + count($perms))).'"></td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print '<select name="label" >';
|
print '<select name="label" >';
|
||||||
print '<option value=""></option>';
|
print '<option value=""></option>';
|
||||||
for ($i = 0; $i<3; $i++) {
|
for ($i = 0; $i < 3; $i++) {
|
||||||
print '<option value="'.dol_escape_htmltag($labels[$i]).'">'.$labels[$i].'</option>';
|
print '<option value="'.dol_escape_htmltag($labels[$i]).'">'.$labels[$i].'</option>';
|
||||||
}
|
}
|
||||||
print '</select></td>';
|
print '</select></td>';
|
||||||
@ -4946,8 +4942,8 @@ if ($module == 'initmodule') {
|
|||||||
|
|
||||||
print '<td><select class="maxwidth" name="crud">';
|
print '<td><select class="maxwidth" name="crud">';
|
||||||
print '<option value=""></option>';
|
print '<option value=""></option>';
|
||||||
for ($i = 0;$i<3;$i++) {
|
foreach ($crud as $key => $val) {
|
||||||
print '<option value="'.$crud[$i].'">'.$langs->trans($crud[$i]).'</option>';
|
print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
@ -5016,7 +5012,7 @@ if ($module == 'initmodule') {
|
|||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven">';
|
||||||
|
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $perm[0];
|
print dol_escape_htmltag($perm[0]);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td>';
|
print '<td>';
|
||||||
@ -5024,7 +5020,7 @@ if ($module == 'initmodule') {
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $perm[4];
|
print dol_escape_htmltag($perm[4]);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td>';
|
print '<td>';
|
||||||
@ -5042,7 +5038,7 @@ if ($module == 'initmodule') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
|
print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user