-->
Welcome, Guest
Username: Password: Remember me

TOPIC: Help needed in left menu entry of new module.

Help needed in left menu entry of new module. 1 year 11 months ago #32101

  • ALSOFT
  • ALSOFT's Avatar
  • OFFLINE
  • Junior
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
Hi Folks,
I am developing a new module to maintain an online dictionary website from inside the Dolibarr CRM. I have success fully create top menu entry for my module. The top menu entry code inside the mymodule class is....
$this->menu[$r++]=array('fk_menu'=>0,			                // '' 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
								'type'=>'top',			                // This is a Top menu entry
								'titre'=>'ALDictionary',
								'mainmenu'=>'ALDictionary',
								'leftmenu'=>'ALDictionary',
								'url'=>'/ALDictionary/index.php',
								'langs'=>'ALDictionary@ALDictionary',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
								'position'=>1000+$r,
								'enabled'=>$conf->ALDictionary->enabled,	// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
								'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

Now i got stuck with ;left menu entry. I tried several way to to get a left menu entry but did not got. Here is my left menu entry code.
$this->menu[$r++]=array('fk_menu'=>'r=0',
													'type'=>'left',
													'titre'=>'MyWidget',
													'mainmenu'=>'ALDictionary',
													'url'=>'/ALDictionary/scripts/card.php?mainmenu=ALDictionary&leftmenu=ALDictionary&action=create',
													'langs'=>'ALDictionary@ALDictionary',
													'position'=>1000+$r,
													'perms'=>'1',
													'enabled'=>'$conf->ALDictionary->enabled',
													'target'=>'',
													'user'=>2);

While i disable and re enable the module nothing i can see in the left side of the Dolibarr.

Please help me.

left-menu-error.png
The administrator has disabled public write access.

Help needed in left menu entry of new module. 1 year 11 months ago #32104

  • caos30
  • caos30's Avatar
  • OFFLINE
  • Junior
  • Posts: 24
  • Thank you received: 15
  • Karma: 2
Oh man... this is really very tricky if you ask me. I passed about 4 hours trying to get this run for my first module :( The documentation is horrible. I accomplished to render the menu but i never accomplished to exactly control de position. Let me expose it below.

I can show you both good examples. The first one is able to create on the left menu of Commercial (top main menu) the section Purchases with sub menu entries New purchase and List:

DoliPurchasesLeftMenu.png

$this->menus = array();
$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=commercial', 
		'type'=>'left', 
		'titre'=>'purchasesMenuTitle1',
		'mainmenu'=>'commercial',
		'leftmenu'=>'purchases',
		'url'=>'/purchases/purchase_list.php',
		'langs'=>'purchases@purchases',	
		'position'=>13,
		'enabled'=>'1', 
		'perms'=>'($user->rights->produit&&$user->rights->fournisseur)', 
		'target'=>'',
		'user'=>0);

$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=commercial,fk_leftmenu=purchases', 
		'type'=>'left', 
		'titre'=>'purchasesMenuTitle2',
		'mainmenu'=>'commercial',
		'leftmenu'=>'',
		'url'=>'/purchases/purchase_edit.php',
		'langs'=>'purchases@purchases',	
		'position'=>14,
		'enabled'=>'1', 
		'perms'=>'($user->rights->produit&&$user->rights->fournisseur)', 
		'target'=>'',
		'user'=>0);

$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=commercial,fk_leftmenu=purchases', 
		'type'=>'left', 
		'titre'=>'purchasesMenuTitle3',
		'mainmenu'=>'commercial',
		'leftmenu'=>'',
		'url'=>'/purchases/purchase_list.php',
		'langs'=>'purchases@purchases',	
		'position'=>14,
		'enabled'=>'1', 
		'perms'=>'($user->rights->produit&&$user->rights->fournisseur)', 
		'target'=>'',
		'user'=>0);

The second example create for the top main menu Products the submenu entry Stock transfers under section Warehouses, and the sub-submenu entry New stock transfer:

DoliStocktransfers_LeftMenu.png

$this->menus = array();
$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock', 
		'type'=>'left', 
		'titre'=>'stocktransfersMenuTitle2',
		'mainmenu'=>'products',
		'leftmenu'=>'stock',
		'url'=>'/stocktransfers/transfer_list.php',
		'langs'=>'stocktransfers@stocktransfers',
		'position'=>4,
		'enabled'=>'1',
		'perms'=>'($user->rights->stock->mouvement->lire&&$user->rights->produit)', 
		'target'=>'',
		'user'=>0);

$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock', 
		'type'=>'left', 
		'titre'=>'stocktransfersMenuTitle1',
		'mainmenu'=>'products',
		'leftmenu'=>'stock',
		'url'=>'/stocktransfers/transfer_edit.php',
		'langs'=>'stocktransfers@stocktransfers',
		'position'=>5,
		'enabled'=>'1',
		'perms'=>'($user->rights->stock->mouvement->creer&&$user->rights->produit)', 
		'target'=>'',
		'user'=>0);

Indeed, viewing your code i would say that you must modify the element fk_menu of your arrays. It must specify the existing top main menu entry and optionally the existing left menu entry where you wants to appear your entry. The element position it really never work for me, so if you get it run then please share your trick ;)
The administrator has disabled public write access.
The following user(s) said Thank You: Peter A. Gebhardt, ALSOFT

Help needed in left menu entry of new module. 1 year 10 months ago #32153

  • ALSOFT
  • ALSOFT's Avatar
  • OFFLINE
  • Junior
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
Dear folk, thank you very much for your prompt reply. You gave a valuable information regrading the menu entry of Dolibarr. By the way the module development document at here has wrong information. This documentation is quite outdated. The main culprit is the definition in main menu entry given below..........
$this->menu[$r]=array(	'fk_menu'=>0,			// Put 0 if this is a top menu
			'type'=>'top',			// This is a Top menu entry
			'titre'=>'MyModule top menu',
			'mainmenu'=>'mymodule',
			'leftmenu'=>'mymodule',
			'url'=>'/mymodule/pagetop.php',
			'langs'=>'mylangfile',	// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
			'position'=>100,
			'enabled'=>'1',			// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
			'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

The statement, 'fk_menu'=>0, // Put 0 if this is a top menu is wrong. There should be the module name itself in place of 0. I have studied about the position element and it worked for me. The more value you choose for position element the more the top menu item placed to the right side of the top menu. The more value you choose for position element of left menu the more the left items will be placed below inside the top menu. Visit http://www.alinscribe.com/articles/407/how-to-define-custom-menu-entries-into-dolibarr-erp-crm.html for more information.
The administrator has disabled public write access.
The following user(s) said Thank You: Peter A. Gebhardt

Help needed in left menu entry of new module. 1 year 10 months ago #32155

  • caos30
  • caos30's Avatar
  • OFFLINE
  • Junior
  • Posts: 24
  • Thank you received: 15
  • Karma: 2
Oh, great! I liked the post on your blog. Indeed, be careful with the attribute 'perms' in that array: it defines the permissions needed for that menu entry be showed to the user logged in Dolibarr.

In my example:
'perms' => '( $user->rights->produit && $user->rights->fournisseur )'

state that the user needs access rights to Products and Thirds of type Supplier. But it can more and more especific. As the official documentation says, if you set '1' as value then ANY USER logged in Dolibarr will see the menu entry.
The administrator has disabled public write access.

Help needed in left menu entry of new module. 1 year 10 months ago #32176

  • ALSOFT
  • ALSOFT's Avatar
  • OFFLINE
  • Junior
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
Thank you very much for your valuable reply. Again I got stuck with the dynamic menu enabled functionality. When i use the string $conf->ALDictionary->enabled under the single quote as below, I can't see any top menu entry.
$this->menu[$r++]=array('fk_menu'=>0,			                // '' 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
								'type'=>'top',			                // This is a Top menu entry
								'titre'=>'ALDictionary',
								'mainmenu'=>'ALDictionary',
								'leftmenu'=>'Grammar',
								'url'=>'/ALDictionary/index.php',
								'langs'=>'ALDictionary@ALDictionary',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
								'position'=>170,
								'enabled'=>'$conf->ALDictionary->enabled',	// Define condition to show or hide menu entry. Use '$conf->ALDictionary->enabled' if entry must be visible if module is enabled.
								'perms'=>'1',			                // Use 'perms'=>'$user->rights->ALDictionary->level1->level2' if you want your menu with a permission rules
								'target'=>'',
								'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both

But when I use the string $conf->ALDictionary->enabled without single quote like below, I get the menu working.
$this->menu[$r++]=array('fk_menu'=>0,			                // '' 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
								'type'=>'top',			                // This is a Top menu entry
								'titre'=>'ALDictionary',
								'mainmenu'=>'ALDictionary',
								'leftmenu'=>'Grammar',
								'url'=>'/ALDictionary/index.php',
								'langs'=>'ALDictionary@ALDictionary',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
								'position'=>170,
								'enabled'=>$conf->ALDictionary->enabled,	// Define condition to show or hide menu entry. Use '$conf->ALDictionary->enabled' if entry must be visible if module is enabled.
								'perms'=>'1',			                // Use 'perms'=>'$user->rights->ALDictionary->level1->level2' if you want your menu with a permission rules
								'target'=>'',
								'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both

But according to the dolibarr documentation of mymodule it should be written inside single quote. Please help me.
The administrator has disabled public write access.

Help needed in left menu entry of new module. 1 year 10 months ago #32177

  • caos30
  • caos30's Avatar
  • OFFLINE
  • Junior
  • Posts: 24
  • Thank you received: 15
  • Karma: 2
Yes, your fears are justified. Let me explain.

I would say that if you put that expression without quotes then it is interpreted by PHP as an assignment and returns TRUE (or '1') when this piece of code is read by Dolibarr, and it happens when you are activating the module on Settings / Modules section of Dolibarr. So it really will store on database the value '1' .. !!! In other words, this means that it's the same than to define 'perms'=>'1' in that file of the module. So it means that any user WILL HAVE PERMISSIONS to access that menu entry, not only those users who has PERMISSION TO ACCESS the module.

Could i explain enough clear? it's a little tricky matter to be explained.

You really would need to define as 'perm'=> a quoted expression to be INTERPRETED in real time for each user logged in Dolibarr. Because they can have different permissions.

Last comment: when i made testing about this question, it was very useful for mine to directly edit the database (using phpMyAdmin in my case) and editing the MENU ENTRY with different "quoted expressions" for that menu entry... until i accomplished my objective. Because it really is VERY SLOW to being modifying the file, uploading it, deactivating module and activating again, each time you need to test the new value for 'perms' ;)
The administrator has disabled public write access.

Help needed in left menu entry of new module. 1 year 10 months ago #32226

  • ALSOFT
  • ALSOFT's Avatar
  • OFFLINE
  • Junior
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
Thank you very much for your prompt reply. On the other hand sorry for my late reply. Your though is correct. But in my case the problem lied somewhere else. I made mistake declaring module's rights class. After a deep debugging I solved the problem. You can find about the solution at http://www.alinscribe.com/articles/439/module-development-error-in-dolibarr-menu-permission-solved.html.
The administrator has disabled public write access.
Time to create page: 0.083 seconds