dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
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 * or see https://www.gnu.org/
19 */
20
25require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
26
27
28
41function print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = 0, $mode = '')
42{
43 global $user, $conf, $langs, $mysoc;
44 global $dolibarr_main_db_name;
45
46 $mainmenu = (empty($_SESSION["mainmenu"]) ? '' : $_SESSION["mainmenu"]);
47 $leftmenu = (empty($_SESSION["leftmenu"]) ? '' : $_SESSION["leftmenu"]);
48
49 $id = 'mainmenu';
50 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
51
52 // Show personalized menus
53 $menuArbo = new Menubase($db, 'auguria');
54 $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria', $tabMenu);
55 '@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,prefix:string}> $newTabMenu';
56
57 $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
58
59 if (empty($noout)) {
61 }
62
63 global $usemenuhider;
64 $usemenuhider = 1;
65
66 // Show/Hide vertical menu. The hamburger icon for .menuhider action.
67 if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
68 $showmode = 1;
69 $classname = 'class="tmenu menuhider nohover"';
70 $idsel = 'menu';
71
72 $menu->add('#', (getDolGlobalInt('THEME_TOPMENU_DISABLE_IMAGE') == 1 ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
73 }
74
75 $num = count($newTabMenu);
76 for ($i = 0; $i < $num; $i++) {
77 //var_dump($type_user.' '.$newTabMenu[$i]['url'].' '.$showmode.' '.$newTabMenu[$i]['perms']);
78 $idsel = (empty($newTabMenu[$i]['mainmenu']) ? 'none' : $newTabMenu[$i]['mainmenu']);
79
80 $shorturl = '';
81
82 $showmode = dol_auguria_showmenu($type_user, $newTabMenu[$i], $listofmodulesforexternal);
83 if ($showmode == 1) {
84 $newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);
85
86 // url = url from host, shorturl = relative path into dolibarr sources
87 $url = $shorturl = $newTabMenu[$i]['url'];
88 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url'])) { // Do not change url content for external links
89 $tmp = explode('?', $newTabMenu[$i]['url'], 2);
90 $url = $shorturl = $tmp[0];
91 $param = (isset($tmp[1]) ? $tmp[1] : '');
92
93 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
94 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($newTabMenu[$i]['url'])) {
95 // @phan-suppress-next-line PhanTypeSuspiciousStringExpression
96 $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
97 }
98 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($newTabMenu[$i]['url'])) {
99 $param .= ($param ? '&' : '').'leftmenu=';
100 }
101 //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
102 $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
103 //$shorturl = $shorturl.($param?'?'.$param:'');
104 $shorturl = $url;
105
106 if (DOL_URL_ROOT) {
107 $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
108 }
109 }
110
111 // TODO Find a generic solution
112 if (preg_match('/search_project_user=__search_project_user__/', $shorturl)) {
113 $search_project_user = GETPOSTINT('search_project_user');
114 if ($search_project_user) {
115 $shorturl = preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl);
116 } else {
117 $shorturl = preg_replace('/search_project_user=__search_project_user__/', '', $shorturl);
118 }
119 }
120
121 // Define the class (top menu selected or not)
122 if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) {
123 $classname = 'class="tmenusel"';
124 } elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) {
125 $classname = 'class="tmenusel"';
126 } else {
127 $classname = 'class="tmenu"';
128 }
129 } elseif ($showmode == 2) {
130 $classname = 'class="tmenu"';
131 } else {
132 $classname = '';
133 }
134
135 $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']);
136 }
137
138 // Sort on position
139 $menu->liste = dol_sort_array($menu->liste, 'position');
140
141 // Output menu entries
142 // Show logo company
143 if (!getDolGlobalString('MAIN_MENU_INVERT') && empty($noout) && getDolGlobalString('MAIN_SHOW_LOGO') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
144 //$mysoc->logo_mini=(empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI);
145 $mysoc->logo_squarred_mini = (!getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI') ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI);
146
147 $logoContainerAdditionalClass = 'backgroundforcompanylogo';
148 if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND')) {
149 $logoContainerAdditionalClass = '';
150 }
151
152 if (!empty($mysoc->logo_squarred_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini)) {
153 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
154 /*} elseif (!empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
155 {
156 $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_mini);
157 }*/
158 } else {
159 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png';
160 $logoContainerAdditionalClass = '';
161 }
162
163 $title = $langs->trans("GoIntoSetupToChangeLogo");
164
165 print "\n".'<!-- Show logo on menu -->'."\n";
166 print_start_menu_entry_auguria('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
167
168 print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
169
171 }
172
173 if (empty($noout)) {
174 foreach ($menu->liste as $menuval) {
175 print_start_menu_entry_auguria($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
176 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);
177 print_end_menu_entry_auguria($menuval['enabled']);
178 }
179 }
180
181 $showmode = 1;
182 if (empty($noout) && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
183 print_start_menu_entry_auguria('', 'class="tmenuend"', $showmode);
186 }
187
188 return 0;
189}
190
191
198{
199 print '<div class="tmenudiv">';
200 print '<ul role="navigation" class="tmenu"'.(getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' alt="Top menu"' : '').'>';
201}
202
211function print_start_menu_entry_auguria($idsel, $classname, $showmode)
212{
213 if ($showmode) {
214 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">';
215 //print '<div class="tmenuleft tmenusep"></div>';
216 print '<div class="tmenucenter">';
217 }
218}
219
233function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget, $menuval = array())
234{
235 global $langs, $conf;
236
237 $classnameimg = str_replace('class="', 'class="tmenuimage ', $classname);
238 $classnametxt = str_replace('class="', 'class="tmenulabel ', $classname);
239
240 if ($showmode == 1) {
241 print '<a '.$classnameimg.' tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
242 print '<div class="'.$id.' '.$idsel.' topmenuimage">';
243
244 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
245 print $menuval['prefix'];
246 } elseif (!empty($menuval['prefix']) && strpos($menuval['prefix'], 'fa-') === 0) {
247 print '<span class="'.$id.' '.$menuval['prefix'].'" id="mainmenuspan_'.$idsel.'"></span>';
248 } else {
249 print '<span class="'.$id.' tmenuimageforpng" id="mainmenuspan_'.$idsel.'"></span>';
250 }
251 print '</div>';
252 print '</a>';
253 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
254 print '<a '.$classnametxt.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">';
255 print '<span class="mainmenuaspan">';
256 print $text;
257 print '</span>';
258 print '</a>';
259 }
260 } elseif ($showmode == 2) {
261 print '<div '.$classnameimg.' title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
262 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled">';
263 if (!empty($menuval['prefix']) && strpos($menuval['prefix'], '<span') === 0) {
264 print $menuval['prefix'];
265 } else {
266 print '<span class="'.$id.' tmenuimageforpng tmenudisabled" id="mainmenuspan_'.$idsel.'"></span>';
267 }
268 print '</div>';
269 print '</div>';
270 if (!getDolGlobalString('THEME_TOPMENU_DISABLE_TEXT')) {
271 print '<span '.$classnametxt.' id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($text.' - '.$langs->trans("NotAllowed")).'">';
272 print '<span class="mainmenuaspan">';
273 print $text;
274 print '</span>';
275 print '</span>';
276 }
277 }
278}
279
287{
288 if ($showmode) {
289 print '</div></li>';
290 }
291 print "\n";
292}
293
300{
301 print '</ul>';
302 print '</div>';
303 print "\n";
304}
305
306
307
324function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0)
325{
326 global $user, $conf, $langs, $hookmanager;
327 global $dolibarr_main_db_name, $mysoc;
328
329 $newmenu = $menu;
330
331 $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
332 $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
333
334 global $usemenuhider;
335 $usemenuhider = 0;
336
337 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
338 print "\n";
339 print "<!-- Begin SearchForm -->\n";
340 print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
341 print $moredata['searchform'];
342 print '</div>'."\n";
343 print "<!-- End SearchForm -->\n";
344 }
345
346 if (is_array($moredata) && !empty($moredata['bookmarks'])) {
347 print "\n";
348 print "<!-- Begin Bookmarks -->\n";
349 print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
350 print $moredata['bookmarks'];
351 print '</div>'."\n";
352 print "<!-- End Bookmarks -->\n";
353 }
354
355 $substitarray = getCommonSubstitutionArray($langs, 0, null, null);
356
357 // We update newmenu with entries found into database
358 $menuArbo = new Menubase($db, 'auguria');
359 $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu);
360
361 // We update newmenu for special dynamic menus
362 if (isModEnabled('bank') && $user->hasRight('banque', 'lire') && $mainmenu == 'bank') { // Entry for each bank account
363 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example
364
365 $sql = "SELECT rowid, label, courant, rappro, courant";
366 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
367 $sql .= " WHERE entity = ".$conf->entity;
368 $sql .= " AND clos = 0";
369 $sql .= " ORDER BY label";
370
371 $resql = $db->query($sql);
372 if ($resql) {
373 $numr = $db->num_rows($resql);
374 $i = 0;
375
376 if ($numr > 0) {
377 $newmenu->add('/compta/bank/list.php?search_status=opened', $langs->trans("BankAccounts"), 0, $user->hasRight('banque', 'lire'));
378 }
379
380 while ($i < $numr) {
381 $objp = $db->fetch_object($resql);
382 $newmenu->add('/compta/bank/card.php?id='.$objp->rowid, $objp->label, 1, $user->hasRight('banque', 'lire'));
383 if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) { // If not cash account and not closed and can be reconciliate
384 $newmenu->add('/compta/bank/bankentries_list.php?id='.$objp->rowid, $langs->trans("Conciliate"), 2, $user->hasRight('banque', 'consolidate'));
385 }
386 $i++;
387 }
388 } else {
389 dol_print_error($db);
390 }
391 $db->free($resql);
392 }
393
394 if (isModEnabled('accounting') && $user->hasRight('accounting', 'comptarapport', 'lire') && $mainmenu == 'accountancy') { // Entry in accountancy journal for each bank account
395 $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->hasRight('accounting', 'comptarapport', 'lire'), '', 'accountancy', 'accountancy_journal', 10);
396
397 // Multi journal
398 $sql = "SELECT rowid, code, label, nature";
399 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
400 $sql .= " WHERE entity = ".$conf->entity;
401 $sql .= " AND active = 1";
402 $sql .= " ORDER BY label DESC";
403
404 $resql = $db->query($sql);
405 if ($resql) {
406 $numr = $db->num_rows($resql);
407 $i = 0;
408
409 if ($numr > 0) {
410 while ($i < $numr) {
411 $objp = $db->fetch_object($resql);
412
413 $nature = '';
414
415 // Must match array $sourceList defined into journals_list.php
416 if ($objp->nature == 2 && isModEnabled('invoice') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_SALES')) {
417 $nature = "sells";
418 }
419 if ($objp->nature == 3
420 && isModEnabled('supplier_invoice')
421 && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_PURCHASES')) {
422 $nature = "purchases";
423 }
424 if ($objp->nature == 4 && isModEnabled('bank')) {
425 $nature = "bank";
426 }
427 if ($objp->nature == 5 && isModEnabled('expensereport') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) {
428 $nature = "expensereports";
429 }
430 if ($objp->nature == 1) {
431 $nature = "various";
432 }
433 if ($objp->nature == 8) {
434 $nature = "inventory";
435 }
436 if ($objp->nature == 9) {
437 $nature = "hasnew";
438 }
439
440 // To enable when page exists
441 if (!getDolGlobalString('ACCOUNTANCY_SHOW_DEVELOP_JOURNAL')) {
442 if ($nature == 'hasnew' || $nature == 'inventory') {
443 $nature = '';
444 }
445 }
446
447 if ($nature) {
448 $langs->load('accountancy');
449 $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ...
450 $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
451 }
452 $i++;
453 }
454 } else {
455 // Should not happen. Entries are added
456 $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->hasRight('accounting', 'comptarapport', 'lire'));
457 }
458 } else {
459 dol_print_error($db);
460 }
461 $db->free($resql);
462 }
463
464 if (isModEnabled('ftp') && $mainmenu == 'ftp') { // Entry for FTP
465 $MAXFTP = 20;
466 $i = 1;
467 while ($i <= $MAXFTP) {
468 $paramkey = 'FTP_NAME_'.$i;
469 //print $paramkey;
470 if (getDolGlobalString($paramkey)) {
471 $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i;
472
473 $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24));
474 }
475 $i++;
476 }
477 }
478
479
480 // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
481 //var_dump($menu_array_before);exit;
482 //var_dump($menu_array_after);exit;
483 $menu_array = $newmenu->liste;
484 if (is_array($menu_array_before)) {
485 $menu_array = array_merge($menu_array_before, $menu_array);
486 }
487 if (is_array($menu_array_after)) {
488 $menu_array = array_merge($menu_array, $menu_array_after);
489 }
490 //var_dump($menu_array);exit;
491 if (!is_array($menu_array)) {
492 return 0;
493 }
494
495 // Allow the $menu_array of the menu to be manipulated by modules
496 $parameters = array(
497 'mainmenu' => $mainmenu,
498 );
499 $hook_items = $menu_array;
500 $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks
501
502 if (is_numeric($reshook)) {
503 if ($reshook == 0 && !empty($hookmanager->results)) {
504 $menu_array[] = $hookmanager->results; // add
505 } elseif ($reshook == 1) {
506 $menu_array = $hookmanager->results; // replace
507 }
508
509 // @todo Sort menu items by 'position' value
510 // $position = array();
511 // foreach ($menu_array as $key => $row) {
512 // $position[$key] = $row['position'];
513 // }
514 // $array1_sort_order = SORT_ASC;
515 // array_multisort($position, $array1_sort_order, $menu_array);
516 }
517
518 // Phan has a hard time tracking the type, for instance because it get hookmanager->results
519 // Force the typing at this point to get useful analysis below:
520 '@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,prefix:string,level:int}> $menu_array';
521
522 // Show menu
523 $invert = !getDolGlobalString('MAIN_MENU_INVERT') ? "" : "invert";
524 if (empty($noout)) {
525 $altok = 0;
526 $blockvmenuopened = false;
527 $lastlevel0 = '';
528 $num = count($menu_array);
529 foreach (array_keys($menu_array) as $i) { // Loop on each menu entry (foreach better for static analysis)
530 $showmenu = true;
531 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($menu_array[$i]['enabled'])) {
532 $showmenu = false;
533 }
534
535 // Begin of new left menu block
536 if (empty($menu_array[$i]['level']) && $showmenu) {
537 $altok++;
538 $blockvmenuopened = true;
539 $lastopened = true;
540 for ($j = ($i + 1); $j < $num; $j++) {
541 if (empty($menu_array[$j]['level'])) {
542 $lastopened = false;
543 }
544 }
545 if ($altok % 2 == 0) {
546 print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
547 } else {
548 print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n";
549 }
550 }
551
552 // Add tabulation
553 $tabstring = '';
554 $tabul = ($menu_array[$i]['level'] - 1);
555 if ($tabul > 0) {
556 for ($j = 0; $j < $tabul; $j++) {
557 $tabstring .= '&nbsp;&nbsp;&nbsp;';
558 }
559 }
560
561 // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
562
563 $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray);
564
565 $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
566 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) {
567 $tmp = explode('?', $menu_array[$i]['url'], 2);
568 $url = $shorturl = $tmp[0];
569 $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
570
571 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
572 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) {
573 $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
574 }
575 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) {
576 $param .= ($param ? '&' : '').'leftmenu=';
577 }
578 //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad
579 $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
580 $shorturlwithoutparam = $shorturl;
581 $shorturl = $shorturl.($param ? '?'.$param : '');
582 }
583
584
585 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";
586
587 // Menu level 0
588 if ($menu_array[$i]['level'] == 0) {
589 if ($menu_array[$i]['enabled']) { // Enabled so visible
590 print '<div class="menu_titre">'.$tabstring;
591 if ($shorturlwithoutparam) {
592 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'].'"' : '').'>';
593 } else {
594 print '<span class="vmenu">';
595 }
596 if (!empty($menu_array[$i]['prefix'])) {
597 if (preg_match('/^fa\-[a-zA-Z0-9\-_]+$/', $menu_array[$i]['prefix'])) {
598 print '<span class="fas '.$menu_array[$i]['prefix'].' paddingright pictofixedwidth"></span>';
599 } else {
600 print $menu_array[$i]['prefix'];
601 }
602 }
603
604 // print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '');
605 print $menu_array[$i]['titre'];
606 if ($shorturlwithoutparam) {
607 print '</a>';
608 } else {
609 print '</span>';
610 }
611 print '</div>'."\n";
612 $lastlevel0 = 'enabled';
613 } elseif ($showmenu) { // Not enabled but visible (so greyed)
614 print '<div class="menu_titre">'.$tabstring;
615 print '<span class="vmenudisabled">';
616 if (!empty($menu_array[$i]['prefix'])) {
617 print $menu_array[$i]['prefix'];
618 }
619 print $menu_array[$i]['titre'];
620 print '</span>';
621 print '</div>'."\n";
622 $lastlevel0 = 'greyed';
623 } else {
624 $lastlevel0 = 'hidden';
625 }
626 if ($showmenu) {
627 print '<div class="menu_top"></div>'."\n";
628 }
629 }
630
631 // Menu level > 0
632 if ($menu_array[$i]['level'] > 0) {
633 $cssmenu = '';
634 if ($menu_array[$i]['url']) {
635 $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url']));
636 }
637
638 if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') {
639 // Enabled so visible, except if parent was not enabled.
640 print '<div class="menu_contenu'.$cssmenu.'">';
641 print $tabstring;
642 if ($shorturlwithoutparam) {
643 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'].'"' : '').'>';
644 } else {
645 print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">';
646 }
647 print $menu_array[$i]['titre'];
648 if ($shorturlwithoutparam) {
649 print '</a>';
650 } else {
651 print '</span>';
652 }
653 // If title is not pure text and contains a table, no carriage return added
654 if (!strstr($menu_array[$i]['titre'], '<table')) {
655 print '<br>';
656 }
657 print '</div>'."\n";
658 } elseif ($showmenu && $lastlevel0 == 'enabled') {
659 // Not enabled but visible (so greyed), except if parent was not enabled.
660 print '<div class="menu_contenu'.$cssmenu.'">';
661 print $tabstring;
662 print '<span class="spanlilevel0 vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</span><br>';
663 print '</div>'."\n";
664 }
665 }
666
667 // If next is a new block or if there is nothing after
668 if (empty($menu_array[$i + 1]['level'])) { // End menu block
669 if ($showmenu) {
670 print '<div class="menu_end"></div>'."\n";
671 }
672 if ($blockvmenuopened) {
673 print '</div>'."\n";
674 $blockvmenuopened = false;
675 }
676 }
677 }
678
679 if ($altok) {
680 print '<div class="blockvmenuend"></div>'; // End menu block
681 }
682 }
683
684 return count($menu_array);
685}
686
687
696function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal)
697{
698 global $conf;
699
700 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
701 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
702 if (empty($menuentry['enabled'])) {
703 return 0; // Entry disabled by condition
704 }
705 if ($type_user && $menuentry['module']) {
706 $tmploops = explode('|', $menuentry['module']);
707 $found = 0;
708 foreach ($tmploops as $tmploop) {
709 if (in_array($tmploop, $listofmodulesforexternal)) {
710 $found++;
711 break;
712 }
713 }
714 if (!$found) {
715 return 0; // Entry is for menus all excluded to external users
716 }
717 }
718 if (!$menuentry['perms'] && $type_user) {
719 return 0; // No permissions and user is external
720 }
721 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
722 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
723 }
724 if (!$menuentry['perms']) {
725 return 2; // No permissions and user is external
726 }
727 return 1;
728}
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='')
Core function to output top menu auguria.
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.
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.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...