From 03d056319ca481dff567702c425b6c0140e640fd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 18 Feb 2014 20:49:22 +0100 Subject: [PATCH] Qual: Clean code for adding menu entries into Modules system admin entry. New: Add entry for admin page Mass barcode init. --- htdocs/core/menus/standard/auguria_menu.php | 28 +++++++++++++++++---- htdocs/core/menus/standard/eldy.lib.php | 4 ++- htdocs/core/modules/modBarcode.class.php | 16 ++++++++++-- htdocs/core/modules/modProduct.class.php | 14 +++++++++++ htdocs/core/modules/modService.class.php | 16 ++++++++++++ htdocs/langs/en_US/admin.lang | 2 ++ htdocs/langs/en_US/products.lang | 2 +- 7 files changed, 73 insertions(+), 9 deletions(-) diff --git a/htdocs/core/menus/standard/auguria_menu.php b/htdocs/core/menus/standard/auguria_menu.php index 74612aa57fd..5f585794d39 100644 --- a/htdocs/core/menus/standard/auguria_menu.php +++ b/htdocs/core/menus/standard/auguria_menu.php @@ -110,11 +110,11 @@ class MenuManager // Modules system tools // TODO Find a way to add parent menu only if child menu exists. For the moment, no other method than hard coded methods. - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules + || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) { if (empty($user->societe_id)) { - //$newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', 'home', 'modulesadmintools'); if ($leftmenu=="modulesadmintools" && $user->admin) { $langs->load("products"); @@ -131,9 +131,27 @@ class MenuManager 'type'=>'left', 'position'=>20 ); - array_unshift($tabMenu,$array_menu_product); - //$newmenu->add("/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ProductVatMassChange"), 1, $user->admin); + array_unshift($tabMenu,$array_menu_product); // add at beginning of array } + if ($leftmenu=="modulesadmintools" && $user->admin) + { + $langs->load("admin"); + $array_menu_product=array( + 'url'=>"/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools", + 'titre'=>$langs->trans("MassBarcodeInit"), + 'enabled'=>($user->admin?true:false), + 'perms'=>($user->admin?true:false), + 'fk_mainmenu'=>'home', + 'fk_leftmenu'=>'modulesadmintools', + 'fk_menu'=>-1, + 'mainmenu'=>'home', + 'leftmenu'=>'modulesadmintools_massbarcode', + 'type'=>'left', + 'position'=>21 + ); + array_unshift($tabMenu,$array_menu_product); // add at beginning of array + } + // Main menu title $array_menu_product=array( 'url'=>"/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", 'titre'=>$langs->trans("ModulesSystemTools"), @@ -146,7 +164,7 @@ class MenuManager 'type'=>'left', 'position'=>20 ); - array_unshift($tabMenu,$array_menu_product); + array_unshift($tabMenu,$array_menu_product); // add at beginning of array } } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 14de23b298f..5a2ae201a0f 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -539,11 +539,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } // Modules system tools - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules + || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) // Some external modules may need to force to have this entry on. { if (empty($user->societe_id)) { $newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', $mainmenu, 'modulesadmintools'); + // Special case: This entry can't be embedded into modules because we need it for both module service and products and we don't want duplicate lines. if ((empty($leftmenu) || $leftmenu=="modulesadmintools") && $user->admin) { $langs->load("products"); diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php index 283d62e2700..92b237236cb 100644 --- a/htdocs/core/modules/modBarcode.class.php +++ b/htdocs/core/modules/modBarcode.class.php @@ -101,14 +101,26 @@ class modBarcode extends DolibarrModules 'leftmenu'=>'barcodeprint', 'type'=>'left', // This is a Left menu entry 'titre'=>'BarCodePrintsheet', - 'url'=>'/barcode/printsheet.php', + 'url'=>'/barcode/printsheet.php?mainmenu=home&leftmenu=modulesadmintools', 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'position'=>200, 'enabled'=>'$conf->barcode->enabled', // 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. 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules 'target'=>'', 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - $r++; + $r++; + + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type'=>'left', // This is a Left menu entry + 'titre'=>'MassBarcodeInit', + 'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools', + 'langs'=>'barcode', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position'=>300, + 'enabled'=>'$conf->barcode->enabled && $leftmenu=="modulesadmintools"', // 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. + 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + 'target'=>'', + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both + $r++; } diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index 43cab4f72cf..fed630a40a2 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -129,6 +129,20 @@ class modProduct extends DolibarrModules $this->rights[$r][4] = 'export'; $r++; + /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert + $r=0; + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type'=>'left', // This is a Left menu entry + 'titre'=>'ProductVatMassChange', + 'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools', + 'langs'=>'admin', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position'=>300, + 'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // 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. + 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + 'target'=>'', + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both + $r++; + */ // Exports //-------- diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php index eb472a25799..780a32ad45c 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -114,6 +114,22 @@ class modService extends DolibarrModules $r++; + /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert + $r=0; + $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode + 'type'=>'left', // This is a Left menu entry + 'titre'=>'ProductVatMassChange', + 'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools', + 'langs'=>'admin', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + 'position'=>300, + 'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // 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. + 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + 'target'=>'', + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both + $r++; + */ + + // Exports //-------- $r=0; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index ae4d11548aa..6d00a3d89bc 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -347,6 +347,8 @@ GetSecuredUrl=Get calculated URL ButtonHideUnauthorized=Hide buttons for unauthorized actions instead of showing disabled buttons ProductVatMassChange=Mass VAT change ProductVatMassChangeDesc=This page can be used to modify a VAT rate defined on products or services from a value to another. Warning, this change is done on all database. +MassBarcodeInit=Mass barcode init +MassBarcodeInitDesc=This page can be used to initialize a barcode on objects that does not have barcode defined. Check before that setup of module barcode is complete. OldVATRates=Old VAT rate NewVATRates=New VAT rate PriceBaseTypeToChange=Modify on prices with base reference value defined on diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 96fdf76379b..abe1ee6ec3d 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -217,4 +217,4 @@ DefinitionOfBarCodeForThirdpartyNotComplete=Definition of type or value of bar c BarCodeDataForProduct=Barcode information of product %s : BarCodeDataForThirdparty=Barcode information of thirdparty %s : BarcodeStickersMask=xxx - +