diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 5d2181c3e82..efe8d87ff86 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -676,6 +676,373 @@ function print_end_menu_array() print "\n"; } +/** + * Core function to output left menu eldy + * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home) + * + * @param DoliDB $db Database handler + * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add) + * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add) + * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) + * @param Menu $menu Object Menu to return back list of menu entries + * @param int $noout Disable output (Initialise &$menu only). + * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x' + * @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. + * @param array $moredata An array with more data to output + * @param int $type_user 0=Menu for backoffice, 1=Menu for front office + * @return int Nb of menu entries + */ +function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0) +{ + + global $user, $conf, $langs, $hookmanager; + + //var_dump($tabMenu); + + $newmenu = $menu; + + $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]); + $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"])); + + $usemenuhider = 0; + + 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 + print "\n"; + print "\n"; + print '
'."\n"; + print $moredata['searchform']; + print '
'."\n"; + print "\n"; + } + + if (is_array($moredata) && !empty($moredata['bookmarks'])) { + print "\n"; + print "\n"; + print '
'."\n"; + print $moredata['bookmarks']; + print '
'."\n"; + print "\n"; + } + + $substitarray = getCommonSubstitutionArray($langs, 0, null, null); + + $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL); + + /** + * We update newmenu with entries found into database + * -------------------------------------------------- + */ + if ($mainmenu) { // If this is empty, loading hard coded menu and loading personalised menu will fail + /* + * Menu HOME + */ + if ($mainmenu == 'home') { + get_left_menu_home($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu THIRDPARTIES + */ + if ($mainmenu == 'companies') { + get_left_menu_thridparties($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu COMMERCIAL (propal, commande, supplier_proposal, supplier_order, contrat, ficheinter) + */ + if ($mainmenu == 'commercial') { + get_left_menu_commercial($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu COMPTA-FINANCIAL + */ + if ($mainmenu == 'billing') { + get_left_menu_billing($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu COMPTA-FINANCIAL + */ + if ($mainmenu == 'accountancy') { + get_left_menu_accountancy($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user, $db); + } + + /* + * Menu BANK + */ + if ($mainmenu == 'bank') { + get_left_menu_bank($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu PRODUCTS-SERVICES + */ + if ($mainmenu == 'products') { + get_left_menu_products($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu PRODUCTS-SERVICES MRP - GPAO + */ + if ($mainmenu == 'mrp') { + get_left_menu_mrp($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu PROJECTS + */ + if ($mainmenu == 'project') { + get_left_menu_projects($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu HRM + */ + if ($mainmenu == 'hrm') { + get_left_menu_hrm($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu TOOLS + */ + if ($mainmenu == 'tools') { + get_left_menu_tools($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + /* + * Menu MEMBERS + */ + if ($mainmenu == 'members') { + get_left_menu_members($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); + } + + // Add personalized menus and modules menus + //var_dump($newmenu->liste); // + $menuArbo = new Menubase($db, 'eldy'); + $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, (empty($user->socid) ? 0 : 1), 'eldy', $tabMenu); + //var_dump($newmenu->liste); // + + if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') { // Entry for FTP + $MAXFTP = 20; + $i = 1; + while ($i <= $MAXFTP) { + $paramkey = 'FTP_NAME_'.$i; + //print $paramkey; + if (!empty($conf->global->$paramkey)) { + $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i; + $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24)); + } + $i++; + } + } + } + + //var_dump($tabMenu); // + //var_dump($newmenu->liste); + + // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after + //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; + } + + // Allow the $menu_array of the menu to be manipulated by modules + $parameters = array( + 'mainmenu' => $mainmenu, + ); + $hook_items = $menu_array; + $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks + + if (is_numeric($reshook)) { + if ($reshook == 0 && !empty($hookmanager->results)) { + $menu_array[] = $hookmanager->results; // add + } elseif ($reshook == 1) { + $menu_array = $hookmanager->results; // replace + } + + // @todo Sort menu items by 'position' value + // $position = array(); + // foreach ($menu_array as $key => $row) { + // $position[$key] = $row['position']; + // } + // array_multisort($position, SORT_ASC, $menu_array); + } + + // TODO Use the position property in menu_array to reorder the $menu_array + //var_dump($menu_array); + /*$new_menu_array = array(); + $level=0; $cusor=0; $position=0; + $nbentry = count($menu_array); + while (findNextEntryForLevel($menu_array, $cursor, $position, $level)) + { + + $cursor++; + }*/ + + // Show menu + $invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert"; + if (empty($noout)) { + $altok = 0; + $blockvmenuopened = false; + $lastlevel0 = ''; + $num = count($menu_array); + for ($i = 0; $i < $num; $i++) { // Loop on each menu entry + $showmenu = true; + if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) { + $showmenu = false; + } + + // Begin of new left menu block + if (empty($menu_array[$i]['level']) && $showmenu) { + $altok++; + $blockvmenuopened = true; + $lastopened = true; + for ($j = ($i + 1); $j < $num; $j++) { + if (empty($menu_array[$j]['level'])) { + $lastopened = false; + } + } + if ($altok % 2 == 0) { + print '
'."\n"; + } else { + print '
'."\n"; + } + } + + // Add tabulation + $tabstring = ''; + $tabul = ($menu_array[$i]['level'] - 1); + if ($tabul > 0) { + for ($j = 0; $j < $tabul; $j++) { + $tabstring .= '   '; + } + } + + // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution + + $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); + + $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url']; + if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) { + $tmp = explode('?', $menu_array[$i]['url'], 2); + $url = $shorturl = $tmp[0]; + $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link + + // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. + if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) { + $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu='; + } + if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) { + $param .= ($param ? '&' : '').'leftmenu='; + } + //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad + $url = dol_buildpath($url, 1).($param ? '?'.$param : ''); + $shorturlwithoutparam = $shorturl; + $shorturl = $shorturl.($param ? '?'.$param : ''); + } + + + print ''."\n"; + + // Menu level 0 + if ($menu_array[$i]['level'] == 0) { + if ($menu_array[$i]['enabled']) { // Enabled so visible + print ''."\n"; + $lastlevel0 = 'enabled'; + } elseif ($showmenu) { // Not enabled but visible (so greyed) + print ''."\n"; + $lastlevel0 = 'greyed'; + } else { + $lastlevel0 = 'hidden'; + } + if ($showmenu) { + print ''."\n"; + } + } + + // Menu level > 0 + if ($menu_array[$i]['level'] > 0) { + $cssmenu = ''; + if ($menu_array[$i]['url']) { + $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url'])); + } + + if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') { + // Enabled so visible, except if parent was not enabled. + print ''."\n"; + } elseif ($showmenu && $lastlevel0 == 'enabled') { + // Not enabled but visible (so greyed), except if parent was not enabled. + print ''."\n"; + } + } + + // If next is a new block or if there is nothing after + if (empty($menu_array[$i + 1]['level'])) { // End menu block + if ($showmenu) { + print ''."\n"; + } + if ($blockvmenuopened) { + print '
'."\n"; + $blockvmenuopened = false; + } + } + } + + if ($altok) { + print '
'; // End menu block + } + } + + return count($menu_array); +} + + /** * Get left Menu HOME * @@ -1516,7 +1883,6 @@ function get_left_menu_accountancy($mainmenu, &$newmenu, $usemenuhider = 1, $lef } } - /** * Get left Menu BANK * @@ -2042,369 +2408,3 @@ function get_left_menu_members($mainmenu, &$newmenu, $usemenuhider = 1, $leftmen } } } - -/** - * Core function to output left menu eldy - * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home) - * - * @param DoliDB $db Database handler - * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add) - * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add) - * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) - * @param Menu $menu Object Menu to return back list of menu entries - * @param int $noout Disable output (Initialise &$menu only). - * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x' - * @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. - * @param array $moredata An array with more data to output - * @param int $type_user 0=Menu for backoffice, 1=Menu for front office - * @return int Nb of menu entries - */ -function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0) -{ - - global $user, $conf, $langs, $hookmanager; - - //var_dump($tabMenu); - - $newmenu = $menu; - - $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]); - $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"])); - - $usemenuhider = 0; - - 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 - print "\n"; - print "\n"; - print '
'."\n"; - print $moredata['searchform']; - print '
'."\n"; - print "\n"; - } - - if (is_array($moredata) && !empty($moredata['bookmarks'])) { - print "\n"; - print "\n"; - print '
'."\n"; - print $moredata['bookmarks']; - print '
'."\n"; - print "\n"; - } - - $substitarray = getCommonSubstitutionArray($langs, 0, null, null); - - $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL); - - /** - * We update newmenu with entries found into database - * -------------------------------------------------- - */ - if ($mainmenu) { // If this is empty, loading hard coded menu and loading personalised menu will fail - /* - * Menu HOME - */ - if ($mainmenu == 'home') { - get_left_menu_home($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu THIRDPARTIES - */ - if ($mainmenu == 'companies') { - get_left_menu_thridparties($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu COMMERCIAL (propal, commande, supplier_proposal, supplier_order, contrat, ficheinter) - */ - if ($mainmenu == 'commercial') { - get_left_menu_commercial($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu COMPTA-FINANCIAL - */ - if ($mainmenu == 'billing') { - get_left_menu_billing($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu COMPTA-FINANCIAL - */ - if ($mainmenu == 'accountancy') { - get_left_menu_accountancy($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user, $db); - } - - /* - * Menu BANK - */ - if ($mainmenu == 'bank') { - get_left_menu_bank($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu PRODUCTS-SERVICES - */ - if ($mainmenu == 'products') { - get_left_menu_products($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu PRODUCTS-SERVICES MRP - GPAO - */ - if ($mainmenu == 'mrp') { - get_left_menu_mrp($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu PROJECTS - */ - if ($mainmenu == 'project') { - get_left_menu_projects($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu HRM - */ - if ($mainmenu == 'hrm') { - get_left_menu_hrm($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu TOOLS - */ - if ($mainmenu == 'tools') { - get_left_menu_tools($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - /* - * Menu MEMBERS - */ - if ($mainmenu == 'members') { - get_left_menu_members($mainmenu, $newmenu, $usemenuhider, $leftmenu, $type_user); - } - - // Add personalized menus and modules menus - //var_dump($newmenu->liste); // - $menuArbo = new Menubase($db, 'eldy'); - $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, (empty($user->socid) ? 0 : 1), 'eldy', $tabMenu); - //var_dump($newmenu->liste); // - - if (!empty($conf->ftp->enabled) && $mainmenu == 'ftp') { // Entry for FTP - $MAXFTP = 20; - $i = 1; - while ($i <= $MAXFTP) { - $paramkey = 'FTP_NAME_'.$i; - //print $paramkey; - if (!empty($conf->global->$paramkey)) { - $link = "/ftp/index.php?idmenu=".$_SESSION["idmenu"]."&numero_ftp=".$i; - $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24)); - } - $i++; - } - } - } - - //var_dump($tabMenu); // - //var_dump($newmenu->liste); - - // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after - //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; - } - - // Allow the $menu_array of the menu to be manipulated by modules - $parameters = array( - 'mainmenu' => $mainmenu, - ); - $hook_items = $menu_array; - $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks - - if (is_numeric($reshook)) { - if ($reshook == 0 && !empty($hookmanager->results)) { - $menu_array[] = $hookmanager->results; // add - } elseif ($reshook == 1) { - $menu_array = $hookmanager->results; // replace - } - - // @todo Sort menu items by 'position' value - // $position = array(); - // foreach ($menu_array as $key => $row) { - // $position[$key] = $row['position']; - // } - // array_multisort($position, SORT_ASC, $menu_array); - } - - // TODO Use the position property in menu_array to reorder the $menu_array - //var_dump($menu_array); - /*$new_menu_array = array(); - $level=0; $cusor=0; $position=0; - $nbentry = count($menu_array); - while (findNextEntryForLevel($menu_array, $cursor, $position, $level)) - { - - $cursor++; - }*/ - - // Show menu - $invert = empty($conf->global->MAIN_MENU_INVERT) ? "" : "invert"; - if (empty($noout)) { - $altok = 0; - $blockvmenuopened = false; - $lastlevel0 = ''; - $num = count($menu_array); - for ($i = 0; $i < $num; $i++) { // Loop on each menu entry - $showmenu = true; - if (!empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) { - $showmenu = false; - } - - // Begin of new left menu block - if (empty($menu_array[$i]['level']) && $showmenu) { - $altok++; - $blockvmenuopened = true; - $lastopened = true; - for ($j = ($i + 1); $j < $num; $j++) { - if (empty($menu_array[$j]['level'])) { - $lastopened = false; - } - } - if ($altok % 2 == 0) { - print '
'."\n"; - } else { - print '
'."\n"; - } - } - - // Add tabulation - $tabstring = ''; - $tabul = ($menu_array[$i]['level'] - 1); - if ($tabul > 0) { - for ($j = 0; $j < $tabul; $j++) { - $tabstring .= '   '; - } - } - - // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution - - $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); - - $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url']; - if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) { - $tmp = explode('?', $menu_array[$i]['url'], 2); - $url = $shorturl = $tmp[0]; - $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link - - // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. - if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) { - $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu='; - } - if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) { - $param .= ($param ? '&' : '').'leftmenu='; - } - //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad - $url = dol_buildpath($url, 1).($param ? '?'.$param : ''); - $shorturlwithoutparam = $shorturl; - $shorturl = $shorturl.($param ? '?'.$param : ''); - } - - - print ''."\n"; - - // Menu level 0 - if ($menu_array[$i]['level'] == 0) { - if ($menu_array[$i]['enabled']) { // Enabled so visible - print ''."\n"; - $lastlevel0 = 'enabled'; - } elseif ($showmenu) { // Not enabled but visible (so greyed) - print ''."\n"; - $lastlevel0 = 'greyed'; - } else { - $lastlevel0 = 'hidden'; - } - if ($showmenu) { - print ''."\n"; - } - } - - // Menu level > 0 - if ($menu_array[$i]['level'] > 0) { - $cssmenu = ''; - if ($menu_array[$i]['url']) { - $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url'])); - } - - if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') { - // Enabled so visible, except if parent was not enabled. - print ''."\n"; - } elseif ($showmenu && $lastlevel0 == 'enabled') { - // Not enabled but visible (so greyed), except if parent was not enabled. - print ''."\n"; - } - } - - // If next is a new block or if there is nothing after - if (empty($menu_array[$i + 1]['level'])) { // End menu block - if ($showmenu) { - print ''."\n"; - } - if ($blockvmenuopened) { - print '
'."\n"; - $blockvmenuopened = false; - } - } - } - - if ($altok) { - print '
'; // End menu block - } - } - - return count($menu_array); -}