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