From e28b304beffb7c7c41ee823b77fd617286beaf4e Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Tue, 25 Aug 2009 14:01:43 +0000
Subject: [PATCH] Add dolibarr_main_demo and dolibarr_main_prod into config
 file instead of database for security reasons.

---
 htdocs/compta/index.php      |  12 +-
 htdocs/conf/conf.php.example | 373 ++++++++++++++++++-----------------
 htdocs/lib/functions.lib.php |  65 +++---
 htdocs/lib/security.lib.php  |   6 +-
 htdocs/public/demo/index.php |   3 +-
 htdocs/user/param_ihm.php    |   8 +-
 6 files changed, 245 insertions(+), 222 deletions(-)

diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index fb7b4348cd9..33e203aa81f 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -33,10 +33,10 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/commande
 if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.commande.class.php');
 if ($conf->tax->enabled) require_once(DOL_DOCUMENT_ROOT.'/chargesociales.class.php');
 
-// L'espace compta/tr�so doit toujours etre actif car c'est un espace partag�
-// par de nombreux modules (banque, facture, commande � facturer, etc...) ind�pendemment
+// L'espace compta/tr�so doit toujours etre actif car c'est un espace partag�
+// par de nombreux modules (banque, facture, commande � facturer, etc...) ind�pendemment
 // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
-// est prot�g� par le droit qui va bien du module concern�.
+// est prot�g� par le droit qui va bien du module concern�.
 //if (!$user->rights->compta->general->lire)
 //  accessforbidden();
 
@@ -653,7 +653,7 @@ if ($conf->tax->enabled && $user->rights->tax->charges->lire)
 }
 
 /*
- * Commandes clients � facturer
+ * Commandes clients � facturer
  */
 if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->commande->lire)
 {
@@ -752,7 +752,7 @@ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->comman
 }
 
 /*
- * Factures clients impay�es
+ * Factures clients impay�es
  */
 if ($conf->facture->enabled && $user->rights->facture->lire)
 {
@@ -851,7 +851,7 @@ if ($conf->facture->enabled && $user->rights->facture->lire)
 }
 
 /*
- * Factures fournisseurs impay�es
+ * Factures fournisseurs impay�es
  */
 if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire)
 {
diff --git a/htdocs/conf/conf.php.example b/htdocs/conf/conf.php.example
index 31d05541dbd..dac87b6ec9d 100644
--- a/htdocs/conf/conf.php.example
+++ b/htdocs/conf/conf.php.example
@@ -1,179 +1,194 @@
-<?php
-#
-# Dolibarr example for conf.php file
-#
-# Do not edit this file without changing its name.
-# This file is used by Dolibarr setup process to create true Dolibarr
-# config file called "conf.php".
-#
-# $Id$
-
-
-# dolibarr_main_url_root
-# This parameter defines the root URL of your Dolibarr index.php page.
-# It must link to the directory htdocs.
-# Examples:
-# $dolibarr_main_url_root="http://localhost";
-# $dolibarr_main_url_root="http://mydolibarrvirtualhost";
-# $dolibarr_main_url_root="http://myserver/dolibarr/htdocs";
-#
-$dolibarr_main_url_root="";
-
-
-# dolibarr_main_document_root
-# This parameter contains absolute file system directory of Dolibarr
-# htdocs directory
-# Examples:
-# $dolibarr_main_document_root="/var/www/dolibarr/htdocs";
-# $dolibarr_main_document_root="C:/My web sites/dolibarr/htdocs";
-#
-$dolibarr_main_document_root="";
-
-
-# dolibarr_main_data_root
-# This parameter contains absolute file system directory of Dolibarr
-# directory used to store uploaded and generated physical files.
-# Examples:
-# $dolibarr_main_document_root="/var/www/dolibarr/documents";
-# $dolibarr_main_document_root="E:/My web sites/dolibarr/documents";
-#
-$dolibarr_main_data_root="";
-
-
-# dolibarr_main_db_host
-# This parameter contains host name or ip address of Dolibarr database
-# server.
-# Examples:
-# $dolibarr_main_db_host="localhost";
-# $dolibarr_main_db_host="127.0.0.1";
-# $dolibarr_main_db_host="192.168.0.10";
-# $dolibarr_main_db_host="mysql.myserver.com";
-#
-$dolibarr_main_db_host="";
-
-
-# dolibarr_main_db_port
-# This parameter contains the port of the Dolibarr database.
-# Default value: none
-# Examples:
-# $dolibarr_main_db_host="3306;
-#
-$dolibarr_main_db_port="";
-
-
-# dolibarr_main_db_name
-# This parameter contains name of Dolibarr database.
-# Examples:
-# $dolibarr_main_db_name="dolibarr";
-# $dolibarr_main_db_name="mydatabase";
-#
-$dolibarr_main_db_name="";
-
-
-# dolibarr_main_db_user
-# This parameter contains user name used to read and write into
-# Dolibarr database.
-# Examples:
-# $dolibarr_main_db_user="admin";
-# $dolibarr_main_db_user="dolibarruser";
-#
-$dolibarr_main_db_user="";
-
-
-# dolibarr_main_db_pass
-# This parameter contains password used to read and write into
-# Dolibarr database.
-# Examples:
-# $dolibarr_main_db_pass="myadminpass";
-# $dolibarr_main_db_pass="myuserpassword";
-#
-$dolibarr_main_db_pass="";
-
-
-# dolibarr_main_db_type
-# This parameter contains the name of the driver used to access your
-# Dolibarr database.
-# Default value: none
-# Possible values: mysql, mysqli, pgsql
-# Examples:
-# $dolibarr_main_db_type="mysql;
-# $dolibarr_main_db_type="mysqli";
-# $dolibarr_main_db_type="pgsql";
-#
-$dolibarr_main_db_type="";
-
-
-# dolibarr_main_db_character_set
-# Database character set used to store data (forced during database creation).
-# Default value: depends on database driver
-# Examples:
-# dolibarr_main_db_character_set="latin1";
-#
-$dolibarr_main_db_character_set="latin1";
-
-
-# dolibarr_main_db_collation
-# Database character set used to sort data (forced during database creation).
-# Default value: depends on database driver
-# Examples:
-# dolibarr_main_db_collation="latin1_swedish_ci";
-#
-$dolibarr_main_db_collation="latin1_swedish_ci";
-
-
-# dolibarr_main_authentication
-# This parameter contains the way authentication is done.
-# If value "ldap" is used, you must also set parameters dolibarr_main_auth_ldap_*
-# Default value: dolibarr
-# Possible values: Any values found in files in htdocs/includes/login directory after
-# the "function_" string and before the ".php" string.
-# Examples:
-# $dolibarr_main_authentication="http";
-# $dolibarr_main_authentication="dolibarr";
-# $dolibarr_main_authentication="ldap";
-#
-$dolibarr_main_authentication="dolibarr";
-
-
-# dolibarr_main_force_https
-# This parameter allows to force the HTTPS mode.
-# Warning: If you enable this parameter, your dolibarr_main_url_root parameter
-# must contains an URL with https and web server must be configured to respond
-# to such an URL.
-# Default value: 0
-# Possible values: 0 or 1
-# Examples:
-# $dolibarr_main_force_https=0;
-#
-$dolibarr_main_force_https="0";
-
-
-# Parameters used to setup LDAP authentication.
-# Uncomment them if dolibarr_main_authentication = "ldap"
-#
-# $dolibarr_main_auth_ldap_host="127.0.0.1";
-# $dolibarr_main_auth_ldap_port="389";
-# $dolibarr_main_auth_ldap_version="3";
-# $dolibarr_main_auth_ldap_servertype="openldap";					# openldap, activedirectory or egroupware
-#
-# Following parameters should not be used in LDAP connection (deprecated ?):
-# $dolibarr_main_auth_ldap_login_attribute="loginfield";	# uid or samaccountname for active directory
-# $dolibarr_main_auth_ldap_dn="";							# Ex: ou=users,dc=my-domain,dc=com
-# $dolibarr_main_auth_ldap_admin_login="";					# Required only if anonymous bind disabled
-# $dolibarr_main_auth_ldap_admin_pass="";					# Required only if anonymous bind disabled
-#
-# $dolibarr_main_auth_ldap_debug="false";
-
-
-# Parameters not used yet
-# dolibarr_smarty_libs_dir,dolibarr_smarty_compile,dolibarr_smarty_cache
-# Examples:
-# $dolibarr_smarty_libs_dir="/var/www/dolibarr/external-libs/smarty/libs/";
-# $dolibarr_smarty_compile="/var/www/dolibarr/documents/temp/smarty_templates";
-# $dolibarr_smarty_cache="/var/www/dolibarr/documents/temp/smarty_cache";
-#
-$dolibarr_smarty_libs_dir="";
-$dolibarr_smarty_compile="";
-$dolibarr_smarty_cache="";
-
-?>
+<?php
+#
+# Dolibarr example for conf.php file
+#
+# Do not edit this file without changing its name.
+# This file is used by Dolibarr setup process to create true Dolibarr
+# config file called "conf.php".
+#
+# $Id$
+
+
+# dolibarr_main_url_root
+# This parameter defines the root URL of your Dolibarr index.php page.
+# It must link to the directory htdocs.
+# Examples:
+# $dolibarr_main_url_root="http://localhost";
+# $dolibarr_main_url_root="http://mydolibarrvirtualhost";
+# $dolibarr_main_url_root="http://myserver/dolibarr/htdocs";
+#
+$dolibarr_main_url_root="";
+
+
+# dolibarr_main_document_root
+# This parameter contains absolute file system directory of Dolibarr
+# htdocs directory
+# Examples:
+# $dolibarr_main_document_root="/var/www/dolibarr/htdocs";
+# $dolibarr_main_document_root="C:/My web sites/dolibarr/htdocs";
+#
+$dolibarr_main_document_root="";
+
+
+# dolibarr_main_data_root
+# This parameter contains absolute file system directory of Dolibarr
+# directory used to store uploaded and generated physical files.
+# Examples:
+# $dolibarr_main_document_root="/var/www/dolibarr/documents";
+# $dolibarr_main_document_root="E:/My web sites/dolibarr/documents";
+#
+$dolibarr_main_data_root="";
+
+
+# dolibarr_main_db_host
+# This parameter contains host name or ip address of Dolibarr database
+# server.
+# Examples:
+# $dolibarr_main_db_host="localhost";
+# $dolibarr_main_db_host="127.0.0.1";
+# $dolibarr_main_db_host="192.168.0.10";
+# $dolibarr_main_db_host="mysql.myserver.com";
+#
+$dolibarr_main_db_host="";
+
+
+# dolibarr_main_db_port
+# This parameter contains the port of the Dolibarr database.
+# Default value: none
+# Examples:
+# $dolibarr_main_db_host="3306;
+#
+$dolibarr_main_db_port="";
+
+
+# dolibarr_main_db_name
+# This parameter contains name of Dolibarr database.
+# Examples:
+# $dolibarr_main_db_name="dolibarr";
+# $dolibarr_main_db_name="mydatabase";
+#
+$dolibarr_main_db_name="";
+
+
+# dolibarr_main_db_user
+# This parameter contains user name used to read and write into
+# Dolibarr database.
+# Examples:
+# $dolibarr_main_db_user="admin";
+# $dolibarr_main_db_user="dolibarruser";
+#
+$dolibarr_main_db_user="";
+
+
+# dolibarr_main_db_pass
+# This parameter contains password used to read and write into
+# Dolibarr database.
+# Examples:
+# $dolibarr_main_db_pass="myadminpass";
+# $dolibarr_main_db_pass="myuserpassword";
+#
+$dolibarr_main_db_pass="";
+
+
+# dolibarr_main_db_type
+# This parameter contains the name of the driver used to access your
+# Dolibarr database.
+# Default value: none
+# Possible values: mysql, mysqli, pgsql
+# Examples:
+# $dolibarr_main_db_type="mysql;
+# $dolibarr_main_db_type="mysqli";
+# $dolibarr_main_db_type="pgsql";
+#
+$dolibarr_main_db_type="";
+
+
+# dolibarr_main_db_character_set
+# Database character set used to store data (forced during database creation).
+# Default value: depends on database driver
+# Examples:
+# dolibarr_main_db_character_set="latin1";
+#
+$dolibarr_main_db_character_set="latin1";
+
+
+# dolibarr_main_db_collation
+# Database character set used to sort data (forced during database creation).
+# Default value: depends on database driver
+# Examples:
+# dolibarr_main_db_collation="latin1_swedish_ci";
+#
+$dolibarr_main_db_collation="latin1_swedish_ci";
+
+
+# dolibarr_main_authentication
+# This parameter contains the way authentication is done.
+# If value "ldap" is used, you must also set parameters dolibarr_main_auth_ldap_*
+# Default value: dolibarr
+# Possible values: Any values found in files in htdocs/includes/login directory after
+# the "function_" string and before the ".php" string.
+# Examples:
+# $dolibarr_main_authentication="http";
+# $dolibarr_main_authentication="dolibarr";
+# $dolibarr_main_authentication="ldap";
+#
+$dolibarr_main_authentication="dolibarr";
+
+
+# dolibarr_main_force_https
+# This parameter allows to force the HTTPS mode.
+# Warning: If you enable this parameter, your dolibarr_main_url_root parameter
+# must contains an URL with https and web server must be configured to respond
+# to such an URL.
+# Default value: 0
+# Possible values: 0 or 1
+# Examples:
+# $dolibarr_main_force_https=0;
+#
+$dolibarr_main_force_https="0";
+
+
+# Parameters used to setup LDAP authentication.
+# Uncomment them if dolibarr_main_authentication = "ldap"
+#
+# $dolibarr_main_auth_ldap_host="127.0.0.1";
+# $dolibarr_main_auth_ldap_port="389";
+# $dolibarr_main_auth_ldap_version="3";
+# $dolibarr_main_auth_ldap_servertype="openldap";					# openldap, activedirectory or egroupware
+#
+# Following parameters should not be used in LDAP connection (deprecated ?):
+# $dolibarr_main_auth_ldap_login_attribute="loginfield";	# uid or samaccountname for active directory
+# $dolibarr_main_auth_ldap_dn="";							# Ex: ou=users,dc=my-domain,dc=com
+# $dolibarr_main_auth_ldap_admin_login="";					# Required only if anonymous bind disabled
+# $dolibarr_main_auth_ldap_admin_pass="";					# Required only if anonymous bind disabled
+#
+# $dolibarr_main_auth_ldap_debug="false";
+
+
+# Parameters not used yet
+# dolibarr_smarty_libs_dir,dolibarr_smarty_compile,dolibarr_smarty_cache
+# Examples:
+# $dolibarr_smarty_libs_dir="/var/www/dolibarr/external-libs/smarty/libs/";
+# $dolibarr_smarty_compile="/var/www/dolibarr/documents/temp/smarty_templates";
+# $dolibarr_smarty_cache="/var/www/dolibarr/documents/temp/smarty_cache";
+#
+$dolibarr_smarty_libs_dir="";
+$dolibarr_smarty_compile="";
+$dolibarr_smarty_cache="";
+
+
+# Login and pass to use in a demo mode
+# Default value: 0
+# Possible values: 0 or 1
+# Examples:
+# $dolibarr_main_demo="autologin,autopass"
+
+
+# When this parameter is defined, all errors messages are not reported.
+# This feature exists for production usage to avoid to give any information to hackers.
+# Default value: 0
+# Possible values: 0 or 1
+# Examples:
+# $dolibarr_main_prod=1
+
+?>
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index b484bd616b8..73b91665c2b 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -1684,12 +1684,13 @@ function dolibarr_print_error($db='',$error='')
  *				On doit appeler cette fonction quand une erreur technique bloquante est rencontree.
  *				Toutefois, il faut essayer de ne l'appeler qu'au sein de pages php, les classes devant
  *				renvoyer leur erreur par l'intermediaire de leur propriete "error".
- *				\param      db      Database handler
- *				\param      error	Chaine erreur ou tableau de chaines erreur complementaires a afficher
+ *	\param      db      Database handler
+ *	\param      error	Chaine erreur ou tableau de chaines erreur complementaires a afficher
  */
 function dol_print_error($db='',$error='')
 {
 	global $conf,$langs,$argv;
+	$out = '';
 	$syslog = '';
 
 	// Si erreur intervenue avant chargement langue
@@ -1699,28 +1700,29 @@ function dol_print_error($db='',$error='')
 		$langs = new Translate("", $conf);
 		$langs->load("main");
 	}
+	$langs->load("errors");
 
 	if ($_SERVER['DOCUMENT_ROOT'])    // Mode web
 	{
-		print $langs->trans("DolibarrHasDetectedError").".<br>\n";
+		$out.=$langs->trans("DolibarrHasDetectedError").".<br>\n";
 		if (! empty($conf->global->MAIN_FEATURES_LEVEL))
-		print "You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.<br>\n";
-		print $langs->trans("InformationToHelpDiagnose").":<br>\n";
-
-		print "<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";;
-		print "<b>".$langs->trans("Date").":</b> ".dol_print_date(time(),'dayhourlog')."<br>\n";;
-		if (isset($conf->global->MAIN_FEATURES_LEVEL)) print "<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";;
-		print "<b>".$langs->trans("Server").":</b> ".$_SERVER["SERVER_SOFTWARE"]."<br>\n";;
-		print "<b>".$langs->trans("Referer").":</b> ".$_SERVER["HTTP_REFERER"]."<br>\n";;
-		print "<b>".$langs->trans("RequestedUrl").":</b> ".$_SERVER["REQUEST_URI"]."<br>\n";;
-		print "<b>".$langs->trans("MenuManager").":</b> ".$conf->left_menu.'/'.$conf->top_menu."<br>\n";
-		print "<br>\n";
+		$out.="You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.<br>\n";
+		$out.=$langs->trans("InformationToHelpDiagnose").":<br>\n";
+
+		$out.="<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";;
+		$out.="<b>".$langs->trans("Date").":</b> ".dol_print_date(time(),'dayhourlog')."<br>\n";;
+		if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out.="<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";;
+		$out.="<b>".$langs->trans("Server").":</b> ".$_SERVER["SERVER_SOFTWARE"]."<br>\n";;
+		$out.="<b>".$langs->trans("Referer").":</b> ".$_SERVER["HTTP_REFERER"]."<br>\n";;
+		$out.="<b>".$langs->trans("RequestedUrl").":</b> ".$_SERVER["REQUEST_URI"]."<br>\n";;
+		$out.="<b>".$langs->trans("MenuManager").":</b> ".$conf->left_menu.'/'.$conf->top_menu."<br>\n";
+		$out.="<br>\n";
 		$syslog.="url=".$_SERVER["REQUEST_URI"];
 		$syslog.=", query_string=".$_SERVER["QUERY_STRING"];
 	}
 	else                              // Mode CLI
 	{
-		print '> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
+		$out.='> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
 		$syslog.="pid=".getmypid();
 	}
 
@@ -1728,18 +1730,18 @@ function dol_print_error($db='',$error='')
 	{
 		if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
 		{
-			print "<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
-			print "<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."<br>\n";
-			print "<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."<br>\n";
-			print "<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."<br>\n";
-			print "<br>\n";
+			$out.="<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
+			$out.="<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."<br>\n";
+			$out.="<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."<br>\n";
+			$out.="<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."<br>\n";
+			$out.="<br>\n";
 		}
 		else                            // Mode CLI
 		{
-			print '> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
-			print '> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n";
-			print '> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."\n";
-			print '> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."\n";
+			$out.='> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
+			$out.='> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n";
+			$out.='> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."\n";
+			$out.='> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."\n";
 
 		}
 		$syslog.=", sql=".$db->lastquery();
@@ -1758,23 +1760,26 @@ function dol_print_error($db='',$error='')
 			$msg=$langs->trans($msg);
 			if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
 			{
-				print "<b>".$langs->trans("Message").":</b> ".$msg."<br>\n" ;
+				$out.="<b>".$langs->trans("Message").":</b> ".$msg."<br>\n" ;
 			}
 			else                            // Mode CLI
 			{
-				print '> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
+				$out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
 			}
 			$syslog.=", msg=".$msg;
 		}
 	}
 	if ($_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_call_file'))
 	{
-		print '<b>XDebug informations:</b>'."<br>\n";
-		print 'File: '.xdebug_call_file()."<br>\n";
-		print 'Line: '.xdebug_call_line()."<br>\n";
-		print "<br>\n";
+		$out.='<b>XDebug informations:</b>'."<br>\n";
+		$out.='File: '.xdebug_call_file()."<br>\n";
+		$out.='Line: '.xdebug_call_line()."<br>\n";
+		$out.="<br>\n";
 	}
 
+	global $dolibarr_main_prod;
+	if (empty($dolibarr_main_prod)) print $out;
+	else print 'Sorry, an error occured but the parameter $dolibarr_main_prod is defined in conf file so no message is reported on browsers. Please read the log file for error message.';
 	dol_syslog("Error ".$syslog, LOG_ERR);
 }
 
diff --git a/htdocs/lib/security.lib.php b/htdocs/lib/security.lib.php
index 19a1fe14ff7..95c2e0a4ef9 100644
--- a/htdocs/lib/security.lib.php
+++ b/htdocs/lib/security.lib.php
@@ -126,9 +126,11 @@ function dol_loginfunction($langs,$conf,$mysoc)
 
 	$demologin='';
 	$demopassword='';
-	if (! empty($conf->global->MAIN_DEMO))
+
+	global $dolibarr_main_demo;
+	if (! empty($dolibarr_main_demo))
 	{
-		$tab=split(',',$conf->global->MAIN_DEMO);
+		$tab=split(',',$dolibarr_main_demo);
 		$demologin=$tab[0];
 		$demopassword=$tab[1];
 	}
diff --git a/htdocs/public/demo/index.php b/htdocs/public/demo/index.php
index e6812600ee1..9c6ed7f2ec7 100644
--- a/htdocs/public/demo/index.php
+++ b/htdocs/public/demo/index.php
@@ -34,7 +34,8 @@ $langs->load("main");
 $langs->load("other");
 
 // Security check
-if (empty($conf->global->MAIN_DEMO)) accessforbidden('Constant MAIN_DEMO must be defined in Home->Setup->Misc with value "default login,default pass" to enable the demo entry page',1,1,1);
+global $dolibarr_main_demo;
+if (empty($dolibarr_main_demo)) accessforbidden('Parameter dolibarr_main_demo must be defined in conf file with value "default login,default pass" to enable the demo entry page',1,1,1);
 
 
 $demoprofiles=array(
diff --git a/htdocs/user/param_ihm.php b/htdocs/user/param_ihm.php
index 60ae8eb8336..514b3553a1a 100644
--- a/htdocs/user/param_ihm.php
+++ b/htdocs/user/param_ihm.php
@@ -166,7 +166,7 @@ if ($_GET["action"] == 'edit')
     print '<tr '.$bc[$var].'><td>'.$langs->trans("Language").'</td>';
     print '<td>'.($conf->global->MAIN_LANG_DEFAULT=='auto'?$langs->trans("AutoDetectLang"):$conf->global->MAIN_LANG_DEFAULT).'</td>';
     print '<td align="left" nowrap="nowrap" width="20%"><input '.$bc[$var].' name="check_MAIN_LANG_DEFAULT" type="checkbox" '.($fuser->conf->MAIN_LANG_DEFAULT?" checked":"");
-    print ! empty($conf->global->MAIN_DEMO)?' disabled="true"':'';	// Disabled for demo
+    print ! empty($dolibarr_main_demo)?' disabled="true"':'';	// Disabled for demo
     print '> '.$langs->trans("UsePersonalValue").'</td>';
     print '<td>';
     $html=new Form($db);
@@ -178,7 +178,7 @@ if ($_GET["action"] == 'edit')
     print '<tr '.$bc[$var].'><td>'.$langs->trans("MaxSizeList").'</td>';
     print '<td>'.$conf->global->MAIN_SIZE_LISTE_LIMIT.'</td>';
     print '<td align="left" nowrap="nowrap" width="20%"><input '.$bc[$var].' name="check_SIZE_LISTE_LIMIT" type="checkbox" '.($fuser->conf->MAIN_SIZE_LISTE_LIMIT?" checked":"");
-    print ! empty($conf->global->MAIN_DEMO)?' disabled="true"':'';	// Disabled for demo
+    print ! empty($dolibarr_main_demo)?' disabled="true"':'';	// Disabled for demo
     print '> '.$langs->trans("UsePersonalValue").'</td>';
     print '<td><input class="flat" name="main_size_liste_limit" size="4" value="' . $fuser->conf->SIZE_LISTE_LIMIT . '"></td></tr>';
 
@@ -186,7 +186,7 @@ if ($_GET["action"] == 'edit')
 
 
     // Theme
-    show_theme($fuser,$conf->global->MAIN_DEMO?0:1,true);
+    show_theme($fuser,empty($dolibarr_main_demo)?1:0,true);
 
     print '</div>';
 
@@ -226,7 +226,7 @@ else
     print '</div>';
 
     print '<div class="tabsAction">';
-	if ($conf->global->MAIN_DEMO)
+	if (! empty($dolibarr_main_demo))
 	{
 		print "<a class=\"butActionRefused\" title=\"".$langs->trans("FeatureDisabledInDemo")."\" href=\"#\">".$langs->trans("Modify")."</a>";
 	}
-- 
GitLab