dolibarr 23.0.3
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 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 $mysoc->logo_squarred_mini = (!getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI') ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI);
165
166 $logoContainerAdditionalClass = 'backgroundforcompanylogo';
167 if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND')) {
168 $logoContainerAdditionalClass = '';
169 }
170
171 if (!empty($mysoc->logo_squarred_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini)) {
172 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
173 /*} elseif (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
174 {
175 $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_mini);
176 }*/
177 } else {
178 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png';
179 $logoContainerAdditionalClass = '';
180 }
181
182 $title = $langs->trans("GoIntoSetupToChangeLogo");
183
184 print "\n".'<!-- Show logo on menu -->'."\n";
185 print_start_menu_entry_auguria('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
186
187 print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
188
190 }
191
192 foreach ($menu->liste as $menuval) {
193 print_start_menu_entry_auguria($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
194 // @phpstan-ignore-next-line
195 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);
196 print_end_menu_entry_auguria($menuval['enabled']);
197 }
198
199 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
200 $showmode = 1;
201 print_start_menu_entry_auguria('', 'class="tmenuend"', $showmode);
204 }
205
206 return 0;
207}
208
209
216{
217 print '<div class="tmenudiv">';
218 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' alt="Top menu"' : '').'>';
219}
220
229function print_start_menu_entry_auguria($idsel, $classname, $showmode)
230{
231 if ($showmode) {
232 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
233 //print '<div class="tmenuleft tmenusep"></div>';
234 print '<div class="tmenucenter">';
235 }
236}
237
251function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
252{
253 global $langs;
254
255 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
256 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
257
258 if ($showmode == 1) {
259 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
260 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
261 $reg = array();
262 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
263 print $menuval['prefix'];
264 } elseif (!empty($menuval['prefix']) && preg_match('/^(fa[rsb]? )?fa-/', $menuval['prefix'], $reg)) {
265 print '<span class="'.$id.' '.(empty($reg[1]) ? 'fa ' : '').$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
266 } else {
267 print '<span class="'.$id.' tmenuimageforpng" id="mainmenuspan_'.$idsel.'"></span>';
268 }
269 print '</div>';
270 print '</a>';
271 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
272 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
273 print '<span class="mainmenuaspan">';
274 print $text;
275 print '</span>';
276 print '</a>';
277 }
278 } elseif ($showmode == 2) {
279 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
280 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
281 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
282 print $menuval['prefix'];
283 } else {
284 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
285 }
286 print '</div>';
287 print '</div>';
288 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
289 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
290 print '<span class="mainmenuaspan">';
291 print $text;
292 print '</span>';
293 print '</span>';
294 }
295 }
296}
297
305{
306 if ($showmode) {
307 print '</div></li>';
308 }
309 print "\n";
310}
311
318{
319 print '</ul>';
320 print '</div>';
321 print "\n";
322}
323
324
325
342function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0)
343{
344 global $user, $conf, $langs, $hookmanager;
345 global $dolibarr_main_db_name, $mysoc;
346
347 $newmenu = $menu;
348
349 $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
350 $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
351
352 global $usemenuhider;
353 $usemenuhider = 0;
354
355 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
356 print "\n";
357 print "<!-- Begin SearchForm -->\n";
358 print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
359 print $moredata['searchform'];
360 print '</div>'."\n";
361 print "<!-- End SearchForm -->\n";
362 }
363
364 if (is_array($moredata) && !empty($moredata['bookmarks'])) {
365 print "\n";
366 print "<!-- Begin Bookmarks -->\n";
367 print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
368 print $moredata['bookmarks'];
369 print '</div>'."\n";
370 print "<!-- End Bookmarks -->\n";
371 }
372
373 $substitarray = getCommonSubstitutionArray($langs, 0, null, null, array('system', 'mycompany', 'date', 'user'));
374
375 // We update newmenu with entries found into database
376 $menuArbo = new Menubase($db, 'auguria');
377 $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu);
378
379 // We update newmenu for special dynamic menus
380 if (isModEnabled('bank') && $user->hasRight('banque', 'lire') && $mainmenu == 'bank') { // Entry for each bank account
381 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example
382
383 $sql = "SELECT rowid, label, courant, rappro, courant";
384 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
385 $sql .= " WHERE entity = ".$conf->entity;
386 $sql .= " AND clos = 0";
387 $sql .= " ORDER BY label";
388
389 $resql = $db->query($sql);
390 if ($resql) {
391 $numr = $db->num_rows($resql);
392 $i = 0;
393
394 if ($numr > 0) {
395 $newmenu->add('/compta/bank/list.php?search_status=opened', $langs->trans("BankAccounts"), 0, $user->hasRight('banque', 'lire'));
396 }
397
398 while ($i < $numr) {
399 $objp = $db->fetch_object($resql);
400 $newmenu->add('/compta/bank/card.php?id='.$objp->rowid, $objp->label, 1, $user->hasRight('banque', 'lire'));
401 if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) { // If not cash account and not closed and can be reconciliate
402 $newmenu->add('/compta/bank/bankentries_list.php?id='.$objp->rowid, $langs->trans("Conciliate"), 2, $user->hasRight('banque', 'consolidate'));
403 }
404 $i++;
405 }
406 } else {
407 dol_print_error($db);
408 }
409 $db->free($resql);
410 }
411
412 if (isModEnabled('accounting') && $user->hasRight('accounting', 'comptarapport', 'lire') && $mainmenu == 'accountancy') { // Entry in accountancy journal for each bank account
413 $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->hasRight('accounting', 'comptarapport', 'lire'), '', 'accountancy', 'accountancy_journal', 10);
414
415 // Multi journal
416 $sql = "SELECT rowid, code, label, nature";
417 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
418 $sql .= " WHERE entity = ".$conf->entity;
419 if (getDolGlobalString('ACCOUNTING_MODE') == 'RECETTES-DEPENSES') {
420 $sql .= " AND nature = 4"; // only bank journal when using treasury accounting mode
421 }
422 $sql .= " AND active = 1";
423 $sql .= " ORDER BY nature ASC, label DESC";
424
425 $resql = $db->query($sql);
426 if ($resql) {
427 $numr = $db->num_rows($resql);
428 $i = 0;
429
430 if ($numr > 0) {
431 while ($i < $numr) {
432 $objp = $db->fetch_object($resql);
433
434 $nature = '';
435
436 // Must match array $sourceList defined into journals_list.php
437 if ($objp->nature == 2 && isModEnabled('invoice') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_SALES')) {
438 $nature = "sells";
439 }
440 if ($objp->nature == 3
441 && isModEnabled('supplier_invoice')
442 && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_PURCHASES')) {
443 $nature = "purchases";
444 }
445 if ($objp->nature == 4 && isModEnabled('bank')) {
446 $nature = "bank";
447 }
448 if ($objp->nature == 5 && isModEnabled('expensereport') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) {
449 $nature = "expensereports";
450 }
451 if ($objp->nature == 1 && (isModEnabled('asset') || isModEnabled('invoice') || isModEnabled('supplier_invoice'))) {
452 $nature = "various";
453 }
454 if ($objp->nature == 8) {
455 $nature = "inventory";
456 }
457 if ($objp->nature == 9) {
458 $nature = "hasnew";
459 }
460
461 // To enable when page exists
462 if (!getDolGlobalString('ACCOUNTANCY_SHOW_DEVELOP_JOURNAL')) {
463 if ($nature == 'hasnew' || $nature == 'inventory') {
464 $nature = '';
465 }
466 }
467
468 if ($nature) {
469 $langs->load('accountancy');
470 $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ...
471
472 if (getDolGlobalString('ACCOUNTING_MODE') == 'RECETTES-DEPENSES') {
473 $journalNaturePrefixUrl = 'treasury';
474 } else {
475 $journalNaturePrefixUrl = $nature;
476 }
477 $newmenu->add('/accountancy/journal/'.$journalNaturePrefixUrl.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
478 }
479 $i++;
480 }
481 } else {
482 // Should not happen. Entries are added
483 $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
484 }
485 } else {
486 dol_print_error($db);
487 }
488 $db->free($resql);
489 }
490
491 if (isModEnabled('ftp') && $mainmenu == 'ftp') { // Entry for FTP
492 $MAXFTP = 20;
493 $i = 1;
494 while ($i <= $MAXFTP) {
495 $paramkey = 'FTP_NAME_'.$i;
496 //print $paramkey;
497 if (getDolGlobalString($paramkey)) {
498 $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i;
499
500 $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24));
501 }
502 $i++;
503 }
504 }
505
506
507 // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
508 //var_dump($menu_array_before);exit;
509 //var_dump($menu_array_after);exit;
510 $menu_array = $newmenu->liste;
511 if (is_array($menu_array_before)) {
512 $menu_array = array_merge($menu_array_before, $menu_array);
513 }
514 if (is_array($menu_array_after)) {
515 $menu_array = array_merge($menu_array, $menu_array_after);
516 }
517 //var_dump($menu_array);exit;
518 if (!is_array($menu_array)) {
519 return 0;
520 }
521
522 // Allow the $menu_array of the menu to be manipulated by modules
523 $parameters = array(
524 'mainmenu' => $mainmenu,
525 );
526 $hook_items = $menu_array;
527 $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks
528
529 if (is_numeric($reshook)) {
530 if ($reshook == 0 && !empty($hookmanager->resArray)) {
531 $menu_array[] = $hookmanager->resArray; // add
532 } elseif ($reshook == 1) {
533 $menu_array = $hookmanager->resArray; // replace
534 }
535
536 // @todo Sort menu items by 'position' value
537 // $position = array();
538 // foreach ($menu_array as $key => $row) {
539 // $position[$key] = $row['position'];
540 // }
541 // $array1_sort_order = SORT_ASC;
542 // array_multisort($position, $array1_sort_order, $menu_array);
543 }
544
545 // Phan has a hard time tracking the type, for instance because it get hookmanager->results
546 // Force the typing at this point to get useful analysis below:
547 '@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';
548
549 // Show menu
550 $invert = !getDolGlobalString('MAIN_MENU_INVERT') ? "" : "invert";
551 if (empty($noout)) {
552 $altok = 0;
553 $blockvmenuopened = false;
554 $lastlevel0 = '';
555 $num = count($menu_array);
556 foreach (array_keys($menu_array) as $i) { // Loop on each menu entry (foreach better for static analysis)
557 $showmenu = true;
558 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($menu_array[$i]['enabled'])) {
559 $showmenu = false;
560 }
561
562 // Begin of new left menu block
563 if (empty($menu_array[$i]['level']) && $showmenu) {
564 $altok++;
565 $blockvmenuopened = true;
566 $lastopened = true;
567 for ($j = ($i + 1); $j < $num; $j++) {
568 if (empty($menu_array[$j]['level'])) {
569 $lastopened = false;
570 }
571 }
572 if ($altok % 2 == 0) {
573 print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
574 } else {
575 print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
576 }
577 }
578
579 // Add tabulation
580 $tabstring = '';
581 $tabul = ($menu_array[$i]['level'] - 1);
582 if ($tabul > 0) {
583 for ($j = 0; $j < $tabul; $j++) {
584 $tabstring .= '&nbsp;&nbsp;&nbsp;';
585 }
586 }
587
588 // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
589
590 $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);
591
592 $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
593 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) {
594 $tmp = explode('?', $menu_array[$i]['url'], 2);
595 $url = $shorturl = $tmp[0];
596 $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
597
598 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
599 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) {
600 $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
601 }
602 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) {
603 $param .= ($param ? '&' : '').'leftmenu=';
604 }
605 //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad
606 $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
607 $shorturlwithoutparam = $shorturl;
608 $shorturl .= ($param ? '?'.$param : '');
609 }
610
611
612 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";
613
614 // Menu level 0
615 if ($menu_array[$i]['level'] == 0) {
616 if ($menu_array[$i]['enabled']) { // Enabled so visible
617 print '<div class="menu_titre">'.$tabstring;
618 if ($shorturlwithoutparam) {
619 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'].'"' : '').'>';
620 } else {
621 print '<span class="vmenu">';
622 }
623 if (!empty($menu_array[$i]['prefix'])) {
624 $reg = array();
625 if (preg_match('/^(fa[rsb]? )?fa-/', $menu_array[$i]['prefix'], $reg)) {
626 print '<span class="'.(empty($reg[1]) ? 'fa ' : '').$menu_array[$i]['prefix'].' paddingright pictofixedwidth"></span>';
627 } else {
628 print $menu_array[$i]['prefix'];
629 }
630 }
631
632 // print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '');
633 print ucfirst($menu_array[$i]['titre']);
634 if ($shorturlwithoutparam) {
635 print '</a>';
636 } else {
637 print '</span>';
638 }
639 print '</div>'."\n";
640 $lastlevel0 = 'enabled';
641 } elseif ($showmenu) { // Not enabled but visible (so greyed)
642 print '<div class="menu_titre">'.$tabstring;
643 print '<span class="vmenudisabled">';
644 if (!empty($menu_array[$i]['prefix'])) {
645 print $menu_array[$i]['prefix'];
646 }
647 print ucfirst($menu_array[$i]['titre']);
648 print '</span>';
649 print '</div>'."\n";
650 $lastlevel0 = 'greyed';
651 } else {
652 $lastlevel0 = 'hidden';
653 }
654 if ($showmenu) {
655 print '<div class="menu_top"></div>'."\n";
656 }
657 }
658
659 // Menu level > 0
660 if ($menu_array[$i]['level'] > 0) {
661 $cssmenu = '';
662 if ($menu_array[$i]['url']) {
663 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
664 }
665
666 if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') {
667 // Enabled so visible, except if parent was not enabled.
668 print '<div class="menu_contenu'.$cssmenu.'">';
669 print $tabstring;
670 if ($shorturlwithoutparam) {
671 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'].'"' : '').'>';
672 } else {
673 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
674 }
675 print ucfirst($menu_array[$i]['titre']);
676 if ($shorturlwithoutparam) {
677 print '</a>';
678 } else {
679 print '</span>';
680 }
681 // If title is not pure text and contains a table, no carriage return added
682 if (!strstr($menu_array[$i]['titre'], '<table')) {
683 print '<br>';
684 }
685 print '</div>'."\n";
686 } elseif ($showmenu && $lastlevel0 == 'enabled') {
687 // Not enabled but visible (so greyed), except if parent was not enabled.
688 print '<div class="menu_contenu'.$cssmenu.'">';
689 print $tabstring;
690 print '<span class="spanlilevel0 vsmenudisabled vsmenudisabledmargin">'.ucfirst($menu_array[$i]['titre']).'</span><br>';
691 print '</div>'."\n";
692 }
693 }
694
695 // If next is a new block or if there is nothing after
696 if (empty($menu_array[$i + 1]['level'])) { // End menu block
697 if ($showmenu) {
698 print '<div class="menu_end"></div>'."\n";
699 }
700 if ($blockvmenuopened) {
701 print '</div>'."\n";
702 $blockvmenuopened = false;
703 }
704 }
705 }
706
707 if ($altok) {
708 print '<div class="blockvmenuend"></div>'; // End menu block
709 }
710 }
711
712 return count($menu_array);
713}
714
715
724function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
725{
726 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
727 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
728 if (empty($menuentry['enabled'])) {
729 return 0; // Entry disabled by condition
730 }
731 if ($type_user && $menuentry['module']) {
732 $tmploops = explode('|', (string) $menuentry['module']);
733 $found = 0;
734 foreach ($tmploops as $tmploop) {
735 if (in_array($tmploop, $listofmodulesforexternal)) {
736 $found++;
737 break;
738 }
739 }
740 if (!$found) {
741 return 0; // Entry is for menus all excluded to external users
742 }
743 }
744 if (!$menuentry['perms'] && $type_user) {
745 return 0; // No permissions and user is external
746 }
747 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
748 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
749 }
750 if (!$menuentry['perms']) {
751 return 2; // No permissions and user is external
752 }
753 return 1;
754}
$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.
const TYPE_CASH
Cash account.
Class to manage menu entries.
global $mysoc
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...