From 25e3109d9124eda4c4322d432fa93cdb54924d46 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 26 Nov 2008 19:37:25 +0000 Subject: [PATCH] Qual: Mutualize duplicate code --- htdocs/admin/ihm.php | 81 +++-------------------- htdocs/lib/admin.lib.php | 9 +-- htdocs/lib/usergroups.lib.php | 120 ++++++++++++++++++++++++++++++---- htdocs/user/param_ihm.php | 70 +------------------- 4 files changed, 124 insertions(+), 156 deletions(-) diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php index a8c1c91e0e2..cdb722ee21e 100644 --- a/htdocs/admin/ihm.php +++ b/htdocs/admin/ihm.php @@ -18,12 +18,13 @@ */ /** - \file htdocs/admin/ihm.php - \brief Page de configuration de l'interface homme machine - \version $Id$ -*/ + * \file htdocs/admin/ihm.php + * \brief Page de configuration de l'interface homme machine + * \version $Id$ + */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formadmin.class.php"); @@ -183,11 +184,11 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit') // Themes - show_theme(1); + show_theme('',1); print '
'; - // Liste des zone de recherche permanantes support�es + // Liste des zone de recherche permanantes supportees print ''; print ''; $var=True; @@ -317,7 +318,7 @@ else // Themes - show_theme(0); + show_theme('',0); print '
'; @@ -355,72 +356,6 @@ else } -function show_theme($edit=0) -{ - global $conf,$langs,$dirtheme,$bc; - - $thumbsbyrow=6; - print '
'.$langs->trans("PermanentLeftSearchForm").''.$langs->trans("Activated").'
'; - print ''; - $var=true; - - $var=!$var; - print ''; - print '
'.$langs->trans("DefaultSkin").'
'; - - print ''; - $handle=opendir($dirtheme); - $i=0; - while (($subdir = readdir($handle))!==false) - { - if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.' - && substr($subdir, 0, 3) <> 'CVS' && ! eregi('common',$subdir)) - { - if ($i % $thumbsbyrow == 0) - { - print ''; - } - - print ''; - - $i++; - - if ($i % $thumbsbyrow == 0) print ''; - } - } - if ($i % $thumbsbyrow != 0) { - while ($i % $thumbsbyrow != 0) { - print ''; - $i++; - } - print ''; - } - print '
'; - $file=$dirtheme."/".$subdir."/thumb.png"; - if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg"; - print '
'; - if ($edit) print ''; - if ($edit) - { - if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive"); - else $title=$langs->trans("ShowPreview"); - } - print ''; - if ($edit) print ''; - print '
'; - if ($subdir == $conf->global->MAIN_THEME) - { - print ' '.$subdir.''; - } - else - { - print ' '.$subdir; - } - print '
 
'; - - print '
'; -} - $db->close(); llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php index d9cb2f8b2c1..9eb15332dbb 100644 --- a/htdocs/lib/admin.lib.php +++ b/htdocs/lib/admin.lib.php @@ -386,10 +386,10 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not /** - \brief Define head array for tabs of security setup pages - \return Array of head - \version $Id$ -*/ + * \brief Define head array for tabs of security setup pages + * \return Array of head + * \version $Id$ + */ function security_prepare_head() { global $langs, $conf, $user; @@ -419,4 +419,5 @@ function security_prepare_head() return $head; } + ?> \ No newline at end of file diff --git a/htdocs/lib/usergroups.lib.php b/htdocs/lib/usergroups.lib.php index ede3f3e7e2a..f7b5ca3b3b0 100644 --- a/htdocs/lib/usergroups.lib.php +++ b/htdocs/lib/usergroups.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2006-2008 Laurent Destailleur * * 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 @@ -15,19 +15,14 @@ * 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/ - * - * $Id$ - * $Source$ */ + /** - \file htdocs/lib/usergroups.lib.php - \brief Ensemble de fonctions de base pour les utilisaterus et groupes - \version $Revision$ - - Ensemble de fonctions de base de dolibarr sous forme d'include -*/ - + * \file htdocs/lib/usergroups.lib.php + * \brief Ensemble de fonctions de base pour la gestion des utilisaterus et groupes + * \version $Id$ + */ function user_prepare_head($user) { global $langs, $conf; @@ -119,4 +114,107 @@ function group_prepare_head($group) return $head; } + +/** + * \brief Show themes thumbs tabs + * \param fuser User concerned or '' for global theme + * \param edit 1 to add edit form + */ +function show_theme($fuser,$edit=0,$foruserprofile=false) +{ + global $conf,$langs,$dirtheme,$bc; + + + $selected_theme=$conf->global->MAIN_THEME; + if (! empty($fuser)) $selected_theme=$fuser->conf->MAIN_THEME; + + $colspan=2; + if ($foruserprofile) $colspan=4; + + $thumbsbyrow=6; + print ''; + if ($foruserprofile) + { + print ''; + print ''; + } + else + { + print ''; + } + print ''; + + $var=false; + + if ($foruserprofile) + { + print ''; + print ''; + print ''; + print ''; + } + + if ($edit) print ''; + if ($edit) + { + if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive"); + else $title=$langs->trans("ShowPreview"); + } + + $var=!$var; + print ''; + print '
'.$langs->trans("Parameter").''.$langs->trans("DefaultValue").' 
'.$langs->trans("DefaultSkin").'
'.$langs->trans("DefaultSkin").''.$conf->global->MAIN_THEME.' '.$langs->trans("UsePersonalValue").' 
'; + + print ''; + $handle=opendir($dirtheme); + $i=0; + while (($subdir = readdir($handle))!==false) + { + if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.' + && substr($subdir, 0, 3) <> 'CVS' && ! eregi('common',$subdir)) + { + if ($i % $thumbsbyrow == 0) + { + print ''; + } + + print ''; + + $i++; + + if ($i % $thumbsbyrow == 0) print ''; + } + } + if ($i % $thumbsbyrow != 0) + { + while ($i % $thumbsbyrow != 0) + { + print ''; + $i++; + } + print ''; + } + print '
'; + $file=$dirtheme."/".$subdir."/thumb.png"; + if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg"; + print '
'; + print 'id:'').'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">'; + if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive"); + else $title=$langs->trans("ShowPreview"); + print ''.$title.''; + print ''; + print '
'; + if ($subdir == $selected_theme) + { + print ' '.$subdir.''; + } + else + { + print ' '.$subdir; + } + print '
 
'; + + print '
'; +} + ?> diff --git a/htdocs/user/param_ihm.php b/htdocs/user/param_ihm.php index 0d813ccf52e..964552cb502 100644 --- a/htdocs/user/param_ihm.php +++ b/htdocs/user/param_ihm.php @@ -174,7 +174,7 @@ if ($_GET["action"] == 'edit') // Theme - show_theme($fuser,$conf->global->MAIN_DEMO?0:1); + show_theme($fuser,$conf->global->MAIN_DEMO?0:1,true); print ''; @@ -209,7 +209,7 @@ else // Skin - show_theme($fuser,0); + show_theme($fuser,0,true); print ''; @@ -237,70 +237,4 @@ else $db->close(); llxFooter('$Date$ - $Revision$'); - - -function show_theme($fuser,$edit=0) -{ - global $conf,$langs,$dirtheme,$bc; - - $thumbsbyrow=6; - - print ''; - print ''; - - $var=false; - - print ''; - print ''; - print ''; - print ''; - - $var=!$var; - print ''; - print '
'.$langs->trans("Parameter").''.$langs->trans("DefaultValue").' 
'.$langs->trans("DefaultSkin").''.$conf->global->MAIN_THEME.'conf->MAIN_THEME?" checked":"").'> '.$langs->trans("UsePersonalValue").' 
'; - - print ''; - $handle=opendir($dirtheme); - $i=0; - while (($subdir = readdir($handle))!==false) - { - if (is_dir($dirtheme."/".$subdir) && substr($subdir, 0, 1) <> '.' - && substr($subdir, 0, 3) <> 'CVS' && ! eregi('common',$subdir)) - { - if ($i % $thumbsbyrow == 0) - { - print ''; - } - - print ''; - - $i++; - - if ($i % $thumbsbyrow == 0) print ''; - } - } - if ($i % $thumbsbyrow != 0) { - while ($i % $thumbsbyrow != 0) { - print ''; - $i++; - } - print ''; - } - print '
'; - $file=$dirtheme."/".$subdir."/thumb.png"; - if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg"; - print '
'; - if ($subdir == $fuser->conf->MAIN_THEME) - { - print ' '.$subdir.''; - } - else - { - print ' '.$subdir; - } - print '
 
'; - - print '
'; -} - ?>