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