dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
16  */
17 
26 class MenuManager
27 {
31  public $db;
32 
33  var $type_user=0; // Put 0 for internal users, 1 for external users
34  var $atarget=""; // To store default target to use onto links
35 
36  var $menu;
37  var $menu_array_after;
38 
39 
46  function __construct($db, $type_user)
47  {
48  $this->type_user=$type_user;
49  $this->db=$db;
50  }
51 
52 
58  function loadMenu()
59  {
60  }
61 
62 
70  function showmenu($mode, $moredata=null)
71  {
72  global $user,$conf,$langs,$dolibarr_main_db_name;
73 
74  $id='mainmenu';
75 
76  require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
77  $this->menu=new Menu();
78 
79  $res='ErrorBadParameterForMode';
80 
81  $noout=0;
82  //if ($mode == 'jmobile') $noout=1;
83 
84  if ($mode == 'topnb')
85  {
86  return 1;
87  }
88 
89  if ($mode == 'top')
90  {
91  if (empty($noout)) print_start_menu_array_empty();
92 
93  $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER));
94 
95  // Show/Hide vertical menu
96  if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
97  {
98  $showmode=1;
99  $classname = 'class="tmenu menuhider"';
100  $idsel='menu';
101 
102  $this->menu->add('#', '', 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
103  }
104 
105  // Home
106  $showmode=1;
107  $classname='class="tmenusel"';
108  $idsel='home';
109 
110  $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
111 
112 
113  // Sort on position
114  $this->menu->liste = dol_sort_array($this->menu->liste, 'position');
115 
116  // Output menu entries
117  foreach($this->menu->liste as $menkey => $menuval)
118  {
119  if (empty($noout)) print_start_menu_entry_empty($menuval['idsel'],$menuval['classname'],$menuval['enabled']);
120  if (empty($noout)) 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));
121  if (empty($noout)) print_end_menu_entry_empty($menuval['enabled']);
122  }
123 
124  $showmode=1;
125  if (empty($noout)) print_start_menu_entry_empty('','class="tmenuend"',$showmode);
126  if (empty($noout)) print_end_menu_entry_empty($showmode);
127 
128  if (empty($noout)) print_end_menu_array_empty();
129 
130  if ($mode == 'jmobile')
131  {
132  $this->topmenu = clone $this->menu;
133  unset($this->menu->liste);
134  }
135  }
136 
137  if ($mode == 'jmobile') // Used to get menu in xml ul/li
138  {
139  // Home
140  $showmode=1;
141  $classname='class="tmenusel"';
142  $idsel='home';
143 
144  $this->menu->add('/index.php', $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '', 10, $id, $idsel, $classname);
145 
146 
147  // $this->menu->liste is top menu
148  //var_dump($this->menu->liste);exit;
149  $lastlevel = array();
150  print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
151  foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
152  {
153  print '<ul class="ulmenu" data-inset="true">';
154  print '<li class="lilevel0">';
155 
156  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
157  $substitarray['__USERID__'] = $user->id; // For backward compatibility
158  $val['url'] = make_substitutions($val['url'], $substitarray);
159 
160  if ($val['enabled'] == 1)
161  {
162  $relurl=dol_buildpath($val['url'],1);
163  $canonurl=preg_replace('/\?.*$/','',$val['url']);
164 
165  print '<a class="alilevel0" href="#">';
166 
167  // Add font-awesome
168  if ($val['level'] == 0 && $val['mainmenu'] == 'home') print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>';
169 
170  print $val['titre'];
171  print '</a>'."\n";
172 
173  // Search submenu fot this mainmenu entry
174  $tmpmainmenu=$val['mainmenu'];
175  $tmpleftmenu='all';
176  $submenu=new Menu();
177 
178  $langs->load("admin"); // Load translation file admin.lang
179  $submenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0);
180  $submenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1);
181  $submenu->add("/admin/modules.php", $langs->trans("Modules"),1);
182  $submenu->add("/admin/menus.php", $langs->trans("Menus"),1);
183  $submenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1);
184  $submenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"),1);
185  $submenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"),1);
186 
187  $submenu->add("/admin/boxes.php", $langs->trans("Boxes"),1);
188  $submenu->add("/admin/delais.php",$langs->trans("Alerts"),1);
189  $submenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1);
190  $submenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1);
191  $submenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1);
192  $submenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1);
193  $submenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"),1);
194  $submenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"),1);
195  $submenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"),1);
196 
197  //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; }
198  //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; }
199  $nexturl=dol_buildpath($submenu->liste[0]['url'],1);
200 
201  $canonrelurl=preg_replace('/\?.*$/','',$relurl);
202  $canonnexturl=preg_replace('/\?.*$/','',$nexturl);
203  //var_dump($canonrelurl);
204  //var_dump($canonnexturl);
205  print '<ul>'."\n";
206  if (($canonrelurl != $canonnexturl && ! in_array($val['mainmenu'],array('tools')))
207  || (strpos($canonrelurl,'/product/index.php') !== false || strpos($canonrelurl,'/compta/bank/list.php') !== false))
208  {
209  // We add sub entry
210  print str_pad('',1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
211  print '<a href="'.$relurl.'">';
212  if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation
213  {
214  if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) print $langs->trans("Access");
215  else print $langs->trans("Dashboard");
216  }
217  else print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
218  print '</a>';
219  print '</li>'."\n";
220  }
221 
222  if ($val['level']==0)
223  {
224  if ($val['enabled'])
225  {
226  $lastlevel[0]='enabled';
227  }
228  else if ($showmenu) // Not enabled but visible (so greyed)
229  {
230  $lastlevel[0]='greyed';
231  }
232  else
233  {
234  $lastlevel[0]='hidden';
235  }
236  }
237 
238  $lastlevel2 = array();
239  foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
240  {
241  $showmenu=true;
242  if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) $showmenu=false;
243 
244  // If at least one parent is not enabled, we do not show any menu of all children
245  if ($val2['level'] > 0)
246  {
247  $levelcursor = $val2['level']-1;
248  while ($levelcursor >= 0)
249  {
250  if ($lastlevel2[$levelcursor] != 'enabled') $showmenu=false;
251  $levelcursor--;
252  }
253  }
254 
255  if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
256  {
257  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
258  $substitarray['__USERID__'] = $user->id; // For backward compatibility
259  $val2['url'] = make_substitutions($val2['url'], $substitarray);
260 
261  $relurl2=dol_buildpath($val2['url'],1);
262  $canonurl2=preg_replace('/\?.*$/','',$val2['url']);
263  //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
264  if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
265 
266  $disabled='';
267  if (! $val2['enabled'])
268  {
269  $disabled=" vsmenudisabled";
270  }
271 
272  print str_pad('',$val2['level']+1);
273  print '<li class="lilevel'.($val2['level']+1);
274  if ($val2['level']==0) print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
275  print $disabled.'">'; // ui-btn to highlight on clic
276  if ($relurl2)
277  {
278  if ($val2['enabled']) // Allowed
279  {
280  print '<a href="'.$relurl2.'"';
281  //print ' data-ajax="false"';
282  print '>';
283  $lastlevel2[$val2['level']]='enabled';
284  }
285  else // Not allowed but visible (greyed)
286  {
287  print '<a href="#" class="vsmenudisabled">';
288  $lastlevel2[$val2['level']]='greyed';
289  }
290  }
291  else
292  {
293  if ($val2['enabled']) // Allowed
294  {
295  $lastlevel2[$val2['level']]='enabled';
296  }
297  else
298  {
299  $lastlevel2[$val2['level']]='greyed';
300  }
301  }
302  //var_dump($val2['level']);
303  //var_dump($lastlevel2);
304  print $val2['titre'];
305  if ($relurl2)
306  {
307  if ($val2['enabled']) // Allowed
308  print '</a>';
309  else
310  print '</a>';
311  }
312  print '</li>'."\n";
313  }
314  }
315  //var_dump($submenu);
316  print '</ul>';
317  }
318  if ($val['enabled'] == 2)
319  {
320  print '<font class="vsmenudisabled">'.$val['titre'].'</font>';
321  }
322  print '</li>';
323  print '</ul>'."\n";
324  }
325  }
326 
327  if ($mode == 'left')
328  {
329  // Put here left menu entries
330  // ***** START *****
331 
332  $langs->load("admin"); // Load translation file admin.lang
333  $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0);
334  $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1);
335  $this->menu->add("/admin/modules.php", $langs->trans("Modules"),1);
336  $this->menu->add("/admin/menus.php", $langs->trans("Menus"),1);
337  $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"),1);
338  $this->menu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"),1);
339  $this->menu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"),1);
340 
341  $this->menu->add("/admin/boxes.php", $langs->trans("Boxes"),1);
342  $this->menu->add("/admin/delais.php",$langs->trans("Alerts"),1);
343  $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1);
344  $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1);
345  $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1);
346  $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1);
347  $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"),1);
348  $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"),1);
349  $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"),1);
350 
351  // ***** END *****
352 
353  // do not change code after this
354 
355  if (empty($noout))
356  {
357  $alt=0; $altok=0; $blockvmenuopened=false;
358  $num=count($this->menu->liste);
359  for ($i = 0; $i < $num; $i++)
360  {
361  $alt++;
362  if (empty($this->menu->liste[$i]['level']))
363  {
364  $altok++;
365  $blockvmenuopened=true;
366  $lastopened=true;
367  for($j = ($i + 1); $j < $num; $j++)
368  {
369  if (empty($menu_array[$j]['level'])) $lastopened=false;
370  }
371  $alt = 0; // For menu manager "empty", we force to not have blockvmenufirst defined
372  $lastopened = 1; // For menu manager "empty", we force to not have blockvmenulast defined
373  if (($alt%2==0))
374  {
375  print '<div class="blockvmenub lockvmenuimpair blockvmenuunique'.($lastopened?' blockvmenulast':'').($alt == 1 ? ' blockvmenufirst':'').'">'."\n";
376  }
377  else
378  {
379  print '<div class="blockvmenu blockvmenupair blockvmenuunique'.($lastopened?' blockvmenulast':'').($alt == 1 ? ' blockvmenufirst':'').'">'."\n";
380  }
381  }
382 
383  // Add tabulation
384  $tabstring='';
385  $tabul=($this->menu->liste[$i]['level'] - 1);
386  if ($tabul > 0)
387  {
388  for ($j=0; $j < $tabul; $j++)
389  {
390  $tabstring.='&nbsp; &nbsp;';
391  }
392  }
393 
394  if ($this->menu->liste[$i]['level'] == 0) {
395  if ($this->menu->liste[$i]['enabled'])
396  {
397  print '<div class="menu_titre">'.$tabstring.'<a class="vmenu" href="'.dol_buildpath($this->menu->liste[$i]['url'],1).'"'.($this->menu->liste[$i]['target']?' target="'.$this->menu->liste[$i]['target'].'"':'').'>'.$this->menu->liste[$i]['titre'].'</a></div>'."\n";
398  }
399  else
400  {
401  print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$this->menu->liste[$i]['titre'].'</font></div>'."\n";
402  }
403  print '<div class="menu_top"></div>'."\n";
404  }
405 
406  if ($this->menu->liste[$i]['level'] > 0)
407  {
408  $cssmenu = '';
409  if ($this->menu->liste[$i]['url']) $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/','',$this->menu->liste[$i]['url']));
410 
411  print '<div class="menu_contenu'.$cssmenu.'">';
412 
413  if ($this->menu->liste[$i]['enabled'])
414  {
415  print $tabstring;
416  if ($this->menu->liste[$i]['url']) print '<a class="vsmenu" href="'.dol_buildpath($this->menu->liste[$i]['url'],1).'"'.($this->menu->liste[$i]['target']?' target="'.$this->menu->liste[$i]['target'].'"':'').'>';
417  else print '<span class="vsmenu">';
418  if ($this->menu->liste[$i]['url']) print $this->menu->liste[$i]['titre'].'</a>';
419  else print '</span>';
420  }
421  else
422  {
423  print $tabstring.'<font class="vsmenudisabled vsmenudisabledmargin">'.$this->menu->liste[$i]['titre'].'</font>';
424  }
425 
426  // If title is not pure text and contains a table, no carriage return added
427  if (! strstr($this->menu->liste[$i]['titre'],'<table')) print '<br>';
428  print '</div>'."\n";
429  }
430 
431  // If next is a new block or end
432  if (empty($this->menu->liste[$i+1]['level']))
433  {
434  print '<div class="menu_end"></div>'."\n";
435  print "</div>\n";
436  }
437  }
438 
439  if ($altok) print '<div class="blockvmenuend"></div>';
440  }
441 
442  if ($mode == 'jmobile')
443  {
444  $this->leftmenu = clone $this->menu;
445  unset($this->menu->liste);
446  }
447  }
448 /*
449  if ($mode == 'jmobile')
450  {
451  foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
452  {
453  print '<ul class="ulmenu" data-inset="true">';
454  print '<li class="lilevel0">';
455 
456  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
457  $substitarray['__USERID__'] = $user->id; // For backward compatibility
458  $val['url'] = make_substitutions($val['url'], $substitarray);
459 
460  if ($val['enabled'] == 1)
461  {
462  $relurl=dol_buildpath($val['url'],1);
463 
464  print '<a href="#">'.$val['titre'].'</a>'."\n";
465  // Search submenu fot this entry
466  $tmpmainmenu=$val['mainmenu'];
467  $tmpleftmenu='all';
468  //$submenu=new Menu();
469  //$res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$submenu,1,$tmpmainmenu,$tmpleftmenu);
470  //$nexturl=dol_buildpath($submenu->liste[0]['url'],1);
471  $submenu=$this->leftmenu;
472 
473  $canonrelurl=preg_replace('/\?.*$/','',$relurl);
474  $canonnexturl=preg_replace('/\?.*$/','',$nexturl);
475  //var_dump($canonrelurl);
476  //var_dump($canonnexturl);
477  print '<ul>';
478  if ($canonrelurl != $canonnexturl && ! in_array($val['mainmenu'],array('home','tools')))
479  {
480  // We add sub entry
481  print '<li><a href="'.$relurl.'">'.$langs->trans("MainArea").'-'.$val['titre'].'</a></li>'."\n";
482  }
483  foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
484  {
485  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
486  $substitarray['__USERID__'] = $user->id; // For backward compatibility
487  $val2['url'] = make_substitutions($val2['url'], $substitarray);
488 
489  $relurl2=dol_buildpath($val2['url'],1);
490  //var_dump($val2);
491  print '<li><a href="'.$relurl2.'">'.$val2['titre'].'</a></li>'."\n";
492  }
493  //var_dump($submenu);
494  print '</ul>';
495  }
496  if ($val['enabled'] == 2)
497  {
498  print '<font class="vsmenudisabled">'.$val['titre'].'</font>';
499  }
500  print '</li>';
501  print '</ul>'."\n";
502 
503  break; // Only first menu entry (so home)
504  }
505  }
506 */
507  unset($this->menu);
508 
509  return $res;
510  }
511 }
512 
513 
520 {
521  global $conf;
522 
523  print '<div class="tmenudiv">';
524  print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?'':' title="Top menu"').'>';
525 }
526 
535 function print_start_menu_entry_empty($idsel,$classname,$showmode)
536 {
537  if ($showmode)
538  {
539  print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
540  //print '<div class="tmenuleft tmenusep"></div>';
541  print '<div class="tmenucenter">';
542  }
543 }
544 
557 function print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget)
558 {
559  global $conf,$langs;
560 
561  if ($showmode == 1)
562  {
563  print '<a class="tmenuimage" tabindex="-1" href="'.$url.'"'.($atarget?' target="'.$atarget.'"':'').'>';
564  print '<div class="'.$id.' '.$idsel.'"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>';
565  print '</a>';
566  print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget?' target="'.$atarget.'"':'').'>';
567  print '<span class="mainmenuaspan">';
568  print $text;
569  print '</span>';
570  print '</a>';
571  }
572  if ($showmode == 2)
573  {
574  print '<div class="'.$id.' '.$idsel.' tmenudisabled"><span class="'.$id.'" id="mainmenuspan_'.$idsel.'"></span></div>';
575  print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">';
576  }
577 }
578 
585 function print_end_menu_entry_empty($showmode)
586 {
587  if ($showmode)
588  {
589  print '</div></li>';
590  print "\n";
591  }
592 }
593 
600 {
601  print '</ul>';
602  print '</div>';
603  print "\n";
604 }
605 
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
print_end_menu_entry_empty($showmode)
Output end menu entry.
Definition: empty.php:585
Class to manage left menus.
Definition: menu.class.php:29
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...
Class to manage menu Auguria.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
print_end_menu_array_empty()
Output menu array.
Definition: empty.php:599
print_start_menu_entry_empty($idsel, $classname, $showmode)
Output start menu entry.
Definition: empty.php:535
print_text_menu_entry_empty($text, $showmode, $url, $id, $idsel, $classname, $atarget)
Output menu entry.
Definition: empty.php:557
print_start_menu_array_empty()
Output menu entry.
Definition: empty.php:519
__construct($db, $type_user)
Constructor.
Definition: empty.php:46
showmenu($mode, $moredata=null)
Show menu.
Definition: empty.php:70
loadMenu()
Load this->tabMenu.
Definition: empty.php:58
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...