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