/**
  * Load this->tabMenu
  *
  * @param	string	$forcemainmenu		To force mainmenu to load
  * @param	string	$forceleftmenu		To force leftmenu to load
  * @return	void
  */
 function loadMenu($forcemainmenu = '', $forceleftmenu = '')
 {
     global $conf, $user, $langs;
     // On sauve en session le menu principal choisi
     if (isset($_GET["mainmenu"])) {
         $_SESSION["mainmenu"] = $_GET["mainmenu"];
     }
     if (isset($_GET["idmenu"])) {
         $_SESSION["idmenu"] = $_GET["idmenu"];
     }
     // Read mainmenu and leftmenu that define which menu to show
     if (isset($_GET["mainmenu"])) {
         // On sauve en session le menu principal choisi
         $mainmenu = $_GET["mainmenu"];
         $_SESSION["mainmenu"] = $mainmenu;
         $_SESSION["leftmenuopened"] = "";
     } else {
         // On va le chercher en session si non defini par le lien
         $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
     }
     if (!empty($forcemainmenu)) {
         $mainmenu = $forcemainmenu;
     }
     if (isset($_GET["leftmenu"])) {
         // On sauve en session le menu principal choisi
         $leftmenu = $_GET["leftmenu"];
         $_SESSION["leftmenu"] = $leftmenu;
         if ($_SESSION["leftmenuopened"] == $leftmenu) {
             //$leftmenu="";
             $_SESSION["leftmenuopened"] = "";
         } else {
             $_SESSION["leftmenuopened"] = $leftmenu;
         }
     } else {
         // On va le chercher en session si non defini par le lien
         $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
     }
     if (!empty($forceleftmenu)) {
         $leftmenu = $forceleftmenu;
     }
     require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php';
     $tabMenu = array();
     $menuArbo = new Menubase($this->db, 'auguria');
     $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
     // 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->barcode->enabled) || !empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) {
         if (empty($user->societe_id)) {
             if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($leftmenu == "modulesadmintools" && $user->admin)) {
                 $langs->load("products");
                 $array_menu_product = array('url' => "/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools", 'titre' => $langs->trans("ProductVatMassChange"), 'enabled' => $user->admin ? true : false, 'perms' => $user->admin ? true : false, 'fk_mainmenu' => 'home', 'fk_leftmenu' => 'modulesadmintools', 'fk_menu' => -1, 'mainmenu' => 'home', 'leftmenu' => 'modulesadmintools_massvat', 'type' => 'left', 'position' => 20);
                 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"), 'enabled' => $user->admin ? true : false, 'perms' => $user->admin ? true : false, 'fk_mainmenu' => 'home', 'fk_menu' => -1, 'mainmenu' => 'home', 'leftmenu' => 'modulesadmintools', 'type' => 'left', 'position' => 20);
             array_unshift($tabMenu, $array_menu_product);
             // add at beginning of array
         }
     }
     $this->tabMenu = $tabMenu;
 }
Esempio n. 2
0
 /**
  * Adds menu entries
  *
  * @return  int Error count (0 if OK)
  */
 function insert_menus()
 {
     global $user;
     require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php';
     $err = 0;
     $this->db->begin();
     foreach ($this->menu as $key => $value) {
         $menu = new Menubase($this->db);
         $menu->menu_handler = 'all';
         $menu->module = $this->rights_class;
         if (!$this->menu[$key]['fk_menu']) {
             $menu->fk_menu = 0;
         } else {
             $foundparent = 0;
             $fk_parent = $this->menu[$key]['fk_menu'];
             if (preg_match('/^r=/', $fk_parent)) {
                 $fk_parent = str_replace('r=', '', $fk_parent);
                 if (isset($this->menu[$fk_parent]['rowid'])) {
                     $menu->fk_menu = $this->menu[$fk_parent]['rowid'];
                     $foundparent = 1;
                 }
             } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
                 $menu->fk_menu = -1;
                 $menu->fk_mainmenu = $reg[1];
                 $menu->fk_leftmenu = $reg[2];
                 $foundparent = 1;
             } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) {
                 $menu->fk_menu = -1;
                 $menu->fk_mainmenu = $reg[1];
                 $menu->fk_leftmenu = '';
                 $foundparent = 1;
             }
             if (!$foundparent) {
                 $this->error = "ErrorBadDefinitionOfMenuArrayInModuleDescriptor";
                 dol_syslog(get_class($this) . "::insert_menus " . $this->error . " " . $this->menu[$key]['fk_menu'], LOG_ERR);
                 $err++;
             }
         }
         $menu->type = $this->menu[$key]['type'];
         $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : '');
         $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : '';
         $menu->titre = $this->menu[$key]['titre'];
         $menu->url = $this->menu[$key]['url'];
         $menu->langs = $this->menu[$key]['langs'];
         $menu->position = $this->menu[$key]['position'];
         $menu->perms = $this->menu[$key]['perms'];
         $menu->target = $this->menu[$key]['target'];
         $menu->user = $this->menu[$key]['user'];
         $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0;
         $menu->position = $this->menu[$key]['position'];
         if (!$err) {
             $result = $menu->create($user);
             // Save menu entry into table llx_menu
             if ($result > 0) {
                 $this->menu[$key]['rowid'] = $result;
             } else {
                 $this->error = $menu->error;
                 dol_syslog(get_class($this) . '::insert_menus result=' . $result . " " . $this->error, LOG_ERR);
                 $err++;
                 break;
             }
         }
     }
     if (!$err) {
         $this->db->commit();
     } else {
         dol_syslog(get_class($this) . "::insert_menus " . $this->error, LOG_ERR);
         $this->db->rollback();
     }
     return $err;
 }
Esempio n. 3
0
    // Boutons
    print '<br><div class="center">';
    print '<input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
    print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
    print '</div>';
    print '</form>';
} elseif ($action == 'edit') {
    print_fiche_titre($langs->trans("ModifMenu"), '', 'title_setup');
    print '<br>';
    print '<form action="./edit.php?action=update" method="POST" name="formmenuedit">';
    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
    print '<input type="hidden" name="handler_origine" value="' . $menu_handler . '">';
    print '<input type="hidden" name="menuId" value="' . $_GET['menuId'] . '">';
    print '<table class="border" width="100%">';
    $menu = new Menubase($db);
    $result = $menu->fetch($_GET['menuId']);
    //var_dump($menu);
    // Id
    print '<tr><td>' . $langs->trans('Id') . '</td><td>' . $menu->id . '</td><td>' . $langs->trans('DetailId') . '</td></tr>';
    // Module
    print '<tr><td>' . $langs->trans('MenuModule') . '</td><td>' . $menu->module . '</td><td>' . $langs->trans('DetailMenuModule') . '</td></tr>';
    // Handler
    if ($menu->menu_handler == 'all') {
        $handler = $langs->trans('AllMenus');
    } else {
        $handler = $menu->menu_handler;
    }
    print '<tr><td class="fieldrequired">' . $langs->trans('MenuHandler') . '</td><td>' . $handler . '</td><td>' . $langs->trans('DetailMenuHandler') . '</td></tr>';
    // User
    print '<tr><td class="nowrap fieldrequired">' . $langs->trans('MenuForUsers') . '</td><td><select class="flat" name="user">';
 private function deleteMenu()
 {
     if ($this->fk_menu > 0) {
         global $db, $conf, $user;
         $menu = new Menubase($db, 'all');
         if ($menu->fetch($this->fk_menu) > 0) {
             $menu->delete($user);
         }
     }
 }
Esempio n. 5
0
/**
 * Core function to output left menu auguria
 *
 * @param	DoliDB		$db                 Database handler
 * @param 	array		$menu_array_before  Table of menu entries to show before entries of menu handler
 * @param   array		$menu_array_after   Table of menu entries to show after entries of menu handler
 * @param  	array		$tabMenu       		If array with menu entries already loaded, we put this array here (in most cases, it's empty)
 * @param	Menu		$menu				Object Menu to return back list of menu entries
 * @param	int			$noout				Disable output (Initialise &$menu only).
 * @param	string		$forcemainmenu		'x'=Force mainmenu to mainmenu='x'
 * @param	string		$forceleftmenu		'all'=Force leftmenu to '' (= all)
 * @param	array		$moredata			An array with more data to output
 * @return	int								Nb of entries
 */
function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null)
{
    global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
    $newmenu = $menu;
    $mainmenu = $forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"];
    $leftmenu = $forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]);
    // Show logo company
    if (empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
        $mysoc->logo_mini = $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
        if (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_mini)) {
            $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_mini);
        } else {
            $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
        }
        $title = $langs->trans("GoIntoSetupToChangeLogo");
        print "\n" . '<!-- Show logo on menu -->' . "\n";
        print '<div class="blockvmenuimpair blockvmenulogo">' . "\n";
        print '<div class="menu_titre" id="menu_titre_logo"></div>';
        print '<div class="menu_top" id="menu_top_logo"></div>';
        print '<div class="menu_contenu" id="menu_contenu_logo">';
        print '<div class="center"><img title="' . dol_escape_htmltag($title) . '" alt="" src="' . $urllogo . '" style="max-width: 80%"></div>' . "\n";
        print '</div>';
        print '<div class="menu_end" id="menu_end_logo"></div>';
        print '</div>' . "\n";
    }
    if (is_array($moredata) && !empty($moredata['searchform'])) {
        print "\n";
        print "<!-- Begin SearchForm -->\n";
        print '<div id="blockvmenusearch" class="blockvmenusearch">' . "\n";
        print $moredata['searchform'];
        print '</div>' . "\n";
        print "<!-- End SearchForm -->\n";
    }
    // We update newmenu with entries found into database
    $menuArbo = new Menubase($db, 'auguria');
    $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, $user->societe_id ? 1 : 0, 'auguria', $tabMenu);
    // We update newmenu for special dynamic menus
    if ($conf->banque->enabled && $user->rights->banque->lire && $mainmenu == 'bank') {
        $sql = "SELECT rowid, label, courant, rappro, courant";
        $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
        $sql .= " WHERE entity = " . $conf->entity;
        $sql .= " AND clos = 0";
        $sql .= " ORDER BY label";
        $resql = $db->query($sql);
        if ($resql) {
            $numr = $db->num_rows($resql);
            $i = 0;
            if ($numr > 0) {
                $newmenu->add('/compta/bank/index.php', $langs->trans("BankAccounts"), 0, $user->rights->banque->lire);
            }
            while ($i < $numr) {
                $objp = $db->fetch_object($resql);
                $newmenu->add('/compta/bank/card.php?id=' . $objp->rowid, $objp->label, 1, $user->rights->banque->lire);
                if ($objp->rappro && $objp->courant != 2 && empty($objp->clos)) {
                    $newmenu->add('/compta/bank/rappro.php?account=' . $objp->rowid, $langs->trans("Conciliate"), 2, $user->rights->banque->consolidate);
                }
                $i++;
            }
        } else {
            dol_print_error($db);
        }
        $db->free($resql);
    }
    if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->mouvements->lire) && $mainmenu == 'accountancy') {
        $newmenu->add('/accountancy/journal/index.php?leftmenu=journal', $langs->trans("Journaux"), 0, $user->rights->banque->lire);
        if ($leftmenu == 'journal') {
            $sql = "SELECT rowid, label, accountancy_journal";
            $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
            $sql .= " WHERE entity = " . $conf->entity;
            $sql .= " AND clos = 0";
            $sql .= " ORDER BY label";
            $resql = $db->query($sql);
            if ($resql) {
                $numr = $db->num_rows($resql);
                $i = 0;
                if ($numr > 0) {
                    while ($i < $numr) {
                        $objp = $db->fetch_object($resql);
                        $newmenu->add('/accountancy/journal/bankjournal.php?id_account=' . $objp->rowid, $langs->trans("Journal") . ' - ' . $objp->label, 1, $user->rights->accounting->comptarapport->lire);
                        $i++;
                    }
                }
            } else {
                dol_print_error($db);
            }
            $db->free($resql);
            // Add other journal
            $newmenu->add("/accountancy/journal/sellsjournal.php?leftmenu=journal", $langs->trans("SellsJournal"), 1, $user->rights->accounting->comptarapport->lire);
            $newmenu->add("/accountancy/journal/purchasesjournal.php?leftmenu=journal", $langs->trans("PurchasesJournal"), 1, $user->rights->accounting->comptarapport->lire);
        }
    }
    if ($conf->ftp->enabled && $mainmenu == 'ftp') {
        $MAXFTP = 20;
        $i = 1;
        while ($i <= $MAXFTP) {
            $paramkey = 'FTP_NAME_' . $i;
            //print $paramkey;
            if (!empty($conf->global->{$paramkey})) {
                $link = "/ftp/index.php?idmenu=" . $_SESSION["idmenu"] . "&numero_ftp=" . $i;
                $newmenu->add($link, dol_trunc($conf->global->{$paramkey}, 24));
            }
            $i++;
        }
    }
    // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
    //var_dump($menu_array_before);exit;
    //var_dump($menu_array_after);exit;
    $menu_array = $newmenu->liste;
    if (is_array($menu_array_before)) {
        $menu_array = array_merge($menu_array_before, $menu_array);
    }
    if (is_array($menu_array_after)) {
        $menu_array = array_merge($menu_array, $menu_array_after);
    }
    //var_dump($menu_array);exit;
    if (!is_array($menu_array)) {
        return 0;
    }
    // Show menu
    if (empty($noout)) {
        $alt = 0;
        $altok = 0;
        $blockvmenuopened = false;
        $num = count($menu_array);
        for ($i = 0; $i < $num; $i++) {
            $showmenu = true;
            if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) {
                $showmenu = false;
            }
            $alt++;
            if (empty($menu_array[$i]['level']) && $showmenu) {
                $altok++;
                $blockvmenuopened = true;
                if ($altok % 2 == 0) {
                    print '<div class="blockvmenuimpair' . ($altok == 1 ? ' blockvmenufirst' : '') . '">' . "\n";
                } else {
                    print '<div class="blockvmenupair' . ($altok == 1 ? ' blockvmenufirst' : '') . '">' . "\n";
                }
            }
            // Place tabulation
            $tabstring = '';
            $tabul = $menu_array[$i]['level'] - 1;
            if ($tabul > 0) {
                for ($j = 0; $j < $tabul; $j++) {
                    $tabstring .= '&nbsp; &nbsp;';
                }
            }
            // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
            $url = dol_buildpath($menu_array[$i]['url'], 1);
            $url = preg_replace('/__LOGIN__/', $user->login, $url);
            $url = preg_replace('/__USERID__/', $user->id, $url);
            if (!preg_match('/mainmenu=/i', $menu_array[$i]['url'])) {
                if (!preg_match('/\\?/', $url)) {
                    $url .= '?';
                } else {
                    $url .= '&';
                }
                $url .= 'mainmenu=' . $mainmenu;
            }
            print '<!-- Process menu entry with mainmenu=' . $menu_array[$i]['mainmenu'] . ', leftmenu=' . $menu_array[$i]['leftmenu'] . ', level=' . $menu_array[$i]['level'] . ' enabled=' . $menu_array[$i]['enabled'] . ' -->' . "\n";
            // Menu niveau 0
            if ($menu_array[$i]['level'] == 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_titre">' . $tabstring . '<a class="vmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>' . $menu_array[$i]['titre'] . '</a></div>';
                } else {
                    if ($showmenu) {
                        print '<div class="menu_titre">' . $tabstring . '<font class="vmenudisabled">' . $menu_array[$i]['titre'] . '</font></div>' . "\n";
                    }
                }
                if ($showmenu) {
                    print '<div class="menu_top"></div>' . "\n";
                }
            }
            // Menu niveau > 0
            if ($menu_array[$i]['level'] > 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_contenu">' . $tabstring;
                    if ($menu_array[$i]['url']) {
                        print '<a class="vsmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>';
                    } else {
                        print '<span class="vsmenu">';
                    }
                    print $menu_array[$i]['titre'];
                    if ($menu_array[$i]['url']) {
                        print '</a>';
                    } else {
                        print '</span>';
                    }
                    // If title is not pure text and contains a table, no carriage return added
                    if (!strstr($menu_array[$i]['titre'], '<table')) {
                        print '<br>';
                    }
                    print '</div>' . "\n";
                } else {
                    if ($showmenu) {
                        print '<div class="menu_contenu">' . $tabstring . '<font class="vsmenudisabled vsmenudisabledmargin">' . $menu_array[$i]['titre'] . '</font><br></div>' . "\n";
                    }
                }
            }
            // If next is a new block or if there is nothing after
            if (empty($menu_array[$i + 1]['level'])) {
                if ($showmenu) {
                    print '<div class="menu_end"></div>' . "\n";
                }
                if ($blockvmenuopened) {
                    print "</div>\n";
                    $blockvmenuopened = false;
                }
            }
        }
        if ($altok) {
            print '<div class="blockvmenuend"></div>';
        }
    }
    if (is_array($moredata) && !empty($moredata['bookmarks'])) {
        print "\n";
        print "<!-- Begin Bookmarks -->\n";
        print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">' . "\n";
        print $moredata['bookmarks'];
        print '</div>' . "\n";
        print "<!-- End Bookmarks -->\n";
    }
    return count($menu_array);
}
Esempio n. 6
0
 /**
  * Load this->tabMenu
  *
  * @param	string	$forcemainmenu		To force mainmenu to load
  * @param	string	$forceleftmenu		To force leftmenu to load
  * @return	void
  */
 function loadMenu($forcemainmenu = '', $forceleftmenu = '')
 {
     global $conf, $user, $langs;
     // On sauve en session le menu principal choisi
     if (isset($_GET["mainmenu"])) {
         $_SESSION["mainmenu"] = $_GET["mainmenu"];
     }
     if (isset($_GET["idmenu"])) {
         $_SESSION["idmenu"] = $_GET["idmenu"];
     }
     // Read mainmenu and leftmenu that define which menu to show
     if (isset($_GET["mainmenu"])) {
         // On sauve en session le menu principal choisi
         $mainmenu = $_GET["mainmenu"];
         $_SESSION["mainmenu"] = $mainmenu;
         $_SESSION["leftmenuopened"] = "";
     } else {
         // On va le chercher en session si non defini par le lien
         $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
     }
     if (!empty($forcemainmenu)) {
         $mainmenu = $forcemainmenu;
     }
     if (isset($_GET["leftmenu"])) {
         // On sauve en session le menu principal choisi
         $leftmenu = $_GET["leftmenu"];
         $_SESSION["leftmenu"] = $leftmenu;
         if ($_SESSION["leftmenuopened"] == $leftmenu) {
             //$leftmenu="";
             $_SESSION["leftmenuopened"] = "";
         } else {
             $_SESSION["leftmenuopened"] = $leftmenu;
         }
     } else {
         // On va le chercher en session si non defini par le lien
         $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
     }
     if (!empty($forceleftmenu)) {
         $leftmenu = $forceleftmenu;
     }
     require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php';
     $tabMenu = array();
     $menuArbo = new Menubase($this->db, 'auguria');
     $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
     $this->tabMenu = $tabMenu;
 }
Esempio n. 7
0
/**
 * Core function to output top menu smartphone
 *
 * @param $db
 * @param $atarget
 * @param $type_user     0=Internal,1=External,2=All
 * @param $limitmenuto	 To limit menu to a top or left menu value
 */
function print_smartphone_menu($db,$atarget,$type_user,$limitmenuto)
{
	require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");

	global $user,$conf,$langs,$dolibarr_main_db_name;

	$submenus='';

	$tabMenu=array();

	$menutop = new Menubase($db,'smartphone','top');
	$menuleft = new Menubase($db,'smartphone','left');
	$newTabMenu = $menutop->menuTopCharger('', '', $type_user, 'smartphone',$tabMenu);
	$numTabMenu = count($newTabMenu);

	print_start_menu_array();
    for($i=0; $i<$numTabMenu; $i++)
	{
		if ($newTabMenu[$i]['enabled'] == true)
		{
			if ($newTabMenu[$i]['right'] == true)	// Is allowed
			{
				// Define url
				if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
				{
					$url = dol_buildpath($newTabMenu[$i]['url'],1);
					$url=preg_replace('/&amp.*/i','',$url);
				}
				else
				{
					$menus='';

					if ($limitmenuto > 0)
					{
						$newmenu = new Menu();
						$leftmenu = $menuleft->menuLeftCharger($newmenu,$newTabMenu[$i]['mainmenu'],'',($user->societe_id?1:0),'smartphone',$tabMenu);
						$menus = $leftmenu->liste;
						//var_dump($menus);
					}

					print_start_menu_entry();

					if (is_array($menus) && !empty($menus) && $limitmenuto > 0)
					{
						$title=$newTabMenu[$i]['titre'];
						// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
						print_text_menu_entry($title);

						$num = count($menus);
						//var_dump($menus);

					    if ($num > 0) print_start_submenu_array();

                        for($j=0; $j<$num; $j++)
						{
							$url=dol_buildpath($menus[$j]['url'],1);
							$url=preg_replace('/&amp.*/i','',$url);

							if ($menus[$j]['level'] == 0)
							{
								print_start_menu_entry();
								if (empty($menus[$j+1]['level'])) print '<a href="'.$url.'"'.($menus[$j]['atarget']?" target='".$menus[$j]['atarget']."'":($atarget?" target=$atarget":'')).'>';
								$title=$menus[$j]['titre'];
								// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($menus[$j]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
								print_text_menu_entry($title);
								if (empty($menus[$j+1]['level'])) print '</a>';
							}

							if ($menus[$j]['level'] > 0)
							{
								if ($menus[$j-1]['level'] == 0) print_start_submenu_array();

								print_start_menu_entry();
								print '<a href="'.$url.'"'.($menus[$j]['atarget']?" target='".$menus[$j]['atarget']."'":($atarget?" target=$atarget":'')).'>';
								$title=$menus[$j]['titre'];
								// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($menus[$j]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
								print_text_menu_entry($title);
								print '</a>';
								print_end_menu_entry();

								if (empty($menus[$j+1]['level'])) print_end_menu();
							}

							if (empty($menus[$j+1]['level'])) print_end_menu_entry();
						}

                    	if ($num > 0) print_end_menu();
					}
					else
					{
						$url=dol_buildpath($newTabMenu[$i]['url'],1);
						$url=preg_replace('/&amp.*/i','',$url);

						print '<a href="'.$url.'"'.($newTabMenu[$i]['atarget']?" target='".$newTabMenu[$i]['atarget']."'":($atarget?" target=$atarget":'')).'>';
						$title=$newTabMenu[$i]['titre'];
						// To remove & and special chars: $title=dol_string_unaccent(dol_string_nospecial(dol_html_entity_decode($newTabMenu[$i]['titre'],ENT_QUOTES,'UTF-8'),'',array('&')));
						print_text_menu_entry($title);
						print '</a>';
					}

					print_end_menu_entry();
				}
			}
		}
	}

	print_end_menu();
	print "\n";
}
Esempio n. 8
0
/**
 * Core function to output left menu eldy
 *
 * @param      db                  Database handler
 * @param      menu_array_before   Table of menu entries to show before entries of menu handler
 * @param      menu_array_after    Table of menu entries to show after entries of menu handler
 */
function print_left_eldy_menu($db, $menu_array_before, $menu_array_after)
{
    global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
    // Read mainmenu and leftmenu that define which menu to show
    if (isset($_GET["mainmenu"])) {
        // On sauve en session le menu principal choisi
        $mainmenu = $_GET["mainmenu"];
        $_SESSION["mainmenu"] = $mainmenu;
        $_SESSION["leftmenuopened"] = "";
    } else {
        // On va le chercher en session si non defini par le lien
        $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
    }
    if (isset($_GET["leftmenu"])) {
        // On sauve en session le menu principal choisi
        $leftmenu = $_GET["leftmenu"];
        $_SESSION["leftmenu"] = $leftmenu;
        if ($_SESSION["leftmenuopened"] == $leftmenu) {
            //$leftmenu="";
            $_SESSION["leftmenuopened"] = "";
        } else {
            $_SESSION["leftmenuopened"] = $leftmenu;
        }
    } else {
        // On va le chercher en session si non defini par le lien
        $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
    }
    $newmenu = new Menu();
    // Show logo company
    if (!empty($conf->global->MAIN_SHOW_LOGO)) {
        $mysoc->logo_mini = $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
        if (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_mini)) {
            $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_mini);
            print "\n" . '<!-- Show logo on menu -->' . "\n";
            print '<div class="blockvmenuimpair">' . "\n";
            print '<div class="menu_titre" id="menu_titre_logo"></div>';
            print '<div class="menu_top" id="menu_top_logo"></div>';
            print '<div class="menu_contenu" id="menu_contenu_logo">';
            print '<center><img title="' . $title . '" src="' . $urllogo . '"></center>' . "\n";
            print '</div>';
            print '<div class="menu_end" id="menu_end_logo"></div>';
            print '</div>' . "\n";
        }
    }
    /**
     * On definit newmenu en fonction de mainmenu et leftmenu
     * ------------------------------------------------------
     */
    if ($mainmenu) {
        /*
         * Menu HOME
         */
        if ($mainmenu == 'home') {
            $langs->load("users");
            if ($user->admin) {
                $langs->load("admin");
                $langs->load("help");
                $newmenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"));
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/modules.php", $langs->trans("Modules"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/menus.php", $langs->trans("Menus"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/boxes.php", $langs->trans("Boxes"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/delais.php", $langs->trans("Alerts"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/proxy.php", $langs->trans("Security"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/limits.php", $langs->trans("MenuLimits"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/mails.php", $langs->trans("Emails"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/sms.php", $langs->trans("Sms"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/dict.php", $langs->trans("DictionnarySetup"), 1);
                }
                if ($leftmenu == "setup") {
                    $newmenu->add("/admin/const.php", $langs->trans("OtherSetup"), 1);
                }
                $newmenu->add("/admin/system/index.php?leftmenu=system", $langs->trans("SystemInfo"));
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/dolibarr.php", $langs->trans("Dolibarr"), 1);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/constall.php", $langs->trans("AllParameters"), 2);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/modules.php", $langs->trans("Modules"), 2);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/triggers.php", $langs->trans("Triggers"), 2);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/about.php", $langs->trans("About"), 2);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/os.php", $langs->trans("OS"), 1);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/web.php", $langs->trans("WebServer"), 1);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/phpinfo.php", $langs->trans("Php"), 1);
                }
                //if ($leftmenu=="system" && function_exists('xdebug_is_enabled')) $newmenu->add("/admin/system/xdebug.php", $langs->trans("XDebug"),1);
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/database.php", $langs->trans("Database"), 1);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/database-tables.php", $langs->trans("Tables"), 2);
                }
                if ($leftmenu == "system") {
                    $newmenu->add("/admin/system/database-tables-contraintes.php", $langs->trans("Constraints"), 2);
                }
                $newmenu->add("/admin/tools/index.php?leftmenu=admintools", $langs->trans("SystemTools"));
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/dolibarr_export.php", $langs->trans("Backup"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/dolibarr_import.php", $langs->trans("Restore"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/update.php", $langs->trans("MenuUpgrade"), 1);
                }
                if ($leftmenu == "admintools" && function_exists('eaccelerator_info')) {
                    $newmenu->add("/admin/tools/eaccelerator.php", $langs->trans("EAccelerator"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/listevents.php", $langs->trans("Audit"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/listsessions.php", $langs->trans("Sessions"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/admin/tools/purge.php", $langs->trans("Purge"), 1);
                }
                if ($leftmenu == "admintools") {
                    $newmenu->add("/support/index.php", $langs->trans("HelpCenter"), 1, 1, 'targethelp');
                }
            }
            $newmenu->add("/user/home.php?leftmenu=users", $langs->trans("MenuUsersAndGroups"));
            if ($leftmenu == "users") {
                $newmenu->add("/user/index.php", $langs->trans("Users"), 1, $user->rights->user->user->lire || $user->admin);
            }
            if ($leftmenu == "users") {
                $newmenu->add("/user/fiche.php?action=create", $langs->trans("NewUser"), 2, $user->rights->user->user->creer || $user->admin);
            }
            if ($leftmenu == "users") {
                $newmenu->add("/user/group/index.php", $langs->trans("Groups"), 1, ($conf->global->MAIN_USE_ADVANCED_PERMS ? $user->rights->user->group_advance->read : $user->rights->user->user->lire) || $user->admin);
            }
            if ($leftmenu == "users") {
                $newmenu->add("/user/group/fiche.php?action=create", $langs->trans("NewGroup"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS ? $user->rights->user->group_advance->write : $user->rights->user->user->creer) || $user->admin);
            }
        }
        /*
         * Menu TIERS
         */
        if ($mainmenu == 'companies') {
            // Societes
            if ($conf->societe->enabled) {
                $langs->load("companies");
                $newmenu->add("/societe/societe.php", $langs->trans("ThirdParty"), 0, $user->rights->societe->lire);
                if ($user->rights->societe->creer) {
                    $newmenu->add("/societe/soc.php?action=create", $langs->trans("MenuNewThirdParty"), 1);
                    if (!$conf->use_javascript_ajax) {
                        $newmenu->add("/societe/soc.php?action=create&amp;private=1", $langs->trans("MenuNewPrivateIndividual"), 1);
                    }
                }
                if (is_dir("societe/groupe")) {
                    $newmenu->add("/societe/groupe/index.php", $langs->trans("MenuSocGroup"), 1);
                }
            }
            // Prospects
            if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
                $langs->load("commercial");
                $newmenu->add("/comm/prospect/prospects.php?leftmenu=prospects", $langs->trans("ListProspectsShort"), 1, $user->rights->societe->lire);
                if ($leftmenu == "prospects") {
                    $newmenu->add("/comm/prospect/prospects.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire);
                }
                if ($leftmenu == "prospects") {
                    $newmenu->add("/comm/prospect/prospects.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire);
                }
                if ($leftmenu == "prospects") {
                    $newmenu->add("/comm/prospect/prospects.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;stcomm=1", $langs->trans("LastProspectToContact"), 2, $user->rights->societe->lire);
                }
                if ($leftmenu == "prospects") {
                    $newmenu->add("/comm/prospect/prospects.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;stcomm=2", $langs->trans("LastProspectContactInProcess"), 2, $user->rights->societe->lire);
                }
                if ($leftmenu == "prospects") {
                    $newmenu->add("/comm/prospect/prospects.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;stcomm=3", $langs->trans("LastProspectContactDone"), 2, $user->rights->societe->lire);
                }
                $newmenu->add("/societe/soc.php?leftmenu=prospects&amp;action=create&amp;type=p", $langs->trans("MenuNewProspect"), 2, $user->rights->societe->creer);
                //$newmenu->add("/contact/index.php?leftmenu=customers&amp;type=p", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire);
            }
            // Clients
            if ($conf->societe->enabled) {
                $langs->load("commercial");
                $newmenu->add("/comm/clients.php?leftmenu=customers", $langs->trans("ListCustomersShort"), 1, $user->rights->societe->lire);
                $newmenu->add("/societe/soc.php?leftmenu=customers&amp;action=create&amp;type=c", $langs->trans("MenuNewCustomer"), 2, $user->rights->societe->creer);
                //$newmenu->add("/contact/index.php?leftmenu=customers&amp;type=c", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire);
            }
            // Fournisseurs
            if ($conf->societe->enabled && $conf->fournisseur->enabled) {
                $langs->load("suppliers");
                $newmenu->add("/fourn/liste.php?leftmenu=suppliers", $langs->trans("ListSuppliersShort"), 1, $user->rights->societe->lire && $user->rights->fournisseur->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/societe/soc.php?leftmenu=suppliers&amp;action=create&amp;type=f", $langs->trans("MenuNewSupplier"), 2, $user->rights->societe->creer && $user->rights->fournisseur->lire);
                }
                //$newmenu->add("/fourn/liste.php?leftmenu=suppliers", $langs->trans("List"), 2, $user->rights->societe->lire && $user->rights->fournisseur->lire);
                //$newmenu->add("/contact/index.php?leftmenu=suppliers&amp;type=f",$langs->trans("Contacts"), 2, $user->rights->societe->lire && $user->rights->fournisseur->lire && $user->rights->societe->contact->lire);
            }
            // Contacts
            $newmenu->add("/contact/index.php?leftmenu=contacts", $langs->trans("ContactsAddresses"), 0, $user->rights->societe->contact->lire);
            $newmenu->add("/contact/fiche.php?leftmenu=contacts&amp;action=create", $langs->trans("NewContact"), 1, $user->rights->societe->contact->creer);
            $newmenu->add("/contact/index.php?leftmenu=contacts", $langs->trans("List"), 1, $user->rights->societe->contact->lire);
            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
                $newmenu->add("/contact/index.php?leftmenu=contacts&type=p", $langs->trans("Prospects"), 2, $user->rights->societe->contact->lire);
            }
            $newmenu->add("/contact/index.php?leftmenu=contacts&type=c", $langs->trans("Customers"), 2, $user->rights->societe->contact->lire);
            if ($conf->fournisseur->enabled) {
                $newmenu->add("/contact/index.php?leftmenu=contacts&type=f", $langs->trans("Suppliers"), 2, $user->rights->societe->contact->lire);
            }
            $newmenu->add("/contact/index.php?leftmenu=contacts&type=o", $langs->trans("Others"), 2, $user->rights->societe->contact->lire);
            //$newmenu->add("/contact/index.php?userid=$user->id", $langs->trans("MyContacts"), 1, $user->rights->societe->contact->lire);
            // Categories
            if ($conf->categorie->enabled) {
                $langs->load("categories");
                // Categories prospects/customers
                $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=2", $langs->trans("CustomersProspectsCategoriesShort"), 0, $user->rights->categorie->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/categories/fiche.php?action=create&amp;type=2", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                }
                // Categories suppliers
                if ($conf->fournisseur->enabled) {
                    $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=1", $langs->trans("SuppliersCategoriesShort"), 0, $user->rights->categorie->lire);
                    if ($user->societe_id == 0) {
                        $newmenu->add("/categories/fiche.php?action=create&amp;type=1", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                    }
                }
                //if ($leftmenu=="cat") $newmenu->add("/categories/liste.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
            }
        }
        /*
         * Menu COMMERCIAL
         */
        if ($mainmenu == 'commercial') {
            $langs->load("companies");
            // Propal
            if (!empty($conf->propal->enabled)) {
                $langs->load("propal");
                $newmenu->add("/comm/propal/index.php?leftmenu=propals", $langs->trans("Prop"), 0, $user->rights->propale->lire);
                $newmenu->add("/societe/societe.php?leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer);
                $newmenu->add("/comm/propal.php?leftmenu=propals", $langs->trans("List"), 1, $user->rights->propale->lire);
                if ($leftmenu == "propals") {
                    $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire);
                }
                if ($leftmenu == "propals") {
                    $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire);
                }
                if ($leftmenu == "propals") {
                    $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=2", $langs->trans("PropalStatusSigned"), 2, $user->rights->propale->lire);
                }
                if ($leftmenu == "propals") {
                    $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=3", $langs->trans("PropalStatusNotSigned"), 2, $user->rights->propale->lire);
                }
                if ($leftmenu == "propals") {
                    $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=4", $langs->trans("PropalStatusBilled"), 2, $user->rights->propale->lire);
                }
                //if ($leftmenu=="propals") $newmenu->add("/comm/propal.php?leftmenu=propals&viewstatut=2,3,4", $langs->trans("PropalStatusClosedShort"), 2, $user->rights->propale->lire);
                $newmenu->add("/comm/propal/stats/index.php?leftmenu=propals", $langs->trans("Statistics"), 1, $user->rights->propale->lire);
            }
            // Customers orders
            if (!empty($conf->commande->enabled)) {
                $langs->load("orders");
                $newmenu->add("/commande/index.php?leftmenu=orders", $langs->trans("CustomersOrders"), 0, $user->rights->commande->lire);
                $newmenu->add("/societe/societe.php?leftmenu=orders", $langs->trans("NewOrder"), 1, $user->rights->commande->creer);
                $newmenu->add("/commande/liste.php?leftmenu=orders", $langs->trans("List"), 1, $user->rights->commande->lire);
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->commande->lire);
                }
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->commande->lire);
                }
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=2", $langs->trans("StatusOrderOnProcessShort"), 2, $user->rights->commande->lire);
                }
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=3", $langs->trans("StatusOrderToBill"), 2, $user->rights->commande->lire);
                }
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=4", $langs->trans("StatusOrderProcessed"), 2, $user->rights->commande->lire);
                }
                if ($leftmenu == "orders") {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&viewstatut=-1", $langs->trans("StatusOrderCanceledShort"), 2, $user->rights->commande->lire);
                }
                $newmenu->add("/commande/stats/index.php?leftmenu=orders", $langs->trans("Statistics"), 1, $user->rights->commande->lire);
            }
            // Suppliers orders
            if (!empty($conf->fournisseur->enabled)) {
                $langs->load("orders");
                $newmenu->add("/fourn/commande/index.php?leftmenu=orders_suppliers", $langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire);
                $newmenu->add("/societe/societe.php?leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
                $newmenu->add("/fourn/commande/liste.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
                $newmenu->add("/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire);
            }
            // Contrat
            if (!empty($conf->contrat->enabled)) {
                $langs->load("contracts");
                $newmenu->add("/contrat/index.php?leftmenu=contracts", $langs->trans("Contracts"), 0, $user->rights->contrat->lire);
                $newmenu->add("/societe/societe.php?leftmenu=contracts", $langs->trans("NewContract"), 1, $user->rights->contrat->creer);
                $newmenu->add("/contrat/liste.php?leftmenu=contracts", $langs->trans("List"), 1, $user->rights->contrat->lire);
                $newmenu->add("/contrat/services.php?leftmenu=contracts", $langs->trans("MenuServices"), 1, $user->rights->contrat->lire);
                if ($leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=0", $langs->trans("MenuInactiveServices"), 2, $user->rights->contrat->lire);
                }
                if ($leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=4", $langs->trans("MenuRunningServices"), 2, $user->rights->contrat->lire);
                }
                if ($leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=4&amp;filter=expired", $langs->trans("MenuExpiredServices"), 2, $user->rights->contrat->lire);
                }
                if ($leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=5", $langs->trans("MenuClosedServices"), 2, $user->rights->contrat->lire);
                }
            }
            // Interventions
            if (!empty($conf->ficheinter->enabled)) {
                $langs->load("interventions");
                $newmenu->add("/fichinter/index.php?leftmenu=ficheinter", $langs->trans("Interventions"), 0, $user->rights->ficheinter->lire);
                $newmenu->add("/fichinter/fiche.php?action=create&leftmenu=ficheinter", $langs->trans("NewIntervention"), 1, $user->rights->ficheinter->creer);
                $newmenu->add("/fichinter/index.php?leftmenu=ficheinter", $langs->trans("List"), 1, $user->rights->ficheinter->lire);
            }
        }
        /*
         * Menu COMPTA-FINANCIAL
         */
        if ($mainmenu == 'accountancy') {
            $langs->load("companies");
            // Customers invoices
            if ($conf->facture->enabled) {
                $langs->load("bills");
                $newmenu->add("/compta/facture.php?leftmenu=customers_bills", $langs->trans("BillsCustomers"), 0, $user->rights->facture->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/compta/clients.php?action=facturer&amp;leftmenu=customers_bills", $langs->trans("NewBill"), 1, $user->rights->facture->creer);
                }
                $newmenu->add("/compta/facture/fiche-rec.php?leftmenu=customers_bills", $langs->trans("Repeatables"), 1, $user->rights->facture->lire);
                $newmenu->add("/compta/facture/impayees.php?leftmenu=customers_bills", $langs->trans("Unpaid"), 1, $user->rights->facture->lire);
                $newmenu->add("/compta/paiement/liste.php?leftmenu=customers_bills_payments", $langs->trans("Payments"), 1, $user->rights->facture->lire);
                if ($conf->global->BILL_ADD_PAYMENT_VALIDATION) {
                    $newmenu->add("/compta/paiement/avalider.php?leftmenu=customers_bills_payments", $langs->trans("MenuToValid"), 2, $user->rights->facture->lire);
                }
                $newmenu->add("/compta/paiement/rapport.php?leftmenu=customers_bills_payments", $langs->trans("Reportings"), 2, $user->rights->facture->lire);
                $newmenu->add("/compta/facture/stats/index.php?leftmenu=customers_bills", $langs->trans("Statistics"), 1, $user->rights->facture->lire);
            }
            // Suppliers
            if ($conf->societe->enabled && $conf->fournisseur->enabled) {
                if ($conf->facture->enabled) {
                    $langs->load("bills");
                    $newmenu->add("/fourn/facture/index.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"), 0, $user->rights->fournisseur->facture->lire);
                    if ($user->societe_id == 0) {
                        $newmenu->add("/fourn/facture/fiche.php?action=create", $langs->trans("NewBill"), 1, $user->rights->fournisseur->facture->creer);
                    }
                    $newmenu->add("/fourn/facture/impayees.php", $langs->trans("Unpaid"), 1, $user->rights->fournisseur->facture->lire);
                    $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire);
                    $newmenu->add("/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->facture->lire);
                }
            }
            // Orders
            if ($conf->commande->enabled) {
                $langs->load("orders");
                if ($conf->facture->enabled) {
                    $newmenu->add("/commande/liste.php?leftmenu=orders&amp;viewstatut=3", $langs->trans("MenuOrdersToBill"), 0, $user->rights->commande->lire);
                }
                //                  if ($leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1 ,$user->rights->commande->lire);
            }
            // Donations
            if ($conf->don->enabled) {
                $langs->load("donations");
                $newmenu->add("/compta/dons/index.php?leftmenu=donations&amp;mainmenu=accountancy", $langs->trans("Donations"), 0, $user->rights->don->lire);
                if ($leftmenu == "donations") {
                    $newmenu->add("/compta/dons/fiche.php?action=create", $langs->trans("NewDonation"), 1, $user->rights->don->creer);
                }
                if ($leftmenu == "donations") {
                    $newmenu->add("/compta/dons/liste.php", $langs->trans("List"), 1, $user->rights->don->lire);
                }
                //if ($leftmenu=="donations") $newmenu->add("/compta/dons/stats.php",$langs->trans("Statistics"), 1, $user->rights->don->lire);
            }
            // Trips and expenses
            if ($conf->deplacement->enabled) {
                $langs->load("trips");
                $newmenu->add("/compta/deplacement/index.php?leftmenu=tripsandexpenses&amp;mainmenu=accountancy", $langs->trans("TripsAndExpenses"), 0, $user->rights->deplacement->lire);
                if ($leftmenu == "tripsandexpenses") {
                    $newmenu->add("/compta/deplacement/fiche.php?action=create&amp;leftmenu=tripsandexpenses&amp;mainmenu=accountancy", $langs->trans("New"), 1, $user->rights->deplacement->creer);
                }
                if ($leftmenu == "tripsandexpenses") {
                    $newmenu->add("/compta/deplacement/list.php?leftmenu=tripsandexpenses&amp;mainmenu=accountancy", $langs->trans("List"), 1, $user->rights->deplacement->lire);
                }
                if ($leftmenu == "tripsandexpenses") {
                    $newmenu->add("/compta/deplacement/stats/index.php?leftmenu=tripsandexpenses&amp;mainmenu=accountancy", $langs->trans("Statistics"), 1, $user->rights->deplacement->lire);
                }
            }
            // Taxes and social contributions
            if ($conf->tax->enabled) {
                $newmenu->add("/compta/charges/index.php?leftmenu=tax&amp;mainmenu=accountancy", $langs->trans("MenuTaxAndDividends"), 0, $user->rights->tax->charges->lire);
                if (preg_match('/^tax/i', $leftmenu)) {
                    $newmenu->add("/compta/sociales/index.php?leftmenu=tax_social", $langs->trans("MenuSocialContributions"), 1, $user->rights->tax->charges->lire);
                }
                if (preg_match('/^tax/i', $leftmenu)) {
                    $newmenu->add("/compta/sociales/charges.php?leftmenu=tax_social&action=create", $langs->trans("MenuNewSocialContribution"), 2, $user->rights->tax->charges->creer);
                }
                if (preg_match('/^tax/i', $leftmenu)) {
                    $newmenu->add("/compta/charges/index.php?leftmenu=tax_social&amp;mainmenu=accountancy&amp;mode=sconly", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                }
                // VAT
                if ($conf->compta->tva) {
                    if (preg_match('/^tax/i', $leftmenu)) {
                        $newmenu->add("/compta/tva/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy", $langs->trans("VAT"), 1, $user->rights->tax->charges->lire);
                    }
                    if (preg_match('/^tax/i', $leftmenu)) {
                        $newmenu->add("/compta/tva/fiche.php?leftmenu=tax_vat&action=create", $langs->trans("NewPayment"), 2, $user->rights->tax->charges->creer);
                    }
                    if (preg_match('/^tax/i', $leftmenu)) {
                        $newmenu->add("/compta/tva/reglement.php?leftmenu=tax_vat", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                    }
                    if (preg_match('/^tax/i', $leftmenu)) {
                        $newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
                    }
                    if (preg_match('/^tax/i', $leftmenu)) {
                        $newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
                    }
                }
            }
            // Compta simple
            if ($conf->comptabilite->enabled && $conf->global->FACTURE_VENTILATION) {
                $newmenu->add("/compta/ventilation/index.php?leftmenu=ventil", $langs->trans("Dispatch"), 0, $user->rights->compta->ventilation->lire);
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/ventilation/liste.php", $langs->trans("ToDispatch"), 1, $user->rights->compta->ventilation->lire);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/ventilation/lignes.php", $langs->trans("Dispatched"), 1, $user->rights->compta->ventilation->lire);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/param/", $langs->trans("Setup"), 1, $user->rights->compta->ventilation->parametrer);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/param/comptes/fiche.php?action=create", $langs->trans("New"), 2, $user->rights->compta->ventilation->parametrer);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/param/comptes/liste.php", $langs->trans("List"), 2, $user->rights->compta->ventilation->parametrer);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/export/", $langs->trans("Export"), 1, $user->rights->compta->ventilation->lire);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/export/index.php?action=export", $langs->trans("New"), 2, $user->rights->compta->ventilation->lire);
                }
                if ($leftmenu == "ventil") {
                    $newmenu->add("/compta/export/liste.php", $langs->trans("List"), 2, $user->rights->compta->ventilation->lire);
                }
            }
            // Compta expert
            if ($conf->accounting->enabled) {
            }
            // Rapports
            if ($conf->comptabilite->enabled || $conf->accounting->enabled) {
                $langs->load("compta");
                // Bilan, resultats
                $newmenu->add("/compta/resultat/index.php?leftmenu=ca&amp;mainmenu=accountancy", $langs->trans("Reportings"), 0, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/resultat/index.php?leftmenu=ca", $langs->trans("ReportInOut"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/resultat/clientfourn.php?leftmenu=ca", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                /* On verra ca avec module compabilite expert
                   if ($leftmenu=="ca") $newmenu->add("/compta/resultat/compteres.php?leftmenu=ca","Compte de resultat",2,$user->rights->compta->resultat->lire);
                   if ($leftmenu=="ca") $newmenu->add("/compta/resultat/bilan.php?leftmenu=ca","Bilan",2,$user->rights->compta->resultat->lire);
                   */
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/stats/index.php?leftmenu=ca", $langs->trans("ReportTurnover"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                /*
                if ($leftmenu=="ca") $newmenu->add("/compta/stats/cumul.php?leftmenu=ca","Cumule",2,$user->rights->compta->resultat->lire);
                if ($conf->propal->enabled) {
                if ($leftmenu=="ca") $newmenu->add("/compta/stats/prev.php?leftmenu=ca","Previsionnel",2,$user->rights->compta->resultat->lire);
                if ($leftmenu=="ca") $newmenu->add("/compta/stats/comp.php?leftmenu=ca","Transforme",2,$user->rights->compta->resultat->lire);
                }
                */
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/stats/casoc.php?leftmenu=ca", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/stats/cabyuser.php?leftmenu=ca", $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                // Journaux
                //if ($leftmenu=="ca") $newmenu->add("/compta/journaux/index.php?leftmenu=ca",$langs->trans("Journaux"),1,$user->rights->compta->resultat->lire||$user->rights->accounting->comptarapport->lire);
                //journaux
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/journal/sellsjournal.php?leftmenu=ca", $langs->trans("SellsJournal"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if ($leftmenu == "ca") {
                    $newmenu->add("/compta/journal/purchasesjournal.php?leftmenu=ca", $langs->trans("PurchasesJournal"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
            }
        }
        /*
         * Menu BANK
         */
        if ($mainmenu == 'bank') {
            $langs->load("withdrawals");
            $langs->load("banks");
            $langs->load("bills");
            // Bank-Caisse
            if ($conf->banque->enabled) {
                $newmenu->add("/compta/bank/index.php?leftmenu=bank&amp;mainmenu=bank", $langs->trans("MenuBankCash"), 0, $user->rights->banque->lire);
                $newmenu->add("/compta/bank/fiche.php?action=create", $langs->trans("MenuNewFinancialAccount"), 1, $user->rights->banque->configurer);
                $newmenu->add("/compta/bank/categ.php", $langs->trans("Rubriques"), 1, $user->rights->banque->configurer);
                $newmenu->add("/compta/bank/search.php", $langs->trans("ListTransactions"), 1, $user->rights->banque->lire);
                $newmenu->add("/compta/bank/budget.php", $langs->trans("ListTransactionsByCategory"), 1, $user->rights->banque->lire);
                $newmenu->add("/compta/bank/virement.php", $langs->trans("BankTransfers"), 1, $user->rights->banque->transfer);
            }
            // Prelevements
            if ($conf->prelevement->enabled) {
                $newmenu->add("/compta/prelevement/index.php?leftmenu=withdraw&amp;mainmenu=bank", $langs->trans("StandingOrders"), 0, $user->rights->prelevement->bons->lire);
                //if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php?status=0&amp;mainmenu=bank",$langs->trans("StandingOrderToProcess"),1,$user->rights->prelevement->bons->lire);
                if ($leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/create.php?mainmenu=bank", $langs->trans("NewStandingOrder"), 1, $user->rights->prelevement->bons->creer);
                }
                if ($leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/bons.php?mainmenu=bank", $langs->trans("WithdrawalsReceipts"), 1, $user->rights->prelevement->bons->lire);
                }
                if ($leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/liste.php?mainmenu=bank", $langs->trans("WithdrawalsLines"), 1, $user->rights->prelevement->bons->lire);
                }
                if ($leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/rejets.php?mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->prelevement->bons->lire);
                }
                if ($leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/stats.php?mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->prelevement->bons->lire);
                }
                //if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/config.php",$langs->trans("Setup"),1,$user->rights->prelevement->bons->configurer);
            }
            // Gestion cheques
            if ($conf->facture->enabled && $conf->banque->enabled) {
                $newmenu->add("/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("MenuChequeDeposits"), 0, $user->rights->banque->cheque);
                $newmenu->add("/compta/paiement/cheque/fiche.php?leftmenu=checks&amp;action=new&amp;mainmenu=bank", $langs->trans("NewChequeDeposit"), 1, $user->rights->banque->cheque);
                $newmenu->add("/compta/paiement/cheque/liste.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->cheque);
            }
        }
        /*
         * Menu PRODUCTS-SERVICES
         */
        if ($mainmenu == 'products') {
            // Products
            if ($conf->product->enabled) {
                $newmenu->add("/product/index.php?leftmenu=product&amp;type=0", $langs->trans("Products"), 0, $user->rights->produit->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/product/fiche.php?leftmenu=product&amp;action=create&amp;type=0", $langs->trans("NewProduct"), 1, $user->rights->produit->creer);
                    $newmenu->add("/product/liste.php?leftmenu=product&amp;type=0", $langs->trans("List"), 1, $user->rights->produit->lire);
                }
                if ($conf->propal->enabled) {
                    $newmenu->add("/product/popuprop.php?leftmenu=stats&amp;type=0", $langs->trans("Statistics"), 1, $user->rights->produit->lire && $user->rights->propale->lire);
                }
                if ($conf->stock->enabled) {
                    $newmenu->add("/product/reassort.php?type=0", $langs->trans("Stocks"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
                }
            }
            // Services
            if ($conf->service->enabled) {
                $newmenu->add("/product/index.php?leftmenu=service&amp;type=1", $langs->trans("Services"), 0, $user->rights->service->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/product/fiche.php?leftmenu=service&amp;action=create&amp;type=1", $langs->trans("NewService"), 1, $user->rights->service->creer);
                }
                $newmenu->add("/product/liste.php?leftmenu=service&amp;type=1", $langs->trans("List"), 1, $user->rights->service->lire);
                if ($conf->propal->enabled) {
                    $newmenu->add("/product/popuprop.php?leftmenu=stats&amp;type=1", $langs->trans("Statistics"), 1, $user->rights->service->lire && $user->rights->propale->lire);
                }
            }
            // Categories
            if ($conf->categorie->enabled) {
                $langs->load("categories");
                $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=0", $langs->trans("Categories"), 0, $user->rights->categorie->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/categories/fiche.php?action=create&amp;type=0", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                }
                //if ($leftmenu=="cat") $newmenu->add("/categories/liste.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
            }
            // Stocks
            if ($conf->stock->enabled) {
                $langs->load("stocks");
                $newmenu->add("/product/stock/index.php?leftmenu=stock", $langs->trans("Stocks"), 0, $user->rights->stock->lire);
                if ($leftmenu == "stock") {
                    $newmenu->add("/product/stock/fiche.php?action=create", $langs->trans("MenuNewWarehouse"), 1, $user->rights->stock->creer);
                }
                if ($leftmenu == "stock") {
                    $newmenu->add("/product/stock/liste.php", $langs->trans("List"), 1, $user->rights->stock->lire);
                }
                if ($leftmenu == "stock") {
                    $newmenu->add("/product/stock/valo.php", $langs->trans("EnhancedValue"), 1, $user->rights->stock->lire);
                }
                if ($leftmenu == "stock") {
                    $newmenu->add("/product/stock/mouvement.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
                }
            }
            // Expeditions
            if ($conf->expedition->enabled) {
                $langs->load("sendings");
                $newmenu->add("/expedition/index.php?leftmenu=sendings", $langs->trans("Shipments"), 0, $user->rights->expedition->lire);
                if ($leftmenu == "sendings") {
                    $newmenu->add("/expedition/liste.php?leftmenu=sendings", $langs->trans("List"), 1, $user->rights->expedition->lire);
                }
                if ($leftmenu == "sendings") {
                    $newmenu->add("/expedition/stats/index.php?leftmenu=sendings", $langs->trans("Statistics"), 1, $user->rights->expedition->lire);
                }
            }
        }
        /*
         * Menu SUPPLIERS
         */
        if ($mainmenu == 'suppliers') {
            $langs->load("suppliers");
            if ($conf->societe->enabled && $conf->fournisseur->enabled) {
                $newmenu->add("/fourn/index.php?leftmenu=suppliers", $langs->trans("Suppliers"), 0, $user->rights->societe->lire && $user->rights->fournisseur->lire);
                // Security check
                if ($user->societe_id == 0) {
                    $newmenu->add("/societe/soc.php?leftmenu=suppliers&amp;action=create&amp;type=f", $langs->trans("NewSupplier"), 1, $user->rights->societe->creer && $user->rights->fournisseur->lire);
                }
                $newmenu->add("/fourn/liste.php", $langs->trans("List"), 1, $user->rights->societe->lire && $user->rights->fournisseur->lire);
                $newmenu->add("/contact/index.php?leftmenu=suppliers&amp;type=f", $langs->trans("Contacts"), 1, $user->rights->societe->contact->lire && $user->rights->fournisseur->lire);
                $newmenu->add("/fourn/stats.php", $langs->trans("Statistics"), 1, $user->rights->societe->lire && $user->rights->fournisseur->lire);
            }
            if ($conf->facture->enabled) {
                $langs->load("bills");
                $newmenu->add("/fourn/facture/index.php", $langs->trans("Bills"), 0, $user->rights->fournisseur->facture->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/fourn/facture/fiche.php?action=create", $langs->trans("NewBill"), 1, $user->rights->fournisseur->facture->creer);
                }
                $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire);
            }
            if ($conf->fournisseur->enabled) {
                $langs->load("orders");
                $newmenu->add("/fourn/commande/index.php?leftmenu=suppliers", $langs->trans("Orders"), 0, $user->rights->fournisseur->commande->lire);
                $newmenu->add("/societe/societe.php?leftmenu=supplier", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
                $newmenu->add("/fourn/commande/liste.php?leftmenu=suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
            }
            if ($conf->categorie->enabled) {
                $langs->load("categories");
                $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=1", $langs->trans("Categories"), 0, $user->rights->categorie->lire);
                if ($user->societe_id == 0) {
                    $newmenu->add("/categories/fiche.php?action=create&amp;type=1", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                }
                //if ($leftmenu=="cat") $newmenu->add("/categories/liste.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
            }
        }
        /*
         * Menu PROJECTS
         */
        if ($mainmenu == 'project') {
            if ($conf->projet->enabled) {
                $langs->load("projects");
                // Project affected to user
                $newmenu->add("/projet/index.php?leftmenu=projects&mode=mine", $langs->trans("MyProjects"), 0, $user->rights->projet->lire);
                $newmenu->add("/projet/fiche.php?leftmenu=projects&action=create&mode=mine", $langs->trans("NewProject"), 1, $user->rights->projet->creer);
                $newmenu->add("/projet/liste.php?leftmenu=projects&mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
                // All project i have permission on
                $newmenu->add("/projet/index.php?leftmenu=projects", $langs->trans("Projects"), 0, $user->rights->projet->lire && $user->rights->projet->lire);
                $newmenu->add("/projet/fiche.php?leftmenu=projects&action=create", $langs->trans("NewProject"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
                $newmenu->add("/projet/liste.php?leftmenu=projects", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
                // Project affected to user
                $newmenu->add("/projet/activity/index.php?mode=mine", $langs->trans("MyActivities"), 0, $user->rights->projet->lire);
                $newmenu->add("/projet/tasks.php?action=create&mode=mine", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
                $newmenu->add("/projet/tasks/index.php?mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
                $newmenu->add("/projet/activity/list.php?mode=mine", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer);
                // All project i have permission on
                $newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire);
                $newmenu->add("/projet/tasks.php?action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
                $newmenu->add("/projet/tasks/index.php", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
                $newmenu->add("/projet/activity/list.php", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
            }
        }
        /*
         * Menu TOOLS
         */
        if ($mainmenu == 'tools') {
            if (!empty($conf->mailing->enabled)) {
                $langs->load("mails");
                $newmenu->add("/comm/mailing/index.php?leftmenu=mailing", $langs->trans("EMailings"), 0, $user->rights->mailing->lire);
                $newmenu->add("/comm/mailing/fiche.php?leftmenu=mailing&amp;action=create", $langs->trans("NewMailing"), 1, $user->rights->mailing->creer);
                $newmenu->add("/comm/mailing/liste.php?leftmenu=mailing", $langs->trans("List"), 1, $user->rights->mailing->lire);
            }
            if (!empty($conf->export->enabled)) {
                $langs->load("exports");
                $newmenu->add("/exports/index.php?leftmenu=export", $langs->trans("FormatedExport"), 0, $user->rights->export->lire);
                $newmenu->add("/exports/export.php?leftmenu=export", $langs->trans("NewExport"), 1, $user->rights->export->creer);
                //$newmenu->add("/exports/export.php?leftmenu=export",$langs->trans("List"),1, $user->rights->export->lire);
            }
            if (!empty($conf->import->enabled)) {
                $langs->load("exports");
                $newmenu->add("/imports/index.php?leftmenu=import", $langs->trans("FormatedImport"), 0, $user->rights->import->run);
                $newmenu->add("/imports/import.php?leftmenu=import", $langs->trans("NewImport"), 1, $user->rights->import->run);
            }
            if (!empty($conf->domain->enabled)) {
                $langs->load("domains");
                $newmenu->add("/domain/index.php?leftmenu=export", $langs->trans("DomainNames"), 0, $user->rights->domain->read);
                $newmenu->add("/domain/fiche.php?action=create&leftmenu=export", $langs->trans("NewDomain"), 1, $user->rights->domain->create);
                $newmenu->add("/domain/index.php?leftmenu=export", $langs->trans("List"), 1, $user->rights->domain->read);
            }
            if (!empty($conf->submiteverywhere->enabled)) {
                $langs->load("submiteverywhere@submiteverywhere");
                $newmenu->add("/submiteverywhere/index.php?leftmenu=submiteverywhere", $langs->trans("News"), 0, $user->rights->submiteverywhere->read);
                $newmenu->add("/submiteverywhere/fiche.php?leftmenu=submiteverywhere&amp;action=create", $langs->trans("NewNews"), 1, $user->rights->submiteverywhere->create);
                $newmenu->add("/submiteverywhere/liste.php?leftmenu=submiteverywhere", $langs->trans("List"), 1, $user->rights->submiteverywhere->read);
            }
        }
        /*
         * Menu MEMBERS
         */
        if ($mainmenu == 'members') {
            if ($conf->adherent->enabled) {
                $langs->load("members");
                $langs->load("compta");
                $newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Members"), 0, $user->rights->adherent->lire);
                $newmenu->add("/adherents/fiche.php?leftmenu=members&amp;action=create", $langs->trans("NewMember"), 1, $user->rights->adherent->creer);
                $newmenu->add("/adherents/liste.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=-1", $langs->trans("MenuMembersToValidate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=1", $langs->trans("MenuMembersValidated"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=1&amp;filter=uptodate", $langs->trans("MenuMembersUpToDate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=1&amp;filter=outofdate", $langs->trans("MenuMembersNotUpToDate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=0", $langs->trans("MenuMembersResiliated"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/stats/index.php?leftmenu=members", $langs->trans("MenuMembersStats"), 1, $user->rights->adherent->lire);
                $newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Subscriptions"), 0, $user->rights->adherent->cotisation->lire);
                $newmenu->add("/adherents/liste.php?leftmenu=members&amp;statut=-1,1&amp;mainmenu=members", $langs->trans("NewSubscription"), 1, $user->rights->adherent->cotisation->creer);
                $newmenu->add("/adherents/cotisations.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->cotisation->lire);
                if ($conf->categorie->enabled) {
                    $langs->load("categories");
                    $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=3", $langs->trans("Categories"), 0, $user->rights->categorie->lire);
                    if ($user->societe_id == 0) {
                        $newmenu->add("/categories/fiche.php?action=create&amp;type=3", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                    }
                    //if ($leftmenu=="cat") $newmenu->add("/categories/liste.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
                }
                $newmenu->add("/adherents/index.php?leftmenu=export&amp;mainmenu=members", $langs->trans("Exports"), 0, $user->rights->adherent->export);
                if ($conf->export->enabled && $leftmenu == "export") {
                    $newmenu->add("/exports/index.php?leftmenu=export", $langs->trans("Datas"), 1, $user->rights->adherent->export);
                }
                if ($leftmenu == "export") {
                    $newmenu->add("/adherents/htpasswd.php?leftmenu=export", $langs->trans("Filehtpasswd"), 1, $user->rights->adherent->export);
                }
                if ($leftmenu == "export") {
                    $newmenu->add("/adherents/cartes/carte.php?leftmenu=export", $langs->trans("MembersCards"), 1, $user->rights->adherent->export);
                }
                // Type
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("MembersTypes"), 0, $user->rights->adherent->configurer);
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members&amp;action=create", $langs->trans("New"), 1, $user->rights->adherent->configurer);
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("List"), 1, $user->rights->adherent->configurer);
            }
        }
        // Affichage des menus personnalises
        require_once DOL_DOCUMENT_ROOT . "/core/class/menubase.class.php";
        $tabMenu = array();
        $menuArbo = new Menubase($db, 'eldy', 'left');
        $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, $user->societe_id ? 1 : 0, 'eldy', $tabMenu);
    }
    //var_dump($menu_array_before);exit;
    //var_dump($menu_array_after);exit;
    $menu_array = $newmenu->liste;
    if (is_array($menu_array_before)) {
        $menu_array = array_merge($menu_array_before, $menu_array);
    }
    if (is_array($menu_array_after)) {
        $menu_array = array_merge($menu_array, $menu_array_after);
    }
    //var_dump($menu_array);exit;
    // Show menu
    $alt = 0;
    if (is_array($menu_array)) {
        for ($i = 0; $i < sizeof($menu_array); $i++) {
            $alt++;
            if (empty($menu_array[$i]['level'])) {
                if ($alt % 2 == 0) {
                    print '<div class="blockvmenuimpair">' . "\n";
                } else {
                    print '<div class="blockvmenupair">' . "\n";
                }
            }
            // Place tabulation
            $tabstring = '';
            $tabul = $menu_array[$i]['level'] - 1;
            if ($tabul > 0) {
                for ($j = 0; $j < $tabul; $j++) {
                    $tabstring .= '&nbsp; &nbsp;';
                }
            }
            // For external modules
            $url = dol_buildpath($menu_array[$i]['url'], 1);
            // Menu niveau 0
            if ($menu_array[$i]['level'] == 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_titre">' . $tabstring . '<a class="vmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>' . $menu_array[$i]['titre'] . '</a></div>' . "\n";
                } else {
                    if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
                        print '<div class="menu_titre">' . $tabstring . '<font class="vmenudisabled">' . $menu_array[$i]['titre'] . '</font></div>' . "\n";
                    }
                }
                print '<div class="menu_top"></div>' . "\n";
            }
            // Menu niveau > 0
            if ($menu_array[$i]['level'] > 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_contenu">' . $tabstring;
                    if ($menu_array[$i]['url']) {
                        print '<a class="vsmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>';
                    }
                    print $menu_array[$i]['titre'];
                    if ($menu_array[$i]['url']) {
                        print '</a>';
                    }
                    // If title is not pure text and contains a table, no carriage return added
                    if (!strstr($menu_array[$i]['titre'], '<table')) {
                        print '<br>';
                    }
                    print '</div>' . "\n";
                } else {
                    if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
                        print '<div class="menu_contenu">' . $tabstring . '<font class="vsmenudisabled">' . $menu_array[$i]['titre'] . '</font><br></div>' . "\n";
                    }
                }
            }
            // If next is a new block or end
            if (empty($menu_array[$i + 1]['level'])) {
                print '<div class="menu_end"></div>' . "\n";
                print "</div>\n";
            }
        }
    }
    return sizeof($menu_array);
}
Esempio n. 9
0
/**
 * Core function to output left menu eldy
 *
 * @param	DoliDB		$db                 Database handler
 * @param 	array		$menu_array_before  Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add)
 * @param   array		$menu_array_after   Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add)
 * @param	array		$tabMenu       	If array with menu entries already loaded, we put this array here (in most cases, it's empty)
 * @param	Menu		$menu				Object Menu to return back list of menu entries
 * @param	int			$noout				Disable output (Initialise &$menu only).
 * @param	string		$forcemainmenu		'x'=Force mainmenu to mainmenu='x'
 * @param	string		$forceleftmenu		'all'=Force leftmenu to '' (= all)
 * @return	int								nb of menu entries
 */
function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '')
{
    global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
    $newmenu = $menu;
    $mainmenu = $forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"];
    $leftmenu = $forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]);
    // Show logo company
    if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
        $mysoc->logo_mini = $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
        if (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_mini)) {
            $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_mini);
        } else {
            $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
        }
        $title = $langs->trans("GoIntoSetupToChangeLogo");
        print "\n" . '<!-- Show logo on menu -->' . "\n";
        print '<div class="blockvmenuimpair">' . "\n";
        print '<div class="menu_titre" id="menu_titre_logo"></div>';
        print '<div class="menu_top" id="menu_top_logo"></div>';
        print '<div class="menu_contenu" id="menu_contenu_logo">';
        print '<div class="center"><img title="' . dol_escape_htmltag($title) . '" alt="" src="' . $urllogo . '" style="max-width: 80%"></div>' . "\n";
        print '</div>';
        print '<div class="menu_end" id="menu_end_logo"></div>';
        print '</div>' . "\n";
    }
    /**
     * We update newmenu with entries found into database
     * --------------------------------------------------
     */
    if ($mainmenu) {
        /*
         * Menu HOME
         */
        if ($mainmenu == 'home') {
            $langs->load("users");
            //if ($user->admin)
            //{
            // Setup
            $newmenu->add("/admin/index.php?mainmenu=home&amp;leftmenu=setup", $langs->trans("Setup"), 0, $user->admin, '', $mainmenu, 'setup');
            if (empty($leftmenu) || $leftmenu == "setup") {
                $langs->load("admin");
                $langs->load("help");
                $warnpicto = '';
                if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
                    $langs->load("errors");
                    $warnpicto = ' ' . img_warning($langs->trans("WarningMandatorySetupNotComplete"));
                }
                $newmenu->add("/admin/company.php?mainmenu=home", $langs->trans("MenuCompanySetup") . $warnpicto, 1);
                $warnpicto = '';
                if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) {
                    $langs->load("errors");
                    $warnpicto = ' ' . img_warning($langs->trans("WarningMandatorySetupNotComplete"));
                }
                $newmenu->add("/admin/modules.php?mainmenu=home", $langs->trans("Modules") . $warnpicto, 1);
                $newmenu->add("/admin/menus.php?mainmenu=home", $langs->trans("Menus"), 1);
                $newmenu->add("/admin/ihm.php?mainmenu=home", $langs->trans("GUISetup"), 1);
                if (!in_array($langs->defaultlang, array('en_US'))) {
                    $newmenu->add("/admin/translation.php", $langs->trans("Translation"), 1);
                }
                $newmenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
                $newmenu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
                $newmenu->add("/admin/security_other.php?mainmenu=home", $langs->trans("Security"), 1);
                $newmenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
                $newmenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
                $newmenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
                $newmenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
                $newmenu->add("/admin/dict.php?mainmenu=home", $langs->trans("Dictionary"), 1);
                $newmenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
            }
            // System tools
            $newmenu->add("/admin/tools/index.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("SystemTools"), 0, $user->admin, '', $mainmenu, 'admintools');
            if (empty($leftmenu) || preg_match('/^admintools/', $leftmenu)) {
                $langs->load("admin");
                $langs->load("help");
                $newmenu->add('/admin/system/dolibarr.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('InfoDolibarr'), 1);
                if (empty($leftmenu) || $leftmenu == 'admintools_info') {
                    $newmenu->add('/admin/system/modules.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Modules'), 2);
                }
                if (empty($leftmenu) || $leftmenu == 'admintools_info') {
                    $newmenu->add('/admin/triggers.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Triggers'), 2);
                }
                //if (empty($leftmenu) || $leftmenu=='admintools_info') $newmenu->add('/admin/system/filecheck.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('FileCheck'), 2);
                $newmenu->add('/admin/system/browser.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoBrowser'), 1);
                $newmenu->add('/admin/system/os.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoOS'), 1);
                $newmenu->add('/admin/system/web.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoWebServer'), 1);
                $newmenu->add('/admin/system/phpinfo.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoPHP'), 1);
                //if (function_exists('xdebug_is_enabled')) $newmenu->add('/admin/system/xdebug.php', $langs->trans('XDebug'),1);
                $newmenu->add('/admin/system/database.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoDatabase'), 1);
                if (function_exists('eaccelerator_info')) {
                    $newmenu->add("/admin/tools/eaccelerator.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("EAccelerator"), 1);
                }
                //$newmenu->add("/admin/system/perf.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("InfoPerf"),1);
                $newmenu->add("/admin/tools/purge.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Purge"), 1);
                $newmenu->add("/admin/tools/dolibarr_export.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Backup"), 1);
                $newmenu->add("/admin/tools/dolibarr_import.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Restore"), 1);
                $newmenu->add("/admin/tools/update.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("MenuUpgrade"), 1);
                $newmenu->add("/admin/tools/listevents.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Audit"), 1);
                $newmenu->add("/admin/tools/listsessions.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Sessions"), 1);
                $newmenu->add('/admin/system/about.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('About'), 1);
                $newmenu->add("/support/index.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("HelpCenter"), 1, 1, 'targethelp');
            }
            // Modules system tools
            if (!empty($conf->product->enabled) || !empty($conf->service->enabled) || !empty($conf->barcode->enabled) || !empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) {
                if (empty($user->societe_id)) {
                    $newmenu->add("/admin/tools/index.php?mainmenu=home&amp;leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, $user->admin, '', $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");
                        $newmenu->add("/product/admin/product_tools.php?mainmenu=home&amp;leftmenu=modulesadmintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
                    }
                }
            }
            //}
            $newmenu->add("/user/home.php?leftmenu=users", $langs->trans("MenuUsersAndGroups"), 0, $user->rights->user->user->lire, '', $mainmenu, 'users');
            if ($user->rights->user->user->lire) {
                if (empty($leftmenu) || $leftmenu == 'none' || $leftmenu == "users") {
                    $newmenu->add("", $langs->trans("Users"), 1, $user->rights->user->user->lire || $user->admin);
                    $newmenu->add("/user/card.php?action=create", $langs->trans("NewUser"), 2, $user->rights->user->user->creer || $user->admin, '', 'home');
                    $newmenu->add("/user/index.php", $langs->trans("ListOfUsers"), 2, $user->rights->user->user->lire || $user->admin);
                    $newmenu->add("/user/hierarchy.php", $langs->trans("HierarchicView"), 2, $user->rights->user->user->lire || $user->admin);
                    $newmenu->add("", $langs->trans("Groups"), 1, $user->rights->user->user->lire || $user->admin);
                    $newmenu->add("/user/group/card.php?action=create", $langs->trans("NewGroup"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS ? $user->rights->user->group_advance->write : $user->rights->user->user->creer) || $user->admin);
                    $newmenu->add("/user/group/index.php", $langs->trans("ListOfGroups"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS ? $user->rights->user->group_advance->read : $user->rights->user->user->lire) || $user->admin);
                }
            }
        }
        /*
         * Menu THIRDPARTIES
         */
        if ($mainmenu == 'companies') {
            // Societes
            if (!empty($conf->societe->enabled)) {
                $langs->load("companies");
                $newmenu->add("/societe/index.php?leftmenu=thirdparties", $langs->trans("ThirdParty"), 0, $user->rights->societe->lire, '', $mainmenu, 'thirdparties');
                if ($user->rights->societe->creer) {
                    $newmenu->add("/societe/soc.php?action=create", $langs->trans("MenuNewThirdParty"), 1);
                    if (!$conf->use_javascript_ajax) {
                        $newmenu->add("/societe/soc.php?action=create&amp;private=1", $langs->trans("MenuNewPrivateIndividual"), 1);
                    }
                }
            }
            $newmenu->add("/societe/list.php?leftmenu=thirdparties", $langs->trans("List"), 1);
            // Prospects
            if (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
                $langs->load("commercial");
                $newmenu->add("/comm/prospect/list.php?leftmenu=prospects", $langs->trans("ListProspectsShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'prospects');
                /* no more required, there is a filter that can do more
                			if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire);
                			if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire);
                			if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=1", $langs->trans("LastProspectToContact"), 2, $user->rights->societe->lire);
                			if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=2", $langs->trans("LastProspectContactInProcess"), 2, $user->rights->societe->lire);
                			if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=3", $langs->trans("LastProspectContactDone"), 2, $user->rights->societe->lire);
                			*/
                $newmenu->add("/societe/soc.php?leftmenu=prospects&amp;action=create&amp;type=p", $langs->trans("MenuNewProspect"), 2, $user->rights->societe->creer);
                //$newmenu->add("/contact/list.php?leftmenu=customers&amp;type=p", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire);
            }
            // Customers/Prospects
            if (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
                $langs->load("commercial");
                $newmenu->add("/comm/list.php?leftmenu=customers", $langs->trans("ListCustomersShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'customers');
                $newmenu->add("/societe/soc.php?leftmenu=customers&amp;action=create&amp;type=c", $langs->trans("MenuNewCustomer"), 2, $user->rights->societe->creer);
                //$newmenu->add("/contact/list.php?leftmenu=customers&amp;type=c", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire);
            }
            // Suppliers
            if (!empty($conf->societe->enabled) && !empty($conf->fournisseur->enabled)) {
                $langs->load("suppliers");
                $newmenu->add("/fourn/list.php?leftmenu=suppliers", $langs->trans("ListSuppliersShort"), 1, $user->rights->fournisseur->lire, '', $mainmenu, 'suppliers');
                $newmenu->add("/societe/soc.php?leftmenu=suppliers&amp;action=create&amp;type=f", $langs->trans("MenuNewSupplier"), 2, $user->rights->societe->creer && $user->rights->fournisseur->lire);
                //$newmenu->add("/fourn/list.php?leftmenu=suppliers", $langs->trans("List"), 2, $user->rights->societe->lire && $user->rights->fournisseur->lire);
                //$newmenu->add("/contact/list.php?leftmenu=suppliers&amp;type=f",$langs->trans("Contacts"), 2, $user->rights->societe->lire && $user->rights->fournisseur->lire && $user->rights->societe->contact->lire);
            }
            // Contacts
            $newmenu->add("/societe/index.php?leftmenu=thirdparties", !empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ThirdParty") : $langs->trans("ContactsAddresses"), 0, $user->rights->societe->contact->lire, '', $mainmenu, 'contacts');
            $newmenu->add("/contact/card.php?leftmenu=contacts&amp;action=create", !empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"), 1, $user->rights->societe->contact->creer);
            $newmenu->add("/contact/list.php?leftmenu=contacts", $langs->trans("List"), 1, $user->rights->societe->contact->lire);
            if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
                $newmenu->add("/contact/list.php?leftmenu=contacts&type=p", $langs->trans("Prospects"), 2, $user->rights->societe->contact->lire);
            }
            if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
                $newmenu->add("/contact/list.php?leftmenu=contacts&type=c", $langs->trans("Customers"), 2, $user->rights->societe->contact->lire);
            }
            if (!empty($conf->fournisseur->enabled)) {
                $newmenu->add("/contact/list.php?leftmenu=contacts&type=f", $langs->trans("Suppliers"), 2, $user->rights->societe->contact->lire);
            }
            $newmenu->add("/contact/list.php?leftmenu=contacts&type=o", $langs->trans("Others"), 2, $user->rights->societe->contact->lire);
            //$newmenu->add("/contact/list.php?userid=$user->id", $langs->trans("MyContacts"), 1, $user->rights->societe->contact->lire);
            // Categories
            if (!empty($conf->categorie->enabled)) {
                $langs->load("categories");
                if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
                    // Categories prospects/customers
                    $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=2", $langs->trans("CustomersProspectsCategoriesShort"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat');
                    $newmenu->add("/categories/card.php?action=create&amp;type=2", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                }
                // Categories Contact
                $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=4", $langs->trans("ContactCategoriesShort"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat');
                $newmenu->add("/categories/card.php?action=create&amp;type=4", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                // Categories suppliers
                if (!empty($conf->fournisseur->enabled)) {
                    $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=1", $langs->trans("SuppliersCategoriesShort"), 0, $user->rights->categorie->lire);
                    $newmenu->add("/categories/card.php?action=create&amp;type=1", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                }
                //if (empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
            }
        }
        /*
         * Menu COMMERCIAL
         */
        if ($mainmenu == 'commercial') {
            $langs->load("companies");
            // Propal
            if (!empty($conf->propal->enabled)) {
                $langs->load("propal");
                $newmenu->add("/comm/propal/index.php?leftmenu=propals", $langs->trans("Prop"), 0, $user->rights->propale->lire, '', $mainmenu, 'propals');
                $newmenu->add("/comm/propal.php?action=create&amp;leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer);
                $newmenu->add("/comm/propal/list.php?leftmenu=propals", $langs->trans("List"), 1, $user->rights->propale->lire);
                if (empty($leftmenu) || $leftmenu == "propals") {
                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire);
                }
                if (empty($leftmenu) || $leftmenu == "propals") {
                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire);
                }
                if (empty($leftmenu) || $leftmenu == "propals") {
                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=2", $langs->trans("PropalStatusSigned"), 2, $user->rights->propale->lire);
                }
                if (empty($leftmenu) || $leftmenu == "propals") {
                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=3", $langs->trans("PropalStatusNotSigned"), 2, $user->rights->propale->lire);
                }
                if (empty($leftmenu) || $leftmenu == "propals") {
                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=4", $langs->trans("PropalStatusBilled"), 2, $user->rights->propale->lire);
                }
                //if (empty($leftmenu) || $leftmenu=="propals") $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=2,3,4", $langs->trans("PropalStatusClosedShort"), 2, $user->rights->propale->lire);
                $newmenu->add("/comm/propal/stats/index.php?leftmenu=propals", $langs->trans("Statistics"), 1, $user->rights->propale->lire);
            }
            // Customers orders
            if (!empty($conf->commande->enabled)) {
                $langs->load("orders");
                $newmenu->add("/commande/index.php?leftmenu=orders", $langs->trans("CustomersOrders"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders');
                $newmenu->add("/commande/card.php?action=create&amp;leftmenu=orders", $langs->trans("NewOrder"), 1, $user->rights->commande->creer);
                $newmenu->add("/commande/list.php?leftmenu=orders", $langs->trans("List"), 1, $user->rights->commande->lire);
                if (empty($leftmenu) || $leftmenu == "orders") {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders") {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders" && !empty($conf->expedition->enabled)) {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=2", $langs->trans("StatusOrderSentShort"), 2, $user->rights->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders") {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=3", $langs->trans("StatusOrderToBill"), 2, $user->rights->commande->lire);
                }
                // The translation key is StatusOrderToBill but it means StatusDelivered. TODO We should renamed this later
                if (empty($leftmenu) || $leftmenu == "orders") {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=4", $langs->trans("StatusOrderProcessed"), 2, $user->rights->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders") {
                    $newmenu->add("/commande/list.php?leftmenu=orders&viewstatut=-1", $langs->trans("StatusOrderCanceledShort"), 2, $user->rights->commande->lire);
                }
                $newmenu->add("/commande/stats/index.php?leftmenu=orders", $langs->trans("Statistics"), 1, $user->rights->commande->lire);
            }
            // Suppliers orders
            if (!empty($conf->fournisseur->enabled)) {
                $langs->load("orders");
                $newmenu->add("/fourn/commande/index.php?leftmenu=orders_suppliers", $langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire, '', $mainmenu, 'orders_suppliers');
                $newmenu->add("/fourn/commande/card.php?action=create&amp;leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
                $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->fournisseur->commande->lire);
                }
                if ((empty($leftmenu) || $leftmenu == "orders_suppliers") && empty($conf->global->SUPPLIER_ORDER_HIDE_VALIDATED)) {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=2", $langs->trans("StatusOrderApprovedShort"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=3", $langs->trans("StatusOrderOnProcessShort"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=4", $langs->trans("StatusOrderReceivedPartiallyShort"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=5", $langs->trans("StatusOrderReceivedAll"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=6,7", $langs->trans("StatusOrderCanceled"), 2, $user->rights->fournisseur->commande->lire);
                }
                if (empty($leftmenu) || $leftmenu == "orders_suppliers") {
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=9", $langs->trans("StatusOrderRefused"), 2, $user->rights->fournisseur->commande->lire);
                }
                $newmenu->add("/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire);
            }
            // Contrat
            if (!empty($conf->contrat->enabled)) {
                $langs->load("contracts");
                $newmenu->add("/contrat/index.php?leftmenu=contracts", $langs->trans("Contracts"), 0, $user->rights->contrat->lire, '', $mainmenu, 'contracts');
                $newmenu->add("/contrat/card.php?action=create&amp;leftmenu=contracts", $langs->trans("NewContract"), 1, $user->rights->contrat->creer);
                $newmenu->add("/contrat/list.php?leftmenu=contracts", $langs->trans("List"), 1, $user->rights->contrat->lire);
                $newmenu->add("/contrat/services.php?leftmenu=contracts", $langs->trans("MenuServices"), 1, $user->rights->contrat->lire);
                if (empty($leftmenu) || $leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=0", $langs->trans("MenuInactiveServices"), 2, $user->rights->contrat->lire);
                }
                if (empty($leftmenu) || $leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=4", $langs->trans("MenuRunningServices"), 2, $user->rights->contrat->lire);
                }
                if (empty($leftmenu) || $leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=4&amp;filter=expired", $langs->trans("MenuExpiredServices"), 2, $user->rights->contrat->lire);
                }
                if (empty($leftmenu) || $leftmenu == "contracts") {
                    $newmenu->add("/contrat/services.php?leftmenu=contracts&amp;mode=5", $langs->trans("MenuClosedServices"), 2, $user->rights->contrat->lire);
                }
            }
            // Interventions
            if (!empty($conf->ficheinter->enabled)) {
                $langs->load("interventions");
                $newmenu->add("/fichinter/list.php?leftmenu=ficheinter", $langs->trans("Interventions"), 0, $user->rights->ficheinter->lire, '', $mainmenu, 'ficheinter', 200);
                $newmenu->add("/fichinter/card.php?action=create&amp;leftmenu=ficheinter", $langs->trans("NewIntervention"), 1, $user->rights->ficheinter->creer, '', '', '', 201);
                $newmenu->add("/fichinter/list.php?leftmenu=ficheinter", $langs->trans("List"), 1, $user->rights->ficheinter->lire, '', '', '', 202);
            }
        }
        /*
         * Menu COMPTA-FINANCIAL
         */
        if ($mainmenu == 'accountancy') {
            $langs->load("companies");
            // Customers invoices
            if (!empty($conf->facture->enabled)) {
                $langs->load("bills");
                $newmenu->add("/compta/facture/list.php", $langs->trans("BillsCustomers"), 0, $user->rights->facture->lire, '', $mainmenu, 'customers_bills');
                $newmenu->add("/compta/facture.php?action=create", $langs->trans("NewBill"), 1, $user->rights->facture->creer);
                $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills", $langs->trans("List"), 1, $user->rights->facture->lire);
                if (empty($leftmenu) || $leftmenu == 'customers_bills') {
                    $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=0", $langs->trans("BillShortStatusDraft"), 2, $user->rights->facture->lire);
                    $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=1", $langs->trans("BillShortStatusNotPaid"), 2, $user->rights->facture->lire);
                    $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=2", $langs->trans("BillShortStatusPaid"), 2, $user->rights->facture->lire);
                    $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills&amp;search_status=3", $langs->trans("BillShortStatusCanceled"), 2, $user->rights->facture->lire);
                }
                $newmenu->add("/compta/facture/fiche-rec.php", $langs->trans("ListOfTemplates"), 1, $user->rights->facture->lire);
                $newmenu->add("/compta/paiement/list.php", $langs->trans("Payments"), 1, $user->rights->facture->lire);
                if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
                    $newmenu->add("/compta/paiement/avalider.php", $langs->trans("MenuToValid"), 2, $user->rights->facture->lire);
                }
                $newmenu->add("/compta/paiement/rapport.php", $langs->trans("Reportings"), 2, $user->rights->facture->lire);
                $newmenu->add("/compta/facture/stats/index.php", $langs->trans("Statistics"), 1, $user->rights->facture->lire);
                $newmenu->add("/compta/facture/mergepdftool.php", $langs->trans("MergingPDFTool"), 1, $user->rights->facture->lire);
            }
            // Suppliers
            if (!empty($conf->societe->enabled) && !empty($conf->fournisseur->enabled)) {
                $langs->load("bills");
                $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"), 0, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
                $newmenu->add("/fourn/facture/card.php?action=create", $langs->trans("NewBill"), 1, $user->rights->fournisseur->facture->creer);
                $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("List"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
                if (empty($leftmenu) || $leftmenu == 'suppliers_bills') {
                    $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&amp;search_status=0", $langs->trans("BillShortStatusDraft"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
                    $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&amp;search_status=1", $langs->trans("BillShortStatusNotPaid"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
                    $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills&amp;search_status=2", $langs->trans("BillShortStatusPaid"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills');
                }
                $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire);
                $newmenu->add("/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->facture->lire);
            }
            // Orders
            if (!empty($conf->commande->enabled)) {
                $langs->load("orders");
                if (!empty($conf->facture->enabled)) {
                    $newmenu->add("/commande/list.php?leftmenu=orders&amp;viewstatut=-3", $langs->trans("MenuOrdersToBill2"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders');
                }
                //                  if (empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
            }
            // Supplier Orders
            if (!empty($conf->fournisseur->enabled)) {
                if (!empty($conf->global->SUPPLIER_MENU_ORDER_RECEIVED_INTO_INVOICE)) {
                    $langs->load("supplier");
                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders&amp;search_status=5", $langs->trans("MenuOrdersSupplierToBill"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders');
                    //                  if (empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
                }
            }
            // Donations
            if (!empty($conf->don->enabled)) {
                $langs->load("donations");
                $newmenu->add("/don/index.php?leftmenu=donations&amp;mainmenu=accountancy", $langs->trans("Donations"), 0, $user->rights->don->lire, '', $mainmenu, 'donations');
                if (empty($leftmenu) || $leftmenu == "donations") {
                    $newmenu->add("/don/card.php?action=create", $langs->trans("NewDonation"), 1, $user->rights->don->creer);
                }
                if (empty($leftmenu) || $leftmenu == "donations") {
                    $newmenu->add("/don/list.php", $langs->trans("List"), 1, $user->rights->don->lire);
                }
                // if ($leftmenu=="donations") $newmenu->add("/don/stats/index.php",$langs->trans("Statistics"), 1, $user->rights->don->lire);
            }
            // Taxes and social contributions
            if (!empty($conf->tax->enabled) || !empty($conf->salaries->enabled) || !empty($conf->loan->enabled)) {
                global $mysoc;
                $permtoshowmenu = !empty($conf->tax->enabled) && $user->rights->tax->charges->lire || !empty($conf->salaries->enabled) && $user->rights->salaries->read || !empty($conf->loan->enabled) && $user->rights->loan->read;
                $newmenu->add("/compta/charges/index.php?leftmenu=tax&amp;mainmenu=accountancy", $langs->trans("MenuSpecialExpenses"), 0, $permtoshowmenu, '', $mainmenu, 'tax');
                // Salaries
                if (!empty($conf->salaries->enabled)) {
                    $langs->load("salaries");
                    $newmenu->add("/compta/salaries/index.php?leftmenu=tax_salary&amp;mainmenu=accountancy", $langs->trans("Salaries"), 1, $user->rights->salaries->read, '', $mainmenu, 'tax_salary');
                    if (empty($leftmenu) || preg_match('/^tax_salary/i', $leftmenu)) {
                        $newmenu->add("/compta/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("NewPayment"), 2, $user->rights->salaries->write);
                    }
                    if (empty($leftmenu) || preg_match('/^tax_salary/i', $leftmenu)) {
                        $newmenu->add("/compta/salaries/index.php?leftmenu=tax_salary", $langs->trans("Payments"), 2, $user->rights->salaries->read);
                    }
                }
                // Loan
                if (!empty($conf->loan->enabled)) {
                    $langs->load("loan");
                    $newmenu->add("/loan/index.php?leftmenu=tax_loan&amp;mainmenu=accountancy", $langs->trans("Loans"), 1, $user->rights->loan->read, '', $mainmenu, 'tax_loan');
                    if (empty($leftmenu) || preg_match('/^tax_loan/i', $leftmenu)) {
                        $newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create", $langs->trans("NewLoan"), 2, $user->rights->loan->write);
                    }
                    if (empty($leftmenu) || preg_match('/^tax_loan/i', $leftmenu)) {
                        $newmenu->add("/loan/index.php?leftmenu=tax_loan", $langs->trans("Payments"), 2, $user->rights->loan->read);
                    }
                    if (empty($leftmenu) || preg_match('/^tax_loan/i', $leftmenu)) {
                        $newmenu->add("/loan/calc.php?leftmenu=tax_loan", $langs->trans("Calculator"), 2, $user->rights->loan->calc);
                    }
                }
                // Social contributions
                if (!empty($conf->tax->enabled)) {
                    $newmenu->add("/compta/sociales/index.php?leftmenu=tax_social", $langs->trans("MenuSocialContributions"), 1, $user->rights->tax->charges->lire);
                    if (empty($leftmenu) || preg_match('/^tax_social/i', $leftmenu)) {
                        $newmenu->add("/compta/sociales/charges.php?leftmenu=tax_social&action=create", $langs->trans("MenuNewSocialContribution"), 2, $user->rights->tax->charges->creer);
                    }
                    if (empty($leftmenu) || preg_match('/^tax_social/i', $leftmenu)) {
                        $newmenu->add("/compta/sociales/index.php?leftmenu=tax_social", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
                    }
                    if (empty($leftmenu) || preg_match('/^tax_social/i', $leftmenu)) {
                        $newmenu->add("/compta/charges/index.php?leftmenu=tax_social&amp;mainmenu=accountancy&amp;mode=sconly", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                    }
                    // VAT
                    if (empty($conf->global->TAX_DISABLE_VAT_MENUS)) {
                        $newmenu->add("/compta/tva/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy", $langs->trans("VAT"), 1, $user->rights->tax->charges->lire, '', $mainmenu, 'tax_vat');
                        if (empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
                            $newmenu->add("/compta/tva/card.php?leftmenu=tax_vat&action=create", $langs->trans("NewPayment"), 2, $user->rights->tax->charges->creer);
                        }
                        if (empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
                            $newmenu->add("/compta/tva/reglement.php?leftmenu=tax_vat", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                        }
                        if (empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
                            $newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
                        }
                        if (empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
                            $newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
                        }
                        global $mysoc;
                        //Local Taxes
                        //Local Taxes 1
                        if ($mysoc->useLocalTax(1) && (isset($mysoc->localtax1_assuj) && $mysoc->localtax1_assuj == "1")) {
                            $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy&amp;localTaxType=1", $langs->transcountry("LT1", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/card.php?leftmenu=tax_vat&action=create&amp;localTaxType=1", $langs->trans("NewPayment"), 2, $user->rights->tax->charges->creer);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat&amp;localTaxType=1", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat&amp;localTaxType=1", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat&amp;localTaxType=1", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
                            }
                        }
                        //Local Taxes 2
                        if ($mysoc->useLocalTax(2) && (isset($mysoc->localtax2_assuj) && $mysoc->localtax2_assuj == "1")) {
                            $newmenu->add("/compta/localtax/index.php?leftmenu=tax_vat&amp;mainmenu=accountancy&amp;localTaxType=2", $langs->transcountry("LT2", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/card.php?leftmenu=tax_vat&action=create&amp;localTaxType=2", $langs->trans("NewPayment"), 2, $user->rights->tax->charges->creer);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/reglement.php?leftmenu=tax_vat&amp;localTaxType=2", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_vat&amp;localTaxType=2", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
                            }
                            if (empty($leftmenu) || preg_match('/^tax/i', $leftmenu)) {
                                $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_vat&amp;localTaxType=2", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
                            }
                        }
                    }
                }
            }
            // Accounting Expert
            if (!empty($conf->accounting->enabled)) {
                $langs->load("accountancy");
                $newmenu->add("/accountancy/customer/index.php?leftmenu=ventil_customer", $langs->trans("CustomersVentilation"), 0, $user->rights->accounting->ventilation->read, '', $mainmenu, 'ventil_customer');
                if (empty($leftmenu) || $leftmenu == "ventil_customer") {
                    $newmenu->add("/accountancy/customer/list.php", $langs->trans("ToDispatch"), 1, $user->rights->accounting->ventilation->dispatch);
                }
                if (empty($leftmenu) || $leftmenu == "ventil_customer") {
                    $newmenu->add("/accountancy/customer/lines.php", $langs->trans("Dispatched"), 1, $user->rights->accounting->ventilation->read);
                }
                if (!empty($conf->fournisseur->enabled)) {
                    $newmenu->add("/accountancy/supplier/index.php?leftmenu=ventil_supplier", $langs->trans("SuppliersVentilation"), 0, $user->rights->accounting->ventilation->read, '', $mainmenu, 'ventil_supplier');
                    if (empty($leftmenu) || $leftmenu == "ventil_supplier") {
                        $newmenu->add("/accountancy/supplier/list.php", $langs->trans("ToDispatch"), 1, $user->rights->accounting->ventilation->dispatch);
                    }
                    if (empty($leftmenu) || $leftmenu == "ventil_supplier") {
                        $newmenu->add("/accountancy/supplier/lines.php", $langs->trans("Dispatched"), 1, $user->rights->accounting->ventilation->read);
                    }
                }
            }
            // Rapports
            if (!empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled)) {
                $langs->load("compta");
                // Bilan, resultats
                $newmenu->add("/compta/resultat/index.php?leftmenu=report&amp;mainmenu=accountancy", $langs->trans("Reportings"), 0, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire, '', $mainmenu, 'ca');
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/resultat/index.php?leftmenu=report", $langs->trans("ReportInOut"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/resultat/clientfourn.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                /* On verra ca avec module compabilite expert
                			if (empty($leftmenu) || preg_match('/report/',$leftmenu)) $newmenu->add("/compta/resultat/compteres.php?leftmenu=report","Compte de resultat",2,$user->rights->compta->resultat->lire);
                			if (empty($leftmenu) || preg_match('/report/',$leftmenu)) $newmenu->add("/compta/resultat/bilan.php?leftmenu=report","Bilan",2,$user->rights->compta->resultat->lire);
                			*/
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/stats/index.php?leftmenu=report", $langs->trans("ReportTurnover"), 1, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                /*
                 if (empty($leftmenu) || preg_match('/report/',$leftmenu)) $newmenu->add("/compta/stats/cumul.php?leftmenu=report","Cumule",2,$user->rights->compta->resultat->lire);
                if (! empty($conf->propal->enabled)) {
                if (empty($leftmenu) || preg_match('/report/',$leftmenu)) $newmenu->add("/compta/stats/prev.php?leftmenu=report","Previsionnel",2,$user->rights->compta->resultat->lire);
                if (empty($leftmenu) || preg_match('/report/',$leftmenu)) $newmenu->add("/compta/stats/comp.php?leftmenu=report","Transforme",2,$user->rights->compta->resultat->lire);
                }
                */
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/stats/casoc.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/stats/cabyuser.php?leftmenu=report", $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                    $newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=report", $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire);
                }
                if (!empty($conf->comptabilite->enabled)) {
                    // Journaux
                    //if ($leftmenu=="ca") $newmenu->add("/compta/journaux/index.php?leftmenu=ca",$langs->trans("Journaux"),1,$user->rights->compta->resultat->lire||$user->rights->accounting->comptarapport->lire);
                    //journaux
                    if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                        $newmenu->add("/compta/journal/sellsjournal.php?leftmenu=report", $langs->trans("SellsJournal"), 1, $user->rights->compta->resultat->lire);
                    }
                    if (empty($leftmenu) || preg_match('/report/', $leftmenu)) {
                        $newmenu->add("/compta/journal/purchasesjournal.php?leftmenu=report", $langs->trans("PurchasesJournal"), 1, $user->rights->compta->resultat->lire);
                    }
                }
                // Report expert
                if (!empty($conf->accounting->enabled)) {
                    $langs->load("accountancy");
                    // Grand livre
                    $newmenu->add("/accountancy/bookkeeping/list.php?leftmenu=bookkeeping", $langs->trans("Bookkeeping"), 0, $user->rights->accounting->mouvements->lire, '', $mainmenu, 'bookkeeping');
                    if (empty($leftmenu) || preg_match('/bookkeeping/', $leftmenu)) {
                        $newmenu->add("/accountancy/bookkeeping/listbyyear.php", $langs->trans("ByYear"), 1, $user->rights->accounting->mouvements->lire);
                    }
                    if (empty($leftmenu) || preg_match('/bookkeeping/', $leftmenu)) {
                        $newmenu->add("/accountancy/bookkeeping/balancebymonth.php", $langs->trans("AccountBalanceByMonth"), 1, $user->rights->accounting->mouvements->lire);
                    }
                    // Accountancy journals
                    if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->mouvements->lire) && $mainmenu == 'accountancy') {
                        $newmenu->add('/accountancy/journal/index.php?leftmenu=journal', $langs->trans("Journaux"), 0, $user->rights->banque->lire);
                        if ($leftmenu == 'journal') {
                            $sql = "SELECT rowid, label, accountancy_journal";
                            $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
                            $sql .= " WHERE entity = " . $conf->entity;
                            $sql .= " AND clos = 0";
                            $sql .= " ORDER BY label";
                            $resql = $db->query($sql);
                            if ($resql) {
                                $numr = $db->num_rows($resql);
                                $i = 0;
                                if ($numr > 0) {
                                    while ($i < $numr) {
                                        $objp = $db->fetch_object($resql);
                                        $newmenu->add('/accountancy/journal/bankjournal.php?id_account=' . $objp->rowid, $langs->trans("Journal") . ' - ' . $objp->label, 1, $user->rights->accounting->comptarapport->lire);
                                        $i++;
                                    }
                                }
                            } else {
                                dol_print_error($db);
                            }
                            $db->free($resql);
                            // Add other journal
                            $newmenu->add("/accountancy/journal/sellsjournal.php?leftmenu=journal", $langs->trans("SellsJournal"), 1, $user->rights->accounting->comptarapport->lire);
                            $newmenu->add("/accountancy/journal/purchasesjournal.php?leftmenu=journal", $langs->trans("PurchasesJournal"), 1, $user->rights->accounting->comptarapport->lire);
                        }
                    }
                }
            }
            // Setup
            if (!empty($conf->accounting->enabled)) {
                $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy", $langs->trans("Fiscalyear"), 0, $user->rights->accounting->fiscalyear, '', $mainmenu, 'fiscalyear');
                $newmenu->add("/accountancy/admin/account.php?mainmenu=accountancy", $langs->trans("Chartofaccounts"), 0, $user->rights->accounting->chartofaccount, '', $mainmenu, 'chartofaccount');
            }
        }
        /*
         * Menu BANK
         */
        if ($mainmenu == 'bank') {
            $langs->load("withdrawals");
            $langs->load("banks");
            $langs->load("bills");
            // Bank-Caisse
            if (!empty($conf->banque->enabled)) {
                $newmenu->add("/compta/bank/index.php?leftmenu=bank&amp;mainmenu=bank", $langs->trans("MenuBankCash"), 0, $user->rights->banque->lire, '', $mainmenu, 'bank');
                $newmenu->add("/compta/bank/card.php?action=create", $langs->trans("MenuNewFinancialAccount"), 1, $user->rights->banque->configurer);
                $newmenu->add("/compta/bank/categ.php", $langs->trans("Rubriques"), 1, $user->rights->banque->configurer);
                $newmenu->add("/compta/bank/search.php", $langs->trans("ListTransactions"), 1, $user->rights->banque->lire);
                $newmenu->add("/compta/bank/budget.php", $langs->trans("ListTransactionsByCategory"), 1, $user->rights->banque->lire);
                $newmenu->add("/compta/bank/virement.php", $langs->trans("BankTransfers"), 1, $user->rights->banque->transfer);
            }
            // Prelevements
            if (!empty($conf->prelevement->enabled)) {
                $newmenu->add("/compta/prelevement/index.php?leftmenu=withdraw&amp;mainmenu=bank", $langs->trans("StandingOrders"), 0, $user->rights->prelevement->bons->lire, '', $mainmenu, 'withdraw');
                //if (empty($leftmenu) || $leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php?status=0&amp;mainmenu=bank",$langs->trans("StandingOrderToProcess"),1,$user->rights->prelevement->bons->lire);
                if (empty($leftmenu) || $leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/create.php?mainmenu=bank", $langs->trans("NewStandingOrder"), 1, $user->rights->prelevement->bons->creer);
                }
                if (empty($leftmenu) || $leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/bons.php?mainmenu=bank", $langs->trans("WithdrawalsReceipts"), 1, $user->rights->prelevement->bons->lire);
                }
                if (empty($leftmenu) || $leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/list.php?mainmenu=bank", $langs->trans("WithdrawalsLines"), 1, $user->rights->prelevement->bons->lire);
                }
                if (empty($leftmenu) || $leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/rejets.php?mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->prelevement->bons->lire);
                }
                if (empty($leftmenu) || $leftmenu == "withdraw") {
                    $newmenu->add("/compta/prelevement/stats.php?mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->prelevement->bons->lire);
                }
                //if (empty($leftmenu) || $leftmenu=="withdraw") $newmenu->add("/compta/prelevement/config.php",$langs->trans("Setup"),1,$user->rights->prelevement->bons->configurer);
            }
            // Gestion cheques
            if (!empty($conf->banque->enabled) && !empty($conf->facture->enabled) || !empty($conf->global->MAIN_MENU_CHEQUE_DEPOSIT_ON)) {
                $newmenu->add("/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("MenuChequeDeposits"), 0, $user->rights->banque->cheque, '', $mainmenu, 'checks');
                $newmenu->add("/compta/paiement/cheque/card.php?leftmenu=checks&amp;action=new&amp;mainmenu=bank", $langs->trans("NewChequeDeposit"), 1, $user->rights->banque->cheque);
                $newmenu->add("/compta/paiement/cheque/list.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->cheque);
            }
        }
        /*
         * Menu PRODUCTS-SERVICES
         */
        if ($mainmenu == 'products') {
            // Products
            if (!empty($conf->product->enabled)) {
                $newmenu->add("/product/index.php?leftmenu=product&amp;type=0", $langs->trans("Products"), 0, $user->rights->produit->lire, '', $mainmenu, 'product');
                $newmenu->add("/product/card.php?leftmenu=product&amp;action=create&amp;type=0", $langs->trans("NewProduct"), 1, $user->rights->produit->creer);
                $newmenu->add("/product/list.php?leftmenu=product&amp;type=0", $langs->trans("List"), 1, $user->rights->produit->lire);
                if (!empty($conf->stock->enabled)) {
                    $newmenu->add("/product/reassort.php?type=0", $langs->trans("Stocks"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
                }
                if (!empty($conf->productbatch->enabled)) {
                    $langs->load("stocks");
                    $newmenu->add("/product/reassortlot.php?type=0", $langs->trans("StocksByLotSerial"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
                }
                if (!empty($conf->propal->enabled)) {
                    $newmenu->add("/product/popuprop.php?leftmenu=stats&amp;type=0", $langs->trans("Statistics"), 1, $user->rights->produit->lire && $user->rights->propale->lire);
                }
            }
            // Services
            if (!empty($conf->service->enabled)) {
                $newmenu->add("/product/index.php?leftmenu=service&amp;type=1", $langs->trans("Services"), 0, $user->rights->service->lire, '', $mainmenu, 'service');
                $newmenu->add("/product/card.php?leftmenu=service&amp;action=create&amp;type=1", $langs->trans("NewService"), 1, $user->rights->service->creer);
                $newmenu->add("/product/list.php?leftmenu=service&amp;type=1", $langs->trans("List"), 1, $user->rights->service->lire);
                if (!empty($conf->propal->enabled)) {
                    $newmenu->add("/product/popuprop.php?leftmenu=stats&amp;type=1", $langs->trans("Statistics"), 1, $user->rights->service->lire && $user->rights->propale->lire);
                }
            }
            // Categories
            if (!empty($conf->categorie->enabled)) {
                $langs->load("categories");
                $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=0", $langs->trans("Categories"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat');
                $newmenu->add("/categories/card.php?action=create&amp;type=0", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                //if (empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
            }
            // Warehouse
            if (!empty($conf->stock->enabled)) {
                $langs->load("stocks");
                $newmenu->add("/product/stock/index.php?leftmenu=stock", $langs->trans("Warehouses"), 0, $user->rights->stock->lire, '', $mainmenu, 'stock');
                $newmenu->add("/product/stock/card.php?action=create", $langs->trans("MenuNewWarehouse"), 1, $user->rights->stock->creer);
                $newmenu->add("/product/stock/list.php", $langs->trans("List"), 1, $user->rights->stock->lire);
                $newmenu->add("/product/stock/mouvement.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
                if ($conf->fournisseur->enabled) {
                    $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire);
                }
                $newmenu->add("/product/stock/massstockmove.php", $langs->trans("StockTransfer"), 1, $user->rights->stock->mouvement->creer);
            }
            // Expeditions
            if (!empty($conf->expedition->enabled)) {
                $langs->load("sendings");
                $newmenu->add("/expedition/index.php?leftmenu=sendings", $langs->trans("Shipments"), 0, $user->rights->expedition->lire, '', $mainmenu, 'sendings');
                $newmenu->add("/expedition/card.php?action=create2&amp;leftmenu=sendings", $langs->trans("NewSending"), 1, $user->rights->expedition->creer);
                $newmenu->add("/expedition/list.php?leftmenu=sendings", $langs->trans("List"), 1, $user->rights->expedition->lire);
                if (empty($leftmenu) || $leftmenu == "sendings") {
                    $newmenu->add("/expedition/list.php?leftmenu=sendings&viewstatut=0", $langs->trans("StatusSendingDraftShort"), 2, $user->rights->expedition->lire);
                }
                if (empty($leftmenu) || $leftmenu == "sendings") {
                    $newmenu->add("/expedition/list.php?leftmenu=sendings&viewstatut=1", $langs->trans("StatusSendingValidatedShort"), 2, $user->rights->expedition->lire);
                }
                if (empty($leftmenu) || $leftmenu == "sendings") {
                    $newmenu->add("/expedition/list.php?leftmenu=sendings&viewstatut=2", $langs->trans("StatusSendingProcessedShort"), 2, $user->rights->expedition->lire);
                }
                $newmenu->add("/expedition/stats/index.php?leftmenu=sendings", $langs->trans("Statistics"), 1, $user->rights->expedition->lire);
            }
        }
        /*
         * Menu SUPPLIERS
         */
        /*
        if ($mainmenu == 'suppliers')
        {
        	$langs->load("suppliers");
        
        	if (! empty($conf->societe->enabled) && ! empty($conf->fournisseur->enabled))
        	{
        		$newmenu->add("/fourn/index.php?leftmenu=suppliers", $langs->trans("Suppliers"), 0, $user->rights->societe->lire && $user->rights->fournisseur->lire, '', $mainmenu, 'suppliers');
        
        		// Security check
        		$newmenu->add("/societe/soc.php?leftmenu=suppliers&amp;action=create&amp;type=f",$langs->trans("NewSupplier"), 1, $user->rights->societe->creer && $user->rights->fournisseur->lire);
        		$newmenu->add("/fourn/list.php",$langs->trans("List"), 1, $user->rights->societe->lire && $user->rights->fournisseur->lire);
        		$newmenu->add("/contact/list.php?leftmenu=suppliers&amp;type=f",$langs->trans("Contacts"), 1, $user->rights->societe->contact->lire && $user->rights->fournisseur->lire);
        		$newmenu->add("/fourn/stats.php",$langs->trans("Statistics"), 1, $user->rights->societe->lire && $user->rights->fournisseur->lire);
        	}
        
        	if (! empty($conf->facture->enabled))
        	{
        		$langs->load("bills");
        		$newmenu->add("/fourn/facture/list.php?leftmenu=orders", $langs->trans("Bills"), 0, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'orders');
        		$newmenu->add("/fourn/facture/card.php?action=create",$langs->trans("NewBill"), 1, $user->rights->fournisseur->facture->creer);
        		$newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire);
        	}
        
        	if (! empty($conf->fournisseur->enabled))
        	{
        		$langs->load("orders");
        		$newmenu->add("/fourn/commande/index.php?leftmenu=suppliers",$langs->trans("Orders"), 0, $user->rights->fournisseur->commande->lire, '', $mainmenu, 'suppliers');
        		$newmenu->add("/societe/societe.php?leftmenu=supplier", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
        		$newmenu->add("/fourn/commande/list.php?leftmenu=suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
        	}
        
        	if (! empty($conf->categorie->enabled))
        	{
        		$langs->load("categories");
        		$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=1", $langs->trans("Categories"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat');
        		$newmenu->add("/categories/card.php?action=create&amp;type=1", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
        		//if (empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
        	}
        
        }
        */
        /*
         * Menu PROJECTS
         */
        if ($mainmenu == 'project') {
            if (!empty($conf->projet->enabled)) {
                $langs->load("projects");
                // Project affected to user
                $newmenu->add("/projet/index.php?leftmenu=projects&mode=mine", $langs->trans("MyProjects"), 0, $user->rights->projet->lire, '', $mainmenu, 'myprojects');
                $newmenu->add("/projet/card.php?leftmenu=projects&action=create&mode=mine", $langs->trans("NewProject"), 1, $user->rights->projet->creer);
                $newmenu->add("/projet/list.php?leftmenu=projects&mode=mine&search_status=1", $langs->trans("List"), 1, $user->rights->projet->lire);
                // All project i have permission on
                $newmenu->add("/projet/index.php?leftmenu=projects", $langs->trans("Projects"), 0, $user->rights->projet->lire && $user->rights->projet->lire, '', $mainmenu, 'projects');
                $newmenu->add("/projet/card.php?leftmenu=projects&action=create", $langs->trans("NewProject"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
                $newmenu->add("/projet/list.php?leftmenu=projects&search_status=1", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
                $newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
                if (empty($conf->global->PROJECT_HIDE_TASKS)) {
                    // Project affected to user
                    $newmenu->add("/projet/activity/index.php?mode=mine", $langs->trans("MyActivities"), 0, $user->rights->projet->lire);
                    $newmenu->add("/projet/tasks.php?action=create&mode=mine", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
                    $newmenu->add("/projet/tasks/index.php?mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
                    $newmenu->add("/projet/activity/perweek.php?mode=mine", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer);
                    // All project i have permission on
                    $newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire);
                    $newmenu->add("/projet/tasks.php?action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
                    $newmenu->add("/projet/tasks/index.php", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
                    $newmenu->add("/projet/activity/perweek.php", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
                }
            }
        }
        /*
         * Menu HRM
         */
        if ($mainmenu == 'hrm') {
            // Leave/Holiday/Vacation module
            if (!empty($conf->holiday->enabled)) {
                $langs->load("holiday");
                $langs->load("trips");
                $newmenu->add("/holiday/list.php?&leftmenu=hrm", $langs->trans("CPTitreMenu"), 0, $user->rights->holiday->read, '', $mainmenu, 'hrm');
                $newmenu->add("/holiday/card.php?&action=request", $langs->trans("New"), 1, $user->rights->holiday->write);
                $newmenu->add("/holiday/list.php?&leftmenu=hrm", $langs->trans("List"), 1, $user->rights->holiday->read);
                $newmenu->add("/holiday/list.php?select_statut=2&leftmenu=hrm", $langs->trans("ListToApprove"), 2, $user->rights->holiday->read);
                $newmenu->add("/holiday/define_holiday.php?&action=request", $langs->trans("MenuConfCP"), 1, $user->rights->holiday->define_holiday);
                $newmenu->add("/holiday/view_log.php?&action=request", $langs->trans("MenuLogCP"), 1, $user->rights->holiday->define_holiday);
                $newmenu->add("/holiday/month_report.php?&action=request", $langs->trans("MenuReportMonth"), 1, $user->rights->holiday->define_holiday);
            }
            // Trips and expenses (old module)
            if (!empty($conf->deplacement->enabled)) {
                $langs->load("trips");
                $newmenu->add("/compta/deplacement/index.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("TripsAndExpenses"), 0, $user->rights->deplacement->lire, '', $mainmenu, 'tripsandexpenses');
                $newmenu->add("/compta/deplacement/card.php?action=create&amp;leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("New"), 1, $user->rights->deplacement->creer);
                $newmenu->add("/compta/deplacement/list.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("List"), 1, $user->rights->deplacement->lire);
                $newmenu->add("/compta/deplacement/stats/index.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("Statistics"), 1, $user->rights->deplacement->lire);
            }
        }
        /*
         * Menu TOOLS
         */
        if ($mainmenu == 'tools') {
            if (!empty($conf->mailing->enabled)) {
                $langs->load("mails");
                $newmenu->add("/comm/mailing/index.php?leftmenu=mailing", $langs->trans("EMailings"), 0, $user->rights->mailing->lire, '', $mainmenu, 'mailing');
                $newmenu->add("/comm/mailing/card.php?leftmenu=mailing&amp;action=create", $langs->trans("NewMailing"), 1, $user->rights->mailing->creer);
                $newmenu->add("/comm/mailing/list.php?leftmenu=mailing", $langs->trans("List"), 1, $user->rights->mailing->lire);
            }
            if (!empty($conf->export->enabled)) {
                $langs->load("exports");
                $newmenu->add("/exports/index.php?leftmenu=export", $langs->trans("FormatedExport"), 0, $user->rights->export->lire, '', $mainmenu, 'export');
                $newmenu->add("/exports/export.php?leftmenu=export", $langs->trans("NewExport"), 1, $user->rights->export->creer);
                //$newmenu->add("/exports/export.php?leftmenu=export",$langs->trans("List"),1, $user->rights->export->lire);
            }
            if (!empty($conf->import->enabled)) {
                $langs->load("exports");
                $newmenu->add("/imports/index.php?leftmenu=import", $langs->trans("FormatedImport"), 0, $user->rights->import->run, '', $mainmenu, 'import');
                $newmenu->add("/imports/import.php?leftmenu=import", $langs->trans("NewImport"), 1, $user->rights->import->run);
            }
        }
        /*
         * Menu MEMBERS
         */
        if ($mainmenu == 'members') {
            if (!empty($conf->adherent->enabled)) {
                $langs->load("members");
                $langs->load("compta");
                $newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Members"), 0, $user->rights->adherent->lire, '', $mainmenu, 'members');
                $newmenu->add("/adherents/card.php?leftmenu=members&amp;action=create", $langs->trans("NewMember"), 1, $user->rights->adherent->creer);
                $newmenu->add("/adherents/list.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=-1", $langs->trans("MenuMembersToValidate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1", $langs->trans("MenuMembersValidated"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1&amp;filter=uptodate", $langs->trans("MenuMembersUpToDate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1&amp;filter=outofdate", $langs->trans("MenuMembersNotUpToDate"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=0", $langs->trans("MenuMembersResiliated"), 2, $user->rights->adherent->lire);
                $newmenu->add("/adherents/stats/index.php?leftmenu=members", $langs->trans("MenuMembersStats"), 1, $user->rights->adherent->lire);
                $newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Subscriptions"), 0, $user->rights->adherent->cotisation->lire);
                $newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=-1,1&amp;mainmenu=members", $langs->trans("NewSubscription"), 1, $user->rights->adherent->cotisation->creer);
                $newmenu->add("/adherents/cotisations.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->cotisation->lire);
                $newmenu->add("/adherents/stats/index.php?leftmenu=members", $langs->trans("MenuMembersStats"), 1, $user->rights->adherent->lire);
                if (!empty($conf->categorie->enabled)) {
                    $langs->load("categories");
                    $newmenu->add("/categories/index.php?leftmenu=cat&amp;type=3", $langs->trans("Categories"), 0, $user->rights->categorie->lire, '', $mainmenu, 'cat');
                    $newmenu->add("/categories/card.php?action=create&amp;type=3", $langs->trans("NewCategory"), 1, $user->rights->categorie->creer);
                    //if (empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
                }
                $newmenu->add("/adherents/index.php?leftmenu=export&amp;mainmenu=members", $langs->trans("Exports"), 0, $user->rights->adherent->export, '', $mainmenu, 'export');
                if (!empty($conf->export->enabled) && (empty($leftmenu) || $leftmenu == "export")) {
                    $newmenu->add("/exports/index.php?leftmenu=export", $langs->trans("Datas"), 1, $user->rights->adherent->export);
                }
                if (empty($leftmenu) || $leftmenu == "export") {
                    $newmenu->add("/adherents/htpasswd.php?leftmenu=export", $langs->trans("Filehtpasswd"), 1, $user->rights->adherent->export);
                }
                if (empty($leftmenu) || $leftmenu == "export") {
                    $newmenu->add("/adherents/cartes/carte.php?leftmenu=export", $langs->trans("MembersCards"), 1, $user->rights->adherent->export);
                }
                // Type
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("MembersTypes"), 0, $user->rights->adherent->configurer, '', $mainmenu, 'setup');
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members&amp;action=create", $langs->trans("New"), 1, $user->rights->adherent->configurer);
                $newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("List"), 1, $user->rights->adherent->configurer);
            }
        }
        // Add personalized menus and modules menus
        $menuArbo = new Menubase($db, 'eldy');
        $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, empty($user->societe_id) ? 0 : 1, 'eldy', $tabMenu);
        // We update newmenu for special dynamic menus
        if (!empty($user->rights->banque->lire) && $mainmenu == 'bank') {
            $sql = "SELECT rowid, label, courant, rappro";
            $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account";
            $sql .= " WHERE entity = " . $conf->entity;
            $sql .= " AND clos = 0";
            $sql .= " ORDER BY label";
            $resql = $db->query($sql);
            if ($resql) {
                $numr = $db->num_rows($resql);
                $i = 0;
                if ($numr > 0) {
                    $newmenu->add('/compta/bank/index.php', $langs->trans("BankAccounts"), 0, $user->rights->banque->lire);
                }
                while ($i < $numr) {
                    $objp = $db->fetch_object($resql);
                    $newmenu->add('/compta/bank/card.php?id=' . $objp->rowid, $objp->label, 1, $user->rights->banque->lire);
                    if ($objp->rappro && $objp->courant != 2 && empty($objp->clos)) {
                        $newmenu->add('/compta/bank/rappro.php?account=' . $objp->rowid, $langs->trans("Conciliate"), 2, $user->rights->banque->consolidate);
                    }
                    $i++;
                }
            } else {
                dol_print_error($db);
            }
            $db->free($resql);
        }
        if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') {
            $MAXFTP = 20;
            $i = 1;
            while ($i <= $MAXFTP) {
                $paramkey = 'FTP_NAME_' . $i;
                //print $paramkey;
                if (!empty($conf->global->{$paramkey})) {
                    $link = "/ftp/index.php?idmenu=" . $_SESSION["idmenu"] . "&numero_ftp=" . $i;
                    $newmenu->add($link, dol_trunc($conf->global->{$paramkey}, 24));
                }
                $i++;
            }
        }
    }
    // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
    //var_dump($menu_array_before);exit;
    //var_dump($menu_array_after);exit;
    $menu_array = $newmenu->liste;
    if (is_array($menu_array_before)) {
        $menu_array = array_merge($menu_array_before, $menu_array);
    }
    if (is_array($menu_array_after)) {
        $menu_array = array_merge($menu_array, $menu_array_after);
    }
    //var_dump($menu_array);exit;
    if (!is_array($menu_array)) {
        return 0;
    }
    // Show menu
    $invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert";
    if (empty($noout)) {
        $alt = 0;
        $blockvmenuopened = false;
        $num = count($menu_array);
        for ($i = 0; $i < $num; $i++) {
            $showmenu = true;
            if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) {
                $showmenu = false;
            }
            $alt++;
            if (empty($menu_array[$i]['level']) && $showmenu) {
                $blockvmenuopened = true;
                if ($alt % 2 == 0) {
                    print '<div class="blockvmenuimpair' . $invert . '">' . "\n";
                } else {
                    print '<div class="blockvmenupair' . $invert . '">' . "\n";
                }
            }
            // Place tabulation
            $tabstring = '';
            $tabul = $menu_array[$i]['level'] - 1;
            if ($tabul > 0) {
                for ($j = 0; $j < $tabul; $j++) {
                    $tabstring .= '&nbsp;&nbsp;&nbsp;';
                }
            }
            // For external modules
            $tmp = explode('?', $menu_array[$i]['url'], 2);
            $url = $tmp[0];
            $param = isset($tmp[1]) ? $tmp[1] : '';
            $url = dol_buildpath($url, 1) . ($param ? '?' . $param : '');
            $url = preg_replace('/__LOGIN__/', $user->login, $url);
            $url = preg_replace('/__USERID__/', $user->id, $url);
            print '<!-- Process menu entry with mainmenu=' . $menu_array[$i]['mainmenu'] . ', leftmenu=' . $menu_array[$i]['leftmenu'] . ', level=' . $menu_array[$i]['level'] . ' enabled=' . $menu_array[$i]['enabled'] . ' -->' . "\n";
            // Menu niveau 0
            if ($menu_array[$i]['level'] == 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_titre">' . $tabstring . '<a class="vmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>' . $menu_array[$i]['titre'] . '</a></div>' . "\n";
                } else {
                    if ($showmenu) {
                        print '<div class="menu_titre">' . $tabstring . '<font class="vmenudisabled">' . $menu_array[$i]['titre'] . '</font></div>' . "\n";
                    }
                }
                if ($showmenu) {
                    print '<div class="menu_top"></div>' . "\n";
                }
            }
            // Menu niveau > 0
            if ($menu_array[$i]['level'] > 0) {
                if ($menu_array[$i]['enabled']) {
                    print '<div class="menu_contenu">' . $tabstring;
                    if ($menu_array[$i]['url']) {
                        print '<a class="vsmenu" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>';
                    } else {
                        print '<span class="vsmenu">';
                    }
                    print $menu_array[$i]['titre'];
                    if ($menu_array[$i]['url']) {
                        print '</a>';
                    } else {
                        print '</span>';
                    }
                    // If title is not pure text and contains a table, no carriage return added
                    if (!strstr($menu_array[$i]['titre'], '<table')) {
                        print '<br>';
                    }
                    print '</div>' . "\n";
                } else {
                    if ($showmenu) {
                        print '<div class="menu_contenu">' . $tabstring . '<font class="vsmenudisabled vsmenudisabledmargin">' . $menu_array[$i]['titre'] . '</font><br></div>' . "\n";
                    }
                }
            }
            // If next is a new block or if there is nothing after
            if (empty($menu_array[$i + 1]['level'])) {
                if ($showmenu) {
                    print '<div class="menu_end"></div>' . "\n";
                }
                if ($blockvmenuopened) {
                    print "</div>\n";
                    $blockvmenuopened = false;
                }
            }
        }
    }
    return count($menu_array);
}
    /**
     *  Insert menus entries found into $this->menu into llx_menu*
     *  @return     int     Nb of errors (0 if OK)
     */
    function insert_menus()
    {
        require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");

        $err=0;

        $this->db->begin();

        //var_dump($this->menu); exit;
        foreach ($this->menu as $key => $value)
        {
            $menu = new Menubase($this->db);
            $menu->menu_handler='all';
            $menu->module=$this->rights_class;
            if (! $this->menu[$key]['fk_menu'])
            {
                $menu->fk_menu=0;
                //print 'aaa'.$this->menu[$key]['fk_menu'];
            }
            else
            {
                //print 'xxx'.$this->menu[$key]['fk_menu'];exit;
                $foundparent=0;
                $fk_parent=$this->menu[$key]['fk_menu'];
                if (preg_match('/r=/',$fk_parent))
                {
                    $fk_parent=str_replace('r=','',$fk_parent);
                    if (isset($this->menu[$fk_parent]['rowid']))
                    {
                        $menu->fk_menu=$this->menu[$fk_parent]['rowid'];
                        $foundparent=1;
                    }
                }
                elseif (preg_match('/mainmenu=(.*),leftmenu=(.*)/',$fk_parent,$reg))
                {
                    $menu->fk_menu=-1;
                    $menu->fk_mainmenu=$reg[1];
                    $menu->fk_leftmenu=$reg[2];
                    $foundparent=1;
                }
                if (! $foundparent)
                {
                    $this->error="ErrorBadDefinitionOfMenuArrayInModuleDescriptor (bad value for key fk_menu)";
                    dol_syslog(get_class($this)."::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR);
                    $err++;
                }
            }
            $menu->type=$this->menu[$key]['type'];
            $menu->mainmenu=$this->menu[$key]['mainmenu'];
            $menu->titre=$this->menu[$key]['titre'];
            $menu->leftmenu=isset($this->menu[$key]['leftmenu'])?$this->menu[$key]['leftmenu']:0;
            $menu->url=$this->menu[$key]['url'];
            $menu->langs=$this->menu[$key]['langs'];
            $menu->position=$this->menu[$key]['position'];
            $menu->perms=$this->menu[$key]['perms'];
            $menu->target=$this->menu[$key]['target'];
            $menu->user=$this->menu[$key]['user'];
            //$menu->constraint=$this->menu[$key]['constraint'];
            $menu->enabled=isset($this->menu[$key]['enabled'])?$this->menu[$key]['enabled']:0;

            if (! $err)
            {
                $result=$menu->create();
                if ($result > 0)
                {
                    $this->menu[$key]['rowid']=$result;
                }
                else
                {
                    $this->error=$menu->error;
                    dol_syslog('DolibarrModules::insert_menus result='.$result." ".$this->error, LOG_ERR);
                    $err++;
                    break;
                }
            }
        }

        if (! $err)
        {
            $this->db->commit();
        }
        else
        {
            dol_syslog(get_class($this)."::insert_menus ".$this->error, LOG_ERR);
            $this->db->rollback();
        }

        return $err;
    }
Esempio n. 11
0
/**
 * Core function to output left menu auguria
 *
 * @param      db                  Database handler
 * @param      menu_array_before   Table of menu entries to show before entries of menu handler
 * @param      menu_array_after    Table of menu entries to show after entries of menu handler
 */
function print_left_auguria_menu($db,$menu_array_before,$menu_array_after)
{
    global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc;

    $overwritemenufor = array();
    $newmenu = new Menu();

    // Read mainmenu and leftmenu that define which menu to show
    if (isset($_GET["mainmenu"])) {
        // On sauve en session le menu principal choisi
        $mainmenu=$_GET["mainmenu"];
        $_SESSION["mainmenu"]=$mainmenu;
        $_SESSION["leftmenuopened"]="";
    } else {
        // On va le chercher en session si non defini par le lien
        $mainmenu=$_SESSION["mainmenu"];
    }

    if (isset($_GET["leftmenu"])) {
        // On sauve en session le menu principal choisi
        $leftmenu=$_GET["leftmenu"];
        $_SESSION["leftmenu"]=$leftmenu;
        if ($_SESSION["leftmenuopened"]==$leftmenu) {
            //$leftmenu="";
            $_SESSION["leftmenuopened"]="";
        }
        else {
            $_SESSION["leftmenuopened"]=$leftmenu;
        }
    } else {
        // On va le chercher en session si non defini par le lien
        $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:'';
    }

    //this->menu_array contains menu in pre.inc.php


    // Show logo company
    if (! empty($conf->global->MAIN_SHOW_LOGO))
    {
        $mysoc->logo_mini=$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
        if (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
        {
            $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode('thumbs/'.$mysoc->logo_mini);
            print "\n".'<!-- Show logo on menu -->'."\n";
            print '<div class="blockvmenuimpair">'."\n";
            print '<div class="menu_titre" id="menu_titre_logo"></div>';
            print '<div class="menu_top" id="menu_top_logo"></div>';
            print '<div class="menu_contenu" id="menu_contenu_logo">';
            print '<center><img title="'.$title.'" src="'.$urllogo.'"></center>'."\n";
            print '</div>';
            print '<div class="menu_end" id="menu_end_logo"></div>';
            print '</div>'."\n";
        }
    }

    /**
     * On definit newmenu en fonction de mainmenu et leftmenu
     * ------------------------------------------------------
     */
    if ($mainmenu)
    {
        require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");

        $menuArbo = new Menubase($db,'auguria','left');
        $newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria');
        //var_dump($newmenu);
    }


    //var_dump($menu_array_before);exit;
    //var_dump($menu_array_after);exit;
    $menu_array=$newmenu->liste;
    if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array);
    if (is_array($menu_array_after))  $menu_array=array_merge($menu_array, $menu_array_after);
    //var_dump($menu_array);exit;

    // Show menu
    $alt=0;
    if (is_array($menu_array))
    {
        for ($i = 0 ; $i < sizeof($menu_array) ; $i++)
        {
            $alt++;
            if (empty($menu_array[$i]['level']))
            {
                if (($alt%2==0))
                {
                	if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_ACCORDION)
                	{
                		print '<div class="blockvmenupair">'."\n";
                	}
                	else
                	{
                		print '<div class="blockvmenuimpair">'."\n";
                	}
                }
                else
                {
                    print '<div class="blockvmenupair">'."\n";
                }
            }

            // Place tabulation
            $tabstring='';
            $tabul=($menu_array[$i]['level'] - 1);
            if ($tabul > 0)
            {
                for ($j=0; $j < $tabul; $j++)
                {
                    $tabstring.='&nbsp; &nbsp;';
                }
            }

            // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
            $url=dol_buildpath($menu_array[$i]['url'],1);

            if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
            {
                if (! preg_match('/\?/',$url)) $url.='?';
                else $url.='&';
                $url.='mainmenu='.$mainmenu;
            }

            // Menu niveau 0
            if ($menu_array[$i]['level'] == 0)
            {
                if ($menu_array[$i]['enabled'])
                {
                    print '<div class="menu_titre">'.$tabstring.'<a class="vmenu" href="'.$url.'"'.($menu_array[$i]['target']?' target="'.$menu_array[$i]['target'].'"':'').'>'.$menu_array[$i]['titre'].'</a></div>';
                }
                else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
                {
                    print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
                }
                print "\n".'<div id="section_content_'.$i.'">'."\n";
                print '<div class="menu_top"></div>'."\n";
            }
            // Menu niveau > 0
            if ($menu_array[$i]['level'] > 0)
            {
                if ($menu_array[$i]['enabled'])
                {
                    print '<div class="menu_contenu">'.$tabstring.'<a class="vsmenu" href="'.$url.'"'.($menu_array[$i]['target']?' target="'.$menu_array[$i]['target'].'"':'').'>'.$menu_array[$i]['titre'].'</a></div>';
                }
                else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
                {
                    print '<div class="menu_contenu">'.$tabstring.'<font class="vsmenudisabled">'.$menu_array[$i]['titre'].'</font></div>';
                }
            }

            // If next is a new block or end
            if (empty($menu_array[$i+1]['level']))
            {
                print '<div class="menu_end"></div>'."\n";
                print "</div><!-- end section content -->\n";
                print "</div><!-- end blockvmenu  pair/impair -->\n";
            }
        }
    }

    return sizeof($menu_array);
}