* Copyright (C) 2009 Regis Houssin * Copyright (C) 2008-2013 Laurent Destailleur * Copyright (C) 2024 MDW * Copyright (C) 2024 Frédéric France * * 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 . */ /** * \file htdocs/core/menus/standard/auguria_menu.php * \brief Menu auguria manager */ /** * Class to manage menu Auguria * * @phan-suppress PhanRedefineClass */ class MenuManager { /** * @var DoliDB Database handler. */ public $db; /** * @var int<0,1> 0 for internal users, 1 for external users */ public $type_user; /** * @var string Default target to use for links */ public $atarget = ""; /** * @var string Menu name */ public $name = "auguria"; /** * @var Menu */ public $menu; /** * @var array,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,level:int,prefix:string}> */ public $menu_array; /** * @var array,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,level:int,prefix:string}> */ public $menu_array_after; /** * @var array,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,level:int,prefix:string}> */ public $tabMenu; /** * Constructor * * @param DoliDB $db Database handler * @param int<0,1> $type_user Type of user */ public function __construct($db, $type_user) { $this->type_user = $type_user; $this->db = $db; } /** * Load this->tabMenu * * @param string $forcemainmenu To force mainmenu to load * @param string $forceleftmenu To force leftmenu to load * @return void */ public function loadMenu($forcemainmenu = '', $forceleftmenu = '') { global $conf, $user, $langs; // We save into session the main menu selected if (GETPOSTISSET("mainmenu")) { $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09'); } if (GETPOSTISSET("idmenu")) { $_SESSION["idmenu"] = GETPOSTINT("idmenu"); } // Read now mainmenu and leftmenu that define which menu to show if (GETPOSTISSET("mainmenu")) { // On sauve en session le menu principal choisi $mainmenu = GETPOST("mainmenu", 'aZ09'); $_SESSION["mainmenu"] = $mainmenu; $_SESSION["leftmenuopened"] = ""; } else { // Look for the menu in the session if not set by the link $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : ''; } if (!empty($forcemainmenu)) { $mainmenu = $forcemainmenu; } if (GETPOSTISSET("leftmenu")) { // On sauve en session le menu principal choisi $leftmenu = GETPOST("leftmenu", 'aZ09'); $_SESSION["leftmenu"] = $leftmenu; if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse //$leftmenu=""; $_SESSION["leftmenuopened"] = ""; } else { $_SESSION["leftmenuopened"] = $leftmenu; } } else { // Look for the menu in the session if not set by the link $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : ''; } if (!empty($forceleftmenu)) { $leftmenu = $forceleftmenu; } require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; $tabMenu = array(); $menuArbo = new Menubase($this->db, 'auguria'); $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu); $this->tabMenu = $tabMenu; //var_dump($tabMenu); //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; } } /** * Show menu. * Menu defined in sql tables were stored into $this->tabMenu BEFORE this is called. * * @param string $mode 'top', 'topnb', 'left', 'jmobile' (used to get full xml ul/li menu) * @param ?array $moredata An array with more data to output * @return int<0,max> 0 or nb of top menu entries if $mode = 'topnb' */ public function showmenu($mode, $moredata = null) { global $conf, $langs, $user; require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php'; if ($this->type_user == 1) { $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1; $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1; } require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php'; $this->menu = new Menu(); if (!getDolGlobalString('MAIN_MENU_INVERT')) { if ($mode == 'top') { print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode); } if ($mode == 'left') { print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata); } } else { $conf->global->MAIN_SHOW_LOGO = 0; if ($mode == 'top') { print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0); } if ($mode == 'left') { print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode); } } if ($mode == 'topnb') { print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); return $this->menu->getNbOfVisibleMenuEntries(); } if ($mode == 'jmobile') { // Used to get menu in xml ul/li print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // $this->menu->liste is top menu //var_dump($this->menu->liste);exit; $lastlevel = array(); $showmenu = true; // Is current menu shown - define here to keep static code checker happy print ''."\n"; foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' print ''."\n"; } } unset($this->menu); //print 'xx'.$mode; return 0; } }