Menü System

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search

= Das System der Dolibarr Menüs =

Dolibarr beinhaltet 2 Menüvorlagen zur Verwaltung:
Standard Menü-Verwaltung (für den Web-Desktop) und
Smartphone Menü-Verwaltung (für mobile Endgeräte)

jeweils für interne und externe Benutzer.

Das Menü-System definiert, welches Einstiegsmenü sichtbar ist, in welcher Bedingung und wo (oben, links).

Der Menümanager wird über Start -> Einstellungen -> Menüs aufgerufen.

Nehmen Sie den Menümanager, den Sie in der Liste wünschen.

If you want to personalize the menu, you can add you own menu entry or develop your own menu manager, that will replace completely the default one. You will decide how you store your menu definition (database like with the menu manager auguria, centralized hard coded menu entries like in the menu eldy, xml files, ...). Like you see, you can offer a menu manager with the behavior you need and the technology you want. See next chapters for that.

Erstellen von Menüeinträgen

Wenn Sie einen neuen Menüeintrag hinzufügen möchten gehen Sie zu Startseite - Einstellungen - Menüs dann wählen Sie Menü Editor. Add an entry. For example to add a menu entry to switch to a page that list opportunities with filters already set, you will add and entry that will looks like this:

Menu editor.png

Entwickeln Sie Ihren eigenen Menü-Manager

Das Ziel dieses Kapitels ist es, hier zu beschreiben, wie man ein komplett eigenes neues Menü-System erstellt (Um die gesamten Menüeinträge zu ersetzen, kompletter Umbruch von dem Konzept der Navigation).


This does not relate how to add menu entries. If you just want to know how to add menu entries within an existing menu manager, when developing an extension or a new module for example, you should look page Module development instead. If you want to completely replace a system menu with your own, the easiest way is to use the menu Manager "eldy_backoffice" as an example:

To develop your own top menu

  1. Copy file htdocs/core/menus/standard/eldy_backoffice.php into a file with a name like htdocs/core/menus/standard/mymenu.php
  2. Edit this file mymenu.php. Function showmenu() of class MenuTop is the function called by Dolibarr, when generating a page, to show the top menu. You can put here the code you want, this function does not change any external vairable and must show using "print" the menu to show. So you can get menu to show from a configuration file, a database and personalized it according to environment. Environment Dolibarr is stored into 3 global variables: $user, $conf, $langs.
$user contains information about current user.
$conf contains information about setup (activated modules, permissions, options, etc...)
$langs contains information about active language.

Beispiel der Funktion showmenu() in der Datei htdocs/core/menus/standard/mymenu.php

    function showmenu()
    {
        global $user,$conf,$langs,$dolibarr_main_db_name;;
        
        print '<table class="tmenu"><tr class="tmenu">';

	    // Menu Home
	    print '<td class="tmenu"><a '.$class.' href="'.DOL_URL_ROOT.'/index.php?mainmenu=home&leftmenu="'.($this->atarget?" target=".$this->atarget:"").'>'.$langs->trans("Home").'</a></td>';
	    
	    // Put here other entries
	    // ...
	    
        print '</tr></table>';
    }

Erstellen des eigenen linken Menü

Im Prinzip ist es das gleiche wie für das obere Menü.

  1. You must edit function showmenu() of class MenuLeft to build your left menu. If you want to show standard menu with just minor changes without redoing everything, you have to loop on content of array $menu->liste. If you want to build a menu completely different and controled only by yourself, you must, into the method showmenu(), create an object $newmenu=new Menu() and use methods $newmenu->add and $newmenu->add_submenu to defined list of left menu entries to show. Once this is done, you show those entries using some "print" to show content of array $newmenu->liste (that we have just defined) instead of printing content of $menu->liste.

Beispiel der Datei htdocs/core/menus/standard/mymenu.php

    function showmenu()
    {
        global $user,$conf,$langs,$dolibarr_main_db_name;
        $newmenu = new Menu();
        
	// Setzen Sie hier linke Menüeinträge
	// ***** START *****

	$langs->load("admin");	// Load translation file admin.lang
	$newmenu->add(DOL_URL_ROOT."/admin/index.php?leftmenu=setup", $langs->trans("Setup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/company.php", $langs->trans("MenuCompanySetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/modules.php", $langs->trans("Modules"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/ihm.php", $langs->trans("GUISetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/boxes.php", $langs->trans("Boxes"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/delais.php",$langs->trans("Alerts"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/triggers.php", $langs->trans("Triggers"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/perms.php", $langs->trans("Security"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/dict.php", $langs->trans("DictionnarySetup"));
	$newmenu->add_submenu(DOL_URL_ROOT."/admin/const.php", $langs->trans("OtherSetup"));
		
	// ***** END *****
		
        // do not change code after this

        // override menu_array by value array in $newmenu
	$this->menu_array=$newmenu->liste;

        $alt=0;
        for ($i = 0 ; $i < sizeof($this->menu_array) ; $i++) 
        {
            $alt++;
            if ($this->menu_array[$i]['level']==0) {
                if (($alt%2==0))
                {
                    print '<div class="blockvmenuimpair">'."\n";
                }
                else
                {
                    print '<div class="blockvmenupair">'."\n";
                }
            }

            if ($this->menu_array[$i]['level']==0) {
                if ($this->menu_array[$i]['enabled'])
                    print '<a class="vmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '<font class="vmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==1) {
                if ($this->menu_array[$i]['enabled'])
                    print '<a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '<font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==2) {
                if ($this->menu_array[$i]['enabled'])
                    print '&nbsp; &nbsp; <a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '&nbsp; &nbsp; <font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            if ($this->menu_array[$i]['level']==3) {
                if ($this->menu_array[$i]['enabled'])
                    print '&nbsp; &nbsp; &nbsp; &nbsp; <a class="vsmenu" href="'.$this->menu_array[$i]['url'].'">'.$this->menu_array[$i]['titre'].'</a><br>';
                else 
                    print '&nbsp; &nbsp; &nbsp; &nbsp; <font class="vsmenudisabled">'.$this->menu_array[$i]['titre'].'</font><br>';
            }
            
            if ($i == (sizeof($this->menu_array)-1) || $this->menu_array[$i+1]['level']==0)  {
                print "</div>\n";
            }
        }

    }

Um den Gebrauch des Menümanagers zu erzwingen

Sie können die Nutzung Ihres eigenen Menü-Managers erzwingen, indem Sie ein Modul erstellen. Dazu müssen Sie die 4 folgenden Konstanten in das Array $this->const Ihrer Modul-Deskriptor-Datei deklarieren (Siehe Module development(Eng.)).

* 1=>array('MAIN_MENU_STANDARD_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 2=>array('MAIN_MENUFRONT_STANDARD_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 3=>array('MAIN_MENU_SMARTPHONE_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),
* 4=>array('MAIN_MENUFRONT_SMARTPHONE_FORCED','chaine','mymodule.php','Force menu handler to this value',1,'current',1),

Ihr Menü-Manager wird verwendet, sobald das Modul aktiviert ist.