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