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