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