From c11f7dfc71ff9d76445e824bad709f58610e1a8e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 5 Mar 2013 15:42:26 +0100 Subject: [PATCH] Next step for rewriting menu managers. --- htdocs/core/class/menu.class.php | 2 +- htdocs/core/getmenu_jmobile.php | 5 +- .../core/menus/smartphone/smartphone.lib.php | 2 +- .../core/menus/smartphone/smartphone_menu.php | 20 ++++-- htdocs/core/menus/standard/auguria.lib.php | 22 +++--- htdocs/core/menus/standard/auguria_menu.php | 30 +++++--- htdocs/core/menus/standard/eldy.lib.php | 32 +++++---- htdocs/core/menus/standard/eldy_menu.php | 32 ++++++--- htdocs/core/menus/standard/empty.php | 72 ++++++++++--------- htdocs/main.inc.php | 1 + 10 files changed, 142 insertions(+), 76 deletions(-) diff --git a/htdocs/core/class/menu.class.php b/htdocs/core/class/menu.class.php index 409301cc367..411158dea84 100644 --- a/htdocs/core/class/menu.class.php +++ b/htdocs/core/class/menu.class.php @@ -54,7 +54,7 @@ class Menu * @param string $url Url to follow on click * @param string $titre Label of menu to add * @param string $level Level of menu to add - * @param int $enabled Menu active or not + * @param int $enabled Menu active or not (0=Not active, 1=Active, 2=Active but grey) * @param string $target Target lien * @param string $mainmenu Main menu ('home', 'companies', 'products', ...) * @param string $leftmenu Left menu ('setup', 'system', 'admintools', ...) diff --git a/htdocs/core/getmenu_jmobile.php b/htdocs/core/getmenu_jmobile.php index a0ab2e5728d..f7eaada8283 100644 --- a/htdocs/core/getmenu_jmobile.php +++ b/htdocs/core/getmenu_jmobile.php @@ -88,10 +88,13 @@ if (! class_exists('MenuManager')) } } $menumanager = new MenuManager($db, empty($user->societe_id)?0:1); +$menumanager->loadMenu(); $menumanager->showmenu('jmobile'); -print ''."\n"; +print ''; + +print ''."\n"; $db->close(); ?> diff --git a/htdocs/core/menus/smartphone/smartphone.lib.php b/htdocs/core/menus/smartphone/smartphone.lib.php index 6271b32b877..ad71482fe10 100755 --- a/htdocs/core/menus/smartphone/smartphone.lib.php +++ b/htdocs/core/menus/smartphone/smartphone.lib.php @@ -33,7 +33,7 @@ * @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_smartphone_menu($db,$atarget,$type_user,$limitmenuto,&$tabMenu) +function print_smartphone_menu($db,$atarget,$type_user,$limitmenuto,&$tabMenu,&$menu) { require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; diff --git a/htdocs/core/menus/smartphone/smartphone_menu.php b/htdocs/core/menus/smartphone/smartphone_menu.php index c547df7b588..1b8b87de0dd 100755 --- a/htdocs/core/menus/smartphone/smartphone_menu.php +++ b/htdocs/core/menus/smartphone/smartphone_menu.php @@ -45,7 +45,15 @@ class MenuSmart { $this->type_user=$type_user; $this->db=$db; - + } + + /** + * Load this->tabMenu + * + * @return void + */ + function loadMenu() + { // On sauve en session le menu principal choisi if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; @@ -86,8 +94,8 @@ class MenuSmart require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; $tabMenu=array(); - $menuArbo = new Menubase($db,'smartphone'); - $menuArbo->menuLoad($mainmenu, $leftmenu, $type_user, 'smartphone', $tabMenu); + $menuArbo = new Menubase($this->db,'smartphone'); + $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'smartphone', $tabMenu); $this->tabMenu=$tabMenu; } @@ -110,7 +118,11 @@ class MenuSmart $conf->global->MAIN_SEARCHFORM_CONTACT=0; } - print_smartphone_menu($this->db,$this->atarget,$this->hideifnotallowed,$mode,$this->tabMenu); + $this->menu=new Menu(); + + print_smartphone_menu($this->db,$this->atarget,$this->hideifnotallowed,$mode,$this->tabMenu,$this->menu); + + unset($this->menu); return 1; } diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php index 03141313182..e96fe021411 100644 --- a/htdocs/core/menus/standard/auguria.lib.php +++ b/htdocs/core/menus/standard/auguria.lib.php @@ -32,9 +32,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; * @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) + * @param array &$menu Object Menu to return back list of menu entries * @return void */ -function print_auguria_menu($db,$atarget,$type_user,&$tabMenu) +function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu) { global $user,$conf,$langs,$dolibarr_main_db_name; @@ -122,7 +123,7 @@ function print_start_menu_entry_auguria($idsel,$classname) * Output menu entry * * @param string $text Text - * @param int $showmode 1 or 2 + * @param int $showmode 1 = allowed or 2 = not allowed * @param string $url Url * @param string $id Id * @param string $idsel Id sel @@ -150,6 +151,10 @@ function print_text_menu_entry_auguria($text, $showmode, $url, $id, $idsel, $cla { print '
'; print ''; + print ''; + print $text; + print ''; + print ''; } } @@ -181,18 +186,19 @@ function print_end_menu_array_auguria() /** * 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) + * @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) + * @param array &$menu Object Menu to return back list of menu entries * @return void */ -function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabMenu) +function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabMenu,&$menu) { global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc; $overwritemenufor = array(); - $newmenu = new Menu(); + $newmenu = $menu; $mainmenu=$_SESSION["mainmenu"]; $leftmenu=$_SESSION["leftmenu"]; diff --git a/htdocs/core/menus/standard/auguria_menu.php b/htdocs/core/menus/standard/auguria_menu.php index 36ca1269761..b7c76af0d32 100644 --- a/htdocs/core/menus/standard/auguria_menu.php +++ b/htdocs/core/menus/standard/auguria_menu.php @@ -47,12 +47,21 @@ class MenuManager */ function __construct($db, $type_user) { - global $conf, $user, $langs; - $this->type_user=$type_user; $this->db=$db; - - // On sauve en session le menu principal choisi + } + + + /** + * Load this->tabMenu + * + * @return void + */ + function loadMenu() + { + global $conf, $user, $langs; + + // On sauve en session le menu principal choisi if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; @@ -92,8 +101,8 @@ class MenuManager require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; $tabMenu=array(); - $menuArbo = new Menubase($db,'auguria'); - $menuArbo->menuLoad($mainmenu, $leftmenu, $type_user, 'auguria', $tabMenu); + $menuArbo = new Menubase($this->db,'auguria'); + $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu); // Modules system tools // TODO Find a way to add parent menu only if child menu exists. For the moment, no other method than hard coded methods. @@ -158,9 +167,14 @@ class MenuManager } $res='ErrorBadParameterForMode'; - if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu); - if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu); + + $this->menu=new Menu(); + + if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu); + if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu); + unset($this->menu); + return $res; } } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 686f3f83754..e5ea13ea1ae 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -31,10 +31,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; * @param DoliDB $db Database handler * @param string $atarget Target * @param int $type_user 0=Menu for backoffice, 1=Menu for front office - * @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) + * @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) + * @param array &$menu Object Menu to return back list of menu entries * @return void */ -function print_eldy_menu($db,$atarget,$type_user,&$tabMenu) +function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu) { global $user,$conf,$langs,$dolibarr_main_db_name; @@ -72,6 +73,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu) print_start_menu_entry($idsel,$classname); print_text_menu_entry($langs->trans("ThirdParties"), $showmode, DOL_URL_ROOT.'/societe/index.php?mainmenu=companies&leftmenu=', $id, $idsel, $classname, $atarget); print_end_menu_entry(); + $menu->add(DOL_URL_ROOT.'/societe/index.php?mainmenu=companies&leftmenu=', $langs->trans("ThirdParties"), 0, $showmode, $atarget, $mainmenu, $leftmenu); } // Products-Services @@ -312,7 +314,7 @@ function print_start_menu_entry($idsel,$classname) * Output menu entry * * @param string $text Text - * @param int $showmode 1 or 2 + * @param int $showmode 1 = allowed or 2 = not allowed * @param string $url Url * @param string $id Id * @param string $idsel Id sel @@ -340,6 +342,10 @@ function print_text_menu_entry($text, $showmode, $url, $id, $idsel, $classname, { print '
'; print ''; + print ''; + print $text; + print ''; + print ''; } } @@ -375,13 +381,14 @@ function print_end_menu_array() * @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) + * @param array &$menu Object Menu to return back list of menu entries * @return void */ -function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu) +function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu,&$menu) { global $user,$conf,$langs,$dolibarr_main_db_name,$mysoc; - $newmenu = new Menu(); + $newmenu = $menu; $mainmenu=$_SESSION["mainmenu"]; $leftmenu=$_SESSION["leftmenu"]; @@ -1241,15 +1248,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu * @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_jmobile_eldy_menu($db,$atarget,$type_user,&$tabMenu) +function print_jmobile_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu) { - print ''; + print ''; } /** diff --git a/htdocs/core/menus/standard/eldy_menu.php b/htdocs/core/menus/standard/eldy_menu.php index afebe8d9e6a..ffe5470728e 100644 --- a/htdocs/core/menus/standard/eldy_menu.php +++ b/htdocs/core/menus/standard/eldy_menu.php @@ -48,7 +48,16 @@ class MenuManager { $this->type_user=$type_user; $this->db=$db; - + } + + + /** + * Load this->tabMenu + * + * @return void + */ + function loadMenu() + { // On sauve en session le menu principal choisi if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; @@ -89,8 +98,8 @@ class MenuManager require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; $tabMenu=array(); - $menuArbo = new Menubase($db,'eldy'); - $menuArbo->menuLoad($mainmenu, $leftmenu, $type_user, 'eldy', $tabMenu); + $menuArbo = new Menubase($this->db,'eldy'); + $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu); $this->tabMenu=$tabMenu; } @@ -112,12 +121,19 @@ class MenuManager $conf->global->MAIN_SEARCHFORM_SOCIETE=0; $conf->global->MAIN_SEARCHFORM_CONTACT=0; } - - $res='ErrorBadParameterForMode'; - if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu); - if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu); - if ($mode == 'jmobile') $res=print_jmobile_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu); + $res='ErrorBadParameterForMode'; + + $this->menu=new Menu(); + + if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu); + if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu); + if ($mode == 'jmobile') $res=print_jmobile_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu); + + unset($this->menu); + + //print 'xx'.$mode; + //var_dump($this->menu); return $res; } diff --git a/htdocs/core/menus/standard/empty.php b/htdocs/core/menus/standard/empty.php index 35e8500e746..83b49382da3 100644 --- a/htdocs/core/menus/standard/empty.php +++ b/htdocs/core/menus/standard/empty.php @@ -29,7 +29,7 @@ class MenuManager var $type_user=0; // Put 0 for internal users, 1 for external users var $atarget=""; // To store default target to use onto links - var $menu_array; + var $menu; var $menu_array_after; @@ -46,6 +46,17 @@ class MenuManager } + /** + * Load this->tabMenu + * + * @return void + */ + function loadMenu() + { + + } + + /** * Show menu * @@ -58,6 +69,8 @@ class MenuManager $id='mainmenu'; + $this->menu=new Menu(); + if ($mode == 'top') { print_start_menu_array_empty(); @@ -74,40 +87,35 @@ class MenuManager if ($mode == 'left') { - $newmenu = new Menu(); - // Put here left menu entries // ***** START ***** $langs->load("admin"); // Load translation file admin.lang - $newmenu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0); - $newmenu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1); - $newmenu->add("/admin/modules.php", $langs->trans("Modules"),1); - $newmenu->add("/admin/menus.php", $langs->trans("Menus"),1); - $newmenu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); - $newmenu->add("/admin/boxes.php", $langs->trans("Boxes"),1); - $newmenu->add("/admin/delais.php",$langs->trans("Alerts"),1); - $newmenu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1); - $newmenu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1); - $newmenu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1); - $newmenu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1); - $newmenu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"),1); - $newmenu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionnarySetup"),1); - $newmenu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"),1); + $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"),0); + $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"),1); + $this->menu->add("/admin/modules.php", $langs->trans("Modules"),1); + $this->menu->add("/admin/menus.php", $langs->trans("Menus"),1); + $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"),1); + $this->menu->add("/admin/boxes.php", $langs->trans("Boxes"),1); + $this->menu->add("/admin/delais.php",$langs->trans("Alerts"),1); + $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"),1); + $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"),1); + $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"),1); + $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"),1); + $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"),1); + $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionnarySetup"),1); + $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"),1); // ***** END ***** // do not change code after this - // override menu_array by value array in $newmenu - $this->menu_array=$newmenu->liste; - $alt=0; - $num=count($this->menu_array); + $num=count($this->menu->liste); for ($i = 0; $i < $num; $i++) { $alt++; - if (empty($this->menu_array[$i]['level'])) + if (empty($this->menu->liste[$i]['level'])) { if (($alt%2==0)) { @@ -121,7 +129,7 @@ class MenuManager // Place tabulation $tabstring=''; - $tabul=($this->menu_array[$i]['level'] - 1); + $tabul=($this->menu->liste[$i]['level'] - 1); if ($tabul > 0) { for ($j=0; $j < $tabul; $j++) @@ -130,31 +138,31 @@ class MenuManager } } - if ($this->menu_array[$i]['level'] == 0) { - if ($this->menu_array[$i]['enabled']) + if ($this->menu->liste[$i]['level'] == 0) { + if ($this->menu->liste[$i]['enabled']) { - print ''."\n"; + print ''."\n"; } else { - print ''."\n"; + print ''."\n"; } print ''."\n"; } - if ($this->menu_array[$i]['level'] > 0) { + if ($this->menu->liste[$i]['level'] > 0) { print ''."\n"; } // If next is a new block or end - if (empty($this->menu_array[$i+1]['level'])) + if (empty($this->menu->liste[$i+1]['level'])) { print ''."\n"; print "\n"; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index bc9cd14a938..a3262e69ec1 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -807,6 +807,7 @@ if (! defined('NOREQUIREMENU')) } } $menumanager = new MenuManager($db, empty($user->societe_id)?0:1); + $menumanager->loadMenu(); }