From 900ed92e3acb82ac2ed6ac3a38f4f4bbf704aa9a Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sat, 26 Mar 2011 12:51:48 +0000
Subject: [PATCH] New: External modules can force skin directory

---
 ChangeLog                     |  1 +
 htdocs/admin/ihm.php          |  2 --
 htdocs/langs/en_US/admin.lang |  1 +
 htdocs/langs/fr_FR/admin.lang |  1 +
 htdocs/lib/usergroups.lib.php | 22 +++++++++++++++++-----
 htdocs/user/param_ihm.php     |  1 -
 6 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f239a0eba31..c25ebb06f25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,7 @@ For users:
 - Fix: Better Postgresql compatibility.
 
 For developers:
+- New: External modules can force skin directory so force their own skins.
 - New: External modules can add their own menu manager.
 - New: External modules can remove tabs.
 - New: External modules can force menu manager.
diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php
index 5854ebe0838..83e5b4d4bea 100644
--- a/htdocs/admin/ihm.php
+++ b/htdocs/admin/ihm.php
@@ -44,8 +44,6 @@ if (!$user->admin)
 
 if (! defined("MAIN_MOTD")) define("MAIN_MOTD","");
 
-$dirtheme = "../theme";
-
 // List of supported permanent search area
 $searchform=array(	"MAIN_SEARCHFORM_SOCIETE","MAIN_SEARCHFORM_CONTACT",
 					"MAIN_SEARCHFORM_PRODUITSERVICE","MAIN_SEARCHFORM_ADHERENT");
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index df85680bb8e..b85ee31aa45 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -297,6 +297,7 @@ DescWeather=The following pictures will be shown on dashboard when number of lat
 KeyForWebServicesAccess=Key to use Web Services (parameter "dolibarrkey" in webservices)
 TestSubmitForm=Input test form
 ThisForceAlsoTheme=Using this menu manager will also use its own theme whatever is user choice. Also this menu manager specialized for smartphones does not works on all smartphone. Use another menu manager if you epxerience problems on yours. 
+ThemeDir=Skins directory
 
 # Modules
 Module0Name=Users & groups
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 716aa2937d7..4f31368d7f1 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -298,6 +298,7 @@ DescWeather=Les graphiques suivant seront affichées sur le tableau de bord si l
 KeyForWebServicesAccess=Clé pour utiliser les Web Services (paramètre "dolibarrkey" dans les webservices)
 TestSubmitForm=Formulaire de test de saisie
 ThisForceAlsoTheme=Utiliser ce gestionnaire de menu force aussi le theme quelquesoit le choix de theme de l'utilisateur. De plus, ce gestionnaire de menu, spécialisé pour smartphone, ne fonctionne que sur certains téléphones. Utiliser un autre gestionnaire si vous constatez des problèmes.
+ThemeDir=Répertoire des thèmes
 
 # Modules= undefined
 Module0Name= Utilisateurs & groupes
diff --git a/htdocs/lib/usergroups.lib.php b/htdocs/lib/usergroups.lib.php
index 9aab60d82c3..cd4704dcf3e 100644
--- a/htdocs/lib/usergroups.lib.php
+++ b/htdocs/lib/usergroups.lib.php
@@ -149,9 +149,12 @@ function group_prepare_head($object)
  */
 function show_theme($fuser,$edit=0,$foruserprofile=false)
 {
-    global $conf,$langs,$dirtheme,$bc;
-
+    global $conf,$langs,$bc;
 
+    
+	$dirtheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',0);
+	$urltheme=dol_buildpath($conf->global->MAIN_FORCETHEMEDIR.'/theme',1);
+	
     $selected_theme=$conf->global->MAIN_THEME;
     if (! empty($fuser)) $selected_theme=$fuser->conf->MAIN_THEME;
 
@@ -170,7 +173,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
     }
     else
     {
-    	print '<tr class="liste_titre"><td>'.$langs->trans("DefaultSkin").'</td>';
+    	print '<tr class="liste_titre"><td width="35%">'.$langs->trans("DefaultSkin").'</td>';
     	print '<td align="right">';
     	$url='http://www.dolistore.com/lang-en/4-skins';
     	if (preg_match('/fr/i',$langs->defaultlang)) $url='http://www.dolistore.com/lang-fr/4-themes';
@@ -192,6 +195,14 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
 	    print '</tr>';
     }
 
+    if (! $foruserprofile)
+    {
+	    print '<tr '.$bc[$var].'>';
+	    print '<td>'.$langs->trans("ThemeDir").'</td>';
+	    print '<td'.($foruserprofile?' colspan="3"':'').'>'.$dirtheme.'</td>';
+	    print '</tr>';
+    }
+        
 	if ($edit)
 	{
 		if ($subdir == $conf->global->MAIN_THEME) $title=$langs->trans("ThemeCurrentlyActive");
@@ -219,12 +230,13 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
 
             print '<td align="center">';
             $file=$dirtheme."/".$subdir."/thumb.png";
-            if (! file_exists($file)) $file=$dirtheme."/common/nophoto.jpg";
+            $url=$urltheme."/".$subdir."/thumb.png";
+            if (! file_exists($file)) $url=$urltheme."/common/nophoto.jpg";
             print '<table><tr><td>';
 			print '<a href="'.$_SERVER["PHP_SELF"].($edit?'?action=edit&theme=':'?theme=').$subdir.(! empty($_GET["optioncss"])?'&optioncss='.$_GET["optioncss"]:'').($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 '<img src="'.$url.'" border="0" width="80" height="60" alt="'.$title.'" title="'.$title.'">';
 			print '</a>';
 			print '</td></tr><tr><td align="center">';
             if ($subdir == $selected_theme)
diff --git a/htdocs/user/param_ihm.php b/htdocs/user/param_ihm.php
index 4cb9c7ae9b4..5c309faae9b 100644
--- a/htdocs/user/param_ihm.php
+++ b/htdocs/user/param_ihm.php
@@ -60,7 +60,6 @@ if ($user->id <> $_REQUEST["id"] && ! $canreaduser) accessforbidden();
 $id=! empty($_GET["id"])?$_GET["id"]:$_POST["id"];
 $dirtop = "../includes/menus/standard";
 $dirleft = "../includes/menus/standard";
-$dirtheme = "../theme";
 
 // Charge utilisateur edite
 $fuser = new User($db);
-- 
GitLab