fix problems in menus for modulebuilder
This commit is contained in:
parent
352ac40d06
commit
8f2076e83e
@ -896,6 +896,17 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
|
|||||||
|
|
||||||
// Init an object
|
// Init an object
|
||||||
if ($dirins && $action == 'initobject' && $module && $objectname) {
|
if ($dirins && $action == 'initobject' && $module && $objectname) {
|
||||||
|
// 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('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings');
|
||||||
|
}
|
||||||
|
|
||||||
$objectname = ucfirst($objectname);
|
$objectname = ucfirst($objectname);
|
||||||
|
|
||||||
$dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
|
$dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
|
||||||
@ -1341,43 +1352,31 @@ 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'=>'mymodule_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(
|
||||||
// '' 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',
|
'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'=>'mymodule_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);
|
||||||
@ -1389,8 +1388,28 @@ if ($dirins && $action == 'initobject' && $module && $objectname) {
|
|||||||
// TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
|
// TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
|
||||||
// TODO Avoid duplicate addition
|
// TODO Avoid duplicate addition
|
||||||
|
|
||||||
dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
|
// 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)) {
|
||||||
|
try {
|
||||||
|
$moduleobj = new $class($db);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$error++;
|
||||||
|
dol_print_error($db, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$menus = $moduleobj->menu;
|
||||||
|
$counter = 0 ;
|
||||||
|
foreach ($menus as $menu) {
|
||||||
|
if ($menu['leftmenu'] == strtolower($module).'_'.strtolower($objectname)) {
|
||||||
|
$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 */'));
|
||||||
|
}
|
||||||
// Add module descriptor to list of files to replace "MyObject' string with real name of object.
|
// Add module descriptor to list of files to replace "MyObject' string with real name of object.
|
||||||
$filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
|
$filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
|
||||||
}
|
}
|
||||||
@ -1728,6 +1747,16 @@ if ($dirins && $action == 'confirm_deletemodule') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
|
if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
|
||||||
|
// check if module is enabled (if it's disabled and send msg event)
|
||||||
|
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 (preg_match('/[^a-z0-9_]/i', $objectname)) {
|
if (preg_match('/[^a-z0-9_]/i', $objectname)) {
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
|
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
|
||||||
@ -1766,53 +1795,43 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//menu for the object selected
|
//menu for the object selected
|
||||||
$stringtoedit = "\$this->menu[\$r++]=array(
|
// load class and check if menu exist for this object
|
||||||
// '' 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
|
$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
|
||||||
'fk_menu'=>'fk_mainmenu=".strtolower($module)."',
|
dol_include_once($pathtofile);
|
||||||
// This is a Left menu entry
|
$class = 'mod'.$module;
|
||||||
'type'=>'left',
|
if (class_exists($class)) {
|
||||||
'titre'=>'List ".ucfirst($objectname)."',
|
try {
|
||||||
'mainmenu'=>'".strtolower($module)."',
|
$moduleobj = new $class($db);
|
||||||
'leftmenu'=>'".strtolower($module)."_".strtolower($objectname)."',
|
} catch (Exception $e) {
|
||||||
'url'=>'/".strtolower($module)."/".strtolower($objectname)."_list.php',
|
$error++;
|
||||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
dol_print_error($db, $e->getMessage());
|
||||||
'langs'=>'".strtolower($module)."@".strtolower($module)."',
|
}
|
||||||
'position'=>1100+\$r,
|
}
|
||||||
// Define condition to show or hide menu entry. Use '\$conf->".strtolower($module)."->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
|
|
||||||
'enabled'=>'\$conf->".strtolower($module)."->enabled',
|
|
||||||
// Use 'perms'=>'\$user->rights->".strtolower($module)."->level1->level2' if you want your menu with a permission rules
|
|
||||||
'perms'=>'1',
|
|
||||||
'target'=>'',
|
|
||||||
// 0=Menu for internal users, 1=external users, 2=both
|
|
||||||
'user'=>2,
|
|
||||||
);
|
|
||||||
\$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=".strtolower($module).",fk_leftmenu=".strtolower($module)."_".strtolower($objectname)."',
|
|
||||||
// This is a Left menu entry
|
|
||||||
'type'=>'left',
|
|
||||||
'titre'=>'New ".ucfirst($objectname)."',
|
|
||||||
'mainmenu'=>'".strtolower($module)."',
|
|
||||||
'leftmenu'=>'".strtolower($module)."_".strtolower($objectname)."',
|
|
||||||
'url'=>'/".strtolower($module)."/".strtolower($objectname)."_card.php?action=create',
|
|
||||||
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
|
|
||||||
'langs'=>'".strtolower($module)."@".strtolower($module)."',
|
|
||||||
'position'=>1100+\$r,
|
|
||||||
// Define condition to show or hide menu entry. Use '\$conf->".strtolower($module)."->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
|
|
||||||
'enabled'=>'\$conf->".strtolower($module)."->enabled',
|
|
||||||
// Use 'perms'=>'\$user->rights->".strtolower($module)."->level1->level2' if you want your menu with a permission rules
|
|
||||||
'perms'=>'1',
|
|
||||||
'target'=>'',
|
|
||||||
// 0=Menu for internal users, 1=external users, 2=both
|
|
||||||
'user'=>2
|
|
||||||
);";
|
|
||||||
|
|
||||||
|
$menus = $moduleobj->menu;
|
||||||
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
$moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
|
||||||
|
|
||||||
$check = dolReplaceInFile($moduledescriptorfile, array($stringtoedit => ''));
|
foreach ($menus as $menu) {
|
||||||
if ($check > 0) {
|
if ($menu['type'] == 'left' && $menu['leftmenu'] == strtolower($module).'_'.strtolower($objectname)) {
|
||||||
dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($objectname).'*/' => ''));
|
$left="\$this->menu[\$r++]=array(
|
||||||
|
'fk_menu'=>'".$menu['fk_menu']."',
|
||||||
|
'type'=>'".$menu['type']."',
|
||||||
|
'titre'=>'".$menu['titre']."',
|
||||||
|
'mainmenu'=>'".$menu['mainmenu']."',
|
||||||
|
'leftmenu'=>'".$menu['leftmenu']."',
|
||||||
|
'url'=>'".$menu['url']."',
|
||||||
|
'langs'=>'".$menu['langs']."',
|
||||||
|
'position'=>1100+\$r,
|
||||||
|
'enabled'=>'".$menu['enabled']."',
|
||||||
|
'perms'=>'".$menu['perms']."',
|
||||||
|
'target'=>'".$menu['target']."',
|
||||||
|
'user'=>".$menu['user'].",
|
||||||
|
);";
|
||||||
|
dolReplaceInFile($moduledescriptorfile, array($left => ''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Remarque : "\n" not handling yet
|
||||||
|
$check = dolReplaceInFile($moduledescriptorfile, array('/*LEFTMENU '.strtoupper($objectname).'*/'."\n" => '',"\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n" => ''));
|
||||||
|
|
||||||
// regenerate permissions and delete them
|
// regenerate permissions and delete them
|
||||||
$rights = "
|
$rights = "
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user