dolibarr 21.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;
43 public $atarget = "";
47 public $name = "empty";
48
52 public $menu;
56 public $menu_array_after;
57
61 public $tabMenu;
62
66 public $topmenu;
70 public $leftmenu;
71
78 public function __construct($db, $type_user)
79 {
80 $this->type_user = $type_user;
81 $this->db = $db;
82 }
83
84
92 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
93 {
94 // Do nothing
95 $this->tabMenu = array();
96 }
97
98
106 public function showmenu($mode, $moredata = null)
107 {
108 global $user, $conf, $langs, $dolibarr_main_db_name;
109
110 $id = 'mainmenu';
111
112 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
113 $this->menu = new Menu();
114
115 $res = 'ErrorBadParameterForMode';
116
117 $noout = 0;
118 //if ($mode == 'jmobile') $noout=1;
119
120 if ($mode == 'topnb') {
121 return 1;
122 }
123
124 if ($mode == 'top') {
125 if (empty($noout)) {
127 }
128
129 $usemenuhider = 1;
130
131 // Show/Hide vertical menu
132 if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
133 $showmode = 1;
134 $classname = 'class="tmenu menuhider nohover"';
135 $idsel = 'menu';
136
137 $this->menu->add('#', '', 0, $showmode, $this->atarget, "xxx", '', 0, $id, $idsel, $classname);
138 }
139
140 // Home
141 $showmode = 1;
142 $classname = 'class="tmenusel"';
143 $idsel = 'home';
144
145 $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
146
147
148 // Sort on position
149 $this->menu->liste = dol_sort_array($this->menu->liste, 'position');
150
151 // Output menu entries
152 foreach ($this->menu->liste as $menkey => $menuval) {
153 if (empty($noout)) {
154 print_start_menu_entry_empty($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
155 }
156 if (empty($noout)) {
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 if (empty($noout)) {
160 print_end_menu_entry_empty($menuval['enabled']);
161 }
162 }
163
164 if (empty($noout) && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
165 print_start_menu_entry_empty('', 'class="tmenuend"', $showmode);
166 }
167 if (empty($noout)) {
169 }
170
171 if (empty($noout)) {
173 }
174
175 if ($mode == 'jmobile') {
176 $this->topmenu = clone $this->menu;
177 unset($this->menu->liste);
178 }
179 }
180
181 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
182 // Home
183 $showmode = 1;
184 $classname = 'class="tmenusel"';
185 $idsel = 'home';
186
187 $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
188
189 $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
190
191 // $this->menu->liste is top menu
192 //var_dump($this->menu->liste);exit;
193 $lastlevel = array();
194 $showmenu = true; // Is current menu shown - define here to keep static code checker happy
195 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
196 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
197 print '<ul class="ulmenu" data-inset="true">';
198 print '<li class="lilevel0">';
199
200 $val['url'] = make_substitutions($val['url'], $substitarray);
201
202 if ($val['enabled'] == 1) {
203 $relurl = dol_buildpath($val['url'], 1);
204 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
205
206 print '<a class="alilevel0" href="#">';
207
208 // Add font-awesome
209 if ($val['level'] == 0 && $val['mainmenu'] == 'home') {
210 print '<span class="fas fa-home fa-fw paddingright" aria-hidden="true"></span>';
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
221 $langs->load("admin"); // Load translation file admin.lang
222 $submenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
223 $submenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
224 $submenu->add("/admin/modules.php", $langs->trans("Modules"), 1);
225 $submenu->add("/admin/menus.php", $langs->trans("Menus"), 1);
226 $submenu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
227 $submenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
228 $submenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
229
230 $submenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
231 $submenu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
232 $submenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
233 $submenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
234 $submenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
235 $submenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
236 $submenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
237 $submenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
238 $submenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
239
240 //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
241 //var_dump($submenu); exit;
242 //}
243 //if ($tmpmainmenu=='accountancy') {
244 //var_dump($submenu->liste); exit;
245 //}
246 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
247
248 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
249 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
250
251 print '<ul>'."\n";
252 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
253 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
254 // We add sub entry
255 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
256 print '<a href="'.$relurl.'">';
257 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
258 if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) {
259 print $langs->trans("Access");
260 } else {
261 print $langs->trans("Dashboard");
262 }
263 } else {
264 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
265 }
266 print '</a>';
267 print '</li>'."\n";
268 }
269
270 if ($val['level'] == 0) {
271 if ($val['enabled']) {
272 $lastlevel[0] = 'enabled';
273 } elseif ($showmenu) { // Not enabled but visible (so greyed)
274 $lastlevel[0] = 'greyed';
275 } else {
276 $lastlevel[0] = 'hidden';
277 }
278 }
279
280 $lastlevel2 = array();
281 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
282 $showmenu = true;
283 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
284 $showmenu = false;
285 }
286
287 // If at least one parent is not enabled, we do not show any menu of all children
288 if ($val2['level'] > 0) {
289 $levelcursor = $val2['level'] - 1;
290 while ($levelcursor >= 0) {
291 // @phan-suppress-next-line PhanTypeInvalidDimOffset
292 if ($lastlevel2[$levelcursor] != 'enabled') {
293 $showmenu = false;
294 }
295 $levelcursor--;
296 }
297 }
298
299 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
300 $val2['url'] = make_substitutions($val2['url'], $substitarray);
301
302 $relurl2 = dol_buildpath($val2['url'], 1);
303 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
304 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
305 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
306 $relurl2 = '';
307 }
308
309 $disabled = '';
310 if (!$val2['enabled']) {
311 $disabled = " vsmenudisabled";
312 }
313
314 // @phan-suppress-next-line PhanParamSuspiciousOrder
315 print str_pad('', $val2['level'] + 1);
316 print '<li class="lilevel'.($val2['level'] + 1);
317 if ($val2['level'] == 0) {
318 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
319 }
320 print $disabled.'">'; // ui-btn to highlight on clic
321 if ($relurl2) {
322 if ($val2['enabled']) {
323 // Allowed
324 print '<a href="'.$relurl2.'">';
325 $lastlevel2[$val2['level']] = 'enabled';
326 } else {
327 // Not allowed but visible (greyed)
328 print '<a href="#" class="vsmenudisabled">';
329 $lastlevel2[$val2['level']] = 'greyed';
330 }
331 } else {
332 if ($val2['enabled']) { // Allowed
333 $lastlevel2[$val2['level']] = 'enabled';
334 } else {
335 $lastlevel2[$val2['level']] = 'greyed';
336 }
337 }
338 print $val2['titre'];
339 if ($relurl2) {
340 print '</a>';
341 }
342 print '</li>'."\n";
343 }
344 }
345 print '</ul>';
346 }
347 if ($val['enabled'] == 2) {
348 print '<span class="vsmenudisabled">'.$val['titre'].'</span>';
349 }
350 print '</li>';
351 print '</ul>'."\n";
352 }
353 }
354
355 if ($mode == 'left') {
356 // Put here left menu entries
357 // ***** START *****
358
359 $langs->load("admin"); // Load translation file admin.lang
360 $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
361 $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
362 $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
363 $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
364 $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
365 $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
366 $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
367
368 $this->menu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
369 $this->menu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
370 $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
371 $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
372 $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
373 $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
374 $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
375 $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
376 $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
377
378 // ***** END *****
379
380 $menu_array_before = array();
381 $menu_array_after = array();
382
383 // do not change code after this
384
385 $menu_array = $this->menu->liste;
386 if (is_array($menu_array_before)) {
387 $menu_array = array_merge($menu_array_before, $menu_array);
388 }
389 if (is_array($menu_array_after)) {
390 $menu_array = array_merge($menu_array, $menu_array_after);
391 }
392 //var_dump($menu_array);exit;
393 if (!is_array($menu_array)) {
394 return 0;
395 }
396
397 '@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,level?:int,prefix:string}> $menu_array';
398
399 if (empty($noout)) {
400 $alt = 0;
401 $altok = 0;
402 $blockvmenuopened = false;
403 $num = count($menu_array);
404 foreach (array_keys($menu_array) as $i) {
405 $alt++;
406 if (empty($menu_array[$i]['level'])) {
407 $altok++;
408 $blockvmenuopened = true;
409 $lastopened = true;
410 for ($j = ($i + 1); $j < $num; $j++) {
411 if (empty($menu_array[$j]['level'])) {
412 $lastopened = false;
413 }
414 }
415 $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
416 $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
417 if (($alt % 2 == 0)) {
418 print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
419 } else {
420 print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
421 }
422 }
423
424 // Add tabulation
425 $tabstring = '';
426 $tabul = ($menu_array[$i]['level'] - 1);
427 if ($tabul > 0) {
428 for ($j = 0; $j < $tabul; $j++) {
429 $tabstring .= '&nbsp; &nbsp;';
430 }
431 }
432
433 if ($menu_array[$i]['level'] == 0) {
434 if ($menu_array[$i]['enabled']) {
435 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";
436 } else {
437 print '<div class="menu_titre">'.$tabstring.'<span class="vmenudisabled">'.$menu_array[$i]['titre'].'</span></div>'."\n";
438 }
439 print '<div class="menu_top"></div>'."\n";
440 }
441
442 if ($menu_array[$i]['level'] > 0) {
443 $cssmenu = '';
444 if ($menu_array[$i]['url']) {
445 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
446 }
447
448 print '<div class="menu_contenu'.$cssmenu.'">';
449
450 if ($menu_array[$i]['enabled']) {
451 print $tabstring;
452 if ($menu_array[$i]['url']) {
453 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'].'"' : '').'>';
454 } else {
455 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
456 }
457 if ($menu_array[$i]['url']) {
458 print $menu_array[$i]['titre'].'</a>';
459 } else {
460 print '</span>';
461 }
462 } else {
463 print $tabstring.'<span class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span>';
464 }
465
466 // If title is not pure text and contains a table, no carriage return added
467 if (!strstr($menu_array[$i]['titre'], '<table')) {
468 print '<br>';
469 }
470 print '</div>'."\n";
471 }
472
473 // If next is a new block or end
474 if (empty($menu_array[$i + 1]['level'])) {
475 print '<div class="menu_end"></div>'."\n";
476 print "</div>\n";
477 }
478 }
479
480 if ($altok) {
481 print '<div class="blockvmenuend"></div>';
482 }
483 }
484
485 if ($mode == 'jmobile') {
486 $this->leftmenu = clone $this->menu;
487 unset($menu_array);
488 }
489 }
490 unset($this->menu);
491
492 return $res;
493 }
494}
495
496
503{
504 print '<div class="tmenudiv">';
505 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' title="Top menu"' : '').'>';
506}
507
516function print_start_menu_entry_empty($idsel, $classname, $showmode)
517{
518 if ($showmode) {
519 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
520 //print '<div class="tmenuleft tmenusep"></div>';
521 print '<div class="tmenucenter">';
522 }
523}
524
538function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
539{
540 global $conf, $langs;
541
542 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
543 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
544
545 if ($showmode == 1) {
546 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
547 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
548 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
549 print $menuval['prefix'];
550 } elseif (!empty($menuval['prefix']) && strpos($menuval['prefix'], 'fa-') === 0) {
551 print '<span class="'.$id.' '.$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
552 } else {
553 print '<span class="'.$id.' tmenuimageforpng" id="mainmenuspan_'.$idsel.'"></span>';
554 }
555 print '</div>';
556 print '</a>';
557 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
558 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
559 print '<span class="mainmenuaspan">';
560 print $text;
561 print '</span>';
562 print '</a>';
563 }
564 }
565 if ($showmode == 2) {
566 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
567 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
568 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
569 print '</div>';
570 print '</div>';
571 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
572 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
573 print '<span class="mainmenuaspan">';
574 print $text;
575 print '</span>';
576 print '</span>';
577 }
578 }
579}
580
587function print_end_menu_entry_empty($showmode)
588{
589 if ($showmode) {
590 print '</div></li>';
591 print "\n";
592 }
593}
594
601{
602 print '</ul>';
603 print '</div>';
604 print "\n";
605}
$id
Definition account.php:39
Class to manage left menus.
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
Definition empty.php:78
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition empty.php:92
showmenu($mode, $moredata=null)
Show menu.
Definition empty.php:106
print_end_menu_entry_empty($showmode)
Output end menu entry.
Definition empty.php:587
print_start_menu_array_empty()
Output menu entry.
Definition empty.php:502
print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval=array())
Output menu entry.
Definition empty.php:538
print_end_menu_array_empty()
Output menu array.
Definition empty.php:600
print_start_menu_entry_empty($idsel, $classname, $showmode)
Output start menu entry.
Definition empty.php:516
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.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
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...