1<?php 2/* Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net> 3 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * or see https://www.gnu.org/ 18 */ 19 20/** 21 * \file htdocs/core/menus/standard/auguria.lib.php 22 * \brief Library for file auguria menus 23 */ 24require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; 25 26 27 28/** 29 * Core function to output top menu auguria 30 * 31 * @param DoliDB $db Database handler 32 * @param string $atarget Target (Example: '' or '_top') 33 * @param int $type_user 0=Menu for backoffice, 1=Menu for front office 34 * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) 35 * @param Menu $menu Object Menu to return back list of menu entries 36 * @param int $noout 1=Disable output (Initialise &$menu only). 37 * @param string $mode 'top', 'topnb', 'left', 'jmobile' 38 * @return int 0 39 */ 40function print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout = 0, $mode = '') 41{ 42 global $user, $conf, $langs, $mysoc; 43 global $dolibarr_main_db_name; 44 45 $mainmenu = (empty($_SESSION["mainmenu"]) ? '' : $_SESSION["mainmenu"]); 46 $leftmenu = (empty($_SESSION["leftmenu"]) ? '' : $_SESSION["leftmenu"]); 47 48 $id = 'mainmenu'; 49 $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL); 50 51 // Show personalized menus 52 $menuArbo = new Menubase($db, 'auguria'); 53 $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria', $tabMenu); 54 55 $substitarray = getCommonSubstitutionArray($langs, 0, null, null); 56 57 if (empty($noout)) print_start_menu_array_auguria(); 58 59 global $usemenuhider; 60 $usemenuhider = 1; 61 62 // Show/Hide vertical menu. The hamburger icon for .menuhider action. 63 if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) 64 { 65 $showmode = 1; 66 $classname = 'class="tmenu menuhider"'; 67 $idsel = 'menu'; 68 69 $menu->add('#', (!empty($conf->global->THEME_TOPMENU_DISABLE_IMAGE) ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname); 70 } 71 72 $num = count($newTabMenu); 73 for ($i = 0; $i < $num; $i++) 74 { 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 $url = $shorturl = $newTabMenu[$i]['url']; 84 85 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url'])) 86 { 87 $tmp = explode('?', $newTabMenu[$i]['url'], 2); 88 $url = $shorturl = $tmp[0]; 89 $param = (isset($tmp[1]) ? $tmp[1] : ''); 90 91 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. 92 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($newTabMenu[$i]['url'])) 93 { 94 $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu='; 95 } 96 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($newTabMenu[$i]['url'])) 97 { 98 $param .= ($param ? '&' : '').'leftmenu='; 99 } 100 //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad 101 $url = dol_buildpath($url, 1).($param ? '?'.$param : ''); 102 //$shorturl = $shorturl.($param?'?'.$param:''); 103 $shorturl = $url; 104 105 if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl); 106 } 107 108 // TODO Find a generic solution 109 if (preg_match('/search_project_user=__search_project_user__/', $shorturl)) 110 { 111 $search_project_user = GETPOST('search_project_user', 'int'); 112 if ($search_project_user) $shorturl = preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl); 113 else $shorturl = preg_replace('/search_project_user=__search_project_user__/', '', $shorturl); 114 } 115 116 // Define the class (top menu selected or not) 117 if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname = 'class="tmenusel"'; 118 elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname = 'class="tmenusel"'; 119 else $classname = 'class="tmenu"'; 120 } elseif ($showmode == 2) { 121 $classname = 'class="tmenu"'; 122 } else { 123 $classname = ''; 124 } 125 126 $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); 127 } 128 129 // Sort on position 130 $menu->liste = dol_sort_array($menu->liste, 'position'); 131 132 // Output menu entries 133 // Show logo company 134 if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) 135 { 136 //$mysoc->logo_mini=(empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI); 137 $mysoc->logo_squarred_mini = (empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI); 138 139 $logoContainerAdditionalClass = 'backgroundforcompanylogo'; 140 if (!empty($conf->global->MAIN_INFO_SOCIETE_LOGO_NO_BACKGROUND)) { 141 $logoContainerAdditionalClass = ''; 142 } 143 144 if (!empty($mysoc->logo_squarred_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_squarred_mini)) 145 { 146 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini); 147 } 148 /*elseif (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini)) 149 { 150 $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_mini); 151 }*/ 152 else { 153 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_512x512_white.png'; 154 $logoContainerAdditionalClass = ''; 155 } 156 157 $title = $langs->trans("GoIntoSetupToChangeLogo"); 158 159 print "\n".'<!-- Show logo on menu -->'."\n"; 160 print_start_menu_entry_auguria('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1); 161 162 print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n"; 163 164 print_end_menu_entry_auguria(4); 165 } 166 167 if (empty($noout)) { 168 foreach ($menu->liste as $menuval) { 169 print_start_menu_entry_auguria($menuval['idsel'], $menuval['classname'], $menuval['enabled']); 170 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)); 171 print_end_menu_entry_auguria($menuval['enabled']); 172 } 173 } 174 175 $showmode = 1; 176 if (empty($noout)) { 177 print_start_menu_entry_auguria('', 'class="tmenuend"', $showmode); 178 print_end_menu_entry_auguria($showmode); 179 print_end_menu_array_auguria(); 180 } 181 182 return 0; 183} 184 185 186/** 187 * Output start menu array 188 * 189 * @return void 190 */ 191function print_start_menu_array_auguria() 192{ 193 global $conf; 194 195 print '<div class="tmenudiv">'; 196 print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>'; 197} 198 199/** 200 * Output start menu entry 201 * 202 * @param string $idsel Text 203 * @param string $classname String to add a css class 204 * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed 205 * @return void 206 */ 207function print_start_menu_entry_auguria($idsel, $classname, $showmode) 208{ 209 if ($showmode) 210 { 211 print '<li '.$classname.' id="mainmenutd_'.$idsel.'">'; 212 //print '<div class="tmenuleft tmenusep"></div>'; 213 print '<div class="tmenucenter">'; 214 } 215} 216 217/** 218 * Output menu entry 219 * 220 * @param string $text Text 221 * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed 222 * @param string $url Url 223 * @param string $id Id 224 * @param string $idsel Id sel 225 * @param string $classname Class name 226 * @param string $atarget Target 227 * @return void 228 */ 229function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $classname, $atarget) 230{ 231 global $langs; 232 233 if ($showmode == 1) { 234 print '<a class="tmenuimage" tabindex="-1" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">'; 235 print '<div class="'.$id.' '.$idsel.' topmenuimage"><span class="'.$id.' tmenuimage" id="mainmenuspan_'.$idsel.'"></span></div>'; 236 print '</a>'; 237 print '<a '.$classname.' id="mainmenua_'.$idsel.'" href="'.$url.'"'.($atarget ? ' target="'.$atarget.'"' : '').' title="'.dol_escape_htmltag($text).'">'; 238 print '<span class="mainmenuaspan">'; 239 print $text; 240 print '</span>'; 241 print '</a>'; 242 } elseif ($showmode == 2) { 243 print '<div class="'.$id.' '.$idsel.' topmenuimage tmenudisabled"><span class="'.$id.'" id="mainmenuspan_'.$idsel.'"></span></div>'; 244 print '<a class="tmenudisabled" id="mainmenua_'.$idsel.'" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'; 245 print '<span class="mainmenuaspan">'; 246 print $text; 247 print '</span>'; 248 print '</a>'; 249 } 250} 251 252/** 253 * Output end menu entry 254 * 255 * @param int $showmode 0 = hide, 1 = allowed or 2 = not allowed 256 * @return void 257 */ 258function print_end_menu_entry_auguria($showmode) 259{ 260 if ($showmode) 261 { 262 print '</div></li>'; 263 } 264 print "\n"; 265} 266 267/** 268 * Output menu array 269 * 270 * @return void 271 */ 272function print_end_menu_array_auguria() 273{ 274 print '</ul>'; 275 print '</div>'; 276 print "\n"; 277} 278 279 280 281/** 282 * Core function to output left menu auguria 283 * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home) 284 * 285 * @param DoliDB $db Database handler 286 * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add) 287 * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add) 288 * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) 289 * @param Menu $menu Object Menu to return back list of menu entries 290 * @param int $noout Disable output (Initialise &$menu only). 291 * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x' 292 * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not defined in session. 293 * @param array $moredata An array with more data to output 294 * @return int Nb of menu entries 295 */ 296function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null) 297{ 298 global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc; 299 300 $newmenu = $menu; 301 302 $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]); 303 $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"])); 304 305 global $usemenuhider; 306 $usemenuhider = 0; 307 308 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 309 { 310 print "\n"; 311 print "<!-- Begin SearchForm -->\n"; 312 print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n"; 313 print $moredata['searchform']; 314 print '</div>'."\n"; 315 print "<!-- End SearchForm -->\n"; 316 } 317 318 if (is_array($moredata) && !empty($moredata['bookmarks'])) 319 { 320 print "\n"; 321 print "<!-- Begin Bookmarks -->\n"; 322 print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n"; 323 print $moredata['bookmarks']; 324 print '</div>'."\n"; 325 print "<!-- End Bookmarks -->\n"; 326 } 327 328 $substitarray = getCommonSubstitutionArray($langs, 0, null, null); 329 330 // We update newmenu with entries found into database 331 $menuArbo = new Menubase($db, 'auguria'); 332 $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu); 333 334 // We update newmenu for special dynamic menus 335 if ($conf->banque->enabled && $user->rights->banque->lire && $mainmenu == 'bank') // Entry for each bank account 336 { 337 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example 338 339 $sql = "SELECT rowid, label, courant, rappro, courant"; 340 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account"; 341 $sql .= " WHERE entity = ".$conf->entity; 342 $sql .= " AND clos = 0"; 343 $sql .= " ORDER BY label"; 344 345 $resql = $db->query($sql); 346 if ($resql) 347 { 348 $numr = $db->num_rows($resql); 349 $i = 0; 350 351 if ($numr > 0) $newmenu->add('/compta/bank/list.php', $langs->trans("BankAccounts"), 0, $user->rights->banque->lire); 352 353 while ($i < $numr) 354 { 355 $objp = $db->fetch_object($resql); 356 $newmenu->add('/compta/bank/card.php?id='.$objp->rowid, $objp->label, 1, $user->rights->banque->lire); 357 if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) // If not cash account and not closed and can be reconciliate 358 { 359 $newmenu->add('/compta/bank/bankentries_list.php?id='.$objp->rowid, $langs->trans("Conciliate"), 2, $user->rights->banque->consolidate); 360 } 361 $i++; 362 } 363 } else dol_print_error($db); 364 $db->free($resql); 365 } 366 367 if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') // Entry in accountancy journal for each bank account 368 { 369 $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->rights->accounting->comptarapport->lire, '', 'accountancy', 'accountancy', 10); 370 371 // Multi journal 372 $sql = "SELECT rowid, code, label, nature"; 373 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal"; 374 $sql .= " WHERE entity = ".$conf->entity; 375 $sql .= " AND active = 1"; 376 $sql .= " ORDER BY label DESC"; 377 378 $resql = $db->query($sql); 379 if ($resql) 380 { 381 $numr = $db->num_rows($resql); 382 $i = 0; 383 384 if ($numr > 0) 385 { 386 while ($i < $numr) 387 { 388 $objp = $db->fetch_object($resql); 389 390 $nature = ''; 391 392 // Must match array $sourceList defined into journals_list.php 393 if ($objp->nature == 2 && !empty($conf->facture->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) $nature = "sells"; 394 if ($objp->nature == 3 395 && (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) 396 && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES)) 397 $nature = "purchases"; 398 if ($objp->nature == 4 && !empty($conf->banque->enabled)) $nature = "bank"; 399 if ($objp->nature == 5 && !empty($conf->expensereport->enabled) && empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) $nature = "expensereports"; 400 if ($objp->nature == 1) $nature = "various"; 401 if ($objp->nature == 8) $nature = "inventory"; 402 if ($objp->nature == 9) $nature = "hasnew"; 403 404 // To enable when page exists 405 if (empty($conf->global->ACCOUNTANCY_SHOW_DEVELOP_JOURNAL)) 406 { 407 if ($nature == 'various' || $nature == 'hasnew' || $nature == 'inventory') $nature = ''; 408 } 409 410 if ($nature) 411 { 412 $langs->load('accountancy'); 413 $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ... 414 $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, $journallabel, 2, $user->rights->accounting->comptarapport->lire); 415 } 416 $i++; 417 } 418 } else { 419 // Should not happend. Entries are added 420 $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->rights->accounting->comptarapport->lire); 421 } 422 } else dol_print_error($db); 423 $db->free($resql); 424 } 425 426 if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') // Entry for FTP 427 { 428 $MAXFTP = 20; 429 $i = 1; 430 while ($i <= $MAXFTP) 431 { 432 $paramkey = 'FTP_NAME_'.$i; 433 //print $paramkey; 434 if (!empty($conf->global->$paramkey)) 435 { 436 $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i; 437 438 $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24)); 439 } 440 $i++; 441 } 442 } 443 444 445 // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after 446 //var_dump($menu_array_before);exit; 447 //var_dump($menu_array_after);exit; 448 $menu_array = $newmenu->liste; 449 if (is_array($menu_array_before)) $menu_array = array_merge($menu_array_before, $menu_array); 450 if (is_array($menu_array_after)) $menu_array = array_merge($menu_array, $menu_array_after); 451 //var_dump($menu_array);exit; 452 if (!is_array($menu_array)) return 0; 453 454 // Show menu 455 $invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert"; 456 if (empty($noout)) 457 { 458 $altok = 0; $blockvmenuopened = false; $lastlevel0 = ''; 459 $num = count($menu_array); 460 for ($i = 0; $i < $num; $i++) // Loop on each menu entry 461 { 462 $showmenu = true; 463 if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) $showmenu = false; 464 465 // Begin of new left menu block 466 if (empty($menu_array[$i]['level']) && $showmenu) 467 { 468 $altok++; 469 $blockvmenuopened = true; 470 $lastopened = true; 471 for ($j = ($i + 1); $j < $num; $j++) 472 { 473 if (empty($menu_array[$j]['level'])) $lastopened = false; 474 } 475 if ($altok % 2 == 0) 476 { 477 print '<div class="blockvmenu blockvmenuimpair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n"; 478 } else { 479 print '<div class="blockvmenu blockvmenupair'.$invert.($lastopened ? ' blockvmenulast' : '').($altok == 1 ? ' blockvmenufirst' : '').'">'."\n"; 480 } 481 } 482 483 // Add tabulation 484 $tabstring = ''; 485 $tabul = ($menu_array[$i]['level'] - 1); 486 if ($tabul > 0) 487 { 488 for ($j = 0; $j < $tabul; $j++) 489 { 490 $tabstring .= ' '; 491 } 492 } 493 494 // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution 495 496 $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); 497 498 $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url']; 499 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) 500 { 501 $tmp = explode('?', $menu_array[$i]['url'], 2); 502 $url = $shorturl = $tmp[0]; 503 $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link 504 505 // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. 506 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) 507 { 508 $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu='; 509 } 510 if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) 511 { 512 $param .= ($param ? '&' : '').'leftmenu='; 513 } 514 //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad 515 $url = dol_buildpath($url, 1).($param ? '?'.$param : ''); 516 $shorturlwithoutparam = $shorturl; 517 $shorturl = $shorturl.($param ? '?'.$param : ''); 518 } 519 520 521 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'].' -->'."\n"; 522 523 // Menu level 0 524 if ($menu_array[$i]['level'] == 0) 525 { 526 if ($menu_array[$i]['enabled']) // Enabled so visible 527 { 528 print '<div class="menu_titre">'.$tabstring; 529 if ($shorturlwithoutparam) print '<a class="vmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>'; 530 else print '<span class="vmenu">'; 531 print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '').$menu_array[$i]['titre']; 532 if ($shorturlwithoutparam) print '</a>'; 533 else print '</span>'; 534 print '</div>'."\n"; 535 $lastlevel0 = 'enabled'; 536 } elseif ($showmenu) // Not enabled but visible (so greyed) 537 { 538 print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>'."\n"; 539 $lastlevel0 = 'greyed'; 540 } else { 541 $lastlevel0 = 'hidden'; 542 } 543 if ($showmenu) 544 { 545 print '<div class="menu_top"></div>'."\n"; 546 } 547 } 548 549 // Menu level > 0 550 if ($menu_array[$i]['level'] > 0) 551 { 552 $cssmenu = ''; 553 if ($menu_array[$i]['url']) $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url'])); 554 555 if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') // Enabled so visible, except if parent was not enabled. 556 { 557 print '<div class="menu_contenu'.$cssmenu.'">'.$tabstring; 558 if ($shorturlwithoutparam) print '<a class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'" href="'.$url.'"'.($menu_array[$i]['target'] ? ' target="'.$menu_array[$i]['target'].'"' : '').'>'; 559 else print '<span class="vsmenu" title="'.dol_escape_htmltag($menu_array[$i]['titre']).'">'; 560 print $menu_array[$i]['titre']; 561 if ($shorturlwithoutparam) print '</a>'; 562 else print '</span>'; 563 // If title is not pure text and contains a table, no carriage return added 564 if (!strstr($menu_array[$i]['titre'], '<table')) print '<br>'; 565 print '</div>'."\n"; 566 } elseif ($showmenu && $lastlevel0 == 'enabled') // Not enabled but visible (so greyed), except if parent was not enabled. 567 { 568 print '<div class="menu_contenu'.$cssmenu.'">'.$tabstring.'<font class="vsmenudisabled vsmenudisabledmargin">'.$menu_array[$i]['titre'].'</font><br></div>'."\n"; 569 } 570 } 571 572 // If next is a new block or if there is nothing after 573 if (empty($menu_array[$i + 1]['level'])) // End menu block 574 { 575 if ($showmenu) 576 print '<div class="menu_end"></div>'."\n"; 577 if ($blockvmenuopened) { print '</div>'."\n"; $blockvmenuopened = false; } 578 } 579 } 580 581 if ($altok) print '<div class="blockvmenuend"></div>'; // End menu block 582 } 583 584 return count($menu_array); 585} 586 587 588/** 589 * Function to test if an entry is enabled or not 590 * 591 * @param string $type_user 0=We need backoffice menu, 1=We need frontoffice menu 592 * @param array $menuentry Array for menu entry 593 * @param array $listofmodulesforexternal Array with list of modules allowed to external users 594 * @return int 0=Hide, 1=Show, 2=Show gray 595 */ 596function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal) 597{ 598 global $conf; 599 600 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms']; 601 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal); 602 if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition 603 if ($type_user && $menuentry['module']) 604 { 605 $tmploops = explode('|', $menuentry['module']); 606 $found = 0; 607 foreach ($tmploops as $tmploop) 608 { 609 if (in_array($tmploop, $listofmodulesforexternal)) { 610 $found++; break; 611 } 612 } 613 if (!$found) return 0; // Entry is for menus all excluded to external users 614 } 615 if (!$menuentry['perms'] && $type_user) return 0; // No permissions and user is external 616 if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) return 0; // No permissions and option to hide when not allowed, even for internal user, is on 617 if (!$menuentry['perms']) return 2; // No permissions and user is external 618 return 1; 619} 620