dolibarr 23.0.3
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 if ($val2['enabled']) { // Allowed
331 $lastlevel2[$val2['level']] = 'enabled';
332 } else {
333 $lastlevel2[$val2['level']] = 'greyed';
334 }
335 }
336
337 // 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...)
338 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
339 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
340 } else {
341 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
342 }
343
344 if ($relurl2) {
345 print '</a>';
346 }
347 print '</li>'."\n";
348 }
349 }
350 print '</ul>';
351 }
352 if ($val['enabled'] == 2) {
353 print '<span class="spanlilevel0 vsmenudisabled">';
354
355 // Add font-awesome
356 if ($val['level'] == 0 && !empty($val['prefix'])) {
357 print $val['prefix'];
358 }
359
360 print ucfirst($val['titre']);
361 print '</span>';
362 }
363 print '</li>';
364 print '</ul>'."\n";
365 }
366 }
367
368 if ($mode == 'left') {
369 // Put here left menu entries
370 // ***** START *****
371
372 $langs->load("admin"); // Load translation file admin.lang
373 $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
374 $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
375 $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
376 $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
377 $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
378 $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
379 $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
380
381 $this->menu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
382 $this->menu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
383 $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
384 $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
385 $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
386 $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
387 $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
388 $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
389 $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
390
391 // ***** END *****
392
393 $menu_array_before = array();
394 $menu_array_after = array();
395
396 // do not change code after this
397
398 $menu_array = $this->menu->liste;
399 if (is_array($menu_array_before)) {
400 $menu_array = array_merge($menu_array_before, $menu_array);
401 }
402 if (is_array($menu_array_after)) {
403 $menu_array = array_merge($menu_array, $menu_array_after);
404 }
405 //var_dump($menu_array);exit;
406 if (!is_array($menu_array)) {
407 return 0;
408 }
409
410 '@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';
411
412 if (empty($noout)) {
413 $alt = 0;
414 $altok = 0;
415 $blockvmenuopened = false;
416 $num = count($menu_array);
417 foreach (array_keys($menu_array) as $i) {
418 $alt++;
419 if (empty($menu_array[$i]['level'])) {
420 $altok++;
421 $blockvmenuopened = true;
422 $lastopened = true;
423 for ($j = ($i + 1); $j < $num; $j++) {
424 if (empty($menu_array[$j]['level'])) {
425 $lastopened = false;
426 }
427 }
428 $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
429 $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
430 if (($alt % 2 == 0)) {
431 print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
432 } else {
433 print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
434 }
435 }
436
437 // Add tabulation
438 $tabstring = '';
439 $tabul = ($menu_array[$i]['level'] - 1);
440 if ($tabul > 0) {
441 for ($j = 0; $j < $tabul; $j++) {
442 $tabstring .= '&nbsp; &nbsp;';
443 }
444 }
445
446 if ($menu_array[$i]['level'] == 0) {
447 if ($menu_array[$i]['enabled']) {
448 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";
449 } else {
450 print '<div class="menu_titre">'.$tabstring.'<span class="vmenudisabled">'.$menu_array[$i]['titre'].'</span></div>'."\n";
451 }
452 print '<div class="menu_top"></div>'."\n";
453 }
454
455 if ($menu_array[$i]['level'] > 0) {
456 $cssmenu = '';
457 if ($menu_array[$i]['url']) {
458 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
459 }
460
461 print '<div class="menu_contenu'.$cssmenu.'">';
462
463 if ($menu_array[$i]['enabled']) {
464 print $tabstring;
465 if ($menu_array[$i]['url']) {
466 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'].'"' : '').'>';
467 } else {
468 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
469 }
470 if ($menu_array[$i]['url']) {
471 print ucfirst($menu_array[$i]['titre']).'</a>';
472 } else {
473 print '</span>';
474 }
475 } else {
476 print $tabstring.'<span class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span>';
477 }
478
479 // If title is not pure text and contains a table, no carriage return added
480 if (!strstr($menu_array[$i]['titre'], '<table')) {
481 print '<br>';
482 }
483 print '</div>'."\n";
484 }
485
486 // If next is a new block or end
487 if (empty($menu_array[$i + 1]['level'])) {
488 print '<div class="menu_end"></div>'."\n";
489 print "</div>\n";
490 }
491 }
492
493 if ($altok) {
494 print '<div class="blockvmenuend"></div>';
495 }
496 }
497
498 if ($mode == 'jmobile') {
499 $this->leftmenu = clone $this->menu;
500 unset($menu_array);
501 }
502 }
503
504 unset($this->menu);
505
506 return 0;
507 }
508}
509
510
517{
518 print '<div class="tmenudiv">';
519 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' title="Top menu"' : '').'>';
520}
521
530function print_start_menu_entry_empty($idsel, $classname, $showmode)
531{
532 if ($showmode) {
533 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
534 //print '<div class="tmenuleft tmenusep"></div>';
535 print '<div class="tmenucenter">';
536 }
537}
538
552function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
553{
554 global $langs;
555
556 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
557 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
558
559 if ($showmode == 1) {
560 $menuval['prefix'] = 'fa-home fa-fw';
561
562 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
563 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
564 $reg = array();
565 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
566 print $menuval['prefix'];
567 } elseif (!empty($menuval['prefix']) && preg_match('/^(fa[rsb]? )?fa-/', $menuval['prefix'], $reg)) {
568 print '<span class="'.$id.' '.(empty($reg[1]) ? 'fa ' : '').$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
569 } else {
570 print '<span class="'.$id.' tmenuimageforpngaaaaa" id="mainmenuspan_'.$idsel.'"></span>';
571 }
572 print '</div>';
573 print '</a>';
574 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
575 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
576 print '<span class="mainmenuaspan">';
577 print $text;
578 print '</span>';
579 print '</a>';
580 }
581 }
582 if ($showmode == 2) {
583 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
584 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
585 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
586 print '</div>';
587 print '</div>';
588 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
589 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
590 print '<span class="mainmenuaspan">';
591 print $text;
592 print '</span>';
593 print '</span>';
594 }
595 }
596}
597
604function print_end_menu_entry_empty($showmode)
605{
606 if ($showmode) {
607 print '</div></li>';
608 print "\n";
609 }
610}
611
618{
619 print '</ul>';
620 print '</div>';
621 print "\n";
622}
$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:604
print_start_menu_array_empty()
Output menu entry.
Definition empty.php:516
print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval=array())
Output menu entry.
Definition empty.php:552
print_end_menu_array_empty()
Output menu array.
Definition empty.php:617
print_start_menu_entry_empty($idsel, $classname, $showmode)
Output start menu entry.
Definition empty.php:530
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...