dolibarr  17.0.4
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@inodbox.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 
28 class MenuManager
29 {
33  public $db;
34 
35  public $type_user; // Put 0 for internal users, 1 for external users
36  public $atarget = ""; // To store default target to use onto links
37  public $name = "eldy";
38 
39  public $menu_array;
40  public $menu_array_after;
41 
42  public $tabMenu;
43 
44 
51  public function __construct($db, $type_user)
52  {
53  $this->type_user = $type_user;
54  $this->db = $db;
55  }
56 
57 
65  public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
66  {
67  global $conf, $user, $langs;
68 
69  // We save into session the main menu selected
70  if (GETPOSTISSET("mainmenu")) {
71  $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
72  }
73  if (GETPOSTISSET("idmenu")) {
74  $_SESSION["idmenu"] = GETPOST("idmenu", 'int');
75  }
76 
77  // Read now mainmenu and leftmenu that define which menu to show
78  if (GETPOSTISSET("mainmenu")) {
79  // On sauve en session le menu principal choisi
80  $mainmenu = GETPOST("mainmenu", 'aZ09');
81  $_SESSION["mainmenu"] = $mainmenu;
82  $_SESSION["leftmenuopened"] = "";
83  } else {
84  // On va le chercher en session si non defini par le lien
85  $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
86  }
87  if (!empty($forcemainmenu)) {
88  $mainmenu = $forcemainmenu;
89  }
90 
91  if (GETPOSTISSET("leftmenu")) {
92  // On sauve en session le menu principal choisi
93  $leftmenu = GETPOST("leftmenu", 'aZ09');
94  $_SESSION["leftmenu"] = $leftmenu;
95 
96  if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
97  //$leftmenu="";
98  $_SESSION["leftmenuopened"] = "";
99  } else {
100  $_SESSION["leftmenuopened"] = $leftmenu;
101  }
102  } else {
103  // On va le chercher en session si non defini par le lien
104  $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
105  }
106  if (!empty($forceleftmenu)) {
107  $leftmenu = $forceleftmenu;
108  }
109 
110  require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
111  $tabMenu = array();
112  $menuArbo = new Menubase($this->db, 'eldy');
113  $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu);
114  $this->tabMenu = $tabMenu;
115  //var_dump($tabMenu);
116 
117  //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
118  }
119 
120 
129  public function showmenu($mode, $moredata = null)
130  {
131  global $conf, $langs, $user;
132 
133  //var_dump($this->tabMenu);
134 
135  require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
136 
137  if ($this->type_user == 1) {
138  $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
139  $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
140  }
141 
142  require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
143  $this->menu = new Menu();
144 
145  if (empty($conf->global->MAIN_MENU_INVERT)) {
146  if ($mode == 'top') {
147  print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
148  }
149  if ($mode == 'left') {
150  print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
151  }
152  } else {
153  $conf->global->MAIN_SHOW_LOGO = 0;
154  if ($mode == 'top') {
155  print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata, $this->type_user);
156  }
157  if ($mode == 'left') {
158  print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
159  }
160  }
161  if ($mode == 'topnb') {
162  print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output
163  return $this->menu->getNbOfVisibleMenuEntries();
164  }
165 
166  if ($mode == 'jmobile') { // Used to get menu in xml ul/li
167  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
168 
169  // $this->menu->liste is top menu
170  //var_dump($this->menu->liste);exit;
171  $lastlevel = array();
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  if ($val['enabled'] == 1) {
178  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
179  $substitarray['__USERID__'] = $user->id; // For backward compatibility
180  $val['url'] = make_substitutions($val['url'], $substitarray);
181 
182  $relurl = dol_buildpath($val['url'], 1);
183  $canonurl = preg_replace('/\?.*$/', '', $val['url']);
184 
185  print '<a class="alilevel0" href="#">';
186 
187  // Add font-awesome
188  if ($val['level'] == 0 && !empty($val['prefix'])) {
189  print $val['prefix'];
190  }
191 
192  print $val['titre'];
193  print '</a>'."\n";
194 
195  // Search submenu fot this mainmenu entry
196  $tmpmainmenu = $val['mainmenu'];
197  $tmpleftmenu = 'all';
198  $submenu = new Menu();
199  print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu, null, $this->type_user); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home)
200  // Note: $submenu contains menu entry with substitution not yet done
201  //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') {
202  //var_dump($submenu); exit;
203  //}
204  //if ($tmpmainmenu=='accountancy') {
205  //var_dump($submenu->liste); exit;
206  //}
207  $nexturl = dol_buildpath(empty($submenu->liste[0]['url']) ? '' : $submenu->liste[0]['url'], 1);
208 
209  $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
210  $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
211  //var_dump($canonrelurl);
212  //var_dump($canonnexturl);
213 
214  print '<ul>'."\n";
215  if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
216  || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
217  // We add sub entry
218  print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
219  print '<a href="'.$relurl.'">';
220 
221  if ($val['level'] == 0) {
222  print '<span class="fa fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
223  }
224 
225  if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
226  if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
227  print $langs->trans("Access");
228  } else {
229  print $langs->trans("Dashboard");
230  }
231  } else {
232  print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
233  }
234  print '</a>';
235  print '</li>'."\n";
236  }
237 
238  /*
239  if ($val['level'] == 0) {
240  if ($val['enabled']) {
241  $lastlevel[0] = 'enabled';
242  } elseif ($showmenu) {
243  // Not enabled but visible (so greyed)
244  $lastlevel[0] = 'greyed';
245  } else {
246  $lastlevel[0] = 'hidden';
247  }
248  }
249  */
250 
251  $lastlevel2 = array();
252  foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
253  $showmenu = true;
254  if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) {
255  $showmenu = false;
256  }
257 
258  // If at least one parent is not enabled, we do not show any menu of all children
259  if ($val2['level'] > 0) {
260  $levelcursor = $val2['level'] - 1;
261  while ($levelcursor >= 0) {
262  if ($lastlevel2[$levelcursor] != 'enabled') {
263  $showmenu = false;
264  }
265  $levelcursor--;
266  }
267  }
268 
269  if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
270  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
271  $substitarray['__USERID__'] = $user->id; // For backward compatibility
272  $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
273 
274  if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
275  $relurl2 = dol_buildpath($val2['url'], 1);
276  } else {
277  $relurl2 = $val2['url'];
278  }
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  print str_pad('', $val2['level'] + 1);
291  print '<li class="lilevel'.($val2['level'] + 1);
292  if ($val2['level'] == 0) {
293  print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
294  }
295  print $disabled.'">'; // ui-btn to highlight on clic
296  if ($relurl2) {
297  if ($val2['enabled']) { // Allowed
298  print '<a href="'.$relurl2.'"';
299  //print ' data-ajax="false"';
300  print '>';
301  $lastlevel2[$val2['level']] = 'enabled';
302  } else // Not allowed but visible (greyed)
303  {
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 
315  // Add font-awesome
316  if ($val2['level'] == 0 && !empty($val2['prefix'])) {
317  print $val2['prefix'];
318  }
319 
320  print $val2['titre'];
321  if ($relurl2) {
322  if ($val2['enabled']) { // Allowed
323  print '</a>';
324  } else {
325  print '</a>';
326  }
327  }
328  print '</li>'."\n";
329  }
330  }
331  //var_dump($submenu);
332  print '</ul>';
333  }
334  if ($val['enabled'] == 2) {
335  print '<span class="spanlilevel0 vsmenudisabled">';
336 
337  // Add font-awesome
338  if ($val['level'] == 0 && !empty($val['prefix'])) {
339  print $val['prefix'];
340  }
341 
342  print $val['titre'];
343  print '</span>';
344  }
345  print '</li>';
346  print '</ul>'."\n";
347  }
348  }
349 
350  unset($this->menu);
351 
352  //print 'xx'.$mode;
353  return 0;
354  }
355 }
Class to manage left menus.
Definition: menu.class.php:30
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
Definition: eldy_menu.php:51
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Definition: eldy_menu.php:65
showmenu($mode, $moredata=null)
Show menu.
Definition: eldy_menu.php:129
Class to manage menu entries.
print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output top menu eldy.
Definition: eldy.lib.php:45
print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout=0, $forcemainmenu='', $forceleftmenu='', $moredata=null, $type_user=0)
Core function to output left menu eldy Fill &$menu (example with $forcemainmenu='home' $forceleftmenu...
Definition: eldy.lib.php:714
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
$conf db
API class for accounts.
Definition: inc.php:41