* Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see http://www.gnu.org/ */ /** * \file htdocs/core/menus/standard/auguria.lib.php * \brief Library for file auguria menus */ require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; /** * Core function to output top menu auguria * * @param DoliDB $db Database handler * @param string $atarget Target * @param int $type_user 0=Internal,1=External,2=All * @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @return void */ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu) { global $user,$conf,$langs,$dolibarr_main_db_name; $mainmenu=$_SESSION["mainmenu"]; $leftmenu=$_SESSION["leftmenu"]; $id='mainmenu'; $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL); //$tabMenu=array(); $menuArbo = new Menubase($db,'auguria'); $newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'auguria',$tabMenu); print_start_menu_array_auguria(); $num = count($newTabMenu); for($i = 0; $i < $num; $i++) { $idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']); $showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal); if ($showmode == 1) { // Define url if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) { $url = $newTabMenu[$i]['url']; } else { $url=dol_buildpath($newTabMenu[$i]['url'],1); if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url)) { if (! preg_match('/\?/',$url)) $url.='?'; else $url.='&'; $url.='mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu='; } //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad } $url=preg_replace('/__LOGIN__/',$user->login,$url); // Define the class (top menu selected or not) if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"'; else if (! empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname='class="tmenusel"'; else $classname='class="tmenu"'; } else if ($showmode == 2) $classname='class="tmenu"'; print_start_menu_entry_auguria($idsel,$classname); print_text_menu_entry_auguria($newTabMenu[$i]['titre'], $showmode, $url, $id, $idsel, $classname, $atarget, $newTabMenu[$i]['target']); print_end_menu_entry_auguria(); } print_end_menu_array_auguria(); print "\n"; } /** * Output start menu array * * @return void */ function print_start_menu_array_auguria() { print '
'; print ''; print '
'; print "\n"; } /** * Core function to output left menu auguria * * @param DoliDB $db Database handler * @param array $menu_array_before Table of menu entries to show before entries of menu handler * @param array $menu_array_after Table of menu entries to show after entries of menu handler * @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @return void */ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabMenu) { global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc; $overwritemenufor = array(); $newmenu = new Menu(); $mainmenu=$_SESSION["mainmenu"]; $leftmenu=$_SESSION["leftmenu"]; // Show logo company if (! empty($conf->global->MAIN_SHOW_LOGO)) { $mysoc->logo_mini=$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI; if (! empty($mysoc->logo_mini) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini)) { $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=companylogo&file='.urlencode('thumbs/'.$mysoc->logo_mini); print "\n".''."\n"; print '
'."\n"; print ''; print ''; print ''; print ''; print '
'."\n"; } } /** * We update newmenu with entries found into database * -------------------------------------------------- */ $menuArbo = new Menubase($db,'auguria'); $newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria',$tabMenu); //var_dump($menu_array_before);exit; //var_dump($menu_array_after);exit; $menu_array=$newmenu->liste; if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array); if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after); //var_dump($menu_array);exit; if (! is_array($menu_array)) return 0; // Show menu $alt=0; $num=count($menu_array); for ($i = 0; $i < $num; $i++) { $alt++; if (empty($menu_array[$i]['level'])) { if (($alt%2==0)) { if ($conf->use_javascript_ajax && ! empty($conf->global->MAIN_MENU_USE_JQUERY_ACCORDION)) { print '
'."\n"; } else { print '
'."\n"; } } else { print '
'."\n"; } } // Place tabulation $tabstring=''; $tabul=($menu_array[$i]['level'] - 1); if ($tabul > 0) { for ($j=0; $j < $tabul; $j++) { $tabstring.='   '; } } // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser. $url=dol_buildpath($menu_array[$i]['url'],1); if (! preg_match('/mainmenu=/i',$menu_array[$i]['url'])) { if (! preg_match('/\?/',$url)) $url.='?'; else $url.='&'; $url.='mainmenu='.$mainmenu; } print ''."\n"; // Menu niveau 0 if ($menu_array[$i]['level'] == 0) { if ($menu_array[$i]['enabled']) { print ''; } else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) { print ''; } print "\n".'
'."\n"; print ''."\n"; } // Menu niveau > 0 if ($menu_array[$i]['level'] > 0) { if ($menu_array[$i]['enabled']) { print ''; } else if (empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) { print ''; } } // If next is a new block or end if (empty($menu_array[$i+1]['level'])) { print ''."\n"; print "
\n"; print "
\n"; } } return count($menu_array); } /** * Function to test if an entry is enabled or not * * @param string $type_user 0=We need backoffice menu, 1=We need frontoffice menu * @param array &$menuentry Array for menu entry * @param array &$listofmodulesforexternal Array with list of modules allowed to external users * @return int 0=Hide, 1=Show, 2=Show gray */ function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexternal) { //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms']; //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal); if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition if ($type_user && $menuentry['module']) { $tmploops=explode('|',$menuentry['module']); $found=0; foreach($tmploops as $tmploop) { if (in_array($tmploop, $listofmodulesforexternal)) { $found++; break; } } if (! $found) return 0; // Entry is for menus all excluded to external users } if (! $menuentry['perms'] && $type_user) return 0; // No permissions and user is external 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 if (! $menuentry['perms']) return 2; // No permissions and user is external return 1; } ?>