dolibarr  16.0.5
empty.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
26 class MenuManager
27 {
31  public $db;
32 
33  public $type_user = 0; // Put 0 for internal users, 1 for external users
34  public $atarget = ""; // To store default target to use onto links
35  public $name = "empty";
36 
37  public $menu;
38  public $menu_array_after;
39 
40  public $tabMenu;
41 
42 
49  public function __construct($db, $type_user)
50  {
51  $this->type_user = $type_user;
52  $this->db = $db;
53  }
54 
55 
63  public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
64  {
65  // Do nothing
66  $this->tabMenu = array();
67  }
68 
69 
77  public function showmenu($mode, $moredata = null)
78  {
79  global $user, $conf, $langs, $dolibarr_main_db_name;
80 
81  $id = 'mainmenu';
82 
83  require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
84  $this->menu = new Menu();
85 
86  $res = 'ErrorBadParameterForMode';
87 
88  $noout = 0;
89  //if ($mode == 'jmobile') $noout=1;
90 
91  if ($mode == 'topnb') {
92  return 1;
93  }
94 
95  if ($mode == 'top') {
96  if (empty($noout)) {
98  }
99 
100  $usemenuhider = 1;
101 
102  // Show/Hide vertical menu
103  if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
104  $showmode = 1;
105  $classname = 'class="tmenu menuhider nohover"';
106  $idsel = 'menu';
107 
108  $this->menu->add('#', '', 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
109  }
110 
111  // Home
112  $showmode = 1;
113  $classname = 'class="tmenusel"';
114  $idsel = 'home';
115 
116  $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
117 
118 
119  // Sort on position
120  $this->menu->liste = dol_sort_array($this->menu->liste, 'position');
121 
122  // Output menu entries
123  foreach ($this->menu->liste as $menkey => $menuval) {
124  if (empty($noout)) {
125  print_start_menu_entry_empty($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
126  }
127  if (empty($noout)) {
128  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'] : $atarget));
129  }
130  if (empty($noout)) {
131  print_end_menu_entry_empty($menuval['enabled']);
132  }
133  }
134 
135  $showmode = 1;
136  if (empty($noout)) {
137  print_start_menu_entry_empty('', 'class="tmenuend"', $showmode);
138  }
139  if (empty($noout)) {
140  print_end_menu_entry_empty($showmode);
141  }
142 
143  if (empty($noout)) {
145  }
146 
147  if ($mode == 'jmobile') {
148  $this->topmenu = clone $this->menu;
149  unset($this->menu->liste);
150  }
151  }
152 
153  if ($mode == 'jmobile') { // Used to get menu in xml ul/li
154  // Home
155  $showmode = 1;
156  $classname = 'class="tmenusel"';
157  $idsel = 'home';
158 
159  $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
160 
161  $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
162 
163  // $this->menu->liste is top menu
164  //var_dump($this->menu->liste);exit;
165  $lastlevel = array();
166  print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
167  foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
168  print '<ul class="ulmenu" data-inset="true">';
169  print '<li class="lilevel0">';
170 
171  $val['url'] = make_substitutions($val['url'], $substitarray);
172 
173  if ($val['enabled'] == 1) {
174  $relurl = dol_buildpath($val['url'], 1);
175  $canonurl = preg_replace('/\?.*$/', '', $val['url']);
176 
177  print '<a class="alilevel0" href="#">';
178 
179  // Add font-awesome
180  if ($val['level'] == 0 && $val['mainmenu'] == 'home') {
181  print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>';
182  }
183 
184  print $val['titre'];
185  print '</a>'."\n";
186 
187  // Search submenu fot this mainmenu entry
188  $tmpmainmenu = $val['mainmenu'];
189  $tmpleftmenu = 'all';
190  $submenu = new Menu();
191 
192  $langs->load("admin"); // Load translation file admin.lang
193  $submenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
194  $submenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
195  $submenu->add("/admin/modules.php", $langs->trans("Modules"), 1);
196  $submenu->add("/admin/menus.php", $langs->trans("Menus"), 1);
197  $submenu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
198  $submenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
199  $submenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
200 
201  $submenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
202  $submenu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
203  $submenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
204  $submenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
205  $submenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
206  $submenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
207  $submenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
208  $submenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
209  $submenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
210 
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($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  print '<ul>'."\n";
224  if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
225  || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
226  // We add sub entry
227  print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
228  print '<a href="'.$relurl.'">';
229  if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
230  if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) {
231  print $langs->trans("Access");
232  } else {
233  print $langs->trans("Dashboard");
234  }
235  } else {
236  print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
237  }
238  print '</a>';
239  print '</li>'."\n";
240  }
241 
242  if ($val['level'] == 0) {
243  if ($val['enabled']) {
244  $lastlevel[0] = 'enabled';
245  } elseif ($showmenu) { // Not enabled but visible (so greyed)
246  $lastlevel[0] = 'greyed';
247  } else {
248  $lastlevel[0] = 'hidden';
249  }
250  }
251 
252  $lastlevel2 = array();
253  foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
254  $showmenu = true;
255  if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) {
256  $showmenu = false;
257  }
258 
259  // If at least one parent is not enabled, we do not show any menu of all children
260  if ($val2['level'] > 0) {
261  $levelcursor = $val2['level'] - 1;
262  while ($levelcursor >= 0) {
263  if ($lastlevel2[$levelcursor] != 'enabled') {
264  $showmenu = false;
265  }
266  $levelcursor--;
267  }
268  }
269 
270  if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
271  $val2['url'] = make_substitutions($val2['url'], $substitarray);
272 
273  $relurl2 = dol_buildpath($val2['url'], 1);
274  $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
275  //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
276  if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
277  $relurl2 = '';
278  }
279 
280  $disabled = '';
281  if (!$val2['enabled']) {
282  $disabled = " vsmenudisabled";
283  }
284 
285  print str_pad('', $val2['level'] + 1);
286  print '<li class="lilevel'.($val2['level'] + 1);
287  if ($val2['level'] == 0) {
288  print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
289  }
290  print $disabled.'">'; // ui-btn to highlight on clic
291  if ($relurl2) {
292  if ($val2['enabled']) {
293  // Allowed
294  print '<a href="'.$relurl2.'">';
295  $lastlevel2[$val2['level']] = 'enabled';
296  } else {
297  // Not allowed but visible (greyed)
298  print '<a href="#" class="vsmenudisabled">';
299  $lastlevel2[$val2['level']] = 'greyed';
300  }
301  } else {
302  if ($val2['enabled']) { // Allowed
303  $lastlevel2[$val2['level']] = 'enabled';
304  } else {
305  $lastlevel2[$val2['level']] = 'greyed';
306  }
307  }
308  //var_dump($val2['level']);
309  //var_dump($lastlevel2);
310  print $val2['titre'];
311  if ($relurl2) {
312  if ($val2['enabled']) {
313  // Allowed
314  print '</a>';
315  } else {
316  // Not allowed
317  print '</a>';
318  }
319  }
320  print '</li>'."\n";
321  }
322  }
323  //var_dump($submenu);
324  print '</ul>';
325  }
326  if ($val['enabled'] == 2) {
327  print '<span class="vsmenudisabled">'.$val['titre'].'</span>';
328  }
329  print '</li>';
330  print '</ul>'."\n";
331  }
332  }
333 
334  if ($mode == 'left') {
335  // Put here left menu entries
336  // ***** START *****
337 
338  $langs->load("admin"); // Load translation file admin.lang
339  $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
340  $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
341  $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
342  $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
343  $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
344  $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"), 1);
345  $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"), 1);
346 
347  $this->menu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"), 1);
348  $this->menu->add("/admin/delais.php?mainmenu=home", $langs->trans("Alerts"), 1);
349  $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
350  $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
351  $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
352  $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
353  $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
354  $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
355  $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
356 
357  // ***** END *****
358 
359  $menu_array_before = array();
360  $menu_array_after = array();
361 
362  // do not change code after this
363 
364  $menu_array = $this->menu->liste;
365  if (is_array($menu_array_before)) {
366  $menu_array = array_merge($menu_array_before, $menu_array);
367  }
368  if (is_array($menu_array_after)) {
369  $menu_array = array_merge($menu_array, $menu_array_after);
370  }
371  //var_dump($menu_array);exit;
372  if (!is_array($menu_array)) {
373  return 0;
374  }
375 
376  if (empty($noout)) {
377  $alt = 0;
378  $altok = 0;
379  $blockvmenuopened = false;
380  $num = count($menu_array);
381  for ($i = 0; $i < $num; $i++) {
382  $alt++;
383  if (empty($menu_array[$i]['level'])) {
384  $altok++;
385  $blockvmenuopened = true;
386  $lastopened = true;
387  for ($j = ($i + 1); $j < $num; $j++) {
388  if (empty($menu_array[$j]['level'])) {
389  $lastopened = false;
390  }
391  }
392  $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
393  $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
394  if (($alt % 2 == 0)) {
395  print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
396  } else {
397  print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened ? ' blockvmenulast' : '').($alt == 1 ? ' blockvmenufirst' : '').'">'."\n";
398  }
399  }
400 
401  // Add tabulation
402  $tabstring = '';
403  $tabul = ($menu_array[$i]['level'] - 1);
404  if ($tabul > 0) {
405  for ($j = 0; $j < $tabul; $j++) {
406  $tabstring .= '&nbsp; &nbsp;';
407  }
408  }
409 
410  if ($menu_array[$i]['level'] == 0) {
411  if ($menu_array[$i]['enabled']) {
412  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";
413  } else {
414  print '<div class="menu_titre">'.$tabstring.'<span class="vmenudisabled">'.$menu_array[$i]['titre'].'</span></div>'."\n";
415  }
416  print '<div class="menu_top"></div>'."\n";
417  }
418 
419  if ($menu_array[$i]['level'] > 0) {
420  $cssmenu = '';
421  if ($menu_array[$i]['url']) {
422  $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
423  }
424 
425  print '<div class="menu_contenu'.$cssmenu.'">';
426 
427  if ($menu_array[$i]['enabled']) {
428  print $tabstring;
429  if ($menu_array[$i]['url']) {
430  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'].'"' : '').'>';
431  } else {
432  print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
433  }
434  if ($menu_array[$i]['url']) {
435  print $menu_array[$i]['titre'].'</a>';
436  } else {
437  print '</span>';
438  }
439  } else {
440  print $tabstring.'<span class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span>';
441  }
442 
443  // If title is not pure text and contains a table, no carriage return added
444  if (!strstr($menu_array[$i]['titre'], '<table')) {
445  print '<br>';
446  }
447  print '</div>'."\n";
448  }
449 
450  // If next is a new block or end
451  if (empty($menu_array[$i + 1]['level'])) {
452  print '<div class="menu_end"></div>'."\n";
453  print "</div>\n";
454  }
455  }
456 
457  if ($altok) {
458  print '<div class="blockvmenuend"></div>';
459  }
460  }
461 
462  if ($mode == 'jmobile') {
463  $this->leftmenu = clone $this->menu;
464  unset($menu_array);
465  }
466  }
467  unset($this->menu);
468 
469  return $res;
470  }
471 }
472 
473 
480 {
481  global $conf;
482 
483  print '<div class="tmenudiv">';
484  print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>';
485 }
486 
495 function print_start_menu_entry_empty($idsel, $classname, $showmode)
496 {
497  if ($showmode) {
498  print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
499  //print '<div class="tmenuleft tmenusep"></div>';
500  print '<div class="tmenucenter">';
501  }
502 }
503 
516 function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget)
517 {
518  global $conf, $langs;
519 
520  $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
521  $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
522 
523  if ($showmode == 1) {
524  print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
525  print '<div class="'.$id.' '.$idsel.' topmenuimage"><span class="'.$id.' tmenuimageforpng" id="mainmenuspan_'.$idsel.'"></span></div>';
526  print '</a>';
527  if (empty($conf->global->THEME_TOPMENU_DISABLE_TEXT)) {
528  print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').'>';
529  print '<span class="mainmenuaspan">';
530  print $text;
531  print '</span>';
532  print '</a>';
533  }
534  }
535  if ($showmode == 2) {
536  print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
537  print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled"><span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span></div>';
538  print '</div>';
539  if (empty($conf->global->THEME_TOPMENU_DISABLE_TEXT)) {
540  print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
541  print '<span class="mainmenuaspan">';
542  print $text;
543  print '</span>';
544  print '</span>';
545  }
546  }
547 }
548 
555 function print_end_menu_entry_empty($showmode)
556 {
557  if ($showmode) {
558  print '</div></li>';
559  print "\n";
560  }
561 }
562 
569 {
570  print '</ul>';
571  print '</div>';
572  print "\n";
573 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
MenuManager\loadMenu
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition: empty.php:63
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
MenuManager
Class to manage menu Auguria.
Definition: auguria_menu.php:29
print_end_menu_entry_empty
print_end_menu_entry_empty($showmode)
Output end menu entry.
Definition: empty.php:555
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
print_end_menu_array_empty
print_end_menu_array_empty()
Output menu array.
Definition: empty.php:568
Menu
Class to manage left menus.
Definition: menu.class.php:29
print_start_menu_array_empty
print_start_menu_array_empty()
Output menu entry.
Definition: empty.php:479
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
print_start_menu_entry_empty
print_start_menu_entry_empty($idsel, $classname, $showmode)
Output start menu entry.
Definition: empty.php:495
print_text_menu_entry_empty
print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget)
Output menu entry.
Definition: empty.php:516
MenuManager\__construct
__construct($db, $type_user)
Constructor.
Definition: empty.php:49
MenuManager\showmenu
showmenu($mode, $moredata=null)
Show menu.
Definition: empty.php:77