dolibarr 25.0.0-alpha
auguria.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2022 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
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 * or see https://www.gnu.org/
21 */
22
27require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
28
43function print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = 0, $mode = '')
44{
45 global $user, $conf, $langs, $mysoc;
46 global $dolibarr_main_db_name;
47
48 $mainmenu = (empty($_SESSION["mainmenu"]) ? '' : $_SESSION["mainmenu"]);
49 $leftmenu = (empty($_SESSION["leftmenu"]) ? '' : $_SESSION["leftmenu"]);
50
51 $id = 'mainmenu';
52 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
53
54 // Show personalized menus
55 $menuArbo = new Menubase($db, 'auguria');
56 $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria', $tabMenu);
57
58 $substitarray = getCommonSubstitutionArray($langs, 0, null, null, array('system', 'mycompany', 'date', 'user'));
59
60 global $usemenuhider;
61 $usemenuhider = 1;
62
63 // Show/Hide vertical menu. The hamburger icon for .menuhider action.
64 if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
65 $showmode = 1;
66 $classname = 'class="tmenu menuhider nohover"';
67 $idsel = 'menu';
68
69 $menu->add('#', (getDolGlobalInt('THEME_TOPMENU_DISABLE_IMAGE') == 1 ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname, '<span class="fas fa-bars size12x"></span>');
70 }
71
72 $num = count($newTabMenu);
73 for ($i = 0; $i < $num; $i++) {
74 //var_dump($type_user.' '.$newTabMenu[$i]['url'].' '.$showmode.' '.$newTabMenu[$i]['perms']);
75 $idsel = (empty($newTabMenu[$i]['mainmenu']) ? 'none' : $newTabMenu[$i]['mainmenu']);
76
77 $shorturl = '';
78
79 $showmode = dol_auguria_showmenu($type_user, $newTabMenu[$i], $listofmodulesforexternal);
80 if ($showmode == 1) {
81 $newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);
82
83 // Phan issue #4881 requires that we reforce the type
84 '@phan-var-force array<array{rowid:string,fk_menu:string,langs:string,enabled:int<0,2>,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,positionfull:int|string,showtopmenuinframe:int,level?:int,prefix:string}> $newTabMenu';
85
86 // url = url from host, shorturl = relative path into dolibarr sources
87 $url = $shorturl = $newTabMenu[$i]['url'];
88
89 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url'])) { // Do not change url content for external links
90 $tmp = explode('?', $newTabMenu[$i]['url'], 2);
91 $url = $shorturl = $tmp[0];
92 $param = (isset($tmp[1]) ? $tmp[1] : '');
93
94 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
95 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($newTabMenu[$i]['url'])) {
96 // @phan-suppress-next-line PhanTypeSuspiciousStringExpression,PhanTypeInvalidDimOffset
97 $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
98 }
99 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($newTabMenu[$i]['url'])) {
100 $param .= ($param ? '&' : '').'leftmenu=';
101 }
102 //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
103 $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
104 //$shorturl = $shorturl.($param?'?'.$param:'');
105 $shorturl = $url;
106
107 if (DOL_URL_ROOT) {
108 $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
109 }
110 }
111
112 // Modify URL for the case we are using the option showtopmenuinframe
113 '@phan-var-force array<array{rowid:string,fk_menu:string,langs:string,enabled:int<0,2>,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,positionfull:int|string,showtopmenuinframe:int,level?:int,prefix:string}> $newTabMenu';
114 // @phan-suppress-next-line PhanTypeInvalidDimOffset
115 if ($newTabMenu[$i]['showtopmenuinframe']) {
116 if (preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url'])) {
117 $url = '/core/frames.php?idmenu='.$newTabMenu[$i]['rowid'];
118 $shorturl = $url;
119 }
120 }
121
122 // TODO Find a generic solution
123 if (preg_match('/search_project_user=__search_project_user__/', $shorturl)) {
124 $search_project_user = GETPOSTINT('search_project_user');
125 if ($search_project_user) {
126 $shorturl = preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl);
127 } else {
128 $shorturl = preg_replace('/search_project_user=__search_project_user__/', '', $shorturl);
129 }
130 }
131
132 // Define the class (top menu selected or not)
133 if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) {
134 $classname = 'class="tmenusel"';
135 } elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) {
136 $classname = 'class="tmenusel"';
137 } else {
138 $classname = 'class="tmenu"';
139 }
140 } elseif ($showmode == 2) {
141 $classname = 'class="tmenu"';
142 } else {
143 $classname = '';
144 }
145
146 $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target'] ? $newTabMenu[$i]['target'] : $atarget), ($newTabMenu[$i]['mainmenu'] ? $newTabMenu[$i]['mainmenu'] : $newTabMenu[$i]['rowid']), ($newTabMenu[$i]['leftmenu'] ? $newTabMenu[$i]['leftmenu'] : ''), $newTabMenu[$i]['position'], $id, $idsel, $classname, $newTabMenu[$i]['prefix']);
147 }
148
149 // Sort on position
150 $menu->liste = dol_sort_array($menu->liste, 'position');
151
152 // If noout is on (for jmobile div menu for example)
153 if ($noout) {
154 return 0;
155 }
156
157 // Output menu entries
158
160
161 // Show logo company
162 if (!getDolGlobalString('MAIN_MENU_INVERT') && getDolGlobalString('MAIN_SHOW_LOGO') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
163 //$mysoc->logo_mini=(empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI);
164 // Use a local variable: $mysoc may not be loaded (pages defining NOREQUIRESOC)
165 $logosquarredmini = getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
166
167 $logoContainerAdditionalClass = 'backgroundforcompanylogo';
168 if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND')) {
169 $logoContainerAdditionalClass = '';
170 }
171
172 if (!empty($logosquarredmini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosquarredmini)) {
173 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$logosquarredmini);
174 /*} elseif (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
175 {
176 $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_mini);
177 }*/
178 } else {
179 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png';
180 $logoContainerAdditionalClass = '';
181 }
182
183 $title = $langs->trans("GoIntoSetupToChangeLogo");
184
185 print "\n".'<!-- Show logo on menu -->'."\n";
186 print_start_menu_entry_auguria('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
187
188 print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
189
191 }
192
193 foreach ($menu->liste as $menuval) {
194 print_start_menu_entry_auguria($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
195 // @phpstan-ignore-next-line
196 print_text_menu_entry_auguria($menuval['titre'], $menuval['enabled'], ($menuval['url'] != '#' ? DOL_URL_ROOT : '').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget), $menuval);
197 print_end_menu_entry_auguria($menuval['enabled']);
198 }
199
200 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
201 $showmode = 1;
202 print_start_menu_entry_auguria('', 'class="tmenuend"', $showmode);
205 }
206
207 return 0;
208}
209
210
217{
218 print '<div class="tmenudiv">';
219 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' alt="Top menu"' : '').'>';
220}
221
230function print_start_menu_entry_auguria($idsel, $classname, $showmode)
231{
232 if ($showmode) {
233 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
234 //print '<div class="tmenuleft tmenusep"></div>';
235 print '<div class="tmenucenter">';
236 }
237}
238
252function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
253{
254 global $langs;
255
256 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
257 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
258
259 if ($showmode == 1) {
260 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
261 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
262 $reg = array();
263 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
264 print $menuval['prefix'];
265 } elseif (!empty($menuval['prefix']) && preg_match('/^(fa[rsb]? )?fa-/', $menuval['prefix'], $reg)) {
266 print '<span class="'.$id.' '.(empty($reg[1]) ? 'fa ' : '').$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
267 } else {
268 print '<span class="'.$id.' tmenuimageforpng" id="mainmenuspan_'.$idsel.'"></span>';
269 }
270 print '</div>';
271 print '</a>';
272 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
273 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
274 print '<span class="mainmenuaspan">';
275 print $text;
276 print '</span>';
277 print '</a>';
278 }
279 } elseif ($showmode == 2) {
280 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
281 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
282 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
283 print $menuval['prefix'];
284 } else {
285 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
286 }
287 print '</div>';
288 print '</div>';
289 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
290 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
291 print '<span class="mainmenuaspan">';
292 print $text;
293 print '</span>';
294 print '</span>';
295 }
296 }
297}
298
306{
307 if ($showmode) {
308 print '</div></li>';
309 }
310 print "\n";
311}
312
319{
320 print '</ul>';
321 print '</div>';
322 print "\n";
323}
324
325
326
343function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0)
344{
345 global $user, $conf, $langs, $hookmanager;
346 global $dolibarr_main_db_name, $mysoc;
347
348 $newmenu = $menu;
349
350 $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
351 $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
352
353 global $usemenuhider;
354 $usemenuhider = 0;
355
356 if (is_array($moredata) && !empty($moredata['searchform'])) { // searchform can contains select2 code or link to show old search form or link to switch on search page
357 print "\n";
358 print "<!-- Begin SearchForm -->\n";
359 print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
360 print $moredata['searchform'];
361 print '</div>'."\n";
362 print "<!-- End SearchForm -->\n";
363 }
364
365 if (is_array($moredata) && !empty($moredata['bookmarks'])) {
366 print "\n";
367 print "<!-- Begin Bookmarks -->\n";
368 print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
369 print $moredata['bookmarks'];
370 print '</div>'."\n";
371 print "<!-- End Bookmarks -->\n";
372 }
373
374 $substitarray = getCommonSubstitutionArray($langs, 0, null, null, array('system', 'mycompany', 'date', 'user'));
375
376 // We update newmenu with entries found into database
377 $menuArbo = new Menubase($db, 'auguria');
378 $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu);
379
380 // We update newmenu for special dynamic menus
381 if (isModEnabled('bank') && $user->hasRight('banque', 'lire') && $mainmenu == 'bank') { // Entry for each bank account
382 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example
383
384 $sql = "SELECT rowid, label, courant, rappro, courant";
385 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
386 $sql .= " WHERE entity = ".((int) $conf->entity);
387 $sql .= " AND clos = 0";
388 $sql .= " ORDER BY label";
389
390 $resql = $db->query($sql);
391 if ($resql) {
392 $numr = $db->num_rows($resql);
393 $i = 0;
394
395 if ($numr > 0) {
396 $newmenu->add('/compta/bank/list.php?search_status=opened', $langs->trans("BankAccounts"), 0, $user->hasRight('banque', 'lire'));
397 }
398
399 while ($i < $numr) {
400 $objp = $db->fetch_object($resql);
401 $newmenu->add('/compta/bank/card.php?id='.$objp->rowid, $objp->label, 1, $user->hasRight('banque', 'lire'));
402 if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) { // If not cash account and not closed and can be reconciliate
403 $newmenu->add('/compta/bank/bankentries_list.php?id='.$objp->rowid, $langs->trans("Conciliate"), 2, $user->hasRight('banque', 'consolidate'));
404 }
405 $i++;
406 }
407 } else {
408 dol_print_error($db);
409 }
410 $db->free($resql);
411 }
412
413 if (isModEnabled('accounting') && $user->hasRight('accounting', 'comptarapport', 'lire') && $mainmenu == 'accountancy') { // Entry in accountancy journal for each bank account
414 $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->hasRight('accounting', 'comptarapport', 'lire'), '', 'accountancy', 'accountancy_journal', 10);
415
416 // Multi journal
417 $sql = "SELECT rowid, code, label, nature";
418 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
419 $sql .= " WHERE entity = ".((int) $conf->entity);
420 if (getDolGlobalString('ACCOUNTING_MODE') == 'RECETTES-DEPENSES') {
421 $sql .= " AND nature = 4"; // only bank journal when using treasury accounting mode
422 }
423 $sql .= " AND active = 1";
424 $sql .= " ORDER BY nature ASC, label DESC";
425
426 $resql = $db->query($sql);
427 if ($resql) {
428 $numr = $db->num_rows($resql);
429 $i = 0;
430
431 if ($numr > 0) {
432 while ($i < $numr) {
433 $objp = $db->fetch_object($resql);
434
435 $nature = '';
436
437 // Must match array $sourceList defined into journals_list.php
438 if ($objp->nature == 2 && isModEnabled('invoice') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_SALES')) {
439 $nature = "sells";
440 }
441 if ($objp->nature == 3
442 && isModEnabled('supplier_invoice')
443 && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_PURCHASES')) {
444 $nature = "purchases";
445 }
446 if ($objp->nature == 4 && isModEnabled('bank')) {
447 $nature = "bank";
448 }
449 if ($objp->nature == 5 && isModEnabled('expensereport') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) {
450 $nature = "expensereports";
451 }
452 if ($objp->nature == 1 && (isModEnabled('asset') || isModEnabled('invoice') || isModEnabled('supplier_invoice'))) {
453 $nature = "various";
454 }
455 if ($objp->nature == 8) {
456 $nature = "inventory";
457 }
458 if ($objp->nature == 9) {
459 $nature = "hasnew";
460 }
461
462 // To enable when page exists
463 if (!getDolGlobalString('ACCOUNTANCY_SHOW_DEVELOP_JOURNAL')) {
464 if ($nature == 'hasnew' || $nature == 'inventory') {
465 $nature = '';
466 }
467 }
468
469 if ($nature) {
470 $langs->load('accountancy');
471 $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ...
472
473 if (getDolGlobalString('ACCOUNTING_MODE') == 'RECETTES-DEPENSES') {
474 $journalNaturePrefixUrl = 'treasury';
475 } else {
476 $journalNaturePrefixUrl = $nature;
477 }
478 $newmenu->add('/accountancy/journal/'.$journalNaturePrefixUrl.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
479 }
480 $i++;
481 }
482 } else {
483 // Should not happen. Entries are added
484 $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
485 }
486 } else {
487 dol_print_error($db);
488 }
489 $db->free($resql);
490 }
491
492 if (isModEnabled('ftp') && $mainmenu == 'ftp') { // Entry for FTP
493 $MAXFTP = 20;
494 $i = 1;
495 while ($i <= $MAXFTP) {
496 $paramkey = 'FTP_NAME_'.$i;
497 //print $paramkey;
498 if (getDolGlobalString($paramkey)) {
499 $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i;
500
501 $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24));
502 }
503 $i++;
504 }
505 }
506
507
508 // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
509 //var_dump($menu_array_before);exit;
510 //var_dump($menu_array_after);exit;
511 $menu_array = $newmenu->liste;
512 if (is_array($menu_array_before)) {
513 $menu_array = array_merge($menu_array_before, $menu_array);
514 }
515 if (is_array($menu_array_after)) {
516 $menu_array = array_merge($menu_array, $menu_array_after);
517 }
518 //var_dump($menu_array);exit;
519 if (!is_array($menu_array)) {
520 return 0;
521 }
522
523 // Allow the $menu_array of the menu to be manipulated by modules
524 $parameters = array(
525 'mainmenu' => $mainmenu,
526 );
527 $hook_items = $menu_array;
528 $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks
529
530 if (is_numeric($reshook)) {
531 if ($reshook == 0 && !empty($hookmanager->resArray)) {
532 $menu_array[] = $hookmanager->resArray; // add
533 } elseif ($reshook == 1) {
534 $menu_array = $hookmanager->resArray; // replace
535 }
536
537 // @todo Sort menu items by 'position' value
538 // $position = array();
539 // foreach ($menu_array as $key => $row) {
540 // $position[$key] = $row['position'];
541 // }
542 // $array1_sort_order = SORT_ASC;
543 // array_multisort($position, $array1_sort_order, $menu_array);
544 }
545
546 // Phan has a hard time tracking the type, for instance because it get hookmanager->results
547 // Force the typing at this point to get useful analysis below:
548 '@phan-var-force array<array{rowid:string,fk_menu:string,langs:string,enabled:int<0,2>,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,showtopmenuinframe:int,prefix:string,level:int}> $menu_array';
549
550 // Show menu
551 $invert = !getDolGlobalString('MAIN_MENU_INVERT') ? "" : "invert";
552 if (empty($noout)) {
553 $altok = 0;
554 $blockvmenuopened = false;
555 $lastlevel0 = '';
556 $num = count($menu_array);
557 foreach (array_keys($menu_array) as $i) { // Loop on each menu entry (foreach better for static analysis)
558 $showmenu = true;
559 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($menu_array[$i]['enabled'])) {
560 $showmenu = false;
561 }
562
563 // Begin of new left menu block
564 if (empty($menu_array[$i]['level']) && $showmenu) {
565 $altok++;
566 $blockvmenuopened = true;
567 $lastopened = true;
568 for ($j = ($i + 1); $j < $num; $j++) {
569 if (empty($menu_array[$j]['level'])) {
570 $lastopened = false;
571 }
572 }
573 if ($altok % 2 == 0) {
574 print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
575 } else {
576 print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
577 }
578 }
579
580 // Add tabulation
581 $tabstring = '';
582 $tabul = ($menu_array[$i]['level'] - 1);
583 if ($tabul > 0) {
584 for ($j = 0; $j < $tabul; $j++) {
585 $tabstring .= '&nbsp;&nbsp;&nbsp;';
586 }
587 }
588
589 // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
590
591 $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);
592
593 $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
594 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) {
595 $tmp = explode('?', $menu_array[$i]['url'], 2);
596 $url = $shorturl = $tmp[0];
597 $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
598
599 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
600 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) {
601 $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
602 }
603 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) {
604 $param .= ($param ? '&' : '').'leftmenu=';
605 }
606 //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad
607 $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
608 $shorturlwithoutparam = $shorturl;
609 $shorturl .= ($param ? '?'.$param : '');
610 }
611
612
613 print '<!-- Process menu entry with mainmenu='.$menu_array[$i]['mainmenu'].', leftmenu='.$menu_array[$i]['leftmenu'].', level='.$menu_array[$i]['level'].' enabled='.$menu_array[$i]['enabled'].', position='.$menu_array[$i]['position'].' prefix='.$menu_array[$i]['prefix'].' -->'."\n";
614
615 // Menu level 0
616 if ($menu_array[$i]['level'] == 0) {
617 if ($menu_array[$i]['enabled']) { // Enabled so visible
618 print '<div class="menu_titre">'.$tabstring;
619 if ($shorturlwithoutparam) {
620 print '<a class="vmenu" title="'.dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
621 } else {
622 print '<span class="vmenu">';
623 }
624 if (!empty($menu_array[$i]['prefix'])) {
625 $reg = array();
626 if (preg_match('/^(fa[rsb]? )?fa-/', $menu_array[$i]['prefix'], $reg)) {
627 print '<span class="'.(empty($reg[1]) ? 'fa ' : '').$menu_array[$i]['prefix'].' paddingright pictofixedwidth"></span>';
628 } else {
629 print $menu_array[$i]['prefix'];
630 }
631 }
632
633 // print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '');
634 print ucfirst($menu_array[$i]['titre']);
635 if ($shorturlwithoutparam) {
636 print '</a>';
637 } else {
638 print '</span>';
639 }
640 print '</div>'."\n";
641 $lastlevel0 = 'enabled';
642 } elseif ($showmenu) { // Not enabled but visible (so greyed)
643 print '<div class="menu_titre">'.$tabstring;
644 print '<span class="vmenudisabled">';
645 if (!empty($menu_array[$i]['prefix'])) {
646 print $menu_array[$i]['prefix'];
647 }
648 print ucfirst($menu_array[$i]['titre']);
649 print '</span>';
650 print '</div>'."\n";
651 $lastlevel0 = 'greyed';
652 } else {
653 $lastlevel0 = 'hidden';
654 }
655 if ($showmenu) {
656 print '<div class="menu_top"></div>'."\n";
657 }
658 }
659
660 // Menu level > 0
661 if ($menu_array[$i]['level'] > 0) {
662 $cssmenu = '';
663 if ($menu_array[$i]['url']) {
664 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
665 }
666
667 if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') {
668 // Enabled so visible, except if parent was not enabled.
669 print '<div class="menu_contenu'.$cssmenu.'">';
670 print $tabstring;
671 if ($shorturlwithoutparam) {
672 print '<a class="vsmenu" title="'.dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>';
673 } else {
674 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
675 }
676 print ucfirst($menu_array[$i]['titre']);
677 if ($shorturlwithoutparam) {
678 print '</a>';
679 } else {
680 print '</span>';
681 }
682 // If title is not pure text and contains a table, no carriage return added
683 if (!strstr($menu_array[$i]['titre'], '<table')) {
684 print '<br>';
685 }
686 print '</div>'."\n";
687 } elseif ($showmenu && $lastlevel0 == 'enabled') {
688 // Not enabled but visible (so greyed), except if parent was not enabled.
689 print '<div class="menu_contenu'.$cssmenu.'">';
690 print $tabstring;
691 print '<span class="spanlilevel0 vsmenudisabled vsmenudisabledmargin">'.ucfirst($menu_array[$i]['titre']).'</span><br>';
692 print '</div>'."\n";
693 }
694 }
695
696 // If next is a new block or if there is nothing after
697 if (empty($menu_array[$i + 1]['level'])) { // End menu block
698 if ($showmenu) {
699 print '<div class="menu_end"></div>'."\n";
700 }
701 if ($blockvmenuopened) {
702 print '</div>'."\n";
703 $blockvmenuopened = false;
704 }
705 }
706 }
707
708 if ($altok) {
709 print '<div class="blockvmenuend"></div>'; // End menu block
710 }
711 }
712
713 return count($menu_array);
714}
715
716
725function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
726{
727 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
728 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
729 if (empty($menuentry['enabled'])) {
730 return 0; // Entry disabled by condition
731 }
732 if ($type_user && $menuentry['module']) {
733 $tmploops = explode('|', (string) $menuentry['module']);
734 $found = 0;
735 foreach ($tmploops as $tmploop) {
736 if (in_array($tmploop, $listofmodulesforexternal)) {
737 $found++;
738 break;
739 }
740 }
741 if (!$found) {
742 return 0; // Entry is for menus all excluded to external users
743 }
744 }
745 if (!$menuentry['perms'] && $type_user) {
746 return 0; // No permissions and user is external
747 }
748 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
749 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
750 }
751 if (!$menuentry['perms']) {
752 return 2; // No permissions and user is external
753 }
754 return 1;
755}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval=array())
Output menu entry.
print_start_menu_entry_auguria($idsel, $classname, $showmode)
Output start menu entry.
print_end_menu_array_auguria()
Output menu array.
print_end_menu_entry_auguria($showmode)
Output end menu entry.
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
print_start_menu_array_auguria()
Output start menu array.
dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
Function to test if an entry is enabled or not.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
const TYPE_CASH
Cash account.
Class to manage menu entries.
global $mysoc
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183