dolibarr  19.0.1
auguria_menu.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
3  * Copyright (C) 2009 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
30 {
34  public $db;
35 
36  public $type_user; // Put 0 for internal users, 1 for external users
37  public $atarget = ""; // To store default target to use onto links
38  public $name = "auguria";
39 
43  public $menu;
44 
45  public $menu_array;
46  public $menu_array_after;
47 
48  public $tabMenu;
49 
50 
57  public function __construct($db, $type_user)
58  {
59  $this->type_user = $type_user;
60  $this->db = $db;
61  }
62 
63 
71  public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
72  {
73  global $conf, $user, $langs;
74 
75  // We save into session the main menu selected
76  if (GETPOSTISSET("mainmenu")) {
77  $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
78  }
79  if (GETPOSTISSET("idmenu")) {
80  $_SESSION["idmenu"] = GETPOST("idmenu", 'int');
81  }
82 
83  // Read now mainmenu and leftmenu that define which menu to show
84  if (GETPOSTISSET("mainmenu")) {
85  // On sauve en session le menu principal choisi
86  $mainmenu = GETPOST("mainmenu", 'aZ09');
87  $_SESSION["mainmenu"] = $mainmenu;
88  $_SESSION["leftmenuopened"] = "";
89  } else {
90  // On va le chercher en session si non defini par le lien
91  $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
92  }
93  if (!empty($forcemainmenu)) {
94  $mainmenu = $forcemainmenu;
95  }
96 
97  if (GETPOSTISSET("leftmenu")) {
98  // On sauve en session le menu principal choisi
99  $leftmenu = GETPOST("leftmenu", 'aZ09');
100  $_SESSION["leftmenu"] = $leftmenu;
101 
102  if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
103  //$leftmenu="";
104  $_SESSION["leftmenuopened"] = "";
105  } else {
106  $_SESSION["leftmenuopened"] = $leftmenu;
107  }
108  } else {
109  // On va le chercher en session si non defini par le lien
110  $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
111  }
112  if (!empty($forceleftmenu)) {
113  $leftmenu = $forceleftmenu;
114  }
115 
116  require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
117  $tabMenu = array();
118  $menuArbo = new Menubase($this->db, 'auguria');
119  $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
120  $this->tabMenu = $tabMenu;
121  //var_dump($tabMenu);
122 
123  //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
124  }
125 
126 
135  public function showmenu($mode, $moredata = null)
136  {
137  global $conf, $langs, $user;
138 
139  require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
140 
141  if ($this->type_user == 1) {
142  $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
143  $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
144  }
145 
146  require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
147  $this->menu = new Menu();
148 
149  if (!getDolGlobalString('MAIN_MENU_INVERT')) {
150  if ($mode == 'top') {
151  print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
152  }
153  if ($mode == 'left') {
154  print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
155  }
156  } else {
157  $conf->global->MAIN_SHOW_LOGO = 0;
158  if ($mode == 'top') {
159  print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
160  }
161  if ($mode == 'left') {
162  print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
163  }
164  }
165 
166  if ($mode == 'topnb') {
167  print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
168  return $this->menu->getNbOfVisibleMenuEntries();
169  }
170 
171  if ($mode == 'jmobile') { // Used to get menu in xml ul/li
172  print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
173 
174  // $this->menu->liste is top menu
175  //var_dump($this->menu->liste);exit;
176  $lastlevel = array();
177  $showmenu = true; // Is current menu shown - define here to keep static code checker happy
178  print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
179  foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
180  print '<ul class="ulmenu" data-inset="true">';
181  print '<li class="lilevel0">';
182  if ($val['enabled'] == 1) {
183  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
184  $substitarray['__USERID__'] = $user->id; // For backward compatibility
185  $val['url'] = make_substitutions($val['url'], $substitarray);
186 
187  $relurl = dol_buildpath($val['url'], 1);
188  $canonurl = preg_replace('/\?.*$/', '', $val['url']);
189 
190  print '<a class="alilevel0" href="#">';
191 
192  // Add font-awesome
193  if ($val['level'] == 0 && !empty($val['prefix'])) {
194  print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
195  }
196 
197  print $val['titre'];
198  print '</a>'."\n";
199 
200  // Search submenu fot this mainmenu entry
201  $tmpmainmenu = $val['mainmenu'];
202  $tmpleftmenu = 'all';
203  $submenu = new Menu();
204  print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
205  if (!empty($submenu->liste[0]['url'])) {
206  $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
207  } else {
208  $nexturl = '';
209  }
210 
211  $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
212  $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
213  //var_dump($canonrelurl);
214  //var_dump($canonnexturl);
215  print '<ul>'."\n";
216  if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
217  || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
218  // We add sub entry
219  print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
220  print '<a href="'.$relurl.'">';
221 
222  if ($val['level'] == 0) {
223  print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
224  }
225 
226  if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
227  if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
228  print $langs->trans("Access");
229  } else {
230  print $langs->trans("Dashboard");
231  }
232  } else {
233  print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
234  }
235  print '</a>';
236  print '</li>'."\n";
237  }
238 
239  if ($val['level'] == 0) {
240  if ($val['enabled']) {
241  $lastlevel[0] = 'enabled';
242  } elseif ($showmenu) { // Not enabled but visible (so greyed)
243  $lastlevel[0] = 'greyed';
244  } else {
245  $lastlevel[0] = 'hidden';
246  }
247  }
248 
249  $lastlevel2 = array();
250  foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
251  $showmenu = true;
252  if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
253  $showmenu = false;
254  }
255 
256  // If at least one parent is not enabled, we do not show any menu of all children
257  if ($val2['level'] > 0) {
258  $levelcursor = $val2['level'] - 1;
259  while ($levelcursor >= 0) {
260  if ($lastlevel2[$levelcursor] != 'enabled') {
261  $showmenu = false;
262  }
263  $levelcursor--;
264  }
265  }
266 
267  if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
268  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
269  $substitarray['__USERID__'] = $user->id; // For backward compatibility
270  $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
271 
272  if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
273  $relurl2 = dol_buildpath($val2['url'], 1);
274  } else {
275  $relurl2 = $val2['url'];
276  }
277  $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
278  //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
279  if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
280  $relurl2 = '';
281  }
282 
283  $disabled = '';
284  if (!$val2['enabled']) {
285  $disabled = " vsmenudisabled";
286  }
287 
288  print str_pad('', $val2['level'] + 1);
289  print '<li class="lilevel'.($val2['level'] + 1);
290  if ($val2['level'] == 0) {
291  print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
292  }
293  print $disabled.'">'; // ui-btn to highlight on clic
294  if ($relurl2) {
295  if ($val2['enabled']) { // Allowed
296  print '<a href="'.$relurl2.'"';
297  //print ' data-ajax="false"';
298  print '>';
299  $lastlevel2[$val2['level']] = 'enabled';
300  } else { // Not allowed but visible (greyed)
301  print '<a href="#" class="vsmenudisabled">';
302  $lastlevel2[$val2['level']] = 'greyed';
303  }
304  } else {
305  if ($val2['enabled']) { // Allowed
306  $lastlevel2[$val2['level']] = 'enabled';
307  } else {
308  $lastlevel2[$val2['level']] = 'greyed';
309  }
310  }
311 
312  if ($val2['level'] == 0 && !empty($val2['prefix'])) {
313  print $val2['prefix'];
314  } else {
315  print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
316  }
317 
318  print $val2['titre'];
319  if ($relurl2) {
320  if ($val2['enabled']) { // Allowed
321  print '</a>';
322  } else {
323  print '</a>';
324  }
325  }
326  print '</li>'."\n";
327  }
328  }
329  //var_dump($submenu);
330  print '</ul>';
331  }
332  if ($val['enabled'] == 2) {
333  print '<span class="spanlilevel0 vsmenudisabled">';
334 
335  // Add font-awesome
336  if ($val['level'] == 0 && !empty($val['prefix'])) {
337  print $val['prefix'];
338  }
339 
340  print $val['titre'];
341  print '</span>';
342  }
343  print '</li>';
344  print '</ul>'."\n";
345  }
346  }
347 
348  unset($this->menu);
349 
350  //print 'xx'.$mode;
351  return 0;
352  }
353 }
print_left_auguria_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 auguria Fill &$menu (example with $forcemainmenu='home' $forceleftm...
print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output top menu auguria.
Definition: auguria.lib.php:40
Class to manage left menus.
Definition: menu.class.php:30
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
showmenu($mode, $moredata=null)
Show menu.
Class to manage menu entries.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.