1<?php
2/* Copyright (C) 2010-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
3 * Copyright (C) 2010      Regis Houssin        <regis.houssin@inodbox.com>
4 * Copyright (C) 2012-2015 Juanjo Menent        <jmenent@2byte.es>
5 * Copyright (C) 2013      Cédric Salvador      <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2015      Marcos García        <marcosgdf@gmail.com>
7 * Copyright (C) 2018      Ferran Marcet        <fmarcet@2byte.es>
8 * Copyright (C) 2018-2019  Frédéric France         <frederic.france@netlogic.fr>
9 * Copyright (C) 2021       Gauthier VERDOL         <gauthier.verdol@atm-consulting.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
26/**
27 *  \file		htdocs/core/menus/standard/eldy.lib.php
28 *  \brief		Library for file eldy menus
29 */
30require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
31
32
33/**
34 * Core function to output top menu eldy
35 *
36 * @param 	DoliDB	$db				Database handler
37 * @param 	string	$atarget		Target (Example: '' or '_top')
38 * @param 	int		$type_user     	0=Menu for backoffice, 1=Menu for front office
39 * @param  	array	$tabMenu        If array with menu entries already loaded, we put this array here (in most cases, it's empty). For eldy menu, it contains menu entries loaded from database.
40 * @param	Menu	$menu			Object Menu to return back list of menu entries
41 * @param	int		$noout			1=Disable output (Initialise &$menu only).
42 * @param	string	$mode			'top', 'topnb', 'left', 'jmobile'
43 * @return	int						0
44 */
45function print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = 0, $mode = '')
46{
47	global $user, $conf, $langs, $mysoc;
48	global $dolibarr_main_db_name;
49
50	$mainmenu = (empty($_SESSION["mainmenu"]) ? '' : $_SESSION["mainmenu"]);
51	$leftmenu = (empty($_SESSION["leftmenu"]) ? '' : $_SESSION["leftmenu"]);
52
53	$id = 'mainmenu';
54	$listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
55
56	$substitarray = getCommonSubstitutionArray($langs, 0, null, null);
57
58	if (empty($noout)) {
59		print_start_menu_array();
60	}
61
62	$usemenuhider = 1;
63
64	// Show/Hide vertical menu. The hamburger icon for .menuhider action.
65	if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
66		$showmode = 1;
67		$classname = 'class="tmenu menuhider"';
68		$idsel = 'menu';
69
70		$menu->add('#', (!empty($conf->global->THEME_TOPMENU_DISABLE_IMAGE) ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
71	}
72
73	$menu_arr = array();
74
75	// Home
76	$menu_arr[] = array(
77		'name' => 'Home',
78		'link' => '/index.php?mainmenu=home&amp;leftmenu=home',
79		'title' => "Home",
80		'level' => 0,
81		'enabled' => $showmode = 1,
82		'target' => $atarget,
83		'mainmenu' => "home",
84		'leftmenu' => '',
85		'position' => 10,
86		'id' => $id,
87		'idsel' => 'home',
88		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "home") ? 'class="tmenusel"' : 'class="tmenu"',
89		'prefix' => '<span class="fa fa-home fa-fw paddingright"></span>',
90		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "home") ? 0 : 1),
91		'loadLangs' => array(),
92		'submenus' => array(),
93	);
94
95	// Members
96	$tmpentry = array(
97		'enabled' => (!empty($conf->adherent->enabled)),
98		'perms' => (!empty($user->rights->adherent->lire)),
99		'module' => 'adherent'
100	);
101	$menu_arr[] = array(
102		'name' => 'Members',
103		'link' => '/adherents/index.php?mainmenu=members&amp;leftmenu=',
104		'title' => "MenuMembers",
105		'level' => 0,
106		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
107		'target' => $atarget,
108		'mainmenu' => "members",
109		'leftmenu' => '',
110		'position' => 18,
111		'id' => $id,
112		'idsel' => 'members',
113		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "members") ? 'class="tmenusel"' : 'class="tmenu"',
114		'prefix' => img_picto('', 'member', 'class="fa-fw paddingright"'),
115		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "members") ? 0 : 1),
116		'loadLangs' => array(),
117		'submenus' => array(),
118	);
119
120	// Third parties
121	$tmpentry = array(
122		'enabled'=> ((!empty($conf->societe->enabled) &&
123			(empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
124			)
125			|| ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
126			),
127		'perms'=> (!empty($user->rights->societe->lire) || !empty($user->rights->fournisseur->lire) || !empty($user->rights->supplier_order->lire) || !empty($user->rights->supplier_invoice->lire) || !empty($user->rights->supplier_proposal->lire)),
128		'module'=>'societe|fournisseur'
129	);
130	$menu_arr[] = array(
131		'name' => 'Companies',
132		'link' => '/societe/index.php?mainmenu=companies&amp;leftmenu=',
133		'title' => "ThirdParties",
134		'level' => 0,
135		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
136		'target' => $atarget,
137		'mainmenu' => "companies",
138		'leftmenu' => '',
139		'position' => 20,
140		'id' => $id,
141		'idsel' => 'companies',
142		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "companies") ? 'class="tmenusel"' : 'class="tmenu"',
143		'prefix' => img_picto('', 'company', 'class="fa-fw paddingright"'),
144		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "companies") ? 0 : 1),
145		'loadLangs' => array("companies", "suppliers"),
146		'submenus' => array(),
147	);
148
149	// Products-Services
150	$tmpentry = array(
151		'enabled'=> (!empty($conf->product->enabled) || !empty($conf->service->enabled) || !empty($conf->expedition->enabled)),
152		'perms'=> (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire) || !empty($user->rights->expedition->lire)),
153		'module'=>'product|service'
154	);
155	$menu_arr[] = array(
156		'name' => 'Products',
157		'link' => '/product/index.php?mainmenu=products&amp;leftmenu=',
158		'title' => (!empty($conf->product->enabled) && !empty($conf->service->enabled))
159					? (array("TMenuProducts", " | ", "TMenuServices"))
160					: (!empty($conf->product->enabled) ? "TMenuProducts" : "TMenuServices"),
161		'level' => 0,
162		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
163		'target' => $atarget,
164		'mainmenu' => "products",
165		'leftmenu' => '',
166		'position' => 30,
167		'id' => $id,
168		'idsel' => 'products',
169		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "products") ? 'class="tmenusel"' : 'class="tmenu"',
170		'prefix' => img_picto('', 'product', 'class="fa-fw paddingright"'),
171		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "products") ? 0 : 1),
172		'loadLangs' => array("products"),
173		'submenus' => array(),
174	);
175
176	// MRP - GPAO
177	$tmpentry = array(
178		'enabled'=>(!empty($conf->bom->enabled) || !empty($conf->mrp->enabled)),
179		'perms'=>(!empty($user->rights->bom->read) || !empty($user->rights->mrp->read)),
180		'module'=>'bom|mrp'
181	);
182	$menu_arr[] = array(
183		'name' => 'TMenuMRP',
184		'link' => '/mrp/index.php?mainmenu=mrp&amp;leftmenu=',
185		'title' => "TMenuMRP",
186		'level' => 0,
187		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
188		'target' => $atarget,
189		'mainmenu' => "mrp",
190		'leftmenu' => '',
191		'position' => 31,
192		'id' => $id,
193		'idsel' => 'mrp',
194		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 'class="tmenusel"' : 'class="tmenu"',
195		'prefix' => img_picto('', 'mrp', 'class="fa-fw paddingright"'),
196		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 0 : 1),
197		'loadLangs' => array("mrp"),
198		'submenus' => array(),
199	);
200
201	// Projects
202	$tmpentry = array(
203		'enabled'=> (!empty($conf->projet->enabled) ? 1 : 0),
204		'perms'=> (!empty($user->rights->projet->lire) ? 1 : 0),
205		'module'=>'projet'
206	);
207	$menu_arr[] = array(
208		'name' => 'Projet',
209		'link' => '/projet/index.php?mainmenu=project&amp;leftmenu=',
210		'title' => (! empty($conf->global->PROJECT_USE_OPPORTUNITIES) && $conf->global->PROJECT_USE_OPPORTUNITIES == 2 ? "Leads" : "Projects"),
211		'level' => 0,
212		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
213		'target' => $atarget,
214		'mainmenu' => "project",
215		'leftmenu' => '',
216		'position' => 35,
217		'id' => $id,
218		'idsel' => 'project',
219		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "project") ? 'class="tmenusel"' : 'class="tmenu"',
220		'prefix' => img_picto('', 'project', 'class="fa-fw paddingright"'),
221		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "project") ? 0 : 1),
222		'loadLangs' => array("projects"),
223		'submenus' => array(),
224	);
225
226	// Commercial (propal, commande, supplier_proposal, supplier_order, contrat, ficheinter)
227	$tmpentry = array(
228		'enabled'=>(!empty($conf->propal->enabled)
229			|| !empty($conf->commande->enabled)
230			|| !empty($conf->fournisseur->enabled)
231			|| !empty($conf->supplier_proposal->enabled)
232			|| !empty($conf->supplier_order->enabled)
233			|| !empty($conf->contrat->enabled)
234			|| !empty($conf->ficheinter->enabled)
235		) ? 1 : 0,
236		'perms'=>(!empty($user->rights->propal->lire)
237			|| !empty($user->rights->commande->lire)
238			|| !empty($user->rights->supplier_proposal->lire)
239			|| !empty($user->rights->fournisseur->lire)
240			|| !empty($user->rights->fournisseur->commande->lire)
241			|| !empty($user->rights->supplier_order->lire)
242			|| !empty($user->rights->contrat->lire)
243			|| !empty($user->rights->ficheinter->lire)
244		),
245		'module'=>'propal|commande|supplier_proposal|supplier_order|contrat|ficheinter'
246	);
247
248	$onlysupplierorder = !empty($user->rights->fournisseur->commande->lire) &&
249		empty($user->rights->propal->lire) &&
250		empty($user->rights->commande->lire) &&
251		empty($user->rights->supplier_order->lire) &&
252		empty($user->rights->supplier_proposal->lire) &&
253		empty($user->rights->contrat->lire) &&
254		empty($user->rights->ficheinter->lire);
255
256	$menu_arr[] = array(
257		'name' => 'Commercial',
258		'link' => ($onlysupplierorder ? '/fourn/commande/index.php?mainmenu=commercial&amp;leftmenu=' : '/comm/index.php?mainmenu=commercial&amp;leftmenu='),
259		'title' => "Commercial",
260		'level' => 0,
261		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
262		'target' => $atarget,
263		'mainmenu' => "commercial",
264		'leftmenu' => '',
265		'position' => 40,
266		'id' => $id,
267		'idsel' => 'commercial',
268		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "commercial") ? 'class="tmenusel"' : 'class="tmenu"',
269		'prefix' => img_picto('', 'contract', 'class="fa-fw paddingright"'),
270		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "commercial") ? 0 : 1),
271		'loadLangs' => array("commercial"),
272		'submenus' => array(),
273	);
274
275	// Billing - Financial
276	$tmpentry = array(
277		'enabled'=>(!empty($conf->facture->enabled) ||
278			!empty($conf->don->enabled) ||
279			!empty($conf->tax->enabled) ||
280			!empty($conf->salaries->enabled) ||
281			!empty($conf->supplier_invoice->enabled) ||
282			!empty($conf->loan->enabled) ||
283			!empty($conf->margins->enabled)
284			) ? 1 : 0,
285		'perms'=>(!empty($user->rights->facture->lire) || !empty($user->rights->don->contact->lire)
286			|| !empty($user->rights->tax->charges->lire) || !empty($user->rights->salaries->read)
287			|| !empty($user->rights->fournisseur->facture->lire) || !empty($user->rights->loan->read) || !empty($user->rights->margins->liretous)),
288		'module'=>'facture|supplier_invoice|don|tax|salaries|loan'
289	);
290	$menu_arr[] = array(
291		'name' => 'Compta',
292		'link' => '/compta/index.php?mainmenu=billing&amp;leftmenu=',
293		'title' =>  "MenuFinancial",
294		'level' => 0,
295		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
296		'target' => $atarget,
297		'mainmenu' => "billing",
298		'leftmenu' => '',
299		'position' => 50,
300		'id' => $id,
301		'idsel' => 'billing',
302		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "billing") ? 'class="tmenusel"' : 'class="tmenu"',
303		'prefix' => img_picto('', 'bill', 'class="fa-fw paddingright"'),
304		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "billing") ? 0 : 1),
305		'loadLangs' => array("compta"),
306		'submenus' => array(),
307	);
308
309	// Bank
310	$tmpentry = array(
311		'enabled'=>(!empty($conf->banque->enabled) || !empty($conf->prelevement->enabled)),
312		'perms'=>(!empty($user->rights->banque->lire) || !empty($user->rights->prelevement->lire) || !empty($user->rights->paymentbybanktransfer->read)),
313		'module'=>'banque|prelevement|paymentbybanktransfer'
314	);
315	$menu_arr[] = array(
316		'name' => 'Bank',
317		'link' => '/compta/bank/list.php?mainmenu=bank&amp;leftmenu=',
318		'title' =>  "MenuBankCash",
319		'level' => 0,
320		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
321		'target' => $atarget,
322		'mainmenu' => "bank",
323		'leftmenu' => '',
324		'position' => 52,
325		'id' => $id,
326		'idsel' => 'bank',
327		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "bank") ? 'class="tmenusel"' : 'class="tmenu"',
328		'prefix' => img_picto('', 'bank_account', 'class="fa-fw paddingright"'),
329		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "bank") ? 0 : 1),
330		'loadLangs' => array("compta", "banks"),
331		'submenus' => array(),
332	);
333
334	// Accounting
335	$tmpentry = array(
336		'enabled'=>(!empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled) || !empty($conf->asset->enabled) || !empty($conf->intracommreport->enabled)),
337		'perms'=>(!empty($user->rights->compta->resultat->lire) || !empty($user->rights->accounting->comptarapport->lire) || !empty($user->rights->accounting->mouvements->lire) || !empty($user->rights->asset->read) || !empty($user->rights->intracommreport->read)),
338		'module'=>'comptabilite|accounting|asset|intracommreport'
339	);
340	$menu_arr[] = array(
341		'name' => 'Accounting',
342		'link' => '/accountancy/index.php?mainmenu=accountancy&amp;leftmenu=',
343		'title' =>  "MenuAccountancy",
344		'level' => 0,
345		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
346		'target' => $atarget,
347		'mainmenu' => "accountancy",
348		'leftmenu' => '',
349		'position' => 54,
350		'id' => $id,
351		'idsel' => 'accountancy',
352		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "accountancy") ? 'class="tmenusel"' : 'class="tmenu"',
353		'prefix' => img_picto('', 'accountancy', 'class="fa-fw paddingright"'),
354		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "accountancy") ? 0 : 1),
355		'loadLangs' => array("compta", "accountancy", "assets", "intracommreport"),
356		'submenus' => array(),
357	);
358
359	// HRM
360	$tmpentry = array(
361		'enabled'=>(!empty($conf->hrm->enabled) || (!empty($conf->holiday->enabled)) || !empty($conf->deplacement->enabled) || !empty($conf->expensereport->enabled) || !empty($conf->recruitment->enabled)),
362		'perms'=>(!empty($user->rights->user->user->lire) || !empty($user->rights->holiday->read) || !empty($user->rights->deplacement->lire) || !empty($user->rights->expensereport->lire) || !empty($user->rights->recruitment->recruitmentjobposition->read)),
363		'module'=>'hrm|holiday|deplacement|expensereport|recruitment'
364	);
365
366	$menu_arr[] = array(
367		'name' => 'HRM',
368		'link' => '/hrm/index.php?mainmenu=hrm&amp;leftmenu=',
369		'title' =>  "HRM",
370		'level' => 0,
371		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
372		'target' => $atarget,
373		'mainmenu' => "hrm",
374		'leftmenu' => '',
375		'position' => 80,
376		'id' => $id,
377		'idsel' => 'hrm',
378		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "hrm") ? 'class="tmenusel"' : 'class="tmenu"',
379		'prefix' => img_picto('', 'hrm', 'class="fa-fw paddingright"'),
380		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "hrm") ? 0 : 1),
381		'loadLangs' => array("holiday"),
382		'submenus' => array(),
383	);
384
385	// Tickets and knowledge base
386	$tmpentry = array(
387		'enabled'=>(!empty($conf->ticket->enabled) || !empty($conf->knowledgemanagement->enabled)),
388		'perms'=>(!empty($user->rights->ticket->read) || !empty($user->rights->knowledgemanagement->knowledgerecord->read)),
389		'module'=>'ticket|knowledgemanagement'
390	);
391	$link = '';
392	if (!empty($conf->ticket->enabled)) {
393		$link = '/ticket/index.php?mainmenu=ticket&amp;leftmenu=';
394	} else {
395		$link = '/knowledgemanagement/knowledgerecord_list.php?mainmenu=ticket&amp;leftmenu=';
396	}
397	$menu_arr[] = array(
398		'name' => 'Ticket',
399		'link' => '/ticket/index.php?mainmenu=ticket&amp;leftmenu=',
400		'title' =>  "Tickets",
401		'level' => 0,
402		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
403		'target' => $atarget,
404		'mainmenu' => "ticket",
405		'leftmenu' => '',
406		'position' => 88,
407		'id' => $id,
408		'idsel' => 'ticket',
409		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "ticket") ? 'class="tmenusel"' : 'class="tmenu"',
410		'prefix' => img_picto('', 'ticket', 'class="fa-fw paddingright"'),
411		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "ticket") ? 0 : 1),
412		'loadLangs' => array("other"),
413		'submenus' => array(),
414	);
415
416	// Tools
417	$tmpentry = array(
418		'enabled'=>1,
419		'perms'=>1,
420		'module'=>''
421	);
422	$menu_arr[] = array(
423		'name' => 'Tools',
424		'link' => '/core/tools.php?mainmenu=tools&amp;leftmenu=',
425		'title' =>  "Tools",
426		'level' => 0,
427		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
428		'target' => $atarget,
429		'mainmenu' => "tools",
430		'leftmenu' => '',
431		'position' => 90,
432		'id' => $id,
433		'idsel' => 'tools',
434		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "tools") ? 'class="tmenusel"' : 'class="tmenu"',
435		'prefix' => img_picto('', 'tools', 'class="fa-fw paddingright"'),
436		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "tools") ? 0 : 1),
437		'loadLangs' => array("other"),
438		'submenus' => array(),
439	);
440
441	// Add menus
442	foreach ($menu_arr as $key => $smenu) {
443		$smenu = (object) $smenu;
444
445		if ($smenu->enabled) {
446			if ($smenu->session) {
447				$_SESSION['idmenu'] = '';
448			}
449
450			// Load Langue
451			if (!empty($smenu->loadLangs)) {
452				$langs->loadLangs($smenu->loadLangs);
453			}
454
455			// Trans title
456			$mtitle = '';
457			if (is_array($smenu->title)) {
458				foreach ($smenu->title as $item) {
459					$mtitle .= $langs->trans($item);
460				}
461			} else {
462				$mtitle = $langs->trans($smenu->title);
463			}
464			// Add item
465			$menu->add($smenu->link, $mtitle, $smenu->level, $smenu->enabled, $smenu->target, $smenu->mainmenu, $smenu->leftmenu, $smenu->position, $smenu->id, $smenu->idsel, $smenu->classname, $smenu->prefix);
466		}
467	}
468
469	// Show personalized menus
470	$menuArbo = new Menubase($db, 'eldy');
471
472	$newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'eldy', $tabMenu); // Return tabMenu with only top entries
473
474	$num = count($newTabMenu);
475	for ($i = 0; $i < $num; $i++) {
476		//var_dump($type_user.' '.$newTabMenu[$i]['url'].' '.$showmode.' '.$newTabMenu[$i]['perms']);
477		$idsel = (empty($newTabMenu[$i]['mainmenu']) ? 'none' : $newTabMenu[$i]['mainmenu']);
478
479		$newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);
480
481		// url = url from host, shorturl = relative path into dolibarr sources
482		$url = $shorturl = $newTabMenu[$i]['url'];
483		if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url'])) {	// Do not change url content for external links
484			$tmp = explode('?', $newTabMenu[$i]['url'], 2);
485			$url = $shorturl = $tmp[0];
486			$param = (isset($tmp[1]) ? $tmp[1] : '');
487
488			if (!preg_match('/mainmenu/i', $param) || !preg_match('/leftmenu/i', $param)) {
489				$param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&amp;leftmenu=';
490			}
491			//$url.="idmenu=".$newTabMenu[$i]['rowid'];    // Already done by menuLoad
492			$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
493			//$shorturl = $shorturl.($param?'?'.$param:'');
494			$shorturl = $url;
495			if (DOL_URL_ROOT) {
496				$shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
497			}
498		}
499
500		$showmode = isVisibleToUserType($type_user, $newTabMenu[$i], $listofmodulesforexternal);
501		if ($showmode == 1) {
502			// Define the class (top menu selected or not)
503			if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) {
504				$classname = 'class="tmenusel"';
505			} elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) {
506				$classname = 'class="tmenusel"';
507			} else {
508				$classname = 'class="tmenu"';
509			}
510		} elseif ($showmode == 2) {
511			$classname = 'class="tmenu"';
512		}
513
514		$menu->add(
515			$shorturl,
516			$newTabMenu[$i]['titre'],
517			0,
518			$showmode,
519			($newTabMenu[$i]['target'] ? $newTabMenu[$i]['target'] : $atarget),
520			($newTabMenu[$i]['mainmenu'] ? $newTabMenu[$i]['mainmenu'] : $newTabMenu[$i]['rowid']),
521			($newTabMenu[$i]['leftmenu'] ? $newTabMenu[$i]['leftmenu'] : ''),
522			$newTabMenu[$i]['position'],
523			$id,
524			$idsel,
525			$classname,
526			$newTabMenu[$i]['prefix']
527		);
528	}
529
530	// Sort on position
531	$menu->liste = dol_sort_array($menu->liste, 'position');
532
533	// Output menu entries
534	// Show logo company
535	if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
536		//$mysoc->logo_mini=(empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI);
537		$mysoc->logo_squarred_mini = (empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI);
538
539		$logoContainerAdditionalClass = 'backgroundforcompanylogo';
540		if (!empty($conf->global->MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND)) {
541			$logoContainerAdditionalClass = '';
542		}
543
544		if (!empty($mysoc->logo_squarred_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini)) {
545			$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
546			/*} elseif (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
547			{
548				$urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_mini);
549			}*/
550		} else {
551			$urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png';
552			$logoContainerAdditionalClass = '';
553		}
554		$title = $langs->trans("GoIntoSetupToChangeLogo");
555
556		print "\n".'<!-- Show logo on menu -->'."\n";
557		print_start_menu_entry('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
558
559		print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
560
561		print_end_menu_entry(4);
562	}
563
564	if (empty($noout)) {
565		foreach ($menu->liste as $menuval) {
566			print_start_menu_entry($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
567			print_text_menu_entry($menuval['titre'], $menuval['enabled'], (($menuval['url'] != '#' && !preg_match('/^(http:\/\/|https:\/\/)/i', $menuval['url'])) ? DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget));
568			print_end_menu_entry($menuval['enabled']);
569		}
570	}
571
572	$showmode = 1;
573	if (empty($noout)) {
574		print_start_menu_entry('', 'class="tmenuend"', $showmode);
575		print_end_menu_entry($showmode);
576		print_end_menu_array();
577	}
578
579	return 0;
580}
581
582
583/**
584 * Output start menu array
585 *
586 * @return	void
587 */
588function print_start_menu_array()
589{
590	global $conf;
591
592	print '<div class="tmenudiv">';
593	print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>';
594}
595
596/**
597 * Output start menu entry
598 *
599 * @param	string	$idsel		Text
600 * @param	string	$classname	String to add a css class
601 * @param	int		$showmode	0 = hide, 1 = allowed or 2 = not allowed
602 * @return	void
603 */
604function print_start_menu_entry($idsel, $classname, $showmode)
605{
606	if ($showmode) {
607		print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
608		//print '<div class="tmenuleft tmenusep"></div>';
609		print '<div class="tmenucenter">';
610	}
611}
612
613/**
614 * Output menu entry
615 *
616 * @param	string	$text		Text
617 * @param	int		$showmode	0 = hide, 1 = allowed or 2 = not allowed
618 * @param	string	$url		Url
619 * @param	string	$id			Id
620 * @param	string	$idsel		Id sel
621 * @param	string	$classname	Class name
622 * @param	string	$atarget	Target
623 * @return	void
624 */
625function print_text_menu_entry($text, $showmode, $url, $id, $idsel, $classname, $atarget)
626{
627	global $conf, $langs;
628
629	//$conf->global->THEME_TOPMENU_DISABLE_TEXT=1;
630	if ($showmode == 1) {
631		print '<a class="tmenuimage" tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
632		print '<div class="'.$id.' '.$idsel.' topmenuimage"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
633		print '</a>';
634		if (empty($conf->global->THEME_TOPMENU_DISABLE_TEXT)) {
635			print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
636			print '<span class="mainmenuaspan">';
637			print $text;
638			print '</span>';
639			print '</a>';
640		}
641	} elseif ($showmode == 2) {
642		print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled"><span class="'.$id.'" id="mainmenuspan_'.$idsel.'"></span></div>';
643		if (empty($conf->global->THEME_TOPMENU_DISABLE_TEXT)) {
644			print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">';
645			print '<span class="mainmenuaspan">';
646			print $text;
647			print '</span>';
648			print '</a>';
649		}
650	}
651}
652
653/**
654 * Output end menu entry
655 *
656 * @param	int		$showmode	0 = hide, 1 = allowed or 2 = not allowed
657 * @return	void
658 */
659function print_end_menu_entry($showmode)
660{
661	if ($showmode) {
662		print '</div></li>';
663	}
664	print "\n";
665}
666
667/**
668 * Output menu array
669 *
670 * @return	void
671 */
672function print_end_menu_array()
673{
674	print '</ul>';
675	print '</div>';
676	print "\n";
677}
678
679
680
681/**
682 * Core function to output left menu eldy
683 * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home)
684 *
685 * @param	DoliDB		$db                 Database handler
686 * @param 	array		$menu_array_before  Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add)
687 * @param   array		$menu_array_after   Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add)
688 * @param	array		$tabMenu       		If array with menu entries already loaded, we put this array here (in most cases, it's empty)
689 * @param	Menu		$menu				Object Menu to return back list of menu entries
690 * @param	int			$noout				Disable output (Initialise &$menu only).
691 * @param	string		$forcemainmenu		'x'=Force mainmenu to mainmenu='x'
692 * @param	string		$forceleftmenu		'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not defined in session.
693 * @param	array		$moredata			An array with more data to output
694 * @param 	int			$type_user     		0=Menu for backoffice, 1=Menu for front office
695 * @return	int								Nb of menu entries
696 */
697function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0)
698{
699	global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
700
701	//var_dump($tabMenu);
702
703	$newmenu = $menu;
704
705	$mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
706	$leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
707
708	$usemenuhider = 0;
709
710	if (is_array($moredata) && !empty($moredata['searchform'])) {	// searchform can contains select2 code or link to show old search form or link to switch on search page
711		print "\n";
712		print "<!-- Begin SearchForm -->\n";
713		print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
714		print $moredata['searchform'];
715		print '</div>'."\n";
716		print "<!-- End SearchForm -->\n";
717	}
718
719	if (is_array($moredata) && !empty($moredata['bookmarks'])) {
720		print "\n";
721		print "<!-- Begin Bookmarks -->\n";
722		print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
723		print $moredata['bookmarks'];
724		print '</div>'."\n";
725		print "<!-- End Bookmarks -->\n";
726	}
727
728	$substitarray = getCommonSubstitutionArray($langs, 0, null, null);
729
730	$listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
731
732	/**
733	 * We update newmenu with entries found into database
734	 * --------------------------------------------------
735	 */
736	if ($mainmenu) {	// If this is empty, loading hard coded menu and loading personalised menu will fail
737		/*
738		 * Menu HOME
739		 */
740		if ($mainmenu == 'home') {
741			$langs->load("users");
742
743			// Home - dashboard
744			$newmenu->add("/index.php?mainmenu=home&amp;leftmenu=home", $langs->trans("MyDashboard"), 0, 1, '', $mainmenu, 'home', 0, '', '', '', '<i class="fa fa-bar-chart fa-fw paddingright pictofixedwidth"></i>');
745
746			// Setup
747			$newmenu->add("/admin/index.php?mainmenu=home&amp;leftmenu=setup", $langs->trans("Setup"), 0, $user->admin, '', $mainmenu, 'setup', 0, '', '', '', '<i class="fa fa-tools fa-fw paddingright pictofixedwidth"></i>');
748
749			if ($usemenuhider || empty($leftmenu) || $leftmenu == "setup") {
750				// Load translation files required by the page
751				$langs->loadLangs(array("admin", "help"));
752
753				$warnpicto = '';
754				if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
755					$langs->load("errors");
756					$warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
757				}
758				$newmenu->add("/admin/company.php?mainmenu=home", $langs->trans("MenuCompanySetup").$warnpicto, 1);
759
760				$warnpicto = '';
761				if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) {	// If only user module enabled
762					$langs->load("errors");
763					$warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
764				}
765				$newmenu->add("/admin/modules.php?mainmenu=home", $langs->trans("Modules").$warnpicto, 1);
766				$newmenu->add("/admin/ihm.php?mainmenu=home", $langs->trans("GUISetup"), 1);
767				$newmenu->add("/admin/menus.php?mainmenu=home", $langs->trans("Menus"), 1);
768
769				$newmenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
770				$newmenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
771				$newmenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
772				$newmenu->add("/admin/delais.php?mainmenu=home", $langs->trans("MenuWarnings"), 1);
773				$newmenu->add("/admin/security_other.php?mainmenu=home", $langs->trans("Security"), 1);
774				$newmenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
775				$newmenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
776
777				$warnpicto = '';
778				if (!empty($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
779					$langs->load("errors");
780					$warnpicto = img_warning($langs->trans("WarningPHPMailD"));
781				}
782				if (!empty($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmail')) && empty($conf->global->MAIN_MAIL_SMTP_SERVER)) {
783					$langs->load("errors");
784					$warnpicto = img_warning($langs->trans("ErrorSetupOfEmailsNotComplete"));
785				}
786
787				$newmenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails").$warnpicto, 1);
788				$newmenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
789				$newmenu->add("/admin/dict.php?mainmenu=home", $langs->trans("Dictionary"), 1);
790				$newmenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
791			}
792
793			// System tools
794			$newmenu->add("/admin/tools/index.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("AdminTools"), 0, $user->admin, '', $mainmenu, 'admintools', 0, '', '', '', '<i class="fa fa-server fa-fw paddingright pictofixedwidth"></i>');
795			if ($usemenuhider || empty($leftmenu) || preg_match('/^admintools/', $leftmenu)) {
796				// Load translation files required by the page
797				$langs->loadLangs(array('admin', 'help'));
798
799				$newmenu->add('/admin/system/dolibarr.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('InfoDolibarr'), 1);
800				if ($usemenuhider || empty($leftmenu) || $leftmenu == 'admintools_info') {
801					$newmenu->add('/admin/system/modules.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Modules'), 2);
802					$newmenu->add('/admin/triggers.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Triggers'), 2);
803					$newmenu->add('/admin/system/filecheck.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('FileCheck'), 2);
804				}
805				$newmenu->add('/admin/system/browser.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoBrowser'), 1);
806				$newmenu->add('/admin/system/os.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoOS'), 1);
807				$newmenu->add('/admin/system/web.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoWebServer'), 1);
808				$newmenu->add('/admin/system/phpinfo.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoPHP'), 1);
809				$newmenu->add('/admin/system/database.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoDatabase'), 1);
810				$newmenu->add("/admin/system/perf.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("InfoPerf"), 1);
811				$newmenu->add("/admin/system/security.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("InfoSecurity"), 1);
812				$newmenu->add("/admin/tools/dolibarr_export.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Backup"), 1);
813				$newmenu->add("/admin/tools/dolibarr_import.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Restore"), 1);
814				$newmenu->add("/admin/tools/update.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("MenuUpgrade"), 1);
815				$newmenu->add("/admin/tools/purge.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Purge"), 1);
816				$newmenu->add("/admin/tools/listevents.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Audit"), 1);
817				$newmenu->add("/admin/tools/listsessions.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("Sessions"), 1);
818				$newmenu->add('/admin/system/about.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('ExternalResources'), 1);
819
820				if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
821					$langs->load("products");
822					$newmenu->add("/product/admin/product_tools.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
823				}
824			}
825
826			$newmenu->add("/user/home.php?leftmenu=users", $langs->trans("MenuUsersAndGroups"), 0, $user->rights->user->user->lire, '', $mainmenu, 'users', 0, '', '', '', img_picto('', 'user', 'class="paddingright pictofixedwidth"'));
827			if ($user->rights->user->user->lire) {
828				if ($usemenuhider || empty($leftmenu) || $leftmenu == "users") {
829					$newmenu->add("", $langs->trans("Users"), 1, $user->rights->user->user->lire || $user->admin);
830					$newmenu->add("/user/card.php?leftmenu=users&action=create", $langs->trans("NewUser"), 2, ($user->rights->user->user->creer || $user->admin) && !(!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE), '', 'home');
831					$newmenu->add("/user/list.php?leftmenu=users", $langs->trans("ListOfUsers"), 2, $user->rights->user->user->lire || $user->admin);
832					$newmenu->add("/user/hierarchy.php?leftmenu=users", $langs->trans("HierarchicView"), 2, $user->rights->user->user->lire || $user->admin);
833					if (!empty($conf->categorie->enabled)) {
834						$langs->load("categories");
835						$newmenu->add("/categories/index.php?leftmenu=users&type=7", $langs->trans("UsersCategoriesShort"), 2, $user->rights->categorie->lire, '', $mainmenu, 'cat');
836					}
837					$newmenu->add("", $langs->trans("Groups"), 1, ($user->rights->user->user->lire || $user->admin) && !(!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE));
838					$newmenu->add("/user/group/card.php?leftmenu=users&action=create", $langs->trans("NewGroup"), 2, ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) ? $user->rights->user->group_advance->write : $user->rights->user->user->creer) || $user->admin) && !(!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE));
839					$newmenu->add("/user/group/list.php?leftmenu=users", $langs->trans("ListOfGroups"), 2, ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) ? $user->rights->user->group_advance->read : $user->rights->user->user->lire) || $user->admin) && !(!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE));
840				}
841			}
842		}
843
844
845		/*
846		 * Menu THIRDPARTIES
847		 */
848		if ($mainmenu == 'companies') {
849			// Societes
850			if (!empty($conf->societe->enabled)) {
851				$langs->load("companies");
852				$newmenu->add("/societe/index.php?leftmenu=thirdparties", $langs->trans("ThirdParty"), 0, $user->rights->societe->lire, '', $mainmenu, 'thirdparties', 0, '', '', '', img_picto('', 'company', 'class="paddingright pictofixedwidth"'));
853
854				if ($user->rights->societe->creer) {
855					$newmenu->add("/societe/card.php?action=create", $langs->trans("MenuNewThirdParty"), 1);
856					if (!$conf->use_javascript_ajax) {
857						$newmenu->add("/societe/card.php?action=create&amp;private=1", $langs->trans("MenuNewPrivateIndividual"), 1);
858					}
859				}
860			}
861
862			$newmenu->add("/societe/list.php?leftmenu=thirdparties", $langs->trans("List"), 1);
863
864			// Prospects
865			if (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
866				$langs->load("commercial");
867				$newmenu->add("/societe/list.php?type=p&amp;leftmenu=prospects", $langs->trans("ListProspectsShort"), 2, $user->rights->societe->lire, '', $mainmenu, 'prospects');
868				/* no more required, there is a filter that can do more
869				if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&amp;sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire);
870				if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&amp;sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire);
871				if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&amp;sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=1", $langs->trans("LastProspectToContact"), 2, $user->rights->societe->lire);
872				if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&amp;sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=2", $langs->trans("LastProspectContactInProcess"), 2, $user->rights->societe->lire);
873				if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&amp;sortfield=s.datec&amp;sortorder=desc&amp;begin=&amp;search_stcomm=3", $langs->trans("LastProspectContactDone"), 2, $user->rights->societe->lire);
874				*/
875				$newmenu->add("/societe/card.php?leftmenu=prospects&amp;action=create&amp;type=p", $langs->trans("MenuNewProspect"), 3, $user->rights->societe->creer);
876			}
877
878			// Customers/Prospects
879			if (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
880				$langs->load("commercial");
881				$newmenu->add("/societe/list.php?type=c&amp;leftmenu=customers", $langs->trans("ListCustomersShort"), 2, $user->rights->societe->lire, '', $mainmenu, 'customers');
882
883				$newmenu->add("/societe/card.php?leftmenu=customers&amp;action=create&amp;type=c", $langs->trans("MenuNewCustomer"), 3, $user->rights->societe->creer);
884			}
885
886			// Suppliers
887			if (!empty($conf->societe->enabled) && (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) || !empty($conf->supplier_proposal->enabled))) {
888				$langs->load("suppliers");
889				$newmenu->add("/societe/list.php?type=f&amp;leftmenu=suppliers", $langs->trans("ListSuppliersShort"), 2, ($user->rights->fournisseur->lire || $user->rights->supplier_order->lire || $user->rights->supplier_invoice->lire || $user->rights->supplier_proposal->lire), '', $mainmenu, 'suppliers');
890				$newmenu->add("/societe/card.php?leftmenu=suppliers&amp;action=create&amp;type=f", $langs->trans("MenuNewSupplier"), 3, $user->rights->societe->creer && ($user->rights->fournisseur->lire || $user->rights->supplier_order->lire || $user->rights->supplier_invoice->lire || $user->rights->supplier_proposal->lire));
891			}
892
893			// Categories
894			if (!empty($conf->categorie->enabled)) {
895				$langs->load("categories");
896				if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
897					// Categories prospects/customers
898					$menutoshow = $langs->trans("CustomersProspectsCategoriesShort");
899					if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
900						$menutoshow = $langs->trans("CustomersCategoriesShort");
901					}
902					if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
903						$menutoshow = $langs->trans("ProspectsCategoriesShort");
904					}
905					$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=2", $menutoshow, 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
906				}
907				// Categories suppliers
908				if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
909					$newmenu->add("/categories/index.php?leftmenu=catfournish&amp;type=1", $langs->trans("SuppliersCategoriesShort"), 1, $user->rights->categorie->lire);
910				}
911			}
912
913			// Contacts
914			$newmenu->add("/societe/index.php?leftmenu=thirdparties", (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")), 0, $user->rights->societe->contact->lire, '', $mainmenu, 'contacts', 0, '', '', '', img_picto('', 'contact', 'class="paddingright pictofixedwidth"'));
915
916			$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);
917			$newmenu->add("/contact/list.php?leftmenu=contacts", $langs->trans("List"), 1, $user->rights->societe->contact->lire);
918			if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
919				$newmenu->add("/contact/list.php?leftmenu=contacts&type=p", $langs->trans("Prospects"), 2, $user->rights->societe->contact->lire);
920			}
921			if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
922				$newmenu->add("/contact/list.php?leftmenu=contacts&type=c", $langs->trans("Customers"), 2, $user->rights->societe->contact->lire);
923			}
924			if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
925				$newmenu->add("/contact/list.php?leftmenu=contacts&type=f", $langs->trans("Suppliers"), 2, $user->rights->societe->contact->lire);
926			}
927			$newmenu->add("/contact/list.php?leftmenu=contacts&type=o", $langs->trans("ContactOthers"), 2, $user->rights->societe->contact->lire);
928			//$newmenu->add("/contact/list.php?userid=$user->id", $langs->trans("MyContacts"), 1, $user->rights->societe->contact->lire);
929
930			// Categories
931			if (!empty($conf->categorie->enabled)) {
932				$langs->load("categories");
933				// Categories Contact
934				$newmenu->add("/categories/index.php?leftmenu=catcontact&amp;type=4", $langs->trans("ContactCategoriesShort"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
935			}
936		}
937
938		/*
939		 * Menu COMMERCIAL (propal, commande, supplier_proposal, supplier_order, contrat, ficheinter)
940		 */
941		if ($mainmenu == 'commercial') {
942			$langs->load("companies");
943
944			// Customer proposal
945			if (!empty($conf->propal->enabled)) {
946				$langs->load("propal");
947				$newmenu->add("/comm/propal/index.php?leftmenu=propals", $langs->trans("Proposals"), 0, $user->rights->propale->lire, '', $mainmenu, 'propals', 100, '', '', '', img_picto('', 'propal', 'class="paddingright pictofixedwidth"'));
948				$newmenu->add("/comm/propal/card.php?action=create&amp;leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer);
949				$newmenu->add("/comm/propal/list.php?leftmenu=propals", $langs->trans("List"), 1, $user->rights->propale->lire);
950				if ($usemenuhider || empty($leftmenu) || $leftmenu == "propals") {
951					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire);
952					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire);
953					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2", $langs->trans("PropalStatusSigned"), 2, $user->rights->propale->lire);
954					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=3", $langs->trans("PropalStatusNotSigned"), 2, $user->rights->propale->lire);
955					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=4", $langs->trans("PropalStatusBilled"), 2, $user->rights->propale->lire);
956					//$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2,3,4", $langs->trans("PropalStatusClosedShort"), 2, $user->rights->propale->lire);
957				}
958				$newmenu->add("/comm/propal/stats/index.php?leftmenu=propals", $langs->trans("Statistics"), 1, $user->rights->propale->lire);
959			}
960
961			// Customers orders
962			if (!empty($conf->commande->enabled)) {
963				$langs->load("orders");
964				$newmenu->add("/commande/index.php?leftmenu=orders", $langs->trans("CustomersOrders"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders', 200, '', '', '', img_picto('', 'order', 'class="paddingright pictofixedwidth"'));
965				$newmenu->add("/commande/card.php?action=create&amp;leftmenu=orders", $langs->trans("NewOrder"), 1, $user->rights->commande->creer);
966				$newmenu->add("/commande/list.php?leftmenu=orders", $langs->trans("List"), 1, $user->rights->commande->lire);
967				if ($usemenuhider || empty($leftmenu) || $leftmenu == "orders") {
968					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->commande->lire);
969					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->commande->lire);
970					if (!empty($conf->expedition->enabled)) {
971						$newmenu->add("/commande/list.php?leftmenu=orders&search_status=2", $langs->trans("StatusOrderSentShort"), 2, $user->rights->commande->lire);
972					}
973					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=3", $langs->trans("StatusOrderDelivered"), 2, $user->rights->commande->lire);
974					//$newmenu->add("/commande/list.php?leftmenu=orders&search_status=4", $langs->trans("StatusOrderProcessed"), 2, $user->rights->commande->lire);
975					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=-1", $langs->trans("StatusOrderCanceledShort"), 2, $user->rights->commande->lire);
976				}
977				$newmenu->add("/commande/stats/index.php?leftmenu=orders", $langs->trans("Statistics"), 1, $user->rights->commande->lire);
978			}
979
980			// Supplier proposal
981			if (!empty($conf->supplier_proposal->enabled)) {
982				$langs->load("supplier_proposal");
983				$newmenu->add("/supplier_proposal/index.php?leftmenu=propals_supplier", $langs->trans("SupplierProposalsShort"), 0, $user->rights->supplier_proposal->lire, '', $mainmenu, 'propals_supplier', 300, '', '', '', img_picto('', 'supplier_proposal', 'class="paddingright pictofixedwidth"'));
984				$newmenu->add("/supplier_proposal/card.php?action=create&amp;leftmenu=supplier_proposals", $langs->trans("SupplierProposalNew"), 1, $user->rights->supplier_proposal->creer);
985				$newmenu->add("/supplier_proposal/list.php?leftmenu=supplier_proposals", $langs->trans("List"), 1, $user->rights->supplier_proposal->lire);
986				$newmenu->add("/comm/propal/stats/index.php?leftmenu=supplier_proposals&amp;mode=supplier", $langs->trans("Statistics"), 1, $user->rights->supplier_proposal->lire);
987			}
988
989			// Suppliers orders
990			if (!empty($conf->supplier_order->enabled)) {
991				$langs->load("orders");
992				$newmenu->add("/fourn/commande/index.php?leftmenu=orders_suppliers", $langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire, '', $mainmenu, 'orders_suppliers', 400, '', '', '', img_picto('', 'supplier_order', 'class="paddingright pictofixedwidth"'));
993				$newmenu->add("/fourn/commande/card.php?action=create&amp;leftmenu=orders_suppliers", $langs->trans("NewSupplierOrderShort"), 1, $user->rights->fournisseur->commande->creer);
994				$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
995
996				if ($usemenuhider || empty($leftmenu) || $leftmenu == "orders_suppliers") {
997					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=0", $langs->trans("StatusSupplierOrderDraftShort"), 2, $user->rights->fournisseur->commande->lire);
998					if (empty($conf->global->SUPPLIER_ORDER_HIDE_VALIDATED)) {
999						$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=1", $langs->trans("StatusSupplierOrderValidated"), 2, $user->rights->fournisseur->commande->lire);
1000					}
1001					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=2", $langs->trans("StatusSupplierOrderApprovedShort"), 2, $user->rights->fournisseur->commande->lire);
1002					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=3", $langs->trans("StatusSupplierOrderOnProcessShort"), 2, $user->rights->fournisseur->commande->lire);
1003					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=4", $langs->trans("StatusSupplierOrderReceivedPartiallyShort"), 2, $user->rights->fournisseur->commande->lire);
1004					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=5", $langs->trans("StatusSupplierOrderReceivedAll"), 2, $user->rights->fournisseur->commande->lire);
1005					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=6,7", $langs->trans("StatusSupplierOrderCanceled"), 2, $user->rights->fournisseur->commande->lire);
1006					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=9", $langs->trans("StatusSupplierOrderRefused"), 2, $user->rights->fournisseur->commande->lire);
1007				}
1008				// Billed is another field. We should add instead a dedicated filter on list. if ($usemenuhider || empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&billed=1", $langs->trans("Billed"), 2, $user->rights->fournisseur->commande->lire);
1009
1010
1011				$newmenu->add("/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire);
1012			}
1013
1014			// Contrat
1015			if (!empty($conf->contrat->enabled)) {
1016				$langs->load("contracts");
1017				$newmenu->add("/contrat/index.php?leftmenu=contracts", $langs->trans("ContractsSubscriptions"), 0, $user->rights->contrat->lire, '', $mainmenu, 'contracts', 2000, '', '', '', img_picto('', 'contract', 'class="paddingright pictofixedwidth"'));
1018				$newmenu->add("/contrat/card.php?action=create&amp;leftmenu=contracts", $langs->trans("NewContractSubscription"), 1, $user->rights->contrat->creer);
1019				$newmenu->add("/contrat/list.php?leftmenu=contracts", $langs->trans("List"), 1, $user->rights->contrat->lire);
1020				$newmenu->add("/contrat/services_list.php?leftmenu=contracts", $langs->trans("MenuServices"), 1, $user->rights->contrat->lire);
1021				if ($usemenuhider || empty($leftmenu) || $leftmenu == "contracts") {
1022					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=0", $langs->trans("MenuInactiveServices"), 2, $user->rights->contrat->lire);
1023					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4", $langs->trans("MenuRunningServices"), 2, $user->rights->contrat->lire);
1024					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4&amp;filter=expired", $langs->trans("MenuExpiredServices"), 2, $user->rights->contrat->lire);
1025					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=5", $langs->trans("MenuClosedServices"), 2, $user->rights->contrat->lire);
1026				}
1027			}
1028
1029			// Interventions
1030			if (!empty($conf->ficheinter->enabled)) {
1031				$langs->load("interventions");
1032				$newmenu->add("/fichinter/index.php?leftmenu=ficheinter", $langs->trans("Interventions"), 0, $user->rights->ficheinter->lire, '', $mainmenu, 'ficheinter', 2200, '', '', '', img_picto('', 'intervention', 'class="paddingright pictofixedwidth"'));
1033				$newmenu->add("/fichinter/card.php?action=create&amp;leftmenu=ficheinter", $langs->trans("NewIntervention"), 1, $user->rights->ficheinter->creer, '', '', '', 201);
1034				$newmenu->add("/fichinter/list.php?leftmenu=ficheinter", $langs->trans("List"), 1, $user->rights->ficheinter->lire, '', '', '', 202);
1035				if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
1036					$newmenu->add("/fichinter/card-rec.php?leftmenu=ficheinter", $langs->trans("ListOfTemplates"), 1, $user->rights->ficheinter->lire, '', '', '', 203);
1037				}
1038				$newmenu->add("/fichinter/stats/index.php?leftmenu=ficheinter", $langs->trans("Statistics"), 1, $user->rights->ficheinter->lire);
1039			}
1040		}
1041
1042
1043		/*
1044		 * Menu COMPTA-FINANCIAL
1045		 */
1046		if ($mainmenu == 'billing') {
1047			$langs->load("companies");
1048
1049			// Customers invoices
1050			if (!empty($conf->facture->enabled)) {
1051				$langs->load("bills");
1052				$newmenu->add("/compta/facture/index.php?leftmenu=customers_bills", $langs->trans("BillsCustomers"), 0, $user->rights->facture->lire, '', $mainmenu, 'customers_bills', 0, '', '', '', img_picto('', 'bill', 'class="paddingright pictofixedwidth"'));
1053				$newmenu->add("/compta/facture/card.php?action=create", $langs->trans("NewBill"), 1, $user->rights->facture->creer);
1054				$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills", $langs->trans("List"), 1, $user->rights->facture->lire, '', $mainmenu, 'customers_bills_list');
1055
1056				if ($usemenuhider || empty($leftmenu) || preg_match('/customers_bills(|_draft|_notpaid|_paid|_canceled)$/', $leftmenu)) {
1057					$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_draft&amp;search_status=0", $langs->trans("BillShortStatusDraft"), 2, $user->rights->facture->lire);
1058					$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_notpaid&amp;search_status=1", $langs->trans("BillShortStatusNotPaid"), 2, $user->rights->facture->lire);
1059					$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_paid&amp;search_status=2", $langs->trans("BillShortStatusPaid"), 2, $user->rights->facture->lire);
1060					$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_canceled&amp;search_status=3", $langs->trans("BillShortStatusCanceled"), 2, $user->rights->facture->lire);
1061				}
1062				$newmenu->add("/compta/facture/invoicetemplate_list.php?leftmenu=customers_bills_templates", $langs->trans("ListOfTemplates"), 1, $user->rights->facture->creer, '', $mainmenu, 'customers_bills_templates'); // No need to see recurring invoices, if user has no permission to create invoice.
1063
1064				$newmenu->add("/compta/paiement/list.php?leftmenu=customers_bills_payment", $langs->trans("Payments"), 1, $user->rights->facture->lire, '', $mainmenu, 'customers_bills_payment');
1065
1066				if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
1067					$newmenu->add("/compta/paiement/tovalidate.php?leftmenu=customers_bills_tovalid", $langs->trans("MenuToValid"), 2, $user->rights->facture->lire, '', $mainmenu, 'customer_bills_tovalid');
1068				}
1069				$newmenu->add("/compta/paiement/rapport.php?leftmenu=customers_bills_reports", $langs->trans("Reportings"), 2, $user->rights->facture->lire, '', $mainmenu, 'customers_bills_reports');
1070
1071				$newmenu->add("/compta/facture/stats/index.php?leftmenu=customers_bills_stats", $langs->trans("Statistics"), 1, $user->rights->facture->lire, '', $mainmenu, 'customers_bills_stats');
1072			}
1073
1074			// Suppliers invoices
1075			if (!empty($conf->societe->enabled) && !empty($conf->supplier_invoice->enabled)) {
1076				$langs->load("bills");
1077				$newmenu->add("/fourn/facture/index.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"), 0, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills', 0, '', '', '', img_picto('', 'supplier_invoice', 'class="paddingright pictofixedwidth"'));
1078				$newmenu->add("/fourn/facture/card.php?leftmenu=suppliers_bills&amp;action=create", $langs->trans("NewBill"), 1, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), '', $mainmenu, 'suppliers_bills_create');
1079				$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("List"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_list');
1080
1081				if ($usemenuhider || empty($leftmenu) || preg_match('/suppliers_bills/', $leftmenu)) {
1082					$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills_draft&amp;search_status=0", $langs->trans("BillShortStatusDraft"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_draft');
1083					$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills_notpaid&amp;search_status=1", $langs->trans("BillShortStatusNotPaid"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_notpaid');
1084					$newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills_paid&amp;search_status=2", $langs->trans("BillShortStatusPaid"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_paid');
1085				}
1086
1087				$newmenu->add("/fourn/paiement/list.php?leftmenu=suppliers_bills_payment", $langs->trans("Payments"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_payment');
1088
1089				$newmenu->add("/fourn/facture/rapport.php?leftmenu=suppliers_bills_report", $langs->trans("Reportings"), 2, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_report');
1090
1091				$newmenu->add("/compta/facture/stats/index.php?mode=supplier&amp;leftmenu=suppliers_bills_stats", $langs->trans("Statistics"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_stats');
1092			}
1093
1094			// Orders
1095			if (!empty($conf->commande->enabled)) {
1096				$langs->load("orders");
1097				if (!empty($conf->facture->enabled)) {
1098					$newmenu->add("/commande/list.php?leftmenu=orders&amp;search_status=-3&amp;billed=0&amp;contextpage=billableorders", $langs->trans("MenuOrdersToBill2"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders', 0, '', '', '', img_picto('', 'order', 'class="paddingright pictofixedwidth"'));
1099				}
1100				//if ($usemenuhider || empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
1101			}
1102
1103			// Supplier Orders to bill
1104			if (!empty($conf->supplier_invoice->enabled)) {
1105				if (!empty($conf->global->SUPPLIER_MENU_ORDER_RECEIVED_INTO_INVOICE)) {
1106					$langs->load("supplier");
1107					$newmenu->add("/fourn/commande/list.php?leftmenu=orders&amp;search_status=5&amp;billed=0", $langs->trans("MenuOrdersSupplierToBill"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders', 0, '', '', '', img_picto('', 'supplier_order', 'class="paddingright pictofixedwidth"'));
1108					//if ($usemenuhider || empty($leftmenu) || $leftmenu=="orders") $newmenu->add("/commande/", $langs->trans("StatusOrderToBill"), 1, $user->rights->commande->lire);
1109				}
1110			}
1111
1112
1113			// Donations
1114			if (!empty($conf->don->enabled)) {
1115				$langs->load("donations");
1116				$newmenu->add("/don/index.php?leftmenu=donations&amp;mainmenu=billing", $langs->trans("Donations"), 0, $user->rights->don->lire, '', $mainmenu, 'donations', 0, '', '', '', img_picto('', 'donation', 'class="paddingright pictofixedwidth"'));
1117				if ($usemenuhider || empty($leftmenu) || $leftmenu == "donations") {
1118					$newmenu->add("/don/card.php?leftmenu=donations&amp;action=create", $langs->trans("NewDonation"), 1, $user->rights->don->creer);
1119					$newmenu->add("/don/list.php?leftmenu=donations", $langs->trans("List"), 1, $user->rights->don->lire);
1120				}
1121				// if ($leftmenu=="donations") $newmenu->add("/don/stats/index.php",$langs->trans("Statistics"), 1, $user->rights->don->lire);
1122			}
1123
1124			// Taxes and social contributions
1125			if (!empty($conf->tax->enabled)) {
1126				$newmenu->add("/compta/charges/index.php?leftmenu=tax&amp;mainmenu=billing", $langs->trans("MenuTaxesAndSpecialExpenses"), 0, $user->rights->tax->charges->lire, '', $mainmenu, 'tax', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1127
1128				$newmenu->add("/compta/sociales/list.php?leftmenu=tax_social", $langs->trans("MenuSocialContributions"), 1, $user->rights->tax->charges->lire);
1129				if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_social/i', $leftmenu)) {
1130					$newmenu->add("/compta/sociales/card.php?leftmenu=tax_social&action=create", $langs->trans("MenuNewSocialContribution"), 2, $user->rights->tax->charges->creer);
1131					$newmenu->add("/compta/sociales/list.php?leftmenu=tax_social", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1132					$newmenu->add("/compta/sociales/payments.php?leftmenu=tax_social&amp;mainmenu=billing", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
1133				}
1134				// VAT
1135				if (empty($conf->global->TAX_DISABLE_VAT_MENUS)) {
1136					global $mysoc;
1137
1138					$newmenu->add("/compta/tva/list.php?leftmenu=tax_vat&amp;mainmenu=billing", $langs->transcountry("VAT", $mysoc->country_code), 1, $user->rights->tax->charges->lire, '', $mainmenu, 'tax_vat');
1139					if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
1140						$newmenu->add("/compta/tva/card.php?leftmenu=tax_vat&action=create", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1141						$newmenu->add("/compta/tva/list.php?leftmenu=tax_vat", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1142						$newmenu->add("/compta/tva/payments.php?mode=tvaonly&amp;leftmenu=tax_vat", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
1143						$newmenu->add("/compta/tva/index.php?leftmenu=tax_vat", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1144						$newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByThirdparties"), 2, $user->rights->tax->charges->lire);
1145						$newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1146					}
1147
1148					//Local Taxes 1
1149					if ($mysoc->useLocalTax(1) && (isset($mysoc->localtax1_assuj) && $mysoc->localtax1_assuj == "1")) {
1150						$newmenu->add("/compta/localtax/list.php?leftmenu=tax_1_vat&amp;mainmenu=billing&amp;localTaxType=1", $langs->transcountry("LT1", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
1151						if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_1_vat/i', $leftmenu)) {
1152							$newmenu->add("/compta/localtax/card.php?leftmenu=tax_1_vat&action=create&amp;localTaxType=1", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1153							$newmenu->add("/compta/localtax/list.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1154							$newmenu->add("/compta/localtax/index.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1155							$newmenu->add("/compta/localtax/clients.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByThirdparties"), 2, $user->rights->tax->charges->lire);
1156							$newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1157						}
1158					}
1159					//Local Taxes 2
1160					if ($mysoc->useLocalTax(2) && (isset($mysoc->localtax2_assuj) && $mysoc->localtax2_assuj == "1")) {
1161						$newmenu->add("/compta/localtax/list.php?leftmenu=tax_2_vat&amp;mainmenu=billing&amp;localTaxType=2", $langs->transcountry("LT2", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
1162						if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_2_vat/i', $leftmenu)) {
1163							$newmenu->add("/compta/localtax/card.php?leftmenu=tax_2_vat&action=create&amp;localTaxType=2", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1164							$newmenu->add("/compta/localtax/list.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1165							$newmenu->add("/compta/localtax/index.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1166							$newmenu->add("/compta/localtax/clients.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByThirdparties"), 2, $user->rights->tax->charges->lire);
1167							$newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1168						}
1169					}
1170				}
1171			}
1172
1173			// Salaries
1174			if (!empty($conf->salaries->enabled)) {
1175				$langs->load("salaries");
1176				$newmenu->add("/salaries/list.php?leftmenu=tax_salary&amp;mainmenu=billing", $langs->trans("Salaries"), 0, $user->rights->salaries->read, '', $mainmenu, 'tax_salary', 0, '', '', '', img_picto('', 'salary', 'class="paddingright pictofixedwidth"'));
1177				if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_salary/i', $leftmenu)) {
1178					$newmenu->add("/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("New"), 1, $user->rights->salaries->write);
1179					$newmenu->add("/salaries/list.php?leftmenu=tax_salary", $langs->trans("List"), 1, $user->rights->salaries->read);
1180					$newmenu->add("/salaries/payments.php?leftmenu=tax_salary", $langs->trans("Payments"), 1, $user->rights->salaries->read);
1181					$newmenu->add("/salaries/stats/index.php?leftmenu=tax_salary", $langs->trans("Statistics"), 1, $user->rights->salaries->read);
1182				}
1183			}
1184
1185			// Loan
1186			if (!empty($conf->loan->enabled)) {
1187				$langs->load("loan");
1188				$newmenu->add("/loan/list.php?leftmenu=tax_loan&amp;mainmenu=billing", $langs->trans("Loans"), 0, $user->rights->loan->read, '', $mainmenu, 'tax_loan', 0, '', '', '', img_picto('', 'loan', 'class="paddingright pictofixedwidth"'));
1189				if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_loan/i', $leftmenu)) {
1190					$newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create", $langs->trans("NewLoan"), 1, $user->rights->loan->write);
1191					//$newmenu->add("/loan/payment/list.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read);
1192				}
1193			}
1194
1195			// Various payment
1196			if (!empty($conf->banque->enabled) && empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) {
1197				$langs->load("banks");
1198				$newmenu->add("/compta/bank/various_payment/list.php?leftmenu=tax_various&amp;mainmenu=billing", $langs->trans("MenuVariousPayment"), 0, $user->rights->banque->lire, '', $mainmenu, 'tax_various', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1199				if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_various/i', $leftmenu)) {
1200					$newmenu->add("/compta/bank/various_payment/card.php?leftmenu=tax_various&action=create", $langs->trans("New"), 1, $user->rights->banque->modifier);
1201					$newmenu->add("/compta/bank/various_payment/list.php?leftmenu=tax_various", $langs->trans("List"), 1, $user->rights->banque->lire);
1202				}
1203			}
1204		}
1205
1206		/*
1207		 * Menu COMPTA-FINANCIAL
1208		 */
1209		if ($mainmenu == 'accountancy') {
1210			$langs->load("companies");
1211
1212			// Accounting (Double entries)
1213			if (!empty($conf->accounting->enabled)) {
1214				//$permtoshowmenu = (!empty($conf->accounting->enabled) || $user->rights->accounting->bind->write || $user->rights->compta->resultat->lire);
1215				//$newmenu->add("/accountancy/index.php?leftmenu=accountancy", $langs->trans("MenuAccountancy"), 0, $permtoshowmenu, '', $mainmenu, 'accountancy');
1216
1217				// Configuration
1218				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_admin", $langs->trans("Setup"), 0, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin', 1, '', '', '', img_picto('', 'technic', 'class="paddingright pictofixedwidth"'));
1219				if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/', $leftmenu)) {
1220					$newmenu->add("/accountancy/admin/index.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("General"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_general', 10);
1221
1222					// Fiscal year - Not really yet used. In a future will lock some periods.
1223					if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
1224						$newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("FiscalPeriod"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'fiscalyear', 20);
1225					}
1226
1227					$newmenu->add("/accountancy/admin/journals_list.php?id=35&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("AccountingJournals"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_journal', 30);
1228					$newmenu->add("/accountancy/admin/accountmodel.php?id=31&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("Pcg_version"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chartmodel', 40);
1229					$newmenu->add("/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("Chartofaccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 41);
1230					$newmenu->add("/accountancy/admin/subaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("ChartOfSubaccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 41);
1231					$newmenu->add("/accountancy/admin/categories_list.php?id=32&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("AccountingCategory"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 50);
1232					$newmenu->add("/accountancy/admin/defaultaccounts.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuDefaultAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 60);
1233					if (!empty($conf->banque->enabled)) {
1234						$newmenu->add("/compta/bank/list.php?mainmenu=accountancy&leftmenu=accountancy_admin&search_status=-1", $langs->trans("MenuBankAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_bank', 70);
1235					}
1236					if (!empty($conf->facture->enabled) || ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled))) {
1237						$newmenu->add("/admin/dict.php?id=10&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuVatAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 80);
1238					}
1239					if (!empty($conf->tax->enabled)) {
1240						$newmenu->add("/admin/dict.php?id=7&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuTaxAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 90);
1241					}
1242					if (!empty($conf->expensereport->enabled)) {
1243						$newmenu->add("/admin/dict.php?id=17&from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuExpenseReportAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 100);
1244					}
1245					$newmenu->add("/accountancy/admin/productaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuProductsAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_product', 110);
1246					if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
1247						$newmenu->add("/accountancy/admin/closure.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuClosureAccounts"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_closure', 120);
1248					}
1249					$newmenu->add("/accountancy/admin/export.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("ExportOptions"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_export', 130);
1250				}
1251
1252				// Transfer in accounting
1253				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_transfer", $langs->trans("TransferInAccounting"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'transfer', 1, '', '', '', img_picto('', 'long-arrow-alt-right', 'class="paddingright pictofixedwidth"'));
1254
1255				// Binding
1256				// $newmenu->add("", $langs->trans("Binding"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch');
1257				if (!empty($conf->facture->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) {
1258					$newmenu->add("/accountancy/customer/index.php?leftmenu=accountancy_dispatch_customer&amp;mainmenu=accountancy", $langs->trans("CustomersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_customer');
1259					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_customer/', $leftmenu)) {
1260						$newmenu->add("/accountancy/customer/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1261						$newmenu->add("/accountancy/customer/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1262					}
1263				}
1264				if (!empty($conf->supplier_invoice->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES)) {
1265					$newmenu->add("/accountancy/supplier/index.php?leftmenu=accountancy_dispatch_supplier&amp;mainmenu=accountancy", $langs->trans("SuppliersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_supplier');
1266					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_supplier/', $leftmenu)) {
1267						$newmenu->add("/accountancy/supplier/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1268						$newmenu->add("/accountancy/supplier/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1269					}
1270				}
1271				if (!empty($conf->expensereport->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) {
1272					$newmenu->add("/accountancy/expensereport/index.php?leftmenu=accountancy_dispatch_expensereport&amp;mainmenu=accountancy", $langs->trans("ExpenseReportsVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_expensereport');
1273					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_expensereport/', $leftmenu)) {
1274						$newmenu->add("/accountancy/expensereport/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1275						$newmenu->add("/accountancy/expensereport/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1276					}
1277				}
1278
1279				// Journals
1280				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') {
1281					$newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->rights->accounting->comptarapport->lire, '', '', '');
1282
1283					// Multi journal
1284					$sql = "SELECT rowid, code, label, nature";
1285					$sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
1286					$sql .= " WHERE entity = ".$conf->entity;
1287					$sql .= " AND active = 1";
1288					$sql .= " ORDER BY nature ASC, label DESC";
1289
1290					$resql = $db->query($sql);
1291					if ($resql) {
1292						$numr = $db->num_rows($resql);
1293						$i = 0;
1294
1295						if ($numr > 0) {
1296							while ($i < $numr) {
1297								$objp = $db->fetch_object($resql);
1298
1299								$nature = '';
1300
1301								// Must match array $sourceList defined into journals_list.php
1302								if ($objp->nature == 2 && !empty($conf->facture->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) {
1303									$nature = "sells";
1304								}
1305								if ($objp->nature == 3
1306									&& ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled))
1307									&& empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES)) {
1308									$nature = "purchases";
1309								}
1310								if ($objp->nature == 4 && !empty($conf->banque->enabled)) {
1311									$nature = "bank";
1312								}
1313								if ($objp->nature == 5 && !empty($conf->expensereport->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) {
1314									$nature = "expensereports";
1315								}
1316								if ($objp->nature == 1) {
1317									$nature = "various";
1318								}
1319								if ($objp->nature == 8) {
1320									$nature = "inventory";
1321								}
1322								if ($objp->nature == 9) {
1323									$nature = "hasnew";
1324								}
1325
1326								// To enable when page exists
1327								if (empty($conf->global->ACCOUNTANCY_SHOW_DEVELOP_JOURNAL)) {
1328									if ($nature == 'various' || $nature == 'hasnew' || $nature == 'inventory') {
1329										$nature = '';
1330									}
1331								}
1332
1333								if ($nature) {
1334									$langs->load('accountancy');
1335									$journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ...
1336									$newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->rights->accounting->comptarapport->lire);
1337								}
1338								$i++;
1339							}
1340						} else {
1341							// Should not happend. Entries are added
1342							$newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->rights->accounting->comptarapport->lire);
1343						}
1344					} else {
1345						dol_print_error($db);
1346					}
1347					$db->free($resql);
1348				}
1349
1350				// Accounting
1351				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_accountancy", $langs->trans("MenuAccountancy"), 0, $user->rights->accounting->mouvements->lire || $user->rights->accounting->comptarapport->lire, '', $mainmenu, 'accountancy', 1, '', '', '', img_picto('', 'accountancy', 'class="paddingright pictofixedwidth"'));
1352
1353				// General Ledger
1354				$newmenu->add("/accountancy/bookkeeping/listbyaccount.php?mainmenu=accountancy&amp;leftmenu=accountancy_accountancy", $langs->trans("Bookkeeping"), 1, $user->rights->accounting->mouvements->lire);
1355
1356				// Journals
1357				$newmenu->add("/accountancy/bookkeeping/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_accountancy", $langs->trans("Journals"), 1, $user->rights->accounting->mouvements->lire);
1358
1359				// Account Balance
1360				$newmenu->add("/accountancy/bookkeeping/balance.php?mainmenu=accountancy&amp;leftmenu=accountancy_accountancy", $langs->trans("AccountBalance"), 1, $user->rights->accounting->mouvements->lire);
1361
1362				// Files
1363				if (empty($conf->global->ACCOUNTANCY_HIDE_EXPORT_FILES_MENU)) {
1364					$newmenu->add("/compta/accounting-files.php?mainmenu=accountancy&amp;leftmenu=accountancy_files", $langs->trans("AccountantFiles"), 1, $user->rights->accounting->mouvements->lire);
1365				}
1366
1367				// Closure
1368				$newmenu->add("/accountancy/closure/index.php?mainmenu=accountancy&amp;leftmenu=accountancy_closure", $langs->trans("MenuAccountancyClosure"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'closure');
1369
1370				// Reports
1371				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_report", $langs->trans("Reportings"), 1, $user->rights->accounting->comptarapport->lire, '', $mainmenu, 'ca');
1372
1373				if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1374					$newmenu->add("/compta/resultat/index.php?leftmenu=accountancy_report", $langs->trans("MenuReportInOut"), 2, $user->rights->accounting->comptarapport->lire);
1375					$newmenu->add("/compta/resultat/clientfourn.php?leftmenu=accountancy_report", $langs->trans("ByPredefinedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1376					$newmenu->add("/compta/resultat/result.php?leftmenu=accountancy_report", $langs->trans("ByPersonalizedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1377				}
1378
1379				$modecompta = 'CREANCES-DETTES';
1380				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') {
1381					$modecompta = 'BOOKKEEPING'; // Not yet implemented. Should be BOOKKEEPINGCOLLECTED
1382				}
1383				if ($modecompta) {
1384					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1385						$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnover"), 2, $user->rights->accounting->comptarapport->lire);
1386						$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1387						$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1388						$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 3, $user->rights->accounting->comptarapport->lire);
1389						$newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"), 3, $user->rights->accounting->comptarapport->lire);
1390					}
1391				}
1392
1393				$modecompta = 'RECETTES-DEPENSES';
1394				//if (! empty($conf->accounting->enabled) && ! empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') $modecompta='';	// Not yet implemented. Should be BOOKKEEPINGCOLLECTED
1395				if ($modecompta) {
1396					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1397						$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnoverCollected"), 2, $user->rights->accounting->comptarapport->lire);
1398						$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1399						$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1400						//$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"),3,$user->rights->accounting->comptarapport->lire);
1401						//$newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"),3,$user->rights->accounting->comptarapport->lire);
1402					}
1403				}
1404
1405				$modecompta = 'CREANCES-DETTES';
1406				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') {
1407					$modecompta = 'BOOKKEEPING'; // Not yet implemented.
1408				}
1409				if ($modecompta && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled))) {
1410					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1411						$newmenu->add("/compta/stats/supplier_turnover.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportPurchaseTurnover"), 2, $user->rights->accounting->comptarapport->lire);
1412						$newmenu->add("/compta/stats/supplier_turnover_by_thirdparty.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1413						$newmenu->add("/compta/stats/supplier_turnover_by_prodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 3, $user->rights->accounting->comptarapport->lire);
1414					}
1415				}
1416
1417				$modecompta = 'RECETTES-DEPENSES';
1418				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') {
1419					$modecompta = 'BOOKKEEPINGCOLLECTED'; // Not yet implemented.
1420				}
1421				if ($modecompta && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled))) {
1422					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1423						$newmenu->add("/compta/stats/supplier_turnover.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportPurchaseTurnoverCollected"), 2, $user->rights->accounting->comptarapport->lire);
1424						$newmenu->add("/compta/stats/supplier_turnover_by_thirdparty.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1425					}
1426				}
1427			}
1428
1429			// Accountancy (simple)
1430			if (!empty($conf->comptabilite->enabled)) {
1431				// Files
1432				if (empty($conf->global->ACCOUNTANCY_HIDE_EXPORT_FILES_MENU)) {
1433					$newmenu->add("/compta/accounting-files.php?mainmenu=accountancy&amp;leftmenu=accountancy_files", $langs->trans("AccountantFiles"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'files');
1434				}
1435
1436				// Bilan, resultats
1437				$newmenu->add("/compta/resultat/index.php?leftmenu=report&amp;mainmenu=accountancy", $langs->trans("Reportings"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'ca');
1438
1439				if ($usemenuhider || empty($leftmenu) || preg_match('/report/', $leftmenu)) {
1440					$newmenu->add("/compta/resultat/index.php?leftmenu=report", $langs->trans("MenuReportInOut"), 1, $user->rights->compta->resultat->lire);
1441					$newmenu->add("/compta/resultat/clientfourn.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1442					/* On verra ca avec module compabilite expert
1443					$newmenu->add("/compta/resultat/compteres.php?leftmenu=report","Compte de resultat",2,$user->rights->compta->resultat->lire);
1444					$newmenu->add("/compta/resultat/bilan.php?leftmenu=report","Bilan",2,$user->rights->compta->resultat->lire);
1445					*/
1446
1447					/*
1448					$newmenu->add("/compta/stats/cumul.php?leftmenu=report","Cumule",2,$user->rights->compta->resultat->lire);
1449					if (! empty($conf->propal->enabled)) {
1450						$newmenu->add("/compta/stats/prev.php?leftmenu=report","Previsionnel",2,$user->rights->compta->resultat->lire);
1451						$newmenu->add("/compta/stats/comp.php?leftmenu=report","Transforme",2,$user->rights->compta->resultat->lire);
1452					}
1453					*/
1454
1455					$modecompta = 'CREANCES-DETTES';
1456					$newmenu->add("/compta/stats/index.php?leftmenu=report&modecompta=".$modecompta, $langs->trans("ReportTurnover"), 1, $user->rights->compta->resultat->lire);
1457					$newmenu->add("/compta/stats/casoc.php?leftmenu=report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1458					$newmenu->add("/compta/stats/cabyuser.php?leftmenu=report&modecompta=".$modecompta, $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire);
1459					$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire);
1460					$newmenu->add("/compta/stats/byratecountry.php?leftmenu=report&modecompta=".$modecompta, $langs->trans("ByVatRate"), 2, $user->rights->compta->resultat->lire);
1461
1462					$modecompta = 'RECETTES-DEPENSES';
1463					$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnoverCollected"), 1, $user->rights->compta->resultat->lire);
1464					$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1465					$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire);
1466
1467					//Achats
1468					$modecompta = 'CREANCES-DETTES';
1469					$newmenu->add("/compta/stats/supplier_turnover.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportPurchaseTurnover"), 1, $user->rights->compta->resultat->lire);
1470					$newmenu->add("/compta/stats/supplier_turnover_by_thirdparty.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1471					$newmenu->add("/compta/stats/supplier_turnover_by_prodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire);
1472
1473					/*
1474					$modecompta = 'RECETTES-DEPENSES';
1475					$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportPurchaseTurnoverCollected"), 1, $user->rights->compta->resultat->lire);
1476					$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1477					$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire);
1478					*/
1479
1480					// Journals
1481					$newmenu->add("/compta/journal/sellsjournal.php?leftmenu=report", $langs->trans("SellsJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 50);
1482					$newmenu->add("/compta/journal/purchasesjournal.php?leftmenu=report", $langs->trans("PurchasesJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 51);
1483				}
1484				//if ($leftmenu=="ca") $newmenu->add("/compta/journaux/index.php?leftmenu=ca",$langs->trans("Journals"),1,$user->rights->compta->resultat->lire||$user->rights->accounting->comptarapport->lire);
1485			}
1486
1487			// Intracomm report
1488			if (!empty($conf->intracommreport->enabled)) {
1489				$newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuIntracommReport"), 0, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1);
1490				if ($usemenuhider || empty($leftmenu) || preg_match('/intracommreport/', $leftmenu)) {
1491					// DEB / DES
1492					$newmenu->add("/intracommreport/card.php?action=create&leftmenu=intracommreport", $langs->trans("MenuIntracommReportNew"), 1, $user->rights->intracommreport->write, '', $mainmenu, 'intracommreport', 1);
1493					$newmenu->add("/intracommreport/list.php?leftmenu=intracommreport", $langs->trans("MenuIntracommReportList"), 1, $user->rights->intracommreport->read, '', $mainmenu, 'intracommreport', 1);
1494				}
1495			}
1496
1497			// Assets
1498			if (!empty($conf->asset->enabled)) {
1499				$newmenu->add("/asset/list.php?leftmenu=asset&amp;mainmenu=accountancy", $langs->trans("MenuAssets"), 0, $user->rights->asset->read, '', $mainmenu, 'asset', 100, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1500				$newmenu->add("/asset/card.php?leftmenu=asset&amp;action=create", $langs->trans("MenuNewAsset"), 1, $user->rights->asset->write);
1501				$newmenu->add("/asset/list.php?leftmenu=asset&amp;mainmenu=accountancy", $langs->trans("MenuListAssets"), 1, $user->rights->asset->read);
1502				$newmenu->add("/asset/type.php?leftmenu=asset_type", $langs->trans("MenuTypeAssets"), 1, $user->rights->asset->read, '', $mainmenu, 'asset_type');
1503				if ($usemenuhider || empty($leftmenu) || preg_match('/asset_type/', $leftmenu)) {
1504					$newmenu->add("/asset/type.php?leftmenu=asset_type&amp;action=create", $langs->trans("MenuNewTypeAssets"), 2, $user->rights->asset->setup_advance);
1505					$newmenu->add("/asset/type.php?leftmenu=asset_type", $langs->trans("MenuListTypeAssets"), 2, $user->rights->asset->read);
1506				}
1507			}
1508		}
1509
1510
1511		/*
1512		 * Menu BANK
1513		 */
1514		if ($mainmenu == 'bank') {
1515			// Load translation files required by the page
1516			$langs->loadLangs(array("withdrawals", "banks", "bills", "categories"));
1517
1518			// Bank-Cash account
1519			if (!empty($conf->banque->enabled)) {
1520				$newmenu->add("/compta/bank/list.php?leftmenu=bank&amp;mainmenu=bank", $langs->trans("MenuBankCash"), 0, $user->rights->banque->lire, '', $mainmenu, 'bank', 0, '', '', '', img_picto('', 'bank_account', 'class="paddingright pictofixedwidth"'));
1521
1522				$newmenu->add("/compta/bank/card.php?action=create", $langs->trans("MenuNewFinancialAccount"), 1, $user->rights->banque->configurer);
1523				$newmenu->add("/compta/bank/list.php?leftmenu=bank&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->lire, '', $mainmenu, 'bank');
1524				$newmenu->add("/compta/bank/bankentries_list.php", $langs->trans("ListTransactions"), 1, $user->rights->banque->lire);
1525				$newmenu->add("/compta/bank/budget.php", $langs->trans("ListTransactionsByCategory"), 1, $user->rights->banque->lire);
1526
1527				$newmenu->add("/compta/bank/transfer.php", $langs->trans("MenuBankInternalTransfer"), 1, $user->rights->banque->transfer);
1528			}
1529
1530			if (!empty($conf->categorie->enabled)) {
1531				$langs->load("categories");
1532				$newmenu->add("/categories/index.php?type=5", $langs->trans("Rubriques"), 1, $user->rights->categorie->creer, '', $mainmenu, 'tags');
1533				$newmenu->add("/compta/bank/categ.php", $langs->trans("RubriquesTransactions"), 1, $user->rights->banque->configurer, '', $mainmenu, 'tags');
1534			}
1535
1536			// Direct debit order
1537			if (!empty($conf->prelevement->enabled)) {
1538				$newmenu->add("/compta/prelevement/index.php?leftmenu=withdraw&amp;mainmenu=bank", $langs->trans("PaymentByDirectDebit"), 0, $user->rights->prelevement->bons->lire, '', $mainmenu, 'withdraw', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1539
1540				if ($usemenuhider || empty($leftmenu) || $leftmenu == "withdraw") {
1541					$newmenu->add("/compta/prelevement/create.php?mainmenu=bank", $langs->trans("NewStandingOrder"), 1, $user->rights->prelevement->bons->creer);
1542
1543					$newmenu->add("/compta/prelevement/orders_list.php?mainmenu=bank", $langs->trans("WithdrawalsReceipts"), 1, $user->rights->prelevement->bons->lire);
1544					$newmenu->add("/compta/prelevement/list.php?mainmenu=bank", $langs->trans("WithdrawalsLines"), 1, $user->rights->prelevement->bons->lire);
1545					$newmenu->add("/compta/prelevement/rejets.php?mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->prelevement->bons->lire);
1546					$newmenu->add("/compta/prelevement/stats.php?mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->prelevement->bons->lire);
1547				}
1548			}
1549
1550			// Bank transfer order
1551			if (!empty($conf->paymentbybanktransfer->enabled)) {
1552				$newmenu->add("/compta/paymentbybanktransfer/index.php?leftmenu=banktransfer&amp;mainmenu=bank", $langs->trans("PaymentByBankTransfer"), 0, $user->rights->paymentbybanktransfer->read, '', $mainmenu, 'banktransfer', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1553
1554				if ($usemenuhider || empty($leftmenu) || $leftmenu == "banktransfer") {
1555					$newmenu->add("/compta/prelevement/create.php?type=bank-transfer&mainmenu=bank", $langs->trans("NewPaymentByBankTransfer"), 1, $user->rights->paymentbybanktransfer->create);
1556
1557					$newmenu->add("/compta/prelevement/orders_list.php?type=bank-transfer&mainmenu=bank", $langs->trans("PaymentByBankTransferReceipts"), 1, $user->rights->paymentbybanktransfer->read);
1558					$newmenu->add("/compta/prelevement/list.php?type=bank-transfer&mainmenu=bank", $langs->trans("PaymentByBankTransferLines"), 1, $user->rights->paymentbybanktransfer->read);
1559					$newmenu->add("/compta/prelevement/rejets.php?type=bank-transfer&mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->paymentbybanktransfer->read);
1560					$newmenu->add("/compta/prelevement/stats.php?type=bank-transfer&mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->paymentbybanktransfer->read);
1561				}
1562			}
1563
1564			// Management of checks
1565			if (empty($conf->global->BANK_DISABLE_CHECK_DEPOSIT) && !empty($conf->banque->enabled) && (!empty($conf->facture->enabled) || !empty($conf->global->MAIN_MENU_CHEQUE_DEPOSIT_ON))) {
1566				$newmenu->add("/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("MenuChequeDeposits"), 0, $user->rights->banque->cheque, '', $mainmenu, 'checks', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1567				if (preg_match('/checks/', $leftmenu)) {
1568					$newmenu->add("/compta/paiement/cheque/card.php?leftmenu=checks_bis&amp;action=new&amp;mainmenu=bank", $langs->trans("NewChequeDeposit"), 1, $user->rights->banque->cheque);
1569					$newmenu->add("/compta/paiement/cheque/list.php?leftmenu=checks_bis&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->cheque);
1570				}
1571			}
1572
1573			// Cash Control
1574			if (!empty($conf->takepos->enabled) || !empty($conf->cashdesk->enabled)) {
1575				$permtomakecashfence = ($user->rights->cashdesk->run || $user->rights->takepos->run);
1576				$newmenu->add("/compta/cashcontrol/cashcontrol_list.php?action=list", $langs->trans("POS"), 0, $permtomakecashfence, '', $mainmenu, 'cashcontrol', 0, '', '', '', img_picto('', 'pos', 'class="pictofixedwidth"'));
1577				$newmenu->add("/compta/cashcontrol/cashcontrol_card.php?action=create", $langs->trans("NewCashFence"), 1, $permtomakecashfence);
1578				$newmenu->add("/compta/cashcontrol/cashcontrol_list.php?action=list", $langs->trans("List"), 1, $permtomakecashfence);
1579			}
1580		}
1581
1582		/*
1583		 * Menu PRODUCTS-SERVICES
1584		 */
1585		if ($mainmenu == 'products') {
1586			// Products
1587			if (!empty($conf->product->enabled)) {
1588				$newmenu->add("/product/index.php?leftmenu=product&amp;type=0", $langs->trans("Products"), 0, $user->rights->produit->lire, '', $mainmenu, 'product', 0, '', '', '', img_picto('', 'product', 'class="pictofixedwidth"'));
1589				$newmenu->add("/product/card.php?leftmenu=product&amp;action=create&amp;type=0", $langs->trans("NewProduct"), 1, $user->rights->produit->creer);
1590				$newmenu->add("/product/list.php?leftmenu=product&amp;type=0", $langs->trans("List"), 1, $user->rights->produit->lire);
1591				if (!empty($conf->stock->enabled)) {
1592					$newmenu->add("/product/reassort.php?type=0", $langs->trans("MenuStocks"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
1593				}
1594				if (!empty($conf->productbatch->enabled)) {
1595					$langs->load("stocks");
1596					$newmenu->add("/product/reassortlot.php?type=0", $langs->trans("StocksByLotSerial"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
1597					$newmenu->add("/product/stock/productlot_list.php", $langs->trans("LotSerial"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
1598				}
1599				if (!empty($conf->variants->enabled)) {
1600					$newmenu->add("/variants/list.php", $langs->trans("VariantAttributes"), 1, $user->rights->produit->lire);
1601				}
1602				if (!empty($conf->propal->enabled) || (!empty($conf->commande->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->facture->enabled) || !empty($conf->fournisseur->enabled) || !empty($conf->supplier_proposal->enabled) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
1603					$newmenu->add("/product/stats/card.php?id=all&leftmenu=stats&type=0", $langs->trans("Statistics"), 1, $user->rights->produit->lire && $user->rights->propale->lire);
1604				}
1605
1606				// Categories
1607				if (!empty($conf->categorie->enabled)) {
1608					$langs->load("categories");
1609					$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=0", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1610					//if ($usemenuhider || empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
1611				}
1612			}
1613
1614			// Services
1615			if (!empty($conf->service->enabled)) {
1616				$newmenu->add("/product/index.php?leftmenu=service&amp;type=1", $langs->trans("Services"), 0, $user->rights->service->lire, '', $mainmenu, 'service', 0, '', '', '', img_picto('', 'service', 'class="pictofixedwidth"'));
1617				$newmenu->add("/product/card.php?leftmenu=service&amp;action=create&amp;type=1", $langs->trans("NewService"), 1, $user->rights->service->creer);
1618				$newmenu->add("/product/list.php?leftmenu=service&amp;type=1", $langs->trans("List"), 1, $user->rights->service->lire);
1619				if (!empty($conf->propal->enabled) || !empty($conf->commande->enabled) || !empty($conf->facture->enabled) || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_proposal->enabled) || !empty($conf->supplier_oder->enabled) || !empty($conf->supplier_invoice->enabled)) {
1620					$newmenu->add("/product/stats/card.php?id=all&leftmenu=stats&type=1", $langs->trans("Statistics"), 1, $user->rights->service->lire && $user->rights->propale->lire);
1621				}
1622				// Categories
1623				if (!empty($conf->categorie->enabled)) {
1624					$langs->load("categories");
1625					$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=0", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1626					//if ($usemenuhider || empty($leftmenu) || $leftmenu=="cat") $newmenu->add("/categories/list.php", $langs->trans("List"), 1, $user->rights->categorie->lire);
1627				}
1628			}
1629
1630			// Warehouse
1631			if (!empty($conf->stock->enabled)) {
1632				$langs->load("stocks");
1633				$newmenu->add("/product/stock/index.php?leftmenu=stock", $langs->trans("Warehouses"), 0, $user->rights->stock->lire, '', $mainmenu, 'stock', 0, '', '', '', img_picto('', 'stock', 'class="pictofixedwidth"'));
1634				$newmenu->add("/product/stock/card.php?action=create", $langs->trans("MenuNewWarehouse"), 1, $user->rights->stock->creer);
1635				$newmenu->add("/product/stock/list.php", $langs->trans("List"), 1, $user->rights->stock->lire);
1636				$newmenu->add("/product/stock/movement_list.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
1637
1638				$newmenu->add("/product/stock/massstockmove.php", $langs->trans("MassStockTransferShort"), 1, $user->rights->stock->mouvement->creer);
1639				if ($conf->supplier_order->enabled) {
1640					$newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire);
1641				}
1642				$newmenu->add("/product/stock/stockatdate.php", $langs->trans("StockAtDate"), 1, $user->rights->produit->lire && $user->rights->stock->lire);
1643
1644				// Categories for warehouses
1645				if (!empty($conf->categorie->enabled)) {
1646					$newmenu->add("/categories/index.php?leftmenu=stock&amp;type=9", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1647				}
1648			}
1649
1650			// Inventory
1651			if (!empty($conf->stock->enabled)) {
1652				$langs->load("stocks");
1653				if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1654					$newmenu->add("/product/inventory/list.php?leftmenu=stock_inventories", $langs->trans("Inventories"), 0, $user->rights->stock->lire, '', $mainmenu, 'stock', 0, '', '', '', img_picto('', 'inventory', 'class="pictofixedwidth"'));
1655					if ($usemenuhider || empty($leftmenu) || $leftmenu == "stock_inventories") {
1656						$newmenu->add("/product/inventory/card.php?action=create&leftmenu=stock_inventories", $langs->trans("NewInventory"), 1, $user->rights->stock->creer);
1657						$newmenu->add("/product/inventory/list.php?leftmenu=stock_inventories", $langs->trans("List"), 1, $user->rights->stock->lire);
1658					}
1659				} else {
1660					$newmenu->add("/product/inventory/list.php?leftmenu=stock_inventories", $langs->trans("Inventories"), 0, $user->rights->stock->inventory_advance->read, '', $mainmenu, 'stock', 0, '', '', '', img_picto('', 'inventory', 'class="pictofixedwidth"'));
1661					if ($usemenuhider || empty($leftmenu) || $leftmenu == "stock_inventories") {
1662						$newmenu->add("/product/inventory/card.php?action=create&leftmenu=stock_inventories", $langs->trans("NewInventory"), 1, $user->rights->stock->inventory_advance->write);
1663						$newmenu->add("/product/inventory/list.php?leftmenu=stock_inventories", $langs->trans("List"), 1, $user->rights->stock->inventory_advance->read);
1664					}
1665				}
1666			}
1667
1668			// Shipments
1669			if (!empty($conf->expedition->enabled)) {
1670				$langs->load("sendings");
1671				$newmenu->add("/expedition/index.php?leftmenu=sendings", $langs->trans("Shipments"), 0, $user->rights->expedition->lire, '', $mainmenu, 'sendings', 0, '', '', '', img_picto('', 'shipment', 'class="pictofixedwidth"'));
1672				$newmenu->add("/expedition/card.php?action=create2&amp;leftmenu=sendings", $langs->trans("NewSending"), 1, $user->rights->expedition->creer);
1673				$newmenu->add("/expedition/list.php?leftmenu=sendings", $langs->trans("List"), 1, $user->rights->expedition->lire);
1674				if ($usemenuhider || empty($leftmenu) || $leftmenu == "sendings") {
1675					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=0", $langs->trans("StatusSendingDraftShort"), 2, $user->rights->expedition->lire);
1676					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=1", $langs->trans("StatusSendingValidatedShort"), 2, $user->rights->expedition->lire);
1677					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=2", $langs->trans("StatusSendingProcessedShort"), 2, $user->rights->expedition->lire);
1678				}
1679				$newmenu->add("/expedition/stats/index.php?leftmenu=sendings", $langs->trans("Statistics"), 1, $user->rights->expedition->lire);
1680			}
1681
1682			// Receptions
1683			if (!empty($conf->reception->enabled)) {
1684				$langs->load("receptions");
1685				$newmenu->add("/reception/index.php?leftmenu=receptions", $langs->trans("Receptions"), 0, $user->rights->reception->lire, '', $mainmenu, 'receptions', 0, '', '', '', img_picto('', 'dollyrevert', 'class="pictofixedwidth"'));
1686				$newmenu->add("/reception/card.php?action=create2&amp;leftmenu=receptions", $langs->trans("NewReception"), 1, $user->rights->reception->creer);
1687				$newmenu->add("/reception/list.php?leftmenu=receptions", $langs->trans("List"), 1, $user->rights->reception->lire);
1688				if ($usemenuhider || empty($leftmenu) || $leftmenu == "receptions") {
1689					$newmenu->add("/reception/list.php?leftmenu=receptions&search_status=0", $langs->trans("StatusReceptionDraftShort"), 2, $user->rights->reception->lire);
1690				}
1691				if ($usemenuhider || empty($leftmenu) || $leftmenu == "receptions") {
1692					$newmenu->add("/reception/list.php?leftmenu=receptions&search_status=1", $langs->trans("StatusReceptionValidatedShort"), 2, $user->rights->reception->lire);
1693				}
1694				if ($usemenuhider || empty($leftmenu) || $leftmenu == "receptions") {
1695					$newmenu->add("/reception/list.php?leftmenu=receptions&search_status=2", $langs->trans("StatusReceptionProcessedShort"), 2, $user->rights->reception->lire);
1696				}
1697				$newmenu->add("/reception/stats/index.php?leftmenu=receptions", $langs->trans("Statistics"), 1, $user->rights->reception->lire);
1698			}
1699		}
1700
1701		/*
1702		 * Menu PRODUCTS-SERVICES MRP - GPAO
1703		 */
1704		if ($mainmenu == 'mrp') {
1705			// BOM
1706			if (!empty($conf->bom->enabled) || !empty($conf->mrp->enabled)) {
1707				$langs->load("mrp");
1708
1709				$newmenu->add("", $langs->trans("MenuBOM"), 0, $user->rights->bom->read, '', $mainmenu, 'bom', 0, '', '', '', img_picto('', 'bom', 'class="paddingrightonly pictofixedwidth"'));
1710				$newmenu->add("/bom/bom_card.php?leftmenu=bom&amp;action=create", $langs->trans("NewBOM"), 1, $user->rights->bom->write, '', $mainmenu, 'bom');
1711				$newmenu->add("/bom/bom_list.php?leftmenu=bom", $langs->trans("List"), 1, $user->rights->bom->read, '', $mainmenu, 'bom');
1712			}
1713
1714			if (!empty($conf->mrp->enabled)) {
1715				$langs->load("mrp");
1716
1717				$newmenu->add("", $langs->trans("MenuMRP"), 0, $user->rights->mrp->read, '', $mainmenu, 'mo', 0, '', '', '', img_picto('', 'mrp', 'class="paddingrightonly pictofixedwidth"'));
1718				$newmenu->add("/mrp/mo_card.php?leftmenu=mo&amp;action=create", $langs->trans("NewMO"), 1, $user->rights->mrp->write, '', $mainmenu, 'mo');
1719				$newmenu->add("/mrp/mo_list.php?leftmenu=mo", $langs->trans("List"), 1, $user->rights->mrp->read, '', $mainmenu, 'mo');
1720			}
1721		}
1722
1723		/*
1724		 * Menu PROJECTS
1725		 */
1726		if ($mainmenu == 'project') {
1727			if (!empty($conf->projet->enabled)) {
1728				$langs->load("projects");
1729
1730				$search_project_user = GETPOST('search_project_user', 'int');
1731
1732				$tmpentry = array(
1733					'enabled'=>(!empty($conf->projet->enabled)),
1734					'perms'=>(!empty($user->rights->projet->lire)),
1735					'module'=>'projet'
1736				);
1737				$showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal);
1738
1739				$titleboth = $langs->trans("LeadsOrProjects");
1740				$titlenew = $langs->trans("NewLeadOrProject"); // Leads and opportunities by default
1741				if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
1742					$titleboth = $langs->trans("Projects");
1743					$titlenew = $langs->trans("NewProject");
1744				}
1745				if (isset($conf->global->PROJECT_USE_OPPORTUNITIES) && $conf->global->PROJECT_USE_OPPORTUNITIES == 2) {	// 2 = leads only
1746					$titleboth = $langs->trans("Leads");
1747					$titlenew = $langs->trans("NewLead");
1748				}
1749
1750				// Project assigned to user
1751				$newmenu->add("/projet/index.php?leftmenu=projects".($search_project_user ? '&search_project_user='.$search_project_user : ''), $titleboth, 0, $user->rights->projet->lire, '', $mainmenu, 'projects', 0, '', '', '', img_picto('', 'project', 'class="pictofixedwidth"'));
1752				$newmenu->add("/projet/card.php?leftmenu=projects&action=create".($search_project_user ? '&search_project_user='.$search_project_user : ''), $titlenew, 1, $user->rights->projet->creer);
1753
1754				if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
1755					$newmenu->add("/projet/list.php?leftmenu=projets".($search_project_user ? '&search_project_user='.$search_project_user : '').'&search_status=99', $langs->trans("List"), 1, $showmode, '', 'project', 'list');
1756				} elseif (isset($conf->global->PROJECT_USE_OPPORTUNITIES) && $conf->global->PROJECT_USE_OPPORTUNITIES == 1) {
1757					$newmenu->add("/projet/list.php?leftmenu=projets".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("List"), 1, $showmode, '', 'project', 'list');
1758					$newmenu->add('/projet/list.php?mainmenu=project&amp;leftmenu=list&search_usage_opportunity=1&search_status=99&search_opp_status=openedopp&contextpage=lead', $langs->trans("ListOpenLeads"), 2, $showmode);
1759					$newmenu->add('/projet/list.php?mainmenu=project&amp;leftmenu=list&search_opp_status=notopenedopp&search_status=99&contextpage=project', $langs->trans("ListOpenProjects"), 2, $showmode);
1760				} elseif (isset($conf->global->PROJECT_USE_OPPORTUNITIES) && $conf->global->PROJECT_USE_OPPORTUNITIES == 2) {	// 2 = leads only
1761					$newmenu->add('/projet/list.php?mainmenu=project&amp;leftmenu=list&search_usage_opportunity=1&search_status=99', $langs->trans("List"), 2, $showmode);
1762				}
1763
1764				$newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire);
1765
1766				// Categories
1767				if (!empty($conf->categorie->enabled)) {
1768					$langs->load("categories");
1769					$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=6", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1770				}
1771
1772				if (empty($conf->global->PROJECT_HIDE_TASKS)) {
1773					// Project affected to user
1774					$newmenu->add("/projet/activity/index.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("Activities"), 0, $user->rights->projet->lire, '', 'project', 'tasks', 0, '', '', '', img_picto('', 'projecttask', 'class="pictofixedwidth"'));
1775					$newmenu->add("/projet/tasks.php?leftmenu=tasks&action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
1776					$newmenu->add("/projet/tasks/list.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("List"), 1, $user->rights->projet->lire);
1777					$newmenu->add("/projet/tasks/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire);
1778
1779					$newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("NewTimeSpent"), 0, $user->rights->projet->lire, '', 'project', 'timespent', 0, '', '', '', img_picto('', 'timespent', 'class="pictofixedwidth"'));
1780				}
1781			}
1782		}
1783
1784		/*
1785		 * Menu HRM
1786		*/
1787		if ($mainmenu == 'hrm') {
1788			// HRM module
1789			if (!empty($conf->hrm->enabled)) {
1790				$langs->load("hrm");
1791
1792				$newmenu->add("/user/list.php?mainmenu=hrm&leftmenu=hrm&mode=employee", $langs->trans("Employees"), 0, $user->rights->user->user->lire, '', $mainmenu, 'hrm', 0, '', '', '', img_picto('', 'user', 'class="pictofixedwidth"'));
1793				$newmenu->add("/user/card.php?mainmenu=hrm&leftmenu=hrm&action=create&employee=1", $langs->trans("NewEmployee"), 1, $user->rights->user->user->creer);
1794				$newmenu->add("/user/list.php?mainmenu=hrm&leftmenu=hrm&mode=employee&contextpage=employeelist", $langs->trans("List"), 1, $user->rights->user->user->lire);
1795			}
1796
1797			// Leave/Holiday/Vacation module
1798			if (!empty($conf->holiday->enabled)) {
1799				// Load translation files required by the page
1800				$langs->loadLangs(array("holiday", "trips"));
1801
1802				$newmenu->add("/holiday/list.php?mainmenu=hrm&leftmenu=hrm", $langs->trans("CPTitreMenu"), 0, $user->rights->holiday->read, '', $mainmenu, 'hrm', 0, '', '', '', img_picto('', 'holiday', 'class="pictofixedwidth"'));
1803				$newmenu->add("/holiday/card.php?mainmenu=hrm&leftmenu=holiday&action=create", $langs->trans("New"), 1, $user->rights->holiday->write);
1804				$newmenu->add("/holiday/list.php?mainmenu=hrm&leftmenu=hrm", $langs->trans("List"), 1, $user->rights->holiday->read);
1805				if ($usemenuhider || empty($leftmenu) || $leftmenu == "hrm") {
1806					$newmenu->add("/holiday/list.php?search_status=1&mainmenu=hrm&leftmenu=hrm", $langs->trans("DraftCP"), 2, $user->rights->holiday->read);
1807					$newmenu->add("/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=hrm", $langs->trans("ToReviewCP"), 2, $user->rights->holiday->read);
1808					$newmenu->add("/holiday/list.php?search_status=3&mainmenu=hrm&leftmenu=hrm", $langs->trans("ApprovedCP"), 2, $user->rights->holiday->read);
1809					$newmenu->add("/holiday/list.php?search_status=4&mainmenu=hrm&leftmenu=hrm", $langs->trans("CancelCP"), 2, $user->rights->holiday->read);
1810					$newmenu->add("/holiday/list.php?search_status=5&mainmenu=hrm&leftmenu=hrm", $langs->trans("RefuseCP"), 2, $user->rights->holiday->read);
1811				}
1812				$newmenu->add("/holiday/define_holiday.php?mainmenu=hrm&action=request", $langs->trans("MenuConfCP"), 1, $user->rights->holiday->read);
1813				$newmenu->add("/holiday/month_report.php?mainmenu=hrm&leftmenu=holiday", $langs->trans("MenuReportMonth"), 1, $user->rights->holiday->readall);
1814				$newmenu->add("/holiday/view_log.php?mainmenu=hrm&leftmenu=holiday&action=request", $langs->trans("MenuLogCP"), 1, $user->rights->holiday->define_holiday);
1815			}
1816
1817			// Trips and expenses (old module)
1818			if (!empty($conf->deplacement->enabled)) {
1819				$langs->load("trips");
1820				$newmenu->add("/compta/deplacement/index.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("TripsAndExpenses"), 0, $user->rights->deplacement->lire, '', $mainmenu, 'tripsandexpenses', 0, '', '', '', img_picto('', 'trip', 'class="pictofixedwidth"'));
1821				$newmenu->add("/compta/deplacement/card.php?action=create&amp;leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("New"), 1, $user->rights->deplacement->creer);
1822				$newmenu->add("/compta/deplacement/list.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("List"), 1, $user->rights->deplacement->lire);
1823				$newmenu->add("/compta/deplacement/stats/index.php?leftmenu=tripsandexpenses&amp;mainmenu=hrm", $langs->trans("Statistics"), 1, $user->rights->deplacement->lire);
1824			}
1825
1826			// Expense report
1827			if (!empty($conf->expensereport->enabled)) {
1828				$langs->load("trips");
1829				$newmenu->add("/expensereport/index.php?leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("TripsAndExpenses"), 0, $user->rights->expensereport->lire, '', $mainmenu, 'expensereport', 0, '', '', '', img_picto('', 'trip', 'class="pictofixedwidth"'));
1830				$newmenu->add("/expensereport/card.php?action=create&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("New"), 1, $user->rights->expensereport->creer);
1831				$newmenu->add("/expensereport/list.php?leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("List"), 1, $user->rights->expensereport->lire);
1832				if ($usemenuhider || empty($leftmenu) || $leftmenu == "expensereport") {
1833					$newmenu->add("/expensereport/list.php?search_status=0&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Draft"), 2, $user->rights->expensereport->lire);
1834					$newmenu->add("/expensereport/list.php?search_status=2&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Validated"), 2, $user->rights->expensereport->lire);
1835					$newmenu->add("/expensereport/list.php?search_status=5&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Approved"), 2, $user->rights->expensereport->lire);
1836					$newmenu->add("/expensereport/list.php?search_status=6&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Paid"), 2, $user->rights->expensereport->lire);
1837					$newmenu->add("/expensereport/list.php?search_status=4&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Canceled"), 2, $user->rights->expensereport->lire);
1838					$newmenu->add("/expensereport/list.php?search_status=99&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Refused"), 2, $user->rights->expensereport->lire);
1839				}
1840				$newmenu->add("/expensereport/stats/index.php?leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Statistics"), 1, $user->rights->expensereport->lire);
1841			}
1842
1843			if (!empty($conf->projet->enabled)) {
1844				if (empty($conf->global->PROJECT_HIDE_TASKS)) {
1845					$langs->load("projects");
1846
1847					$search_project_user = GETPOST('search_project_user', 'int');
1848
1849					$newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("NewTimeSpent"), 0, $user->rights->projet->lire, '', $mainmenu, 'timespent', 0, '', '', '', img_picto('', 'timespent', 'class="pictofixedwidth"'));
1850				}
1851			}
1852		}
1853
1854
1855		/*
1856		 * Menu TOOLS
1857		 */
1858		if ($mainmenu == 'tools') {
1859			if (empty($user->socid)) { // limit to internal users
1860				$langs->load("mails");
1861				$newmenu->add("/admin/mails_templates.php?leftmenu=email_templates", $langs->trans("EMailTemplates"), 0, 1, '', $mainmenu, 'email_templates', 0, '', '', '', img_picto('', 'email', 'class="paddingright pictofixedwidth"'));
1862			}
1863
1864			if (!empty($conf->mailing->enabled)) {
1865				$newmenu->add("/comm/mailing/index.php?leftmenu=mailing", $langs->trans("EMailings"), 0, $user->rights->mailing->lire, '', $mainmenu, 'mailing', 0, '', '', '', img_picto('', 'email', 'class="paddingright pictofixedwidth"'));
1866				$newmenu->add("/comm/mailing/card.php?leftmenu=mailing&amp;action=create", $langs->trans("NewMailing"), 1, $user->rights->mailing->creer);
1867				$newmenu->add("/comm/mailing/list.php?leftmenu=mailing", $langs->trans("List"), 1, $user->rights->mailing->lire);
1868			}
1869
1870			if (!empty($conf->export->enabled)) {
1871				$langs->load("exports");
1872				$newmenu->add("/exports/index.php?leftmenu=export", $langs->trans("FormatedExport"), 0, $user->rights->export->lire, '', $mainmenu, 'export', 0, '', '', '', img_picto('', 'technic', 'class="paddingright pictofixedwidth"'));
1873				$newmenu->add("/exports/export.php?leftmenu=export", $langs->trans("NewExport"), 1, $user->rights->export->creer);
1874				//$newmenu->add("/exports/export.php?leftmenu=export",$langs->trans("List"),1, $user->rights->export->lire);
1875			}
1876
1877			if (!empty($conf->import->enabled)) {
1878				$langs->load("exports");
1879				$newmenu->add("/imports/index.php?leftmenu=import", $langs->trans("FormatedImport"), 0, $user->rights->import->run, '', $mainmenu, 'import', 0, '', '', '', img_picto('', 'technic', 'class="paddingright pictofixedwidth"'));
1880				$newmenu->add("/imports/import.php?leftmenu=import", $langs->trans("NewImport"), 1, $user->rights->import->run);
1881			}
1882		}
1883
1884		/*
1885		 * Menu MEMBERS
1886		 */
1887		if ($mainmenu == 'members') {
1888			if (!empty($conf->adherent->enabled)) {
1889				// Load translation files required by the page
1890				$langs->loadLangs(array("members", "compta"));
1891
1892				$newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Members"), 0, $user->rights->adherent->lire, '', $mainmenu, 'members', 0, '', '', '', img_picto('', 'member', 'class="paddingright pictofixedwidth"'));
1893				$newmenu->add("/adherents/card.php?leftmenu=members&amp;action=create", $langs->trans("NewMember"), 1, $user->rights->adherent->creer);
1894				$newmenu->add("/adherents/list.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->lire);
1895				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=-1", $langs->trans("MenuMembersToValidate"), 2, $user->rights->adherent->lire);
1896				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1", $langs->trans("MenuMembersValidated"), 2, $user->rights->adherent->lire);
1897				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1&amp;filter=withoutsubscription", $langs->trans("WithoutSubscription"), 3, $user->rights->adherent->lire);
1898				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1&amp;filter=uptodate", $langs->trans("UpToDate"), 3, $user->rights->adherent->lire);
1899				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=1&amp;filter=outofdate", $langs->trans("OutOfDate"), 3, $user->rights->adherent->lire);
1900				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=0", $langs->trans("MenuMembersResiliated"), 2, $user->rights->adherent->lire);
1901				$newmenu->add("/adherents/stats/index.php?leftmenu=members", $langs->trans("MenuMembersStats"), 1, $user->rights->adherent->lire);
1902
1903				$newmenu->add("/adherents/cartes/carte.php?leftmenu=export", $langs->trans("MembersCards"), 1, $user->rights->adherent->export);
1904				if (!empty($conf->global->MEMBER_LINK_TO_HTPASSWDFILE) && ($usemenuhider || empty($leftmenu) || $leftmenu == 'none' || $leftmenu == "members" || $leftmenu == "export")) {
1905					$newmenu->add("/adherents/htpasswd.php?leftmenu=export", $langs->trans("Filehtpasswd"), 1, $user->rights->adherent->export);
1906				}
1907
1908				if (!empty($conf->categorie->enabled)) {
1909					$langs->load("categories");
1910					$newmenu->add("/categories/index.php?leftmenu=cat&amp;type=3", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1911				}
1912
1913				$newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Subscriptions"), 0, $user->rights->adherent->cotisation->lire, '', $mainmenu, 'members', 0, '', '', '', img_picto('', 'payment', 'class="paddingright pictofixedwidth"'));
1914				$newmenu->add("/adherents/list.php?leftmenu=members&amp;statut=-1,1&amp;mainmenu=members", $langs->trans("NewSubscription"), 1, $user->rights->adherent->cotisation->creer);
1915				$newmenu->add("/adherents/subscription/list.php?leftmenu=members", $langs->trans("List"), 1, $user->rights->adherent->cotisation->lire);
1916				$newmenu->add("/adherents/stats/index.php?leftmenu=members", $langs->trans("MenuMembersStats"), 1, $user->rights->adherent->lire);
1917
1918				//$newmenu->add("/adherents/index.php?leftmenu=export&amp;mainmenu=members",$langs->trans("Tools"),0,$user->rights->adherent->export, '', $mainmenu, 'export');
1919				//if (! empty($conf->export->enabled) && ($usemenuhider || empty($leftmenu) || $leftmenu=="export")) $newmenu->add("/exports/index.php?leftmenu=export",$langs->trans("Datas"),1,$user->rights->adherent->export);
1920
1921				// Type
1922				$newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("MembersTypes"), 0, $user->rights->adherent->configurer, '', $mainmenu, 'setup', 0, '', '', '', img_picto('', 'members', 'class="paddingright pictofixedwidth"'));
1923				$newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members&amp;action=create", $langs->trans("New"), 1, $user->rights->adherent->configurer);
1924				$newmenu->add("/adherents/type.php?leftmenu=setup&amp;mainmenu=members", $langs->trans("List"), 1, $user->rights->adherent->configurer);
1925			}
1926		}
1927
1928		// Add personalized menus and modules menus
1929		//var_dump($newmenu->liste);    //
1930		$menuArbo = new Menubase($db, 'eldy');
1931		$newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, (empty($user->socid) ? 0 : 1), 'eldy', $tabMenu);
1932		//var_dump($newmenu->liste);    //
1933
1934		if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') {	// Entry for FTP
1935			$MAXFTP = 20;
1936			$i = 1;
1937			while ($i <= $MAXFTP) {
1938				$paramkey = 'FTP_NAME_'.$i;
1939				//print $paramkey;
1940				if (!empty($conf->global->$paramkey)) {
1941					$link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i;
1942					$newmenu->add($link, dol_trunc($conf->global->$paramkey, 24));
1943				}
1944				$i++;
1945			}
1946		}
1947	}
1948
1949	//var_dump($tabMenu);    //
1950	//var_dump($newmenu->liste);
1951
1952	// Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
1953	//var_dump($menu_array_before);exit;
1954	//var_dump($menu_array_after);exit;
1955	$menu_array = $newmenu->liste;
1956	if (is_array($menu_array_before)) {
1957		$menu_array = array_merge($menu_array_before, $menu_array);
1958	}
1959	if (is_array($menu_array_after)) {
1960		$menu_array = array_merge($menu_array, $menu_array_after);
1961	}
1962	//var_dump($menu_array);exit;
1963	if (!is_array($menu_array)) {
1964		return 0;
1965	}
1966
1967	// TODO Use the position property in menu_array to reorder the $menu_array
1968	//var_dump($menu_array);
1969	/*$new_menu_array = array();
1970	$level=0; $cusor=0; $position=0;
1971	$nbentry = count($menu_array);
1972	while (findNextEntryForLevel($menu_array, $cursor, $position, $level))
1973	{
1974
1975		$cursor++;
1976	}*/
1977
1978	// Show menu
1979	$invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert";
1980	if (empty($noout)) {
1981		$altok = 0;
1982		$blockvmenuopened = false;
1983		$lastlevel0 = '';
1984		$num = count($menu_array);
1985		for ($i = 0; $i < $num; $i++) {     // Loop on each menu entry
1986			$showmenu = true;
1987			if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) {
1988				$showmenu = false;
1989			}
1990
1991			// Begin of new left menu block
1992			if (empty($menu_array[$i]['level']) && $showmenu) {
1993				$altok++;
1994				$blockvmenuopened = true;
1995				$lastopened = true;
1996				for ($j = ($i + 1); $j < $num; $j++) {
1997					if (empty($menu_array[$j]['level'])) {
1998						$lastopened = false;
1999					}
2000				}
2001				if ($altok % 2 == 0) {
2002					print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
2003				} else {
2004					print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
2005				}
2006			}
2007
2008			// Add tabulation
2009			$tabstring = '';
2010			$tabul = ($menu_array[$i]['level'] - 1);
2011			if ($tabul > 0) {
2012				for ($j = 0; $j < $tabul; $j++) {
2013					$tabstring .= '&nbsp;&nbsp;&nbsp;';
2014				}
2015			}
2016
2017			// $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
2018
2019			$menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);
2020
2021			$url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
2022			if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) {
2023				$tmp = explode('?', $menu_array[$i]['url'], 2);
2024				$url = $shorturl = $tmp[0];
2025				$param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
2026
2027				// Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
2028				if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) {
2029					$param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
2030				}
2031				if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) {
2032					$param .= ($param ? '&' : '').'leftmenu=';
2033				}
2034				//$url.="idmenu=".$menu_array[$i]['rowid'];    // Already done by menuLoad
2035				$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
2036				$shorturlwithoutparam = $shorturl;
2037				$shorturl = $shorturl.($param ? '?'.$param : '');
2038			}
2039
2040
2041			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'].', position='.$menu_array[$i]['position'].' -->'."\n";
2042
2043			// Menu level 0
2044			if ($menu_array[$i]['level'] == 0) {
2045				if ($menu_array[$i]['enabled']) {     // Enabled so visible
2046					print '<div class="menu_titre">'.$tabstring;
2047					if ($shorturlwithoutparam) {
2048						print '<a class="vmenu" title="'.dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
2049					} else {
2050						print '<span class="vmenu">';
2051					}
2052					print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '').$menu_array[$i]['titre'];
2053					if ($shorturlwithoutparam) {
2054						print '</a>';
2055					} else {
2056						print '</span>';
2057					}
2058					print '</div>'."\n";
2059					$lastlevel0 = 'enabled';
2060				} elseif ($showmenu) {                 // Not enabled but visible (so greyed)
2061					print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>'."\n";
2062					$lastlevel0 = 'greyed';
2063				} else {
2064					$lastlevel0 = 'hidden';
2065				}
2066				if ($showmenu) {
2067					print '<div class="menu_top"></div>'."\n";
2068				}
2069			}
2070
2071			// Menu level > 0
2072			if ($menu_array[$i]['level'] > 0) {
2073				$cssmenu = '';
2074				if ($menu_array[$i]['url']) {
2075					$cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
2076				}
2077
2078				if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') {
2079					// Enabled so visible, except if parent was not enabled.
2080					print '<div class="menu_contenu'.$cssmenu.'">';
2081					print $tabstring;
2082					if ($shorturlwithoutparam) {
2083						print '<a class="vsmenu" title="'.dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
2084					} else {
2085						print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
2086					}
2087					print $menu_array[$i]['titre'];
2088					if ($shorturlwithoutparam) {
2089						print '</a>';
2090					} else {
2091						print '</span>';
2092					}
2093					// If title is not pure text and contains a table, no carriage return added
2094					if (!strstr($menu_array[$i]['titre'], '<table')) {
2095						print '<br>';
2096					}
2097					print '</div>'."\n";
2098				} elseif ($showmenu && $lastlevel0 == 'enabled') {
2099					// Not enabled but visible (so greyed), except if parent was not enabled.
2100					print '<div class="menu_contenu'.$cssmenu.'">';
2101					print $tabstring;
2102					print '<font class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</font><br></div>'."\n";
2103				}
2104			}
2105
2106			// If next is a new block or if there is nothing after
2107			if (empty($menu_array[$i + 1]['level'])) {               // End menu block
2108				if ($showmenu) {
2109					print '<div class="menu_end"></div>'."\n";
2110				}
2111				if ($blockvmenuopened) {
2112					print '</div>'."\n";
2113					$blockvmenuopened = false;
2114				}
2115			}
2116		}
2117
2118		if ($altok) {
2119			print '<div class="blockvmenuend"></div>'; // End menu block
2120		}
2121	}
2122
2123	return count($menu_array);
2124}
2125