dolibarr 20.0.2
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 } else {
166 $conf->global->MAIN_SHOW_LOGO = 0;
167 if ($mode == 'top') {
168 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
169 }
170 if ($mode == 'left') {
171 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
172 }
173 }
174 if ($mode == 'topnb') {
175 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output
176 return $this->menu->getNbOfVisibleMenuEntries();
177 }
178
179 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
180 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
181
182 // $this->menu->liste is top menu
183 //var_dump($this->menu->liste);exit;
184 $lastlevel = array();
185 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
186 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
187 print '<ul class="ulmenu" data-inset="true">';
188 print '<li class="lilevel0">';
189
190 if ($val['enabled'] == 1) {
191 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
192 $substitarray['__USERID__'] = $user->id; // For backward compatibility
193 $val['url'] = make_substitutions($val['url'], $substitarray);
194
195 if (!preg_match('/^http/', $val['url'])) {
196 $relurl = dol_buildpath($val['url'], 1);
197 } else {
198 $relurl = $val['url'];
199 }
200
201 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
202
203 print '<a class="alilevel0" href="#">';
204
205 // Add font-awesome
206 if ($val['level'] == 0 && !empty($val['prefix'])) {
207 if (preg_match('/^fa\-[a-zA-Z0-9\-_]+$/', $val['prefix'])) {
208 print '<span class="fas '.$val['prefix'].' paddingright pictofixedwidth"></span>';
209 } else {
210 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
211 }
212 }
213 print $val['titre'];
214 print '</a>'."\n";
215
216 // Search submenu for this mainmenu entry
217 $tmpmainmenu = $val['mainmenu'];
218 $tmpleftmenu = 'all';
219 $submenu = new Menu();
220 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)
221 // Note: $submenu contains menu entry with substitution not yet done
222 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
223 //var_dump($submenu); exit;
224 //}
225 //if ($tmpmainmenu=='accountancy') {
226 //var_dump($submenu->liste); exit;
227 //}
228 $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
229
230 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
231 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
232 //var_dump($canonrelurl);
233 //var_dump($canonnexturl);
234
235 print '<ul>'."\n";
236 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
237 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
238 // We add sub entry
239 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
240 print '<a href="'.$relurl.'">';
241
242 if ($val['level'] == 0) {
243 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
244 }
245
246 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
247 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
248 print $langs->trans("Access");
249 } else {
250 print $langs->trans("Dashboard");
251 }
252 } else {
253 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
254 }
255 print '</a>';
256 print '</li>'."\n";
257 }
258
259 /*
260 if ($val['level'] == 0) {
261 if ($val['enabled']) {
262 $lastlevel[0] = 'enabled';
263 } elseif ($showmenu) {
264 // Not enabled but visible (so greyed)
265 $lastlevel[0] = 'greyed';
266 } else {
267 $lastlevel[0] = 'hidden';
268 }
269 }
270 */
271
272 $lastlevel2 = array();
273 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
274 $showmenu = true;
275 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
276 $showmenu = false;
277 }
278
279 // If at least one parent is not enabled, we do not show any menu of all children
280 if ($val2['level'] > 0) {
281 $levelcursor = $val2['level'] - 1;
282 while ($levelcursor >= 0) {
283 if ($lastlevel2[$levelcursor] != 'enabled') {
284 $showmenu = false;
285 }
286 $levelcursor--;
287 }
288 }
289
290 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
291 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
292 $substitarray['__USERID__'] = $user->id; // For backward compatibility
293 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
294
295 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
296 $relurl2 = dol_buildpath($val2['url'], 1);
297 } else {
298 $relurl2 = $val2['url'];
299 }
300 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
301 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
302 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
303 $relurl2 = '';
304 }
305
306 $disabled = '';
307 if (!$val2['enabled']) {
308 $disabled = " vsmenudisabled";
309 }
310
311 // @phan-suppress-next-line PhanParamSuspiciousOrder
312 print str_pad('', $val2['level'] + 1);
313 print '<li class="lilevel'.($val2['level'] + 1);
314 if ($val2['level'] == 0) {
315 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
316 }
317 print $disabled.'">'; // ui-btn to highlight on clic
318 if ($relurl2) {
319 if ($val2['enabled']) { // Allowed
320 print '<a href="'.$relurl2.'"';
321 //print ' data-ajax="false"';
322 print '>';
323 $lastlevel2[$val2['level']] = 'enabled';
324 } else { // Not allowed but visible (greyed)
325 print '<a href="#" class="vsmenudisabled">';
326 $lastlevel2[$val2['level']] = 'greyed';
327 }
328 } else {
329 if ($val2['enabled']) { // Allowed
330 $lastlevel2[$val2['level']] = 'enabled';
331 } else {
332 $lastlevel2[$val2['level']] = 'greyed';
333 }
334 }
335
336 // Add font-awesome (if $val2['level'] == 0, we are on level2
337 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
338 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
339 }
340
341 print $val2['titre'];
342 if ($relurl2) {
343 print '</a>';
344 }
345 print '</li>'."\n";
346 }
347 }
348 //var_dump($submenu);
349 print '</ul>';
350 }
351 if ($val['enabled'] == 2) {
352 print '<span class="spanlilevel0 vsmenudisabled">';
353
354 // Add font-awesome
355 if ($val['level'] == 0 && !empty($val['prefix'])) {
356 print $val['prefix'];
357 }
358
359 print $val['titre'];
360 print '</span>';
361 }
362 print '</li>';
363 print '</ul>'."\n";
364 }
365 }
366
367 unset($this->menu);
368
369 //print 'xx'.$mode;
370 return 0;
371 }
372}
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.