dolibarr 25.0.0-alpha
empty.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
29class MenuManager
30{
34 public $db;
35
39 public $type_user = 0;
40
44 public $atarget = "";
45
49 public $name = "empty";
50
54 public $menu;
55
59 public $menu_array_after;
60
64 public $tabMenu;
65
69 public $topmenu;
73 public $leftmenu;
74
81 public function __construct($db, $type_user)
82 {
83 $this->type_user = $type_user;
84 $this->db = $db;
85 }
86
87
95 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
96 {
97 // Do nothing
98 $this->tabMenu = array();
99 }
100
101
109 public function showmenu($mode, $moredata = null)
110 {
111 global $langs, $user, $dolibarr_main_db_name;
112
113 $id = 'mainmenu';
114
115 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
116 $this->menu = new Menu();
117
118 $noout = 0;
119 //if ($mode == 'jmobile') $noout=1;
120
121 if ($mode == 'topnb') {
122 return 1;
123 }
124
125 if ($mode == 'top') {
126 if (empty($noout)) {
128 }
129
130 $usemenuhider = 1;
131
132 // Show/Hide vertical menu
133 if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
134 $showmode = 1;
135 $classname = 'class="tmenu menuhider nohover"';
136 $idsel = 'menu';
137
138 $this->menu->add('#', '', 0, $showmode, $this->atarget, "xxx", '', 0, $id, $idsel, $classname);
139 }
140
141 // Home
142 $showmode = 1;
143 $classname = 'class="tmenusel"';
144 $idsel = 'home';
145
146 $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
147
148
149 // Sort on position
150 $this->menu->liste = dol_sort_array($this->menu->liste, 'position');
151
152 // Output menu entries
153 if (empty($noout)) {
154 foreach ($this->menu->liste as $menkey => $menuval) {
155 print_start_menu_entry_empty($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
156
157 print_text_menu_entry_empty($menuval['titre'], $menuval['enabled'], ($menuval['url'] != '#' ? DOL_URL_ROOT : '').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $this->atarget));
158
159 print_end_menu_entry_empty($menuval['enabled']);
160 }
161
162 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
163 print_start_menu_entry_empty('', 'class="tmenuend"', $showmode);
164 }
165
167
169 }
170 }
171
172 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
173 // Home
174 $showmode = 1;
175 $classname = 'class="tmenusel"';
176 $idsel = 'home';
177
178 $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
179
180 $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
181
182 // $this->menu->liste is top menu
183 //var_dump($this->menu->liste);exit;
184 $lastlevel = array();
185 $showmenu = true; // Is current menu shown - define here to keep static code checker happy
186 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
187 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
188 print '<ul class="ulmenu" data-inset="true">';
189 print '<li class="lilevel0">';
190
191 if ($val['enabled'] == 1) {
192 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
193 $substitarray['__USERID__'] = $user->id; // For backward compatibility
194 $val['url'] = make_substitutions($val['url'], $substitarray);
195
196 if (!preg_match('/^http/', $val['url'])) {
197 $relurl = dol_buildpath($val['url'], 1);
198 } else {
199 $relurl = $val['url'];
200 }
201
202 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
203
204 print '<a class="alilevel0" href="#">';
205
206 // Add font-awesome
207 if ($val['level'] == 0 && $val['mainmenu'] == 'home') {
208 print '<span class="fas fa-home fa-fw paddingright" aria-hidden="true"></span>';
209 }
210
211 print ucfirst($val['titre']);
212 print '</a>'."\n";
213
214 // Search submenu for this mainmenu entry
215 $tmpmainmenu = $val['mainmenu'];
216 $tmpleftmenu = 'all';
217 $submenu = new Menu();
218
219 $langs->load("admin"); // Load translation file admin.lang
220 $submenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
221 $submenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
222 $submenu->add("/admin/modules.php", $langs->trans("Modules"), 1);
223 $submenu->add("/admin/menus.php", $langs->trans("Menus"), 1);
224 $submenu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
225 $submenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
226 $submenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
227
228 $submenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
229 $submenu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
230 $submenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
231 $submenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
232 $submenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
233 $submenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
234 $submenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
235 $submenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
236 $submenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
237
238 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
239 //var_dump($submenu); exit;
240 //}
241 //if ($tmpmainmenu=='accountancy') {
242 //var_dump($submenu->liste); exit;
243 //}
244 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
245
246 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
247 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
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 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
256 if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) {
257 print $langs->trans("Access");
258 } else {
259 print $langs->trans("Dashboard");
260 }
261 } else {
262 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
263 }
264 print '</a>';
265 print '</li>'."\n";
266 }
267
268 if ($val['level'] == 0) {
269 if ($val['enabled']) {
270 $lastlevel[0] = 'enabled';
271 } elseif ($showmenu) { // Not enabled but visible (so greyed)
272 $lastlevel[0] = 'greyed';
273 } else {
274 $lastlevel[0] = 'hidden';
275 }
276 }
277
278 $lastlevel2 = array();
279 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
280 $showmenu = true;
281 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
282 $showmenu = false;
283 }
284
285 // If at least one parent is not enabled, we do not show any menu of all children
286 if ($val2['level'] > 0) {
287 $levelcursor = $val2['level'] - 1;
288 while ($levelcursor >= 0) {
289 // @phan-suppress-next-line PhanTypeInvalidDimOffset
290 if ($lastlevel2[$levelcursor] != 'enabled') {
291 $showmenu = false;
292 }
293 $levelcursor--;
294 }
295 }
296
297 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
298 $val2['url'] = make_substitutions($val2['url'], $substitarray);
299
300 $relurl2 = dol_buildpath($val2['url'], 1);
301 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
302 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
303 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
304 $relurl2 = '';
305 }
306
307 $disabled = '';
308 if (!$val2['enabled']) {
309 $disabled = " vsmenudisabled";
310 }
311
312 // @phan-suppress-next-line PhanParamSuspiciousOrder
313 print str_repeat(' ', ($val2['level'] + 1));
314 print '<li class="lilevel'.($val2['level'] + 1);
315 if ($val2['level'] == 0) {
316 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
317 }
318 print $disabled.'">'; // ui-btn to highlight on clic
319 if ($relurl2) {
320 if ($val2['enabled']) {
321 // Allowed
322 print '<a href="'.$relurl2.'">';
323 $lastlevel2[$val2['level']] = 'enabled';
324 } else {
325 // Not allowed but visible (greyed)
326 print '<a href="#" class="vsmenudisabled">';
327 $lastlevel2[$val2['level']] = 'greyed';
328 }
329 } else {
330 print '<span'.($val2['enabled'] ? '' : ' class="vsmenudisabled"').'>';
331 if ($val2['enabled']) { // Allowed
332 $lastlevel2[$val2['level']] = 'enabled';
333 } else {
334 $lastlevel2[$val2['level']] = 'greyed';
335 }
336 }
337
338 // 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...)
339 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
340 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
341 } else {
342 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
343 }
344
345 if ($relurl2) {
346 print '</a>';
347 } else {
348 print '</span>';
349 }
350 print '</li>'."\n";
351 }
352 }
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 ucfirst($val['titre']);
364 print '</span>';
365 }
366 print '</li>';
367 print '</ul>'."\n";
368 }
369 }
370
371 if ($mode == 'left') {
372 // Put here left menu entries
373 // ***** START *****
374
375 $langs->load("admin"); // Load translation file admin.lang
376 $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
377 $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
378 $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
379 $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
380 $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
381 $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
382 $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
383
384 $this->menu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
385 $this->menu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
386 $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
387 $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
388 $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
389 $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
390 $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
391 $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
392 $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
393
394 // ***** END *****
395
396 $menu_array_before = array();
397 $menu_array_after = array();
398
399 // do not change code after this
400
401 $menu_array = $this->menu->liste;
402 if (is_array($menu_array_before)) {
403 $menu_array = array_merge($menu_array_before, $menu_array);
404 }
405 if (is_array($menu_array_after)) {
406 $menu_array = array_merge($menu_array, $menu_array_after);
407 }
408 //var_dump($menu_array);exit;
409 if (!is_array($menu_array)) {
410 return 0;
411 }
412
413 '@phan-var-force array<array{rowid:string,fk_menu:string,langs:string,enabled:int<0,2>,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,positionfull:int|string,showtopmenuinframe:int,level?:int,prefix:string}> $menu_array';
414
415 if (empty($noout)) {
416 $alt = 0;
417 $altok = 0;
418 $blockvmenuopened = false;
419 $num = count($menu_array);
420 foreach (array_keys($menu_array) as $i) {
421 $alt++;
422 if (empty($menu_array[$i]['level'])) {
423 $altok++;
424 $blockvmenuopened = true;
425 $lastopened = true;
426 for ($j = ($i + 1); $j < $num; $j++) {
427 if (empty($menu_array[$j]['level'])) {
428 $lastopened = false;
429 }
430 }
431 $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
432 $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
433 if (($alt % 2 == 0)) {
434 print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
435 } else {
436 print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
437 }
438 }
439
440 // Add tabulation
441 $tabstring = '';
442 $tabul = ($menu_array[$i]['level'] - 1);
443 if ($tabul > 0) {
444 for ($j = 0; $j < $tabul; $j++) {
445 $tabstring .= '&nbsp; &nbsp;';
446 }
447 }
448
449 if ($menu_array[$i]['level'] == 0) {
450 if ($menu_array[$i]['enabled']) {
451 print '<div class="menu_titre">'.$tabstring.'<a class="vmenu" href="'.dol_buildpath($menu_array[$i]['url'], 1).'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>'.$menu_array[$i]['titre'].'</a></div>'."\n";
452 } else {
453 print '<div class="menu_titre">'.$tabstring.'<span class="vmenudisabled">'.$menu_array[$i]['titre'].'</span></div>'."\n";
454 }
455 print '<div class="menu_top"></div>'."\n";
456 }
457
458 if ($menu_array[$i]['level'] > 0) {
459 $cssmenu = '';
460 if ($menu_array[$i]['url']) {
461 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
462 }
463
464 print '<div class="menu_contenu'.$cssmenu.'">';
465
466 if ($menu_array[$i]['enabled']) {
467 print $tabstring;
468 if ($menu_array[$i]['url']) {
469 print '<a class="vsmenu" itle="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.dol_buildpath($menu_array[$i]['url'], 1).'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
470 } else {
471 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
472 }
473 if ($menu_array[$i]['url']) {
474 print ucfirst($menu_array[$i]['titre']).'</a>';
475 } else {
476 print '</span>';
477 }
478 } else {
479 print $tabstring.'<span class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span>';
480 }
481
482 // If title is not pure text and contains a table, no carriage return added
483 if (!strstr($menu_array[$i]['titre'], '<table')) {
484 print '<br>';
485 }
486 print '</div>'."\n";
487 }
488
489 // If next is a new block or end
490 if (empty($menu_array[$i + 1]['level'])) {
491 print '<div class="menu_end"></div>'."\n";
492 print "</div>\n";
493 }
494 }
495
496 if ($altok) {
497 print '<div class="blockvmenuend"></div>';
498 }
499 }
500
501 if ($mode == 'jmobile') {
502 $this->leftmenu = clone $this->menu;
503 unset($menu_array);
504 }
505 }
506
507 unset($this->menu);
508
509 return 0;
510 }
511}
512
513
520{
521 print '<div class="tmenudiv">';
522 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' title="Top menu"' : '').'>';
523}
524
533function print_start_menu_entry_empty($idsel, $classname, $showmode)
534{
535 if ($showmode) {
536 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
537 //print '<div class="tmenuleft tmenusep"></div>';
538 print '<div class="tmenucenter">';
539 }
540}
541
555function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
556{
557 global $langs;
558
559 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
560 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
561
562 if ($showmode == 1) {
563 $menuval['prefix'] = 'fa-home fa-fw';
564
565 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
566 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
567 $reg = array();
568 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
569 print $menuval['prefix'];
570 } elseif (!empty($menuval['prefix']) && preg_match('/^(fa[rsb]? )?fa-/', $menuval['prefix'], $reg)) {
571 print '<span class="'.$id.' '.(empty($reg[1]) ? 'fa ' : '').$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
572 } else {
573 print '<span class="'.$id.' tmenuimageforpngaaaaa" id="mainmenuspan_'.$idsel.'"></span>';
574 }
575 print '</div>';
576 print '</a>';
577 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
578 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
579 print '<span class="mainmenuaspan">';
580 print $text;
581 print '</span>';
582 print '</a>';
583 }
584 }
585 if ($showmode == 2) {
586 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
587 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
588 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
589 print '</div>';
590 print '</div>';
591 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
592 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
593 print '<span class="mainmenuaspan">';
594 print $text;
595 print '</span>';
596 print '</span>';
597 }
598 }
599}
600
607function print_end_menu_entry_empty($showmode)
608{
609 if ($showmode) {
610 print '</div></li>';
611 print "\n";
612 }
613}
614
621{
622 print '</ul>';
623 print '</div>';
624 print "\n";
625}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
Class to manage left menus.
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
Definition empty.php:81
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition empty.php:95
showmenu($mode, $moredata=null)
Output menu on screen.
Definition empty.php:109
print_end_menu_entry_empty($showmode)
Output end menu entry.
Definition empty.php:607
print_start_menu_array_empty()
Output menu entry.
Definition empty.php:519
print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval=array())
Output menu entry.
Definition empty.php:555
print_end_menu_array_empty()
Output menu array.
Definition empty.php:620
print_start_menu_entry_empty($idsel, $classname, $showmode)
Output start menu entry.
Definition empty.php:533
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183