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