dolibarr 18.0.6
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 // On sauve en session le menu principal choisi
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 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') {
124 //var_dump($this->tabMenu);
125 //}
126 }
127
128
137 public function showmenu($mode, $moredata = null)
138 {
139 global $conf, $langs, $user;
140
141 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
142
143 if ($this->type_user == 1) {
144 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
145 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
146 }
147
148 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
149 $this->menu = new Menu();
150
151 if (empty($conf->global->MAIN_MENU_INVERT)) {
152 if ($mode == 'top') {
153 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
154 }
155 if ($mode == 'left') {
156 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
157 }
158 } else {
159 $conf->global->MAIN_SHOW_LOGO = 0;
160 if ($mode == 'top') {
161 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
162 }
163 if ($mode == 'left') {
164 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
165 }
166 }
167
168 if ($mode == 'topnb') {
169 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
170 return $this->menu->getNbOfVisibleMenuEntries();
171 }
172
173 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
174 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
175
176 // $this->menu->liste is top menu
177 //var_dump($this->menu->liste);exit;
178 $lastlevel = array();
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 $val['prefix'];
196 } elseif ($val['level'] == 0 && $val['mainmenu'] == 'home') {
197 print '<span class="fa fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
198 }
199
200 print $val['titre'];
201 print '</a>'."\n";
202
203 // Search submenu fot this mainmenu entry
204 $tmpmainmenu = $val['mainmenu'];
205 $tmpleftmenu = 'all';
206 $submenu = new Menu();
207 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
208 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
209
210 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
211 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
212 //var_dump($canonrelurl);
213 //var_dump($canonnexturl);
214 print '<ul>'."\n";
215 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
216 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
217 // We add sub entry
218 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
219 print '<a href="'.$relurl.'">';
220 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
221 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab'))) {
222 print $langs->trans("Access");
223 } else {
224 print $langs->trans("Dashboard");
225 }
226 } else {
227 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
228 }
229 print '</a>';
230 print '</li>'."\n";
231 }
232
233 if ($val['level'] == 0) {
234 if ($val['enabled']) {
235 $lastlevel[0] = 'enabled';
236 } elseif ($showmenu) { // Not enabled but visible (so greyed)
237 $lastlevel[0] = 'greyed';
238 } else {
239 $lastlevel[0] = 'hidden';
240 }
241 }
242
243 $lastlevel2 = array();
244 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
245 $showmenu = true;
246 if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) {
247 $showmenu = false;
248 }
249
250 // If at least one parent is not enabled, we do not show any menu of all children
251 if ($val2['level'] > 0) {
252 $levelcursor = $val2['level'] - 1;
253 while ($levelcursor >= 0) {
254 if ($lastlevel2[$levelcursor] != 'enabled') {
255 $showmenu = false;
256 }
257 $levelcursor--;
258 }
259 }
260
261 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
262 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
263 $substitarray['__USERID__'] = $user->id; // For backward compatibility
264 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
265
266 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
267 $relurl2 = dol_buildpath($val2['url'], 1);
268 } else {
269 $relurl2 = $val2['url'];
270 }
271 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
272 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
273 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
274 $relurl2 = '';
275 }
276
277 $disabled = '';
278 if (!$val2['enabled']) {
279 $disabled = " vsmenudisabled";
280 }
281
282 print str_pad('', $val2['level'] + 1);
283 print '<li class="lilevel'.($val2['level'] + 1);
284 if ($val2['level'] == 0) {
285 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
286 }
287 print $disabled.'">'; // ui-btn to highlight on clic
288 if ($relurl2) {
289 if ($val2['enabled']) { // Allowed
290 print '<a href="'.$relurl2.'"';
291 //print ' data-ajax="false"';
292 print '>';
293 $lastlevel2[$val2['level']] = 'enabled';
294 } else { // Not allowed but visible (greyed)
295 print '<a href="#" class="vsmenudisabled">';
296 $lastlevel2[$val2['level']] = 'greyed';
297 }
298 } else {
299 if ($val2['enabled']) { // Allowed
300 $lastlevel2[$val2['level']] = 'enabled';
301 } else {
302 $lastlevel2[$val2['level']] = 'greyed';
303 }
304 }
305
306 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
307 print $val2['prefix'];
308 } else {
309 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
310 }
311
312 print $val2['titre'];
313 if ($relurl2) {
314 if ($val2['enabled']) { // Allowed
315 print '</a>';
316 } else {
317 print '</a>';
318 }
319 }
320 print '</li>'."\n";
321 }
322 }
323 //var_dump($submenu);
324 print '</ul>';
325 }
326 if ($val['enabled'] == 2) {
327 print '<span class="spanlilevel0 vsmenudisabled">';
328
329 // Add font-awesome
330 if ($val['level'] == 0 && !empty($val['prefix'])) {
331 print $val['prefix'];
332 }
333
334 print $val['titre'];
335 print '</span>';
336 }
337 print '</li>';
338 print '</ul>'."\n";
339 }
340 }
341
342 unset($this->menu);
343
344 //print 'xx'.$mode;
345 return 0;
346 }
347}
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.
Class to manage left menus.
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.