Qual: Simplify system for menu manager. Only one file, one class per

manager.
This commit is contained in:
Laurent Destailleur 2013-01-25 17:44:23 +01:00
parent 2aa548560b
commit c2d334624b
13 changed files with 111 additions and 213 deletions

View File

@ -4,9 +4,12 @@ English Dolibarr ChangeLog
***** ChangeLog for 3.4 compared to 3.3 *****
For users:
- New: Some performance enhancements
- New: Some performance enhancements.
- New: Can attach files onto trip and expenses modules.
For developers:
- System of menu managers has been rewritten to reduce code to do same things.
- An external module can force its theme.
For translators:

View File

@ -77,10 +77,6 @@ if ($action == 'update' && empty($_POST["cancel"]))
// Define list of menu handlers to initialize
$listofmenuhandler=array();
$listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENU_STANDARD"])]=1;
$listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENUFRONT_STANDARD"])]=1;
if (isset($_POST["MAIN_MENU_SMARTPHONE"])) $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENU_SMARTPHONE"])]=1;
if (isset($_POST["MAIN_MENUFRONT_SMARTPHONE"])) $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENUFRONT_SMARTPHONE"])]=1;
// Initialize menu handlers
foreach ($listofmenuhandler as $key => $val)

View File

@ -121,7 +121,7 @@ class FormAdmin
global $langs,$conf;
// Clean parameters
if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // For compatibility
// Check parameters
if (! is_array($dirmenuarray)) return -1;
@ -143,7 +143,11 @@ class FormAdmin
if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
{
if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files
$filelib=preg_replace('/\.php$/i','',$file);
if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
$filelib=preg_replace('/\.php$/i','',$file);
$prefix='';
// 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
if (preg_match('/^eldy/i',$file)) $prefix='0';

View File

@ -1,60 +0,0 @@
<?php
/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007-2010 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/menus/smartphone/smartphone_backoffice.php
* \brief Gestionnaire nomme smartphone du menu smartphone
*/
/**
* Class to manage smartphone menu smartphone (for internal users)
*/
class MenuSmart
{
var $db;
var $atarget=""; // Valeur du target a utiliser dans les liens
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
function __construct($db)
{
$this->db=$db;
}
/**
* Show menu
*
* @param string $limitmenuto To limit menu to a top or left menu value
* @return void
*/
function showmenu($limitmenuto)
{
require_once DOL_DOCUMENT_ROOT.'/core/menus/smartphone/smartphone.lib.php';
print_smartphone_menu($this->db,$this->atarget,$this->hideifnotallowed,$limitmenuto);
}
}
?>

View File

@ -17,45 +17,57 @@
*/
/**
* \file htdocs/core/menus/smartphone/smartphone_frontoffice.php
* \brief Gestionnaire nomme smartphone du menu smartphone
* \file htdocs/core/menus/smartphone/smartphone_menu.php
* \brief Menu smartphone manager
*/
/**
* Class to manage smartphone menu smartphone (for external users)
* Class to manage smartphone menu smartphone
*/
class MenuSmart
{
var $hideifnotallowed=1; // Put 0 for back office menu, 1 for front office menu
var $atarget=""; // Valeur du target a utiliser dans les liens
var $name="smartphone";
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param DoliDB $db Database handler
* @param int $type_user Type of user
*/
function __construct($db)
function __construct($db, $type_user)
{
$this->db=$db;
}
/**
* Show menu
* Show menu
*
* @param string $limitmenuto To limit menu to a top or left menu value
* @return void
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
*/
function showmenu($limitmenuto)
function showmenu($mode)
{
require_once DOL_DOCUMENT_ROOT.'/core/menus/smartphone/smartphone.lib.php';
global $conf;
require_once DOL_DOCUMENT_ROOT.'/core/menus/smartphone/smartphone.lib.php';
print_smartphone_menu($this->db,$this->atarget,$this->hideifnotallowed,$limitmenuto);
if ($this->type_user == 1)
{
$conf->global->MAIN_SEARCHFORM_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=0;
}
print_smartphone_menu($this->db,$this->atarget,$this->hideifnotallowed,$mode);
return 1;
}
}
?>
?>

View File

@ -1,74 +0,0 @@
<?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/menus/standard/auguria_backoffice.php
* \brief Gestionnaire nomme Auguria du menu du haut
*
* \remarks La construction d'un gestionnaire pour le menu du haut est simple:
* \remarks Toutes les entrees de menu a faire apparaitre dans la barre du haut
* \remarks doivent etre affichees par <a class="tmenu" href="...?mainmenu=...">...</a>
* \remarks ou si menu selectionne <a class="tmenusel" href="...?mainmenu=...">...</a>
*/
/**
* Classe permettant la gestion du menu du haut Auguria
*/
class MenuManager
{
var $db;
var $type_user=0; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens
var $menu_array;
var $menu_array_after;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db=$db;
}
/**
* Show menu
*
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
*/
function showmenu($mode)
{
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
$res='ErrorBadParameterForMode';
if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user);
if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after);
return $res;
}
}
?>

View File

@ -18,25 +18,21 @@
*/
/**
* \file htdocs/core/menus/standard/auguria_frontoffice.php
* \brief Gestionnaire nomme Auguria du menu du haut
*
* \remarks La construction d'un gestionnaire pour le menu du haut est simple:
* \remarks Toutes les entrees de menu a faire apparaitre dans la barre du haut
* \remarks doivent etre affichees par <a class="tmenu" href="...?mainmenu=...">...</a>
* \remarks ou si menu selectionne <a class="tmenusel" href="...?mainmenu=...">...</a>
* \file htdocs/core/menus/standard/auguria_menu.php
* \brief Menu auguria manager
*/
/**
* Classe permettant la gestion du menu du haut Auguria
* Class to manage menu Auguria
*/
class MenuManager
{
var $db;
var $type_user=1; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens
var $type_user; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens
var $name="auguria";
var $menu_array;
var $menu_array_after;
@ -44,11 +40,13 @@ class MenuManager
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param DoliDB $db Database handler
* @param int $type_user Type of user
*/
function __construct($db)
function __construct($db, $type_user)
{
$this->db=$db;
$this->type_user=$type_user;
$this->db=$db;
}
@ -64,9 +62,12 @@ class MenuManager
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
$conf->global->MAIN_SEARCHFORM_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=0;
if ($this->type_user == 1)
{
$conf->global->MAIN_SEARCHFORM_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=0;
}
$res='ErrorBadParameterForMode';
if ($mode == 'top') $res=print_auguria_menu($this->db,$this->atarget,$this->type_user);
if ($mode == 'left') $res=print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after);

View File

@ -17,25 +17,21 @@
*/
/**
* \file htdocs/core/menus/standard/eldy_frontoffice.php
* \brief Gestionnaire nomme eldy du menu du haut
*
* \remarks La construction d'un gestionnaire pour le menu du haut est simple:
* \remarks Toutes les entrees de menu a faire apparaitre dans la barre du haut
* \remarks doivent etre affichees par <a class="tmenu" href="...?mainmenu=...">...</a>
* \remarks ou si menu selectionne <a class="tmenusel" href="...?mainmenu=...">...</a>
* \file htdocs/core/menus/standard/eldy_menu.php
* \brief Menu eldy manager
*/
/**
* Class to manage menu Eldy (for external users)
* Class to manage menu Eldy
*/
class MenuManager
{
var $db;
var $type_user=1; // Put 0 for internal users, 1 for external users
var $type_user; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens
var $name="eldy";
var $menu_array;
var $menu_array_after;
@ -43,10 +39,12 @@ class MenuManager
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param DoliDB $db Database handler
* @param int $type_user Type of user
*/
function __construct($db)
function __construct($db, $type_user)
{
$this->type_user=$type_user;
$this->db=$db;
}
@ -54,8 +52,8 @@ class MenuManager
/**
* Show menu
*
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
*/
function showmenu($mode)
{
@ -63,8 +61,11 @@ class MenuManager
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
$conf->global->MAIN_SEARCHFORM_SOCIETE=0;
$conf->global->MAIN_SEARCHFORM_CONTACT=0;
if ($this->type_user == 1)
{
$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);

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007-2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007-2009 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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
@ -17,25 +17,21 @@
*/
/**
* \file htdocs/core/menus/standard/eldy_backoffice.php
* \brief Gestionnaire nomme eldy du menu du haut
*
* \remarks La construction d'un gestionnaire pour le menu du haut est simple:
* \remarks Toutes les entrees de menu a faire apparaitre dans la barre du haut
* \remarks doivent etre affichees par <a class="tmenu" href="...?mainmenu=...">...</a>
* \remarks ou si menu selectionne <a class="tmenusel" href="...?mainmenu=...">...</a>
* \file htdocs/core/menus/standard/eldy_menu.php
* \brief Menu eldy manager
*/
/**
* Classe to manage menu Eldy
* Class to manage menu Eldy
*/
class MenuManager
{
var $db;
var $type_user=0; // Put 0 for internal users, 1 for external users
var $type_user; // Put 0 for internal users, 1 for external users
var $atarget=""; // Valeur du target a utiliser dans les liens
var $name="eldy";
var $menu_array;
var $menu_array_after;
@ -43,10 +39,12 @@ class MenuManager
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param DoliDB $db Database handler
* @param int $type_user Type of user
*/
function __construct($db)
function __construct($db, $type_user)
{
$this->type_user=$type_user;
$this->db=$db;
}
@ -54,17 +52,25 @@ class MenuManager
/**
* Show menu
*
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
* @param string $mode 'top' or 'left'
* @return int Number of menu entries shown
*/
function showmenu($mode)
{
global $conf;
require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php';
if ($this->type_user == 1)
{
$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);
if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after);
return $res;
}

View File

@ -23,3 +23,11 @@ create table llx_adherent_type_extrafields
import_key varchar(14) -- import key
) ENGINE=innodb;
ALTER TABLE llx_adherent_type_extrafields ADD INDEX idx_adherent_type_extrafields (fk_object);
UPDATE llx_const set value='eldy_menu.php' where value='eldy_backoffice.php';
UPDATE llx_const set value='eldy_menu.php' where value='eldy_frontoffice.php';
UPDATE llx_const set value='auguria_menu.php' where value='auguria_backoffice.php';
UPDATE llx_const set value='auguria_menu.php' where value='auguria_frontoffice.php';
UPDATE llx_const set value='smartphone_menu.php' where value='smartphone_backoffice.php';
UPDATE llx_const set value='smartphone_menu.php' where value='smartphone_frontoffice.php';

View File

@ -565,6 +565,7 @@ ThisLimitIsDefinedInSetup=Dolibarr limit (Menu home-setup-security): %s Kb, PHP
NoFileFound=No documents saved in this directory
CurrentUserLanguage=Current language
CurrentTheme=Current theme
CurrentMenuManager=current men manager
DisabledModules=Disabled modules
For=For
ForCustomer=For customer

View File

@ -568,6 +568,7 @@ ThisLimitIsDefinedInSetup=Limite Dolibarr (Menu accueil-configuration-sécurité
NoFileFound=Pas de documents stockés dans cette rubrique
CurrentUserLanguage=Langue utilisateur actuelle
CurrentTheme=Thème courant
CurrentMenuManager=Gestionnaire de menu courant
DisabledModules=Modules désactivés
For=Pour
ForCustomer=Pour le client

View File

@ -778,21 +778,18 @@ if (! empty($conf->multicompany->enabled) && GETPOST('action') == 'switchentity'
// Init menu manager
if (empty($user->societe_id)) // If internal user or not defined
{
$conf->standard_menu=(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED);
$conf->standard_menu=(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?(empty($conf->global->MAIN_MENU_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENU_STANDARD):$conf->global->MAIN_MENU_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?(empty($conf->global->MAIN_MENU_SMARTPHONE)?'smartphone_menu.php':$conf->global->MAIN_MENU_SMARTPHONE):$conf->global->MAIN_MENU_SMARTPHONE_FORCED);
}
else // If external user
{
$conf->standard_menu=(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED);
$conf->standard_menu=(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?(empty($conf->global->MAIN_MENUFRONT_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENUFRONT_STANDARD):$conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE)?'smartphone_menu.php':$conf->global->MAIN_MENUFRONT_SMARTPHONE):$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED);
}
// For backward compatibility
if (empty($conf->standard_menu)) $conf->standard_menu ='eldy_backoffice.php';
elseif ($conf->standard_menu == 'eldy.php') $conf->standard_menu='eldy_backoffice.php';
// Load the menu manager (only if not already done)
$file_menu=empty($conf->browser->phone)?$conf->standard_menu:$conf->smart_menu;
if (GETPOST('menu')) $file_menu=GETPOST('menu'); // menu=eldy_backoffice.php
if (GETPOST('menu')) $file_menu=GETPOST('menu'); // example: menu=eldy_menu.php
if (! class_exists('MenuManager'))
{
$menufound=0;
@ -804,11 +801,12 @@ if (! class_exists('MenuManager'))
}
if (! $menufound) // If failed to include, we try with standard
{
$file_menu='eldy_backoffice.php';
dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
$file_menu='eldy_menu.php';
include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
}
}
$menumanager = new MenuManager($db);
$menumanager = new MenuManager($db, empty($user->societe_id)?0:1);
@ -1337,6 +1335,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
$loginhtmltext.='<br><b>'.$langs->trans("PreviousConnexion").'</b>: '.dol_print_date($user->datepreviouslogin,"dayhour");
$loginhtmltext.='<br><b>'.$langs->trans("AuthenticationMode").'</b>: '.$_SESSION["dol_authmode"];
$loginhtmltext.='<br><b>'.$langs->trans("CurrentTheme").'</b>: '.$conf->theme;
$loginhtmltext.='<br><b>'.$langs->trans("CurrentMenuManager").'</b>: '.$menumanager->name;
$s=picto_from_langcode($langs->getDefaultLang());
$loginhtmltext.='<br><b>'.$langs->trans("CurrentUserLanguage").'</b>: '.($s?$s.' ':'').$langs->getDefaultLang();
$loginhtmltext.='<br><b>'.$langs->trans("Browser").'</b>: '.$conf->browser->name.($conf->browser->version?' '.$conf->browser->version:'').' ('.$_SERVER['HTTP_USER_AGENT'].')';