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