Qual: Mutualize duplicate code

This commit is contained in:
Laurent Destailleur 2008-11-26 19:37:25 +00:00
parent 62b3d11542
commit 25e3109d91
4 changed files with 124 additions and 156 deletions

View File

@ -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 '<br>';
// Liste des zone de recherche permanantes support<EFBFBD>es
// Liste des zone de recherche permanantes supportees
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="35%">'.$langs->trans("PermanentLeftSearchForm").'</td><td>'.$langs->trans("Activated").'</td></tr>';
$var=True;
@ -317,7 +318,7 @@ else
// Themes
show_theme(0);
show_theme('',0);
print '<br>';
@ -355,72 +356,6 @@ else
}
function show_theme($edit=0)
{
global $conf,$langs,$dirtheme,$bc;
$thumbsbyrow=6;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="'.$thumbsbyrow.'">'.$langs->trans("DefaultSkin").'</td></tr>';
$var=true;
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="2">';
print '<table class="notopnoleftnoright" width="100%">';
$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 '<tr '.$bc[$var].'>';
}
print '<td align="center">';
$file=$dirtheme."/".$subdir."/thumb.png";
if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg";
print '<table><tr><td>';
if ($edit) print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">';
if ($edit)
{
if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
else $title=$langs->trans("ShowPreview");
}
print '<img src="'.$file.'" width="80" height="60" border="0" title="'.$title.'">';
if ($edit) print '</a>';
print '</td></tr><tr><td align="center">';
if ($subdir == $conf->global->MAIN_THEME)
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
}
else
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
}
print '</td></tr></table></td>';
$i++;
if ($i % $thumbsbyrow == 0) print '</tr>';
}
}
if ($i % $thumbsbyrow != 0) {
while ($i % $thumbsbyrow != 0) {
print '<td>&nbsp;</td>';
$i++;
}
print '</tr>';
}
print '</table>';
print '</td></tr>';
print '</table>';
}
$db->close();
llxFooter('$Date$ - $Revision$');

View File

@ -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;
}
?>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2006-2008 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
@ -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 '<table class="noborder" width="100%">';
if ($foruserprofile)
{
print '<tr class="liste_titre"><td width="25%">'.$langs->trans("Parameter").'</td><td width="25%">'.$langs->trans("DefaultValue").'</td>';
print '<td colspan="2">&nbsp;</td>';
}
else
{
print '<tr class="liste_titre"><td colspan="'.$thumbsbyrow.'">'.$langs->trans("DefaultSkin").'</td></tr>';
}
print '</tr>';
$var=false;
if ($foruserprofile)
{
print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultSkin").'</td>';
print '<td>'.$conf->global->MAIN_THEME.'</td>';
print '<td '.$bc[$var].' align="left" nowrap="nowrap" width="20%"><input '.$bc[$var].' name="check_MAIN_THEME"'.($edit?'':' disabled').' type="checkbox" '.($selected_theme?" checked":"").'> '.$langs->trans("UsePersonalValue").'</td>';
print '<td '.$bc[$var].'>&nbsp;</td></tr>';
}
if ($edit) print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.'" style="font-weight: normal;" alt="'.$langs->trans("Preview").'">';
if ($edit)
{
if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
else $title=$langs->trans("ShowPreview");
}
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="'.$colspan.'">';
print '<table class="notopnoleftnoright" width="100%">';
$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 '<tr '.$bc[$var].'>';
}
print '<td align="center">';
$file=$dirtheme."/".$subdir."/thumb.png";
if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg";
print '<table><tr><td>';
print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.($fuser?'&id='.$fuser->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 '<img src="'.$file.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'">';
print '</a>';
print '</td></tr><tr><td align="center">';
if ($subdir == $selected_theme)
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
}
else
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
}
print '</td></tr></table></td>';
$i++;
if ($i % $thumbsbyrow == 0) print '</tr>';
}
}
if ($i % $thumbsbyrow != 0)
{
while ($i % $thumbsbyrow != 0)
{
print '<td>&nbsp;</td>';
$i++;
}
print '</tr>';
}
print '</table>';
print '</td></tr>';
print '</table>';
}
?>

View File

@ -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 '</div>';
@ -209,7 +209,7 @@ else
// Skin
show_theme($fuser,0);
show_theme($fuser,0,true);
print '</div>';
@ -237,70 +237,4 @@ else
$db->close();
llxFooter('$Date$ - $Revision$');
function show_theme($fuser,$edit=0)
{
global $conf,$langs,$dirtheme,$bc;
$thumbsbyrow=6;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="25%">'.$langs->trans("Parameter").'</td><td width="25%">'.$langs->trans("DefaultValue").'</td><td colspan="2">&nbsp;</td></tr>';
$var=false;
print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultSkin").'</td>';
print '<td>'.$conf->global->MAIN_THEME.'</td>';
print '<td '.$bc[$var].' align="left" nowrap="nowrap" width="20%"><input '.$bc[$var].' name="check_MAIN_THEME"'.($edit?'':' disabled').' type="checkbox" '.($fuser->conf->MAIN_THEME?" checked":"").'> '.$langs->trans("UsePersonalValue").'</td>';
print '<td '.$bc[$var].'>&nbsp;</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="4">';
print '<table class="notopnoleftnoright" width="100%">';
$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 '<tr '.$bc[$var].'>';
}
print '<td align="center">';
$file=$dirtheme."/".$subdir."/thumb.png";
if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg";
print '<table><tr><td><img src="'.$file.'" width="80" height="60"></td></tr><tr><td align="center">';
if ($subdir == $fuser->conf->MAIN_THEME)
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="main_theme" value="'.$subdir.'"> <b>'.$subdir.'</b>';
}
else
{
print '<input '.($edit?'':'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="main_theme" value="'.$subdir.'"> '.$subdir;
}
print '</td></tr></table></td>';
$i++;
if ($i % $thumbsbyrow == 0) print '</tr>';
}
}
if ($i % $thumbsbyrow != 0) {
while ($i % $thumbsbyrow != 0) {
print '<td>&nbsp;</td>';
$i++;
}
print '</tr>';
}
print '</table>';
print '</td></tr>';
print '</table>';
}
?>