dolibarr 19.0.4
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 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
28class MenuManager
29{
33 public $db;
34
35 public $type_user; // Put 0 for internal users, 1 for external users
36 public $atarget = ""; // To store default target to use onto links
37 public $name = "eldy";
38
42 public $menu;
43
44 public $menu_array;
45 public $menu_array_after;
46
47 public $tabMenu;
48
49
56 public function __construct($db, $type_user)
57 {
58 $this->type_user = $type_user;
59 $this->db = $db;
60 }
61
62
70 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
71 {
72 global $conf, $user, $langs;
73
74 // We save into session the main menu selected
75 if (GETPOSTISSET("mainmenu")) {
76 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
77 }
78 if (GETPOSTISSET("idmenu")) {
79 $_SESSION["idmenu"] = GETPOST("idmenu", 'int');
80 }
81
82 // Read now mainmenu and leftmenu that define which menu to show
83 if (GETPOSTISSET("mainmenu")) {
84 // On sauve en session le menu principal choisi
85 $mainmenu = GETPOST("mainmenu", 'aZ09');
86 $_SESSION["mainmenu"] = $mainmenu;
87 $_SESSION["leftmenuopened"] = "";
88 } else {
89 // On va le chercher en session si non defini par le lien
90 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
91 }
92 if (!empty($forcemainmenu)) {
93 $mainmenu = $forcemainmenu;
94 }
95
96 if (GETPOSTISSET("leftmenu")) {
97 // On sauve en session le menu principal choisi
98 $leftmenu = GETPOST("leftmenu", 'aZ09');
99 $_SESSION["leftmenu"] = $leftmenu;
100
101 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
102 //$leftmenu="";
103 $_SESSION["leftmenuopened"] = "";
104 } else {
105 $_SESSION["leftmenuopened"] = $leftmenu;
106 }
107 } else {
108 // On va le chercher en session si non defini par le lien
109 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
110 }
111 if (!empty($forceleftmenu)) {
112 $leftmenu = $forceleftmenu;
113 }
114
115 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
116 $tabMenu = array();
117 $menuArbo = new Menubase($this->db, 'eldy');
118 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
119 $this->tabMenu = $tabMenu;
120 //var_dump($tabMenu);
121
122 //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
123 }
124
125
134 public function showmenu($mode, $moredata = null)
135 {
136 global $conf, $langs, $user;
137
138 //var_dump($this->tabMenu);
139
140 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
141
142 if ($this->type_user == 1) {
143 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
144 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
145 }
146
147 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
148 $this->menu = new Menu();
149
150 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
151 if ($mode == 'top') {
152 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
153 }
154 if ($mode == 'left') {
155 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
156 }
157 } else {
158 $conf->global->MAIN_SHOW_LOGO = 0;
159 if ($mode == 'top') {
160 print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
161 }
162 if ($mode == 'left') {
163 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
164 }
165 }
166 if ($mode == 'topnb') {
167 print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output
168 return $this->menu->getNbOfVisibleMenuEntries();
169 }
170
171 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
172 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
173
174 // $this->menu->liste is top menu
175 //var_dump($this->menu->liste);exit;
176 $lastlevel = array();
177 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
178 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
179 print '<ul class="ulmenu" data-inset="true">';
180 print '<li class="lilevel0">';
181
182 if ($val['enabled'] == 1) {
183 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
184 $substitarray['__USERID__'] = $user->id; // For backward compatibility
185 $val['url'] = make_substitutions($val['url'], $substitarray);
186
187 if (!preg_match('/^http/', $val['url'])) {
188 $relurl = dol_buildpath($val['url'], 1);
189 } else {
190 $relurl = $val['url'];
191 }
192
193 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
194
195 print '<a class="alilevel0" href="#">';
196
197 // Add font-awesome
198 if ($val['level'] == 0 && !empty($val['prefix'])) {
199 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
200 }
201
202 print $val['titre'];
203 print '</a>'."\n";
204
205 // Search submenu fot this mainmenu entry
206 $tmpmainmenu = $val['mainmenu'];
207 $tmpleftmenu = 'all';
208 $submenu = new Menu();
209 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)
210 // Note: $submenu contains menu entry with substitution not yet done
211 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
212 //var_dump($submenu); exit;
213 //}
214 //if ($tmpmainmenu=='accountancy') {
215 //var_dump($submenu->liste); exit;
216 //}
217 $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
218
219 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
220 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
221 //var_dump($canonrelurl);
222 //var_dump($canonnexturl);
223
224 print '<ul>'."\n";
225 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
226 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
227 // We add sub entry
228 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
229 print '<a href="'.$relurl.'">';
230
231 if ($val['level'] == 0) {
232 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
233 }
234
235 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
236 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
237 print $langs->trans("Access");
238 } else {
239 print $langs->trans("Dashboard");
240 }
241 } else {
242 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
243 }
244 print '</a>';
245 print '</li>'."\n";
246 }
247
248 /*
249 if ($val['level'] == 0) {
250 if ($val['enabled']) {
251 $lastlevel[0] = 'enabled';
252 } elseif ($showmenu) {
253 // Not enabled but visible (so greyed)
254 $lastlevel[0] = 'greyed';
255 } else {
256 $lastlevel[0] = 'hidden';
257 }
258 }
259 */
260
261 $lastlevel2 = array();
262 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
263 $showmenu = true;
264 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
265 $showmenu = false;
266 }
267
268 // If at least one parent is not enabled, we do not show any menu of all children
269 if ($val2['level'] > 0) {
270 $levelcursor = $val2['level'] - 1;
271 while ($levelcursor >= 0) {
272 if ($lastlevel2[$levelcursor] != 'enabled') {
273 $showmenu = false;
274 }
275 $levelcursor--;
276 }
277 }
278
279 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
280 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
281 $substitarray['__USERID__'] = $user->id; // For backward compatibility
282 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
283
284 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
285 $relurl2 = dol_buildpath($val2['url'], 1);
286 } else {
287 $relurl2 = $val2['url'];
288 }
289 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
290 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
291 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
292 $relurl2 = '';
293 }
294
295 $disabled = '';
296 if (!$val2['enabled']) {
297 $disabled = " vsmenudisabled";
298 }
299
300 print str_pad('', $val2['level'] + 1);
301 print '<li class="lilevel'.($val2['level'] + 1);
302 if ($val2['level'] == 0) {
303 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
304 }
305 print $disabled.'">'; // ui-btn to highlight on clic
306 if ($relurl2) {
307 if ($val2['enabled']) { // Allowed
308 print '<a href="'.$relurl2.'"';
309 //print ' data-ajax="false"';
310 print '>';
311 $lastlevel2[$val2['level']] = 'enabled';
312 } else { // Not allowed but visible (greyed)
313 print '<a href="#" class="vsmenudisabled">';
314 $lastlevel2[$val2['level']] = 'greyed';
315 }
316 } else {
317 if ($val2['enabled']) { // Allowed
318 $lastlevel2[$val2['level']] = 'enabled';
319 } else {
320 $lastlevel2[$val2['level']] = 'greyed';
321 }
322 }
323
324 // Add font-awesome (if $val2['level'] == 0, we are on level2
325 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
326 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
327 }
328
329 print $val2['titre'];
330 if ($relurl2) {
331 if ($val2['enabled']) { // Allowed
332 print '</a>';
333 } else {
334 print '</a>';
335 }
336 }
337 print '</li>'."\n";
338 }
339 }
340 //var_dump($submenu);
341 print '</ul>';
342 }
343 if ($val['enabled'] == 2) {
344 print '<span class="spanlilevel0 vsmenudisabled">';
345
346 // Add font-awesome
347 if ($val['level'] == 0 && !empty($val['prefix'])) {
348 print $val['prefix'];
349 }
350
351 print $val['titre'];
352 print '</span>';
353 }
354 print '</li>';
355 print '</ul>'."\n";
356 }
357 }
358
359 unset($this->menu);
360
361 //print 'xx'.$mode;
362 return 0;
363 }
364}
Class to manage left menus.
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
Definition eldy_menu.php:56
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition eldy_menu.php:70
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:45
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:735
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.