dolibarr 21.0.0-alpha
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;
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 global $conf, $user, $langs;
97
98 // We save into session the main menu selected
99 if (GETPOSTISSET("mainmenu")) {
100 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
101 }
102 if (GETPOSTISSET("idmenu")) {
103 $_SESSION["idmenu"] = GETPOSTINT("idmenu");
104 }
105
106 // Read now mainmenu and leftmenu that define which menu to show
107 if (GETPOSTISSET("mainmenu")) {
108 // On sauve en session le menu principal choisi
109 $mainmenu = GETPOST("mainmenu", 'aZ09');
110 $_SESSION["mainmenu"] = $mainmenu;
111 $_SESSION["leftmenuopened"] = "";
112 } else {
113 // Look for the menu in the session if not set by the link
114 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
115 }
116 if (!empty($forcemainmenu)) {
117 $mainmenu = $forcemainmenu;
118 }
119
120 if (GETPOSTISSET("leftmenu")) {
121 // On sauve en session le menu principal choisi
122 $leftmenu = GETPOST("leftmenu", 'aZ09');
123 $_SESSION["leftmenu"] = $leftmenu;
124
125 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
126 //$leftmenu="";
127 $_SESSION["leftmenuopened"] = "";
128 } else {
129 $_SESSION["leftmenuopened"] = $leftmenu;
130 }
131 } else {
132 // Look for the menu in the session if not set by the link
133 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
134 }
135 if (!empty($forceleftmenu)) {
136 $leftmenu = $forceleftmenu;
137 }
138
139 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
140 $tabMenu = array();
141 $menuArbo = new Menubase($this->db, 'eldy');
142 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
143 $this->tabMenu = $tabMenu;
144 }
145
146
155 public function showmenu($mode, $moredata = null)
156 {
157 global $conf, $langs, $user;
158
159 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
160
161 if ($this->type_user == 1) {
162 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
163 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
164 }
165
166 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
167 $this->menu = new Menu();
168
169 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
170 if ($mode == 'top') {
171 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
172 }
173 if ($mode == 'left') {
174 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
175 }
176 if ($mode == 'leftdropdown') {
177 //$leftmenudropdown = print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
178 $leftmenudropdown = print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 1, '', '', $moredata, $this->type_user);
179 }
180 } else {
181 $conf->global->MAIN_SHOW_LOGO = 0;
182 if ($mode == 'top') {
183 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
184 }
185 if ($mode == 'left') {
186 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
187 }
188 }
189 if ($mode == 'topnb') {
190 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output
191 return $this->menu->getNbOfVisibleMenuEntries();
192 }
193
194 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
195 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
196
197 // $this->menu->liste is top menu
198 //var_dump($this->menu->liste);exit;
199 $lastlevel = array();
200 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
201 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
202 print '<ul class="ulmenu" data-inset="true">';
203 print '<li class="lilevel0">';
204
205 if ($val['enabled'] == 1) {
206 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
207 $substitarray['__USERID__'] = $user->id; // For backward compatibility
208 $val['url'] = make_substitutions($val['url'], $substitarray);
209
210 if (!preg_match('/^http/', $val['url'])) {
211 $relurl = dol_buildpath($val['url'], 1);
212 } else {
213 $relurl = $val['url'];
214 }
215
216 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
217
218 print '<a class="alilevel0" href="#">';
219
220 // Add font-awesome
221 if ($val['level'] == 0 && !empty($val['prefix'])) {
222 if (preg_match('/^fa\-[a-zA-Z0-9\-_]+$/', $val['prefix'])) {
223 print '<span class="fas '.$val['prefix'].' paddingright pictofixedwidth"></span>';
224 } else {
225 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
226 }
227 }
228 print $val['titre'];
229 print '</a>'."\n";
230
231 // Search submenu for this mainmenu entry
232 $tmpmainmenu = $val['mainmenu'];
233 $tmpleftmenu = 'all';
234 $submenu = new Menu();
235 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)
236 // Note: $submenu contains menu entry with substitution not yet done
237 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
238 //var_dump($submenu); exit;
239 //}
240 //if ($tmpmainmenu=='accountancy') {
241 //var_dump($submenu->liste); exit;
242 //}
243 $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
244
245 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
246 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
247 //var_dump($canonrelurl);
248 //var_dump($canonnexturl);
249
250 print '<ul>'."\n";
251 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
252 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
253 // We add sub entry
254 print str_pad('', 1).'<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 /*
275 if ($val['level'] == 0) {
276 if ($val['enabled']) {
277 $lastlevel[0] = 'enabled';
278 } elseif ($showmenu) {
279 // Not enabled but visible (so greyed)
280 $lastlevel[0] = 'greyed';
281 } else {
282 $lastlevel[0] = 'hidden';
283 }
284 }
285 */
286
287 $lastlevel2 = array();
288 '@phan-var-force array<string> $lastlevel2';
289 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu','prefix']
290 $showmenu = true;
291 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
292 $showmenu = false;
293 }
294
295 // If at least one parent is not enabled, we do not show any menu of all children
296 if ($val2['level'] > 0) {
297 $levelcursor = $val2['level'] - 1;
298 while ($levelcursor >= 0) {
299 if ($lastlevel2[$levelcursor] != 'enabled') {
300 $showmenu = false;
301 }
302 $levelcursor--;
303 }
304 }
305
306 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
307 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
308 $substitarray['__USERID__'] = $user->id; // For backward compatibility
309 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
310
311 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
312 $relurl2 = dol_buildpath($val2['url'], 1);
313 } else {
314 $relurl2 = $val2['url'];
315 }
316 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
317 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
318 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
319 $relurl2 = '';
320 }
321
322 $disabled = '';
323 if (!$val2['enabled']) {
324 $disabled = " vsmenudisabled";
325 }
326
327 // @phan-suppress-next-line PhanParamSuspiciousOrder
328 print str_pad('', $val2['level'] + 1);
329 print '<li class="lilevel'.($val2['level'] + 1);
330 if ($val2['level'] == 0) {
331 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
332 }
333 print $disabled.'">'; // ui-btn to highlight on clic
334 if ($relurl2) {
335 if ($val2['enabled']) { // Allowed
336 print '<a href="'.$relurl2.'"';
337 //print ' data-ajax="false"';
338 print '>';
339 $lastlevel2[$val2['level']] = 'enabled';
340 } else { // Not allowed but visible (greyed)
341 print '<a href="#" class="vsmenudisabled">';
342 $lastlevel2[$val2['level']] = 'greyed';
343 }
344 } else {
345 if ($val2['enabled']) { // Allowed
346 $lastlevel2[$val2['level']] = 'enabled';
347 } else {
348 $lastlevel2[$val2['level']] = 'greyed';
349 }
350 }
351
352 // Add font-awesome (if $val2['level'] == 0, we are on level2
353 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
354 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
355 }
356
357 print $val2['titre'];
358 if ($relurl2) {
359 print '</a>';
360 }
361 print '</li>'."\n";
362 }
363 }
364 //var_dump($submenu);
365 print '</ul>';
366 }
367 if ($val['enabled'] == 2) {
368 print '<span class="spanlilevel0 vsmenudisabled">';
369
370 // Add font-awesome
371 if ($val['level'] == 0 && !empty($val['prefix'])) {
372 print $val['prefix'];
373 }
374
375 print $val['titre'];
376 print '</span>';
377 }
378 print '</li>';
379 print '</ul>'."\n";
380 }
381 }
382
383 unset($this->menu);
384
385 //print 'xx'.$mode;
386 return 0;
387 }
388}
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)
Show menu.
Class to manage menu entries.
print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output top menu eldy.
Definition eldy.lib.php:46
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:737
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.