dolibarr  7.0.0-beta
eldy_menu.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2007-2009 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
17  */
18 
28 class MenuManager
29 {
30  var $db;
31  var $type_user; // Put 0 for internal users, 1 for external users
32  var $atarget=""; // To store default target to use onto links
33  var $name="eldy";
34 
35  var $menu_array;
36  var $menu_array_after;
37 
38  var $tabMenu;
39 
40 
47  function __construct($db, $type_user)
48  {
49  $this->type_user=$type_user;
50  $this->db=$db;
51  }
52 
53 
61  function loadMenu($forcemainmenu='',$forceleftmenu='')
62  {
63  // On sauve en session le menu principal choisi
64  if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"];
65  if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"];
66 
67  // Read mainmenu and leftmenu that define which menu to show
68  if (isset($_GET["mainmenu"]))
69  {
70  // On sauve en session le menu principal choisi
71  $mainmenu=$_GET["mainmenu"];
72  $_SESSION["mainmenu"]=$mainmenu;
73  $_SESSION["leftmenuopened"]="";
74  }
75  else
76  {
77  // On va le chercher en session si non defini par le lien
78  $mainmenu=isset($_SESSION["mainmenu"])?$_SESSION["mainmenu"]:'';
79  }
80  if (! empty($forcemainmenu)) $mainmenu=$forcemainmenu;
81 
82  if (isset($_GET["leftmenu"]))
83  {
84  // On sauve en session le menu principal choisi
85  $leftmenu=$_GET["leftmenu"];
86  $_SESSION["leftmenu"]=$leftmenu;
87 
88  if ($_SESSION["leftmenuopened"]==$leftmenu) // To collapse
89  {
90  //$leftmenu="";
91  $_SESSION["leftmenuopened"]="";
92  }
93  else
94  {
95  $_SESSION["leftmenuopened"]=$leftmenu;
96  }
97  } else {
98  // On va le chercher en session si non defini par le lien
99  $leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:'';
100  }
101  if (! empty($forceleftmenu)) $leftmenu=$forceleftmenu;
102 
103  require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
104  $tabMenu=array();
105  $menuArbo = new Menubase($this->db,'eldy');
106  $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
107  $this->tabMenu=$tabMenu;
108 
109  //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
110  }
111 
112 
120  function showmenu($mode, $moredata=null)
121  {
122  global $conf, $langs, $user;
123 
124  require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
125 
126  if ($this->type_user == 1)
127  {
128  $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED=1;
129  $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED=1;
130  }
131 
132  require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
133  $this->menu=new Menu();
134 
135  if (empty($conf->global->MAIN_MENU_INVERT))
136  {
137  if ($mode == 'top') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode);
138  if ($mode == 'left') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0,'','',$moredata);
139  }
140  else
141  {
142  $conf->global->MAIN_SHOW_LOGO=0;
143  if ($mode == 'top') print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0);
144  if ($mode == 'left') print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode);
145  }
146 
147  if ($mode == 'topnb')
148  {
149  print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // no output
150  return $this->menu->getNbOfVisibleMenuEntries();
151  }
152 
153  if ($mode == 'jmobile') // Used to get menu in xml ul/li
154  {
155  print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); // Fill this->menu that is empty with top menu
156 
157  // $this->menu->liste is top menu
158  //var_dump($this->menu->liste);exit;
159  $lastlevel = array();
160  print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
161  foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
162  {
163  print '<ul class="ulmenu" data-inset="true">';
164  print '<li class="lilevel0">';
165 
166  if ($val['enabled'] == 1)
167  {
168  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
169  $substitarray['__USERID__'] = $user->id; // For backward compatibility
170  $val['url'] = make_substitutions($val['url'], $substitarray);
171 
172  $relurl=dol_buildpath($val['url'],1);
173  $canonurl=preg_replace('/\?.*$/','',$val['url']);
174 
175  print '<a class="alilevel0" href="#">';
176 
177  // Add font-awesome
178  if ($val['level'] == 0 && $val['mainmenu'] == 'home') print '<span class="fa fa-home fa-fw paddingright" aria-hidden="true"></span>';
179 
180  print $val['titre'];
181  print '</a>'."\n";
182 
183  // Search submenu fot this mainmenu entry
184  $tmpmainmenu=$val['mainmenu'];
185  $tmpleftmenu='all';
186  $submenu=new Menu();
187  print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$submenu,1,$tmpmainmenu,$tmpleftmenu); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home)
188  //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; }
189  //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; }
190  $nexturl=dol_buildpath($submenu->liste[0]['url'],1);
191 
192  $canonrelurl=preg_replace('/\?.*$/','',$relurl);
193  $canonnexturl=preg_replace('/\?.*$/','',$nexturl);
194  //var_dump($canonrelurl);
195  //var_dump($canonnexturl);
196  print '<ul>'."\n";
197  if (($canonrelurl != $canonnexturl && ! in_array($val['mainmenu'],array('tools')))
198  || (strpos($canonrelurl,'/product/index.php') !== false || strpos($canonrelurl,'/compta/bank/list.php') !== false))
199  {
200  // We add sub entry
201  print str_pad('',1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
202  print '<a href="'.$relurl.'">';
203  if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation
204  {
205  if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab'))) print $langs->trans("Access");
206  else print $langs->trans("Dashboard");
207  }
208  else print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
209  print '</a>';
210  print '</li>'."\n";
211  }
212 
213  if ($val['level']==0)
214  {
215  if ($val['enabled'])
216  {
217  $lastlevel[0]='enabled';
218  }
219  else if ($showmenu) // Not enabled but visible (so greyed)
220  {
221  $lastlevel[0]='greyed';
222  }
223  else
224  {
225  $lastlevel[0]='hidden';
226  }
227  }
228 
229  $lastlevel2 = array();
230  foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
231  {
232  $showmenu=true;
233  if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) $showmenu=false;
234 
235  // If at least one parent is not enabled, we do not show any menu of all children
236  if ($val2['level'] > 0)
237  {
238  $levelcursor = $val2['level']-1;
239  while ($levelcursor >= 0)
240  {
241  if ($lastlevel2[$levelcursor] != 'enabled') $showmenu=false;
242  $levelcursor--;
243  }
244  }
245 
246  if ($showmenu) // Visible (option to hide when not allowed is off or allowed)
247  {
248  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
249  $substitarray['__USERID__'] = $user->id; // For backward compatibility
250  $val2['url'] = make_substitutions($val2['url'], $substitarray);
251 
252  $relurl2=dol_buildpath($val2['url'],1);
253  $canonurl2=preg_replace('/\?.*$/','',$val2['url']);
254  //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
255  if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2='';
256 
257  $disabled='';
258  if (! $val2['enabled'])
259  {
260  $disabled=" vsmenudisabled";
261  }
262 
263  print str_pad('',$val2['level']+1);
264  print '<li class="lilevel'.($val2['level']+1);
265  if ($val2['level']==0) print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
266  print $disabled.'">'; // ui-btn to highlight on clic
267  if ($relurl2)
268  {
269  if ($val2['enabled']) // Allowed
270  {
271  print '<a href="'.$relurl2.'"';
272  //print ' data-ajax="false"';
273  print '>';
274  $lastlevel2[$val2['level']]='enabled';
275  }
276  else // Not allowed but visible (greyed)
277  {
278  print '<a href="#" class="vsmenudisabled">';
279  $lastlevel2[$val2['level']]='greyed';
280  }
281  }
282  else
283  {
284  if ($val2['enabled']) // Allowed
285  {
286  $lastlevel2[$val2['level']]='enabled';
287  }
288  else
289  {
290  $lastlevel2[$val2['level']]='greyed';
291  }
292  }
293  //var_dump($val2['level']);
294  //var_dump($lastlevel2);
295  print $val2['titre'];
296  if ($relurl2)
297  {
298  if ($val2['enabled']) // Allowed
299  print '</a>';
300  else
301  print '</a>';
302  }
303  print '</li>'."\n";
304  }
305 
306 
307  }
308  //var_dump($submenu);
309  print '</ul>';
310  }
311  if ($val['enabled'] == 2)
312  {
313  print '<font class="vsmenudisabled">'.$val['titre'].'</font>';
314  }
315  print '</li>';
316  print '</ul>'."\n";
317  }
318  }
319 
320  unset($this->menu);
321 
322  //print 'xx'.$mode;
323  return 0;
324  }
325 
326 }
327 
Class to manage left menus.
Definition: menu.class.php:29
print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout=0, $forcemainmenu='', $forceleftmenu='', $moredata=null)
Core function to output left menu eldy Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='al...
Definition: eldy.lib.php:451
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition: eldy_menu.php:61
Class to manage menu entries.
Class to manage menu Auguria.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output top menu eldy.
Definition: eldy.lib.php:42
__construct($db, $type_user)
Constructor.
Definition: eldy_menu.php:47
print
Draft customers invoices.
Definition: index.php:91
showmenu($mode, $moredata=null)
Show menu.
Definition: eldy_menu.php:120
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...