From d4e89552e3ecd325b7e5ebdef9625c97095d2a7f Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Mon, 28 Dec 2009 01:53:45 +0000
Subject: [PATCH] Fix: Code to manage view output must be stored or initialized
 into main and not into master (dedicated to all script included command line
 scripts).

---
 htdocs/main.inc.php   | 27 +++++++++++++++++++++++++--
 htdocs/master.inc.php | 25 -------------------------
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index b6864e8d4e5..acf069d40f7 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -201,7 +201,7 @@ if (! defined('NOTOKENRENEWAL'))
 	if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken'];
 	$_SESSION['newtoken'] = $token;
 }
-if (! empty($conf->global->MAIN_SECURITY_CSRF))	// Check validity of token, only if not option enabled (this option breaks some features sometimes)
+if (! empty($conf->global->MAIN_SECURITY_CSRF))	// Check validity of token, only if option enabled (this option breaks some features sometimes)
 {
 	if (isset($_POST['token']) && isset($_SESSION['token']))
 	{
@@ -225,6 +225,29 @@ if (! empty($_SESSION["disablemodules"]))
 	}
 }
 
+// Init Smarty
+// TODO activer smarty par defaut ?
+if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY)
+{
+	// Usage of const in conf.php file can overwrite default dir.
+	if (empty($dolibarr_smarty_libs_dir)) $dolibarr_smarty_libs_dir=DOL_DOCUMENT_ROOT.'/includes/smarty/libs/';
+	if (empty($dolibarr_smarty_compile))  $dolibarr_smarty_compile=DOL_DATA_ROOT.'/smarty/templates/temp';
+	if (empty($dolibarr_smarty_cache))    $dolibarr_smarty_cache=DOL_DATA_ROOT.'/smarty/cache/temp';
+
+	$smarty_libs = $dolibarr_smarty_libs_dir. "Smarty.class.php";
+	if (@include_once($smarty_libs))
+	{
+		$smarty = new Smarty();
+		$smarty->compile_dir = $dolibarr_smarty_compile;
+		$smarty->cache_dir = $dolibarr_smarty_cache;
+		//$smarty->config_dir = '/web/www.domain.com/smarty/configs';
+	}
+	else
+	{
+		dol_print_error('',"Library Smarty ".$smarty_libs." not found.");
+	}
+}
+
 
 /*
  * Phase authentication / login
@@ -355,7 +378,7 @@ if (! isset($_SESSION["dol_login"]))
 		// We show login page
 		include_once(DOL_DOCUMENT_ROOT."/lib/security.lib.php");
 		// TODO activer smarty par defaut ?
-		if ($conf->global->MAIN_SMARTY)
+		if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY)
 		{
 			dol_loginfunction2($langs,$conf,$mysoc);
 		}
diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php
index b1a7a147998..09d27744824 100644
--- a/htdocs/master.inc.php
+++ b/htdocs/master.inc.php
@@ -417,29 +417,4 @@ if (! defined('MAGPIE_CACHE_DIR'))    { define('MAGPIE_CACHE_DIR',   $conf->exte
 
 if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR');
 
-
-// If there is at least one module using Smarty
-// FIXME Smarty is an output framework so it should be required and used only in main.inc.php and not in master.inc.php
-// TODO activer smarty par defaut ?
-if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY)
-{
-	// Usage of const in conf.php file can overwrite default dir.
-	if (empty($dolibarr_smarty_libs_dir)) $dolibarr_smarty_libs_dir=DOL_DOCUMENT_ROOT.'/includes/smarty/libs/';
-	if (empty($dolibarr_smarty_compile))  $dolibarr_smarty_compile=DOL_DATA_ROOT.'/smarty/templates/temp';
-	if (empty($dolibarr_smarty_cache))    $dolibarr_smarty_cache=DOL_DATA_ROOT.'/smarty/cache/temp';
-
-	$smarty_libs = $dolibarr_smarty_libs_dir. "Smarty.class.php";
-	if (@include_once($smarty_libs))
-	{
-		$smarty = new Smarty();
-		$smarty->compile_dir = $dolibarr_smarty_compile;
-		$smarty->cache_dir = $dolibarr_smarty_cache;
-		//$smarty->config_dir = '/web/www.domain.com/smarty/configs';
-	}
-	else
-	{
-		dol_print_error('',"Library Smarty ".$smarty_libs." not found.");
-	}
-}
-
 ?>
-- 
GitLab