From 459855a636cf0760b99bc0c8c2cc287eff9a07c4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Feb 2010 15:07:46 +0000 Subject: [PATCH] Mutualize code in menu --- htdocs/admin/menus.php | 166 +++++++++--------- htdocs/html.formadmin.class.php | 13 +- .../includes/menus/barre_top/auguria.lib.php | 112 ++++++++++++ .../menus/barre_top/auguria_backoffice.php | 74 +------- .../menus/barre_top/auguria_frontoffice.php | 73 +------- htdocs/includes/menus/barre_top/eldy.lib.php | 8 +- htdocs/product.class.php | 37 +++- 7 files changed, 245 insertions(+), 238 deletions(-) create mode 100644 htdocs/includes/menus/barre_top/auguria.lib.php diff --git a/htdocs/admin/menus.php b/htdocs/admin/menus.php index c5ace7f0b35..efb36c74239 100644 --- a/htdocs/admin/menus.php +++ b/htdocs/admin/menus.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ /** * \file htdocs/admin/menus.php * \ingroup core - * \brief Page de configuration des gestionnaires de menu + * \brief Page to setup menu manager to use * \version $Id$ */ @@ -35,16 +35,16 @@ $langs->load("companies"); $langs->load("products"); $langs->load("admin"); -if (!$user->admin) - accessforbidden(); +// Security check +if (!$user->admin) accessforbidden(); $dirtop = "../includes/menus/barre_top"; $dirleft = "../includes/menus/barre_left"; /* -* Actions -*/ + * Actions + */ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["cancel"])) { @@ -57,7 +57,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can dolibarr_set_const($db, "MAIN_MENUFRONT_BARRELEFT",$_POST["main_menufront_barreleft"],'chaine',0,'',$conf->entity); // Define list of menu handlers to initialize - $listofmenuhandler=array(); + $listofmenuhandler=array(); $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["main_menu_barretop"])]=1; $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["main_menufront_barretop"])]=1; $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["main_menu_barreleft"])]=1; @@ -82,8 +82,8 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can /* -* Affichage -*/ + * View + */ $html=new Form($db); $htmladmin=new FormAdmin($db); @@ -114,98 +114,98 @@ dol_fiche_head($head, 'handler', $langs->trans("Menus")); if (isset($_GET["action"]) && $_GET["action"] == 'edit') { - print '
'; - print ''; - print ''; + print ''; + print ''; + print ''; - clearstatcache(); + clearstatcache(); - // Gestionnaires de menu - $var=true; + // Gestionnaires de menu + $var=true; - print ''; - print ''; - print '
'.$langs->trans("Menu").''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + print ''; - // Menu top - $var=!$var; - print ''; - print ''; - print ''; - print ''; + // Menu top + $var=!$var; + print ''; + print ''; + print ''; + print ''; - // Menu left - $var=!$var; - print ''; - print ''; - print ''; - print ''; + // Menu left + $var=!$var; + print ''; + print ''; + print ''; + print ''; - print '
'.$langs->trans("Menu").''; print $html->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc")); - print ''; + print ''; print $html->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc")); - print '
'.$langs->trans("DefaultMenuTopManager").''; - print $htmladmin->select_menu($conf->global->MAIN_MENU_BARRETOP,'main_menu_barretop',$dirtop); - print ''; - print $htmladmin->select_menu($conf->global->MAIN_MENUFRONT_BARRETOP,'main_menufront_barretop',$dirtop); - print '
'.$langs->trans("DefaultMenuTopManager").''; + print $htmladmin->select_menu($conf->global->MAIN_MENU_BARRETOP,'main_menu_barretop',$dirtop); + print ''; + print $htmladmin->select_menu($conf->global->MAIN_MENUFRONT_BARRETOP,'main_menufront_barretop',$dirtop); + print '
'.$langs->trans("DefaultMenuLeftManager").''; - print $htmladmin->select_menu($conf->global->MAIN_MENU_BARRELEFT,'main_menu_barreleft',$dirleft); - print ''; - print $htmladmin->select_menu($conf->global->MAIN_MENUFRONT_BARRELEFT,'main_menufront_barreleft',$dirleft); - print '
'.$langs->trans("DefaultMenuLeftManager").''; + print $htmladmin->select_menu($conf->global->MAIN_MENU_BARRELEFT,'main_menu_barreleft',$dirleft); + print ''; + print $htmladmin->select_menu($conf->global->MAIN_MENUFRONT_BARRELEFT,'main_menufront_barreleft',$dirleft); + print '
'; + print '
'; print '
'; - print ''; - print '     '; + print ''; + print '     '; print ''; - print '
'; + print ''; - print '
'; + print ''; } else { - // Gestionnaires de menu - $var=true; + // Gestionnaires de menu + $var=true; - print ''; - print ''; - print '
'.$langs->trans("Menu").''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + print ''; - $var=!$var; - print ''; - print ''; - print ''; - print ''; + $var=!$var; + print ''; + print ''; + print ''; + print ''; - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; - print '
'.$langs->trans("Menu").''; print $html->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc")); - print ''; + print ''; print $html->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc")); - print '
'.$langs->trans("DefaultMenuTopManager").''; - $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENU_BARRETOP); - print $filelib; - print ''; - $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENUFRONT_BARRETOP); - print $filelib; - print '
'.$langs->trans("DefaultMenuTopManager").''; + $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENU_BARRETOP); + print $filelib; + print ''; + $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENUFRONT_BARRETOP); + print $filelib; + print '
'.$langs->trans("DefaultMenuLeftManager").''; - $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENU_BARRELEFT); - print $filelib; - print ''; - $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENUFRONT_BARRELEFT); - print $filelib; - print '
'.$langs->trans("DefaultMenuLeftManager").''; + $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENU_BARRELEFT); + print $filelib; + print ''; + $filelib=preg_replace('/.php$/i','',$conf->global->MAIN_MENUFRONT_BARRELEFT); + print $filelib; + print '
'; + print '
'; } print ''; @@ -213,9 +213,9 @@ print ''; if (! isset($_GET["action"]) || $_GET["action"] != 'edit') { - print '
'; - print ''.$langs->trans("Modify").''; - print '
'; + print '
'; + print ''.$langs->trans("Modify").''; + print '
'; } $db->close(); diff --git a/htdocs/html.formadmin.class.php b/htdocs/html.formadmin.class.php index fa930f3d542..b96d556465f 100644 --- a/htdocs/html.formadmin.class.php +++ b/htdocs/html.formadmin.class.php @@ -67,7 +67,7 @@ class FormAdmin } asort($langs_available); - + foreach ($langs_available as $key => $value) { if ($filter && is_array($filter)) @@ -108,14 +108,11 @@ class FormAdmin { if (is_file($dirmenu."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') { - $filelib=preg_replace('/\.php$/i','',$file); + if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files + $filelib=preg_replace('/\.php$/i','',$file); $prefix=''; - if (preg_match('/^eldy/i',$file)) $prefix='0'; // Recommanded - else if (preg_match('/^auguria/i',$file)) $prefix='2'; // Other - else if (preg_match('/^default/i',$file)) $prefix='2'; // Other - else if (preg_match('/^rodolphe/i',$file)) $prefix='2'; // Other - else if (preg_match('/^empty/i',$file)) $prefix='2'; // Other - else $prefix='1'; // Experimental + if (preg_match('/^eldy/i',$file)) $prefix='0'; // 0=Recommanded, 1=Experimental, 2=Other + else $prefix='2'; if ($file == $selected) { diff --git a/htdocs/includes/menus/barre_top/auguria.lib.php b/htdocs/includes/menus/barre_top/auguria.lib.php new file mode 100644 index 00000000000..6278c755736 --- /dev/null +++ b/htdocs/includes/menus/barre_top/auguria.lib.php @@ -0,0 +1,112 @@ + + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/includes/menus/barre_top/auguria.lib.php + * \brief Library for file auguria menus + * \version $Id$ + */ + + + +/** + * Core function to output top menu auguria + * + * @param unknown_type $db + * @param unknown_type $atarget + * @param unknown_type $hideifnotallowed + */ +function print_auguria_menu($db,$atarget,$hideifnotallowed) +{ + require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php"); + + global $user,$conf,$langs,$dolibarr_main_db_name; + + // On sauve en session le menu principal choisi + if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; + if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; + $_SESSION["leftmenuopened"]=""; + + $menuArbo = new Menubase($db,'auguria','top'); + $tabMenu = $menuArbo->menuTopCharger($hideifnotallowed,$_SESSION['mainmenu'], 'auguria'); + + + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
    '."\n"; + else print ''."\n"; + + for($i=0; $iglobal->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
  • '; + else print '
  • '."\n"; + } + else + { + if (! $hideifnotallowed) + { + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
  • '; + else print '
  • '."\n"; + } + } + } + } + + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; + else print '
    '; + + print ''; + print $tabMenu[$i]['titre']; + print ''; + + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; + else print ''; + + print ''.$tabMenu[$i]['titre'].''; + + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; + else print '
    '."\n"; +} + +?> diff --git a/htdocs/includes/menus/barre_top/auguria_backoffice.php b/htdocs/includes/menus/barre_top/auguria_backoffice.php index ba03879b27e..c99694f3d19 100644 --- a/htdocs/includes/menus/barre_top/auguria_backoffice.php +++ b/htdocs/includes/menus/barre_top/auguria_backoffice.php @@ -57,79 +57,9 @@ class MenuTop { */ function showmenu() { - require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php"); + require_once(DOL_DOCUMENT_ROOT.'/includes/menus/barre_top/auguria.lib.php'); - global $user,$conf,$langs,$dolibarr_main_db_name; - - // On sauve en session le menu principal choisi - if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; - if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; - $_SESSION["leftmenuopened"]=""; - - $menuArbo = new Menubase($this->db,'auguria','top'); - $tabMenu = $menuArbo->menuTopCharger($this->hideifnotallowed,$_SESSION['mainmenu'], 'auguria'); - - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
      '."\n"; - else print ''."\n"; - - for($i=0; $iglobal->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
    • '; - else print '
    • '."\n"; - } - else - { - if (! $this->hideifnotallowed) - { - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
    • '; - else print '
    • '."\n"; - } - } - } - } - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print '
      '; - - print 'atarget?" target=$this->atarget":"")).'>'; - print $tabMenu[$i]['titre']; - print ''; - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print ''; - - print ''.$tabMenu[$i]['titre'].''; - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print '
      '."\n"; + print_auguria_menu($this->db,$this->atarget,$this->hideifnotallowed); } } diff --git a/htdocs/includes/menus/barre_top/auguria_frontoffice.php b/htdocs/includes/menus/barre_top/auguria_frontoffice.php index 91847e3db46..4e4fc77be81 100644 --- a/htdocs/includes/menus/barre_top/auguria_frontoffice.php +++ b/htdocs/includes/menus/barre_top/auguria_frontoffice.php @@ -58,78 +58,9 @@ class MenuTop { */ function showmenu() { - require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php"); + require_once(DOL_DOCUMENT_ROOT.'/includes/menus/barre_top/auguria.lib.php'); - global $user,$conf,$langs,$dolibarr_main_db_name; - - // On sauve en session le menu principal choisi - if (isset($_GET["mainmenu"])) $_SESSION["mainmenu"]=$_GET["mainmenu"]; - if (isset($_GET["idmenu"])) $_SESSION["idmenu"]=$_GET["idmenu"]; - $_SESSION["leftmenuopened"]=""; - - $menuArbo = new Menubase($this->db,'auguria','top'); - $tabMenu = $menuArbo->menuTopCharger($this->hideifnotallowed,$_SESSION['mainmenu'], 'auguria'); - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
        '."\n"; - else print ''."\n"; - - for($i=0; $iglobal->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
      • '; - else print '
      • '."\n"; - } - else - { - if (! $this->hideifnotallowed) - { - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '
      • '; - else print '
      • '."\n"; - } - } - } - } - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print '
        '; - - print 'atarget?" target=$this->atarget":"")).'>'; - print $tabMenu[$i]['titre']; - print ''; - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print ''; - - print ''.$tabMenu[$i]['titre'].''; - - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; - else print '
        '."\n"; + print_auguria_menu($this->db,$this->atarget,$this->hideifnotallowed); } } diff --git a/htdocs/includes/menus/barre_top/eldy.lib.php b/htdocs/includes/menus/barre_top/eldy.lib.php index c79ea07185e..d795a4cafe7 100644 --- a/htdocs/includes/menus/barre_top/eldy.lib.php +++ b/htdocs/includes/menus/barre_top/eldy.lib.php @@ -24,7 +24,13 @@ */ - +/** + * Core function to output top menu eldy + * + * @param unknown_type $db + * @param unknown_type $atarget + * @param unknown_type $hideifnotallowed + */ function print_eldy_menu($db,$atarget,$hideifnotallowed) { global $user,$conf,$langs,$dolibarr_main_db_name; diff --git a/htdocs/product.class.php b/htdocs/product.class.php index d83b206199e..8ba221f4635 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2402,8 +2402,10 @@ class Product extends CommonObject * \param nbbyrow Nombre vignettes par ligne (si mode vignette) * \return int Nombre de photos affichees */ - function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5) + function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0) { + global $user; + include_once(DOL_DOCUMENT_ROOT ."/lib/files.lib.php"); $pdir = get_exdir($this->id,2) . $this->id ."/photos/"; @@ -2427,12 +2429,14 @@ class Product extends CommonObject { $nbphoto++; $photo = $file; + $viewfilename = $file; if ($size == 1) { // Format vignette // On determine nom du fichier vignette $photo_vignette=''; if (preg_match('/(\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i',$photo,$regs)) { $photo_vignette=preg_replace('/'.$regs[0].'/i','',$photo)."_small".$regs[0]; + if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; } @@ -2444,7 +2448,7 @@ class Product extends CommonObject print ''; // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine - if ($photo_vignette && dol_is_file($dirthumb.$photo_vignette)) { + if ($photo_vignette) { print ''; } else { @@ -2453,6 +2457,22 @@ class Product extends CommonObject print ''; + if ($showfilename) print '
        '.$viewfilename; + if ($showaction) + { + print '
        '; + // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites + if ($photo_vignette && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$photo) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight)) + { + print ''.img_refresh($langs->trans('GenerateThumb')).'  '; + } + if ($user->rights->produit->creer || $user->rights->service->creer) + { + print ''; + print img_delete().''; + } + } + if ($nbbyrow) print ''; if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; @@ -2460,6 +2480,16 @@ class Product extends CommonObject if ($size == 0) { // Format origine print ''; + + if ($showfilename) print '
        '.$viewfilename; + if ($showaction) + { + if ($user->rights->produit->creer || $user->rights->service->creer) + { + print ''; + print img_delete().''; + } + } } // On continue ou on arrete de boucler ? @@ -2470,7 +2500,8 @@ class Product extends CommonObject if ($nbbyrow && $size==1) { // Ferme tableau - while ($nbphoto % $nbbyrow) { + while ($nbphoto % $nbbyrow) + { print ' '; $nbphoto++; }