dolibarr 23.0.3
eldy_menu.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2007-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
32class MenuManager
33{
37 public $db;
38
42 public $type_user = 0;
43
47 public $atarget = "";
48
52 public $name = "eldy";
53
57 public $menu;
58
62 public $menu_array;
66 public $menu_array_after;
67
71 public $tabMenu;
72
73
80 public function __construct($db, $type_user)
81 {
82 $this->type_user = $type_user;
83 $this->db = $db;
84 }
85
86
94 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
95 {
96 // We save into session the main menu selected
97 if (GETPOSTISSET("mainmenu")) {
98 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
99 }
100 if (GETPOSTISSET("idmenu")) {
101 $_SESSION["idmenu"] = GETPOSTINT("idmenu");
102 }
103
104 // Read now mainmenu and leftmenu that define which menu to show
105 if (GETPOSTISSET("mainmenu")) {
106 // On sauve en session le menu principal choisi
107 $mainmenu = GETPOST("mainmenu", 'aZ09');
108 $_SESSION["mainmenu"] = $mainmenu;
109 $_SESSION["leftmenuopened"] = "";
110 } else {
111 // Look for the menu in the session if not set by the link
112 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
113 }
114 if (!empty($forcemainmenu)) {
115 $mainmenu = $forcemainmenu;
116 }
117
118 if (GETPOSTISSET("leftmenu")) {
119 // On sauve en session le menu principal choisi
120 $leftmenu = GETPOST("leftmenu", 'aZ09');
121 $_SESSION["leftmenu"] = $leftmenu;
122
123 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
124 //$leftmenu="";
125 $_SESSION["leftmenuopened"] = "";
126 } else {
127 $_SESSION["leftmenuopened"] = $leftmenu;
128 }
129 } else {
130 // Look for the menu in the session if not set by the link
131 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
132 }
133 if (!empty($forceleftmenu)) {
134 $leftmenu = $forceleftmenu;
135 }
136
137 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
138 $tabMenu = array();
139 $menuArbo = new Menubase($this->db, 'eldy');
140 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
141 $this->tabMenu = $tabMenu;
142 }
143
144
153 public function showmenu($mode, $moredata = null)
154 {
155 global $conf, $langs, $user;
156
157 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
158
159 if ($this->type_user == 1) {
160 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
161 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
162 }
163
164 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
165 $this->menu = new Menu();
166
167 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
168 if ($mode == 'top') {
169 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
170 }
171 if ($mode == 'left') {
172 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
173 }
174 if ($mode == 'leftdropdown') {
175 //$leftmenudropdown = print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
176 $leftmenudropdown = print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 1, '', '', $moredata, $this->type_user);
177 }
178 } else {
179 $conf->global->MAIN_SHOW_LOGO = 0;
180 if ($mode == 'top') {
181 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
182 }
183 if ($mode == 'left') {
184 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
185 }
186 }
187 if ($mode == 'topnb') {
188 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output
189 return $this->menu->getNbOfVisibleMenuEntries();
190 }
191
192 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
193 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // Fill this->menu that is empty with top menu
194
195 // $this->menu->liste is top menu
196 //var_dump($this->menu->liste);exit;
197 $lastlevel = array();
198 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
199 print '<ul class="ulmenu ullevel0" data-inset="true">'."\n";
200 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
201 if ($val['enabled'] == 1) {
202 print '<li class="lilevel0">';
203
204 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
205 $substitarray['__USERID__'] = $user->id; // For backward compatibility
206 $val['url'] = make_substitutions($val['url'], $substitarray);
207
208 if (!preg_match('/^http/', $val['url'])) {
209 $relurl = dol_buildpath($val['url'], 1);
210 } else {
211 $relurl = $val['url'];
212 }
213
214 // Label li level 0
215 print '<a class="alilevel0" href="#">';
216 // Add font-awesome
217 if ($val['level'] == 0 && !empty($val['prefix'])) {
218 $reg = array();
219 if (preg_match('/^(fa[rsb]? )?fa-/', $val['prefix'], $reg)) {
220 print '<span class="'.(empty($reg[1]) ? 'fa ' : '').$val['prefix'].' paddingright pictofixedwidth"></span>';
221 } else {
222 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
223 }
224 }
225 print ucfirst($val['titre']);
226 print '</a>'."\n";
227
228 // Search submenu for this mainmenu entry
229 $tmpmainmenu = $val['mainmenu'];
230 $tmpleftmenu = 'all';
231 $submenu = new Menu();
232 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu, null, $this->type_user); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home)
233 // Note: $submenu contains menu entry with substitution not yet done
234 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
235 //var_dump($submenu); exit;
236 //}
237 //if ($tmpmainmenu=='accountancy') {
238 //var_dump($submenu->liste); exit;
239 //}
240 $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
241
242 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
243 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
244 //var_dump($canonrelurl);
245 //var_dump($canonnexturl);
246
247 // Start a new ul level 1
248 $level = 1;
249 print str_repeat(' ', $level).'<ul class="ullevel1">'."\n";
250
251 // Do we have to add an extra entry that is not into menu array ?
252 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
253 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
254 print str_repeat(' ', $level).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
255 print '<a href="'.$relurl.'">';
256
257 if ($val['level'] == 0) {
258 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
259 }
260
261 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
262 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
263 print $langs->trans("Access");
264 } else {
265 print $langs->trans("Dashboard");
266 }
267 } else {
268 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
269 }
270 print '</a>';
271 print '</li>'."\n";
272 }
273
274 $lastlevel2 = array();
275 $lastlinelevel = $level;
276
277 '@phan-var-force array<string> $lastlevel2';
278 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu','prefix']
279 $showmenu = true;
280 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
281 $showmenu = false;
282 }
283
284 // If at least one parent is not enabled, we do not show any menu of all children
285 if ($val2['level'] > 0) {
286 $levelcursor = $val2['level'] - 1;
287 while ($levelcursor >= 0) {
288 if ($lastlevel2[$levelcursor] != 'enabled') {
289 $showmenu = false;
290 }
291 $levelcursor--;
292 }
293 }
294
295 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
296 $newlinelevel = ($val2['level'] + 1);
297 if ($newlinelevel > $lastlinelevel) {
298 print str_repeat(' ', $newlinelevel).'<ul class="ullevel'.$newlinelevel.'" xx>'."\n";
299 }
300 $lastlinelevel = ($val2['level'] + 1);
301
302 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
303 $substitarray['__USERID__'] = $user->id; // For backward compatibility
304 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
305
306 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
307 $relurl2 = dol_buildpath($val2['url'], 1);
308 } else {
309 $relurl2 = $val2['url'];
310 }
311 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
312 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
313 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
314 $relurl2 = '';
315 }
316
317 $disabled = '';
318 if (!$val2['enabled']) {
319 $disabled = " vsmenudisabled";
320 }
321
322 // Show entry li level $val2['level']+1
323
324 // @phan-suppress-next-line PhanParamSuspiciousOrder
325 print str_repeat(' ', ($val2['level'] + 1));
326 print '<li class="lilevel'.($val2['level'] + 1);
327 if ($val2['level'] == 0) {
328 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
329 }
330 print $disabled.'">'; // ui-btn to highlight on clic
331
332 if ($relurl2) {
333 if ($val2['enabled']) {
334 // Allowed
335 print '<a href="'.$relurl2.'">';
336 $lastlevel2[$val2['level']] = 'enabled';
337 } else {
338 // Not allowed but visible (greyed)
339 print '<a href="#" class="vsmenudisabled">';
340 $lastlevel2[$val2['level']] = 'greyed';
341 }
342 } else {
343 if ($val2['enabled']) { // Allowed
344 $lastlevel2[$val2['level']] = 'enabled';
345 } else {
346 $lastlevel2[$val2['level']] = 'greyed';
347 }
348 }
349
350 // Add font-awesome for level 0 and 1 (if $val2['level'] == 1, we are on level2, if $val2['level'] == 2, we are on level 3...)
351 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
352 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
353 } else {
354 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth level'.($val2['level'] + 1).'"></i>';
355 }
356
357 print ucfirst($val2['titre']);
358 if ($relurl2) {
359 print '</a>';
360 }
361
362 $currentlevel = (empty($submenu->liste[$key2]) ? 1 : $submenu->liste[$key2]['level'] + 1);
363 $nextlevel = (empty($submenu->liste[$key2 + 1]) ? 1 : $submenu->liste[$key2 + 1]['level'] + 1);
364 // If there is no lower level
365 if ($nextlevel > $currentlevel) {
366 // There is a submenu with a lower level, we do not close the li
367 print "\n";
368 } elseif ($nextlevel < $currentlevel) {
369 // Next menu is lower
370 print '</li>'."\n";
371 $fromcursor = 0;
372 while ($fromcursor < ($currentlevel - $nextlevel)) {
373 print str_repeat(' ', $currentlevel - $fromcursor).'</ul>'."\n";
374 print str_repeat(' ', $currentlevel - $fromcursor - 1).'</li>'."\n"; // end level $val2['level']+1
375 $fromcursor++;
376 }
377 } else {
378 print '</li>'."\n"; // end level $val2['level']+1
379 }
380 }
381 //var_dump($submenu);
382 }
383
384 print str_repeat(' ', $level).'</ul>'."\n"; // end ul level 1
385 print str_repeat(' ', $level - 1).'</li>'."\n"; // end ul level 1
386 } elseif ($val['enabled'] == 2) {
387 print '<li class="lilevel0">';
388
389 // Label li level 0
390 print '<span class="spanlilevel0 vsmenudisabled">';
391
392 // Add font-awesome
393 if ($val['level'] == 0 && !empty($val['prefix'])) {
394 print $val['prefix'];
395 }
396
397 print ucfirst($val['titre']);
398 print '</span>';
399
400 print '</li>'."\n"; // close entry level 0
401 }
402 }
403 print '</ul>'."\n"; // close entry level 0
404 }
405
406 unset($this->menu);
407
408 //print 'xx'.$mode;
409 return 0;
410 }
411}
Class to manage left menus.
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
Definition eldy_menu.php:80
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition eldy_menu.php:94
showmenu($mode, $moredata=null)
Output menu on screen.
Class to manage menu entries.
print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output the top menu eldy.
Definition eldy.lib.php:49
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.