dolibarr 22.0.5
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 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 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
200 print '<ul class="ulmenu" data-inset="true">';
201 print '<li class="lilevel0">';
202
203 if ($val['enabled'] == 1) {
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 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
215
216 print '<a class="alilevel0" href="#">';
217
218 // Add font-awesome
219 if ($val['level'] == 0 && !empty($val['prefix'])) {
220 $reg = array();
221 if (preg_match('/^(fa[rsb]? )?fa-/', $val['prefix'], $reg)) {
222 print '<span class="'.(empty($reg[1]) ? 'fa ' : '').$val['prefix'].' paddingright pictofixedwidth"></span>';
223 } else {
224 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
225 }
226 }
227 print $val['titre'];
228 print '</a>'."\n";
229
230 // Search submenu for this mainmenu entry
231 $tmpmainmenu = $val['mainmenu'];
232 $tmpleftmenu = 'all';
233 $submenu = new Menu();
234 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)
235 // Note: $submenu contains menu entry with substitution not yet done
236 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
237 //var_dump($submenu); exit;
238 //}
239 //if ($tmpmainmenu=='accountancy') {
240 //var_dump($submenu->liste); exit;
241 //}
242 $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
243
244 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
245 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
246 //var_dump($canonrelurl);
247 //var_dump($canonnexturl);
248
249 print '<ul>'."\n";
250 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
251 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
252 // We add sub entry
253 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
254 print '<a href="'.$relurl.'">';
255
256 if ($val['level'] == 0) {
257 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
258 }
259
260 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
261 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
262 print $langs->trans("Access");
263 } else {
264 print $langs->trans("Dashboard");
265 }
266 } else {
267 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
268 }
269 print '</a>';
270 print '</li>'."\n";
271 }
272
273 /*
274 if ($val['level'] == 0) {
275 if ($val['enabled']) {
276 $lastlevel[0] = 'enabled';
277 } elseif ($showmenu) {
278 // Not enabled but visible (so greyed)
279 $lastlevel[0] = 'greyed';
280 } else {
281 $lastlevel[0] = 'hidden';
282 }
283 }
284 */
285
286 $lastlevel2 = array();
287 '@phan-var-force array<string> $lastlevel2';
288 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu','prefix']
289 $showmenu = true;
290 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
291 $showmenu = false;
292 }
293
294 // If at least one parent is not enabled, we do not show any menu of all children
295 if ($val2['level'] > 0) {
296 $levelcursor = $val2['level'] - 1;
297 while ($levelcursor >= 0) {
298 if ($lastlevel2[$levelcursor] != 'enabled') {
299 $showmenu = false;
300 }
301 $levelcursor--;
302 }
303 }
304
305 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
306 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
307 $substitarray['__USERID__'] = $user->id; // For backward compatibility
308 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
309
310 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
311 $relurl2 = dol_buildpath($val2['url'], 1);
312 } else {
313 $relurl2 = $val2['url'];
314 }
315 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
316 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
317 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
318 $relurl2 = '';
319 }
320
321 $disabled = '';
322 if (!$val2['enabled']) {
323 $disabled = " vsmenudisabled";
324 }
325
326 // @phan-suppress-next-line PhanParamSuspiciousOrder
327 print str_pad('', ($val2['level'] + 1));
328 print '<li class="lilevel'.($val2['level'] + 1);
329 if ($val2['level'] == 0) {
330 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
331 }
332 print $disabled.'">'; // ui-btn to highlight on clic
333 if ($relurl2) {
334 if ($val2['enabled']) {
335 // Allowed
336 print '<a href="'.$relurl2.'">';
337 $lastlevel2[$val2['level']] = 'enabled';
338 } else {
339 // Not allowed but visible (greyed)
340 print '<a href="#" class="vsmenudisabled">';
341 $lastlevel2[$val2['level']] = 'greyed';
342 }
343 } else {
344 if ($val2['enabled']) { // Allowed
345 $lastlevel2[$val2['level']] = 'enabled';
346 } else {
347 $lastlevel2[$val2['level']] = 'greyed';
348 }
349 }
350
351 // 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...)
352 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
353 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
354 } else {
355 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth level'.($val2['level']+1).'"></i>';
356 }
357
358 print $val2['titre'];
359 if ($relurl2) {
360 print '</a>';
361 }
362 print '</li>'."\n";
363 }
364 }
365 //var_dump($submenu);
366 print '</ul>';
367 }
368 if ($val['enabled'] == 2) {
369 print '<span class="spanlilevel0 vsmenudisabled">';
370
371 // Add font-awesome
372 if ($val['level'] == 0 && !empty($val['prefix'])) {
373 print $val['prefix'];
374 }
375
376 print $val['titre'];
377 print '</span>';
378 }
379 print '</li>';
380 print '</ul>'."\n";
381 }
382 }
383
384 unset($this->menu);
385
386 //print 'xx'.$mode;
387 return 0;
388 }
389}
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:48
print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout=0, $forcemainmenu='', $forceleftmenu='', $moredata=null, $type_user=0)
Core function to output left menu eldy Fill &$menu (example with $forcemainmenu='home' $forceleftmenu...
Definition eldy.lib.php:758
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79