dolibarr 23.0.3
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-2025 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
34{
38 public $db;
39
43 public $type_user;
44
48 public $atarget = "";
49
53 public $name = "auguria";
54
58 public $menu;
59
63 public $menu_array;
67 public $menu_array_after;
68
72 public $tabMenu;
73
74
81 public function __construct($db, $type_user)
82 {
83 $this->type_user = $type_user;
84 $this->db = $db;
85 }
86
87
95 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
96 {
97 // We save into session the main menu selected
98 if (GETPOSTISSET("mainmenu")) {
99 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
100 }
101 if (GETPOSTISSET("idmenu")) {
102 $_SESSION["idmenu"] = GETPOSTINT("idmenu");
103 }
104
105 // Read now mainmenu and leftmenu that define which menu to show
106 if (GETPOSTISSET("mainmenu")) {
107 // On sauve en session le menu principal choisi
108 $mainmenu = GETPOST("mainmenu", 'aZ09');
109 $_SESSION["mainmenu"] = $mainmenu;
110 $_SESSION["leftmenuopened"] = "";
111 } else {
112 // Look for the menu in the session if not set by the link
113 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
114 }
115 if (!empty($forcemainmenu)) {
116 $mainmenu = $forcemainmenu;
117 }
118
119 if (GETPOSTISSET("leftmenu")) {
120 // On sauve en session le menu principal choisi
121 $leftmenu = GETPOST("leftmenu", 'aZ09');
122 $_SESSION["leftmenu"] = $leftmenu;
123
124 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
125 //$leftmenu="";
126 $_SESSION["leftmenuopened"] = "";
127 } else {
128 $_SESSION["leftmenuopened"] = $leftmenu;
129 }
130 } else {
131 // Look for the menu in the session if not set by the link
132 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
133 }
134 if (!empty($forceleftmenu)) {
135 $leftmenu = $forceleftmenu;
136 }
137
138 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
139 $tabMenu = array();
140 $menuArbo = new Menubase($this->db, 'auguria');
141 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
142 $this->tabMenu = $tabMenu;
143 //var_dump($tabMenu);
144
145 //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
146 }
147
148
157 public function showmenu($mode, $moredata = null)
158 {
159 global $conf, $langs, $user;
160
161 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
162
163 if ($this->type_user == 1) {
164 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
165 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
166 }
167
168 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
169 $this->menu = new Menu();
170
171 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
172 if ($mode == 'top') {
173 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
174 }
175 if ($mode == 'left') {
176 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
177 }
178 } else {
179 $conf->global->MAIN_SHOW_LOGO = 0;
180 if ($mode == 'top') {
181 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
182 }
183 if ($mode == 'left') {
184 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
185 }
186 }
187
188 if ($mode == 'topnb') {
189 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
190 return $this->menu->getNbOfVisibleMenuEntries();
191 }
192
193 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
194 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
195
196 // $this->menu->liste is top menu
197 //var_dump($this->menu->liste);exit;
198 $lastlevel = array();
199 $showmenu = true; // Is current menu shown - define here to keep static code checker happy
200 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
201 print '<ul class="ulmenu ullevel0" data-inset="true">'."\n";
202 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
203 if ($val['enabled'] == 1) {
204 print '<li class="lilevel0">';
205
206 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
207 $substitarray['__USERID__'] = $user->id; // For backward compatibility
208 $val['url'] = make_substitutions($val['url'], $substitarray);
209
210 $relurl = dol_buildpath($val['url'], 1);
211 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
212
213 // Label li level 0
214 print '<a class="alilevel0" href="#">';
215
216 // Add font-awesome
217 if ($val['level'] == 0 && !empty($val['prefix'])) {
218 $reg = array();
219 if (preg_match('/^(fa[rsb]? )?fa-/', $val['prefix'], $reg)) {
220 print '<span class="'.(empty($reg[1]) ? 'fa ' : '').$val['prefix'].' paddingright pictofixedwidth"></span>';
221 } else {
222 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
223 }
224 }
225
226 print ucfirst($val['titre']);
227 print '</a>'."\n";
228
229 // Search submenu for this mainmenu entry
230 $tmpmainmenu = $val['mainmenu'];
231 $tmpleftmenu = 'all';
232 $submenu = new Menu();
233 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
234 if (!empty($submenu->liste[0]['url'])) {
235 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
236 } else {
237 $nexturl = '';
238 }
239
240 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
241 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
242 //var_dump($canonrelurl);
243 //var_dump($canonnexturl);
244
245 // Start a new ul level 1
246 $level = 1;
247 print str_repeat(' ', $level).'<ul class="ullevel1">'."\n";
248
249 // Do we have to add an extra entry that is not into menu array ?
250 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
251 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
252 print str_repeat(' ', $level).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
253 print '<a href="'.$relurl.'">';
254
255 if ($val['level'] == 0) {
256 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
257 }
258
259 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
260 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
261 print $langs->trans("Access");
262 } else {
263 print $langs->trans("Dashboard");
264 }
265 } else {
266 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
267 }
268 print '</a>';
269 print '</li>'."\n";
270 }
271
272 if ($val['level'] == 0) {
273 if ($val['enabled']) {
274 $lastlevel[0] = 'enabled';
275 } elseif ($showmenu) { // Not enabled but visible (so greyed)
276 $lastlevel[0] = 'greyed';
277 } else {
278 $lastlevel[0] = 'hidden';
279 }
280 }
281
282 $lastlevel2 = array();
283 $lastlinelevel = $level;
284
285 '@phan-var-force array<string> $lastlevel2';
286 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu','prefix']
287 $showmenu = true;
288 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
289 $showmenu = false;
290 }
291
292 // If at least one parent is not enabled, we do not show any menu of all children
293 if ($val2['level'] > 0) {
294 $levelcursor = $val2['level'] - 1;
295 while ($levelcursor >= 0) {
296 // @phan-suppress-next-line PhanTypeInvalidDimOffset
297 if ($lastlevel2[$levelcursor] != 'enabled') {
298 $showmenu = false;
299 }
300 $levelcursor--;
301 }
302 }
303
304 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
305 $newlinelevel = ($val2['level'] + 1);
306 if ($newlinelevel > $lastlinelevel) {
307 print str_repeat(' ', $newlinelevel).'<ul class="ullevel'.$newlinelevel.'" xx>'."\n";
308 }
309 $lastlinelevel = ($val2['level'] + 1);
310
311 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
312 $substitarray['__USERID__'] = $user->id; // For backward compatibility
313 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
314
315 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
316 $relurl2 = dol_buildpath($val2['url'], 1);
317 } else {
318 $relurl2 = $val2['url'];
319 }
320 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
321 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
322 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
323 $relurl2 = '';
324 }
325
326 $disabled = '';
327 if (!$val2['enabled']) {
328 $disabled = " vsmenudisabled";
329 }
330
331 // Show entry li level $val2['level']+1
332
333 // @phan-suppress-next-line PhanParamSuspiciousOrder
334 print str_repeat(' ', ($val2['level'] + 1));
335 print '<li class="lilevel'.($val2['level'] + 1);
336 if ($val2['level'] == 0) {
337 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
338 }
339 print $disabled.'">'; // ui-btn to highlight on clic
340 if ($relurl2) {
341 if ($val2['enabled']) {
342 // Allowed
343 print '<a href="'.$relurl2.'">';
344 $lastlevel2[$val2['level']] = 'enabled';
345 } else {
346 // Not allowed but visible (greyed)
347 print '<a href="#" class="vsmenudisabled">';
348 $lastlevel2[$val2['level']] = 'greyed';
349 }
350 } else {
351 if ($val2['enabled']) { // Allowed
352 $lastlevel2[$val2['level']] = 'enabled';
353 } else {
354 $lastlevel2[$val2['level']] = 'greyed';
355 }
356 }
357
358 // Add font-awesome for level 0 and 1 (if $val2['level'] == 1, we are on level2, if $val2['level'] == 2, we are on level 3...)
359 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
360 print $val2['prefix']; // the picto must have class="pictofixedwidth paddingright"
361 } else {
362 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth level'.($val2['level'] + 1).'"></i>';
363 }
364
365 print $val2['titre'];
366 if ($relurl2) {
367 print '</a>';
368 }
369
370
371 $currentlevel = (empty($submenu->liste[$key2]) ? 1 : $submenu->liste[$key2]['level'] + 1);
372 $nextlevel = (empty($submenu->liste[$key2 + 1]) ? 1 : $submenu->liste[$key2 + 1]['level'] + 1);
373 // If there is no lower level
374 if ($nextlevel > $currentlevel) {
375 // There is a submenu with a lower level, we do not close the li
376 print "\n";
377 } elseif ($nextlevel < $currentlevel) {
378 // Next menu is lower
379 print '</li>'."\n";
380 $fromcursor = 0;
381 while ($fromcursor < ($currentlevel - $nextlevel)) {
382 print str_repeat(' ', $currentlevel - $fromcursor).'</ul>'."\n";
383 print str_repeat(' ', $currentlevel - $fromcursor - 1).'</li>'."\n"; // end level $val2['level']+1
384 $fromcursor++;
385 }
386 } else {
387 print '</li>'."\n"; // end level $val2['level']+1
388 }
389 }
390 //var_dump($submenu);
391 }
392
393 print str_repeat(' ', $level).'</ul>'."\n"; // end ul level 1
394 print str_repeat(' ', $level - 1).'</li>'."\n"; // end ul level 1
395 } elseif ($val['enabled'] == 2) {
396 print '<li class="lilevel0">';
397
398 // Label li level 0
399 print '<span class="spanlilevel0 vsmenudisabled">';
400
401 // Add font-awesome
402 if ($val['level'] == 0 && !empty($val['prefix'])) {
403 print $val['prefix'];
404 }
405
406 print $val['titre'];
407 print '</span>';
408
409 print '</li>'."\n"; // close entry level 0
410 }
411 }
412 print '</ul>'."\n"; // close entry level 0
413 }
414
415 unset($this->menu);
416
417 //print 'xx'.$mode;
418 return 0;
419 }
420}
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='')
@phan-file-suppress PhanTypeInvalidDimOffset
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)
Output menu on screen.
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 a Dolibarr global constant string value.