2006-02-03 17:42:39 +01:00
< ? PHP
2009-01-15 23:49:06 +01:00
/* Copyright ( C ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2006-02-03 17:42:39 +01:00
* Copyright ( C ) 2003 Xavier Dutoit < doli @ sydesy . com >
2010-09-21 19:02:57 +02:00
* Copyright ( C ) 2004 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2006-02-03 17:42:39 +01:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2010-09-21 19:02:57 +02:00
* Copyright ( C ) 2005 - 2010 Regis Houssin < regis @ dolibarr . fr >
2009-01-15 23:49:06 +01:00
* Copyright ( C ) 2005 Simon Tosser < simon @ kornog - computing . com >
* Copyright ( C ) 2006 Andre Cianfarani < andre . cianfarani @ acdeveloppement . net >
2010-02-07 11:28:40 +01:00
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
2006-02-03 17:42:39 +01:00
*
* 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
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
/**
2008-11-28 00:24:50 +01:00
* \file htdocs / master . inc . php
* \ingroup core
* \brief File that defines environment for all Dolibarr process ( pages or scripts )
2009-09-03 01:46:55 +02:00
* This script reads the conf . php file , init $lang , $db and empty $user
2008-11-28 00:24:50 +01:00
* \version $Id $
*/
2006-02-03 17:42:39 +01:00
2010-08-09 21:08:22 +02:00
define ( 'DOL_VERSION' , '3.0.0-alpha' ); // Also defined in htdocs/install/inc.php (Ex: x.y.z-alpha, x.y.z)
2009-01-15 23:49:06 +01:00
define ( 'EURO' , chr ( 128 ));
2006-02-03 17:42:39 +01:00
2007-05-10 20:25:19 +02:00
// Definition des constantes syslog
2006-02-03 17:42:39 +01:00
if ( function_exists ( " define_syslog_variables " ))
{
2009-10-19 20:54:50 +02:00
if ( version_compare ( PHP_VERSION , '5.3.0' , '<' ))
{
define_syslog_variables (); // Deprecated since php 5.3.0, syslog variables no longer need to be initialized
}
2006-02-03 17:42:39 +01:00
}
2007-05-10 20:25:19 +02:00
else
{
// Pour PHP sans syslog (comme sous Windows)
define ( 'LOG_EMERG' , 0 );
define ( 'LOG_ALERT' , 1 );
define ( 'LOG_CRIT' , 2 );
define ( 'LOG_ERR' , 3 );
define ( 'LOG_WARNING' , 4 );
define ( 'LOG_NOTICE' , 5 );
define ( 'LOG_INFO' , 6 );
define ( 'LOG_DEBUG' , 7 );
}
2009-10-22 02:36:21 +02:00
2007-05-10 20:25:19 +02:00
// Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL)
2006-02-03 17:42:39 +01:00
error_reporting ( E_ALL ^ E_NOTICE );
2009-01-21 16:06:34 +01:00
//error_reporting(E_ALL);
2006-02-03 17:42:39 +01:00
2008-03-17 03:53:48 +01:00
// Include configuration
2008-03-17 03:53:48 +01:00
$result =@ include_once ( " conf/conf.php " );
2010-10-01 20:33:07 +02:00
if ( ! $result && ! empty ( $_SERVER [ " GATEWAY_INTERFACE " ])) // If install not done and we are in a web session
2008-03-17 23:34:09 +01:00
{
2010-10-01 20:33:07 +02:00
header ( " Location: install/index.php " );
exit ;
2008-03-17 23:34:09 +01:00
}
2010-10-01 20:33:07 +02:00
// Security: CSRF protection
// This test check if referrer ($_SERVER['HTTP_REFERER']) is same web site than Dolibarr ($_SERVER['HTTP_HOST'])
// when we post forms (we allow GET to allow direct link to access a particular page).
if ( ! defined ( 'NOCSRFCHECK' ) && empty ( $dolibarr_nocsrfcheck ) && ! empty ( $_SERVER [ 'REQUEST_METHOD' ]) && $_SERVER [ 'REQUEST_METHOD' ] != 'GET' && ! empty ( $_SERVER [ 'HTTP_HOST' ]) && ! empty ( $_SERVER [ 'HTTP_REFERER' ]) && ! preg_match ( '/' . preg_quote ( $_SERVER [ 'HTTP_HOST' ], '/' ) . '/i' , $_SERVER [ 'HTTP_REFERER' ]))
{
//print 'HTTP_POST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];
2010-10-01 20:48:00 +02:00
print " Access refused by CSRF protection in main.inc.php. \n " ;
print " If you access your server behind a proxy using url rewriting, you might add the line \$ dolibarr_nocsrfcheck=1 into your conf.php file. \n " ;
die ;
2010-10-01 20:33:07 +02:00
}
2008-03-17 03:53:48 +01:00
if ( empty ( $dolibarr_main_db_host ))
2006-02-03 17:42:39 +01:00
{
2009-10-29 23:28:03 +01:00
print 'Dolibarr setup was run but was not completed.<br>' . " \n " ;
print 'Please, click <a href="install/index.php">here to finish Dolibarr install process</a> ...' . " \n " ;
2010-10-01 20:48:00 +02:00
die ;
2006-02-03 17:42:39 +01:00
}
2010-02-20 12:40:36 +01:00
if ( empty ( $dolibarr_main_url_root ))
{
2010-02-20 12:54:54 +01:00
print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>' . " \n " ;
print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)' . " \n " ;
2010-10-01 20:48:00 +02:00
die ;
2010-02-20 12:40:36 +01:00
}
2008-03-10 23:38:43 +01:00
if ( empty ( $dolibarr_main_db_type )) $dolibarr_main_db_type = 'mysql' ; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
if ( empty ( $dolibarr_main_data_root ))
{
// Si repertoire documents non defini, on utilise celui par defaut
2009-10-21 20:14:00 +02:00
$dolibarr_main_data_root = str_replace ( " /htdocs " , " " , $dolibarr_main_document_root );
2008-03-10 23:38:43 +01:00
$dolibarr_main_data_root .= " /documents " ;
2006-02-03 17:42:39 +01:00
}
2009-10-22 02:36:21 +02:00
2009-08-13 15:34:05 +02:00
// Define some constants
define ( 'DOL_DOCUMENT_ROOT' , $dolibarr_main_document_root ); // Filesystem pages php (htdocs)
define ( 'DOL_DATA_ROOT' , $dolibarr_main_data_root ); // Filesystem donnes (documents)
2010-05-10 15:18:59 +02:00
define ( 'DOL_CLASS_PATH' , 'class/' ); // Filsystem path to class dir
2010-02-20 12:40:36 +01:00
// If dolibarr_main_url_root = auto (Hidden feature for developers only), we try to forge it.
2009-10-20 19:53:24 +02:00
if ( $dolibarr_main_url_root == 'auto' && ! empty ( $_SERVER [ " SCRIPT_URL " ]) && ! empty ( $_SERVER [ " SCRIPT_URI " ]))
2009-10-09 20:32:35 +02:00
{
2009-10-22 02:36:21 +02:00
$dolibarr_main_url_root = str_replace ( $_SERVER [ " SCRIPT_URL " ], '' , $_SERVER [ " SCRIPT_URI " ]);
2009-10-09 20:32:35 +02:00
}
2009-08-13 15:34:05 +02:00
define ( 'DOL_MAIN_URL_ROOT' , $dolibarr_main_url_root ); // URL relative root
2010-10-03 02:12:54 +02:00
$uri = preg_replace ( '/^http(s?):\/\//i' , '' , constant ( 'DOL_MAIN_URL_ROOT' )); // $uri contains url without http*
2009-08-13 15:34:05 +02:00
$suburi = strstr ( $uri , '/' ); // $suburi contains url without domain
if ( $suburi == '/' ) $suburi = '' ; // If $suburi is /, it is now ''
2010-01-13 14:11:32 +01:00
define ( 'DOL_URL_ROOT' , $suburi ); // URL relative root ('', '/dolibarr', ...)
2009-08-13 15:34:05 +02:00
if ( ! empty ( $dolibarr_main_url_root_static )) define ( 'DOL_URL_ROOT_FULL_STATIC' , $dolibarr_main_url_root_static ); // Used to put static images on another domain
2006-02-03 17:42:39 +01:00
2007-10-07 21:30:03 +02:00
/*
2009-10-22 02:36:21 +02:00
* Include functions
2007-10-07 21:30:03 +02:00
*/
2009-10-22 02:36:21 +02:00
2008-04-05 16:18:13 +02:00
if ( ! file_exists ( DOL_DOCUMENT_ROOT . " /lib/functions.lib.php " ))
2007-10-07 21:30:03 +02:00
{
2009-04-29 20:44:37 +02:00
print " Error: Dolibarr config file content seems to be not correctly defined.<br> \n " ;
2007-10-07 21:30:03 +02:00
print " Please run dolibarr setup by calling page <b>/install</b>.<br> \n " ;
exit ;
}
2008-04-09 20:13:45 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/functions.lib.php " ); // Need 970ko memory (1.1 in 2.2)
2009-08-21 21:09:20 +02:00
2009-10-22 02:36:21 +02:00
2009-08-21 21:09:20 +02:00
// If password is encoded, we decode it
2009-10-21 16:02:14 +02:00
if ( preg_match ( '/crypted:/i' , $dolibarr_main_db_pass ) || ! empty ( $dolibarr_main_db_encrypted_pass ))
2008-04-29 23:13:49 +02:00
{
require_once ( DOL_DOCUMENT_ROOT . " /lib/security.lib.php " );
2009-10-21 16:02:14 +02:00
if ( preg_match ( '/crypted:/i' , $dolibarr_main_db_pass ))
2009-08-21 21:09:20 +02:00
{
2009-10-21 16:02:14 +02:00
$dolibarr_main_db_pass = preg_replace ( '/crypted:/i' , '' , $dolibarr_main_db_pass );
2009-08-21 21:09:20 +02:00
$dolibarr_main_db_pass = dol_decode ( $dolibarr_main_db_pass );
$dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass ; // We need to set this as it is used to know the password was initially crypted
}
else $dolibarr_main_db_pass = dol_decode ( $dolibarr_main_db_encrypted_pass );
2008-04-29 23:13:49 +02:00
}
2008-04-09 20:13:45 +02:00
//print memory_get_usage();
2008-01-10 18:35:45 +01:00
2009-10-22 02:36:21 +02:00
/*
* Create $conf object
*/
2010-04-28 12:02:54 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /core/class/conf.class.php " );
2007-04-25 13:45:01 +02:00
2006-02-03 17:42:39 +01:00
$conf = new Conf ();
2009-04-23 15:19:28 +02:00
2007-07-13 14:57:07 +02:00
// Identifiant propres au serveur base de donnee
2006-02-03 17:42:39 +01:00
$conf -> db -> host = $dolibarr_main_db_host ;
2008-03-10 23:38:43 +01:00
if ( empty ( $dolibarr_main_db_port )) $dolibarr_main_db_port = 0 ; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
$conf -> db -> port = $dolibarr_main_db_port ;
2006-02-03 17:42:39 +01:00
$conf -> db -> name = $dolibarr_main_db_name ;
$conf -> db -> user = $dolibarr_main_db_user ;
$conf -> db -> pass = $dolibarr_main_db_pass ;
2008-03-10 23:38:43 +01:00
if ( empty ( $dolibarr_main_db_type )) $dolibarr_main_db_type = 'mysql' ; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
2006-02-03 17:42:39 +01:00
$conf -> db -> type = $dolibarr_main_db_type ;
2009-01-15 23:49:06 +01:00
if ( empty ( $dolibarr_main_db_prefix )) $dolibarr_main_db_prefix = 'llx_' ;
2006-02-03 17:42:39 +01:00
$conf -> db -> prefix = $dolibarr_main_db_prefix ;
2009-08-26 20:59:13 +02:00
if ( empty ( $dolibarr_main_db_character_set )) $dolibarr_main_db_character_set = 'latin1' ; // Old installation
$conf -> db -> character_set = $dolibarr_main_db_character_set ;
if ( empty ( $dolibarr_main_db_collation )) $dolibarr_main_db_collation = 'latin1_swedish_ci' ; // Old installation
2007-12-21 20:14:11 +01:00
$conf -> db -> dolibarr_main_db_collation = $dolibarr_main_db_collation ;
2009-06-27 08:56:41 +02:00
if ( empty ( $dolibarr_main_db_encryption )) $dolibarr_main_db_encryption = 0 ;
$conf -> db -> dolibarr_main_db_encryption = $dolibarr_main_db_encryption ;
2009-08-30 03:39:40 +02:00
if ( empty ( $dolibarr_main_db_cryptkey )) $dolibarr_main_db_cryptkey = '' ;
2009-06-27 08:56:41 +02:00
$conf -> db -> dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey ;
2010-06-07 07:11:45 +02:00
if ( empty ( $dolibarr_main_limit_users )) $dolibarr_main_limit_users = 0 ;
$conf -> file -> main_limit_users = $dolibarr_main_limit_users ;
2010-04-25 15:55:58 +02:00
if ( defined ( 'TEST_DB_FORCE_TYPE' )) $conf -> db -> type = constant ( 'TEST_DB_FORCE_TYPE' ); // For test purpose
2007-07-13 14:57:07 +02:00
// Identifiant autres
2009-05-08 03:23:33 +02:00
$conf -> file -> main_authentication = empty ( $dolibarr_main_authentication ) ? '' : $dolibarr_main_authentication ;
2008-04-06 22:17:11 +02:00
// Force https
2009-05-08 03:23:33 +02:00
$conf -> file -> main_force_https = empty ( $dolibarr_main_force_https ) ? '' : $dolibarr_main_force_https ;
2009-01-15 23:49:06 +01:00
// Define charset for HTML Output (can set hidden value force_charset in conf.php file)
if ( empty ( $force_charset_do_notuse )) $force_charset_do_notuse = 'UTF-8' ;
2009-05-08 03:23:33 +02:00
$conf -> file -> character_set_client = strtoupper ( $force_charset_do_notuse );
2009-05-23 19:44:36 +02:00
// Cookie cryptkey
2009-05-24 02:19:06 +02:00
$conf -> file -> cookie_cryptkey = empty ( $dolibarr_main_cookie_cryptkey ) ? '' : $dolibarr_main_cookie_cryptkey ;
2007-05-25 22:02:23 +02:00
2008-12-07 20:19:32 +01:00
// Define array of document root directories
2009-05-08 03:23:33 +02:00
$conf -> file -> dol_document_root = array ( DOL_DOCUMENT_ROOT );
2009-01-15 23:49:06 +01:00
if ( ! empty ( $dolibarr_main_document_root_alt ))
2008-12-07 20:19:32 +01:00
{
// dolibarr_main_document_root_alt contains several directories
2009-10-20 15:14:44 +02:00
$values = preg_split ( '/[;,]/' , $dolibarr_main_document_root_alt );
2008-12-07 20:19:32 +01:00
foreach ( $values as $value )
{
2009-05-08 03:23:33 +02:00
$conf -> file -> dol_document_root [] = $value ;
2008-12-07 20:19:32 +01:00
}
}
2008-12-08 01:01:00 +01:00
// Define prefix
2007-05-25 22:02:23 +02:00
if ( isset ( $_SERVER [ " LLX_DBNAME " ])) $dolibarr_main_db_prefix = $_SERVER [ " LLX_DBNAME " ];
2006-02-03 17:42:39 +01:00
define ( 'MAIN_DB_PREFIX' , $dolibarr_main_db_prefix );
2006-09-17 17:51:52 +02:00
// Detection browser
if ( isset ( $_SERVER [ " HTTP_USER_AGENT " ]))
{
2010-09-29 13:08:52 +02:00
// If phone/smartphone, we set phone os name.
2009-10-24 08:10:00 +02:00
if ( preg_match ( '/android/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'android' ;
elseif ( preg_match ( '/blackberry/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'blackberry' ;
elseif ( preg_match ( '/iphone/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'iphone' ;
2009-12-30 00:12:40 +01:00
elseif ( preg_match ( '/ipod/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'iphone' ;
2009-10-24 08:10:00 +02:00
elseif ( preg_match ( '/palm/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'palm' ;
elseif ( preg_match ( '/symbian/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'symbian' ;
elseif ( preg_match ( '/webos/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'webos' ;
2010-09-25 13:03:58 +02:00
elseif ( preg_match ( '/maemo/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'maemo' ;
2009-11-09 09:58:24 +01:00
// MS products at end
2009-10-24 08:10:00 +02:00
elseif ( preg_match ( '/iemobile/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'windowsmobile' ;
elseif ( preg_match ( '/windows ce/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> phone = 'windowsmobile' ;
2009-11-09 09:58:24 +01:00
// Name
if ( preg_match ( '/firefox/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'firefox' ;
elseif ( preg_match ( '/chrome/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'chrome' ;
elseif ( preg_match ( '/iceweasel/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'iceweasel' ;
elseif (( empty ( $conf -> browser -> phone ) || preg_match ( '/iphone/i' , $_SERVER [ " HTTP_USER_AGENT " ])) && preg_match ( '/safari/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'safari' ; // Safari is often present in string but its not.
elseif ( preg_match ( '/opera/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'opera' ;
// MS products at end
elseif ( preg_match ( '/msie/i' , $_SERVER [ " HTTP_USER_AGENT " ])) $conf -> browser -> name = 'ie' ;
else $conf -> browser -> name = 'unknown' ;
2009-09-15 03:22:19 +02:00
// Other
2009-07-28 00:48:05 +02:00
if ( in_array ( $conf -> browser -> name , array ( 'firefox' , 'iceweasel' ))) $conf -> browser -> firefox = 1 ;
2006-09-17 17:51:52 +02:00
}
2007-12-30 19:47:45 +01:00
// Chargement des includes principaux de librairies communes
2010-04-29 17:23:21 +02:00
if ( ! defined ( 'NOREQUIREUSER' )) require_once ( DOL_DOCUMENT_ROOT . " /user/class/user.class.php " ); // Need 500ko memory
2010-04-28 12:11:41 +02:00
if ( ! defined ( 'NOREQUIRETRAN' )) require_once ( DOL_DOCUMENT_ROOT . " /core/class/translate.class.php " );
2010-04-29 16:54:12 +02:00
if ( ! defined ( 'NOREQUIRESOC' )) require_once ( DOL_DOCUMENT_ROOT . " /societe/class/societe.class.php " );
2007-12-30 19:47:45 +01:00
if ( ! defined ( 'NOREQUIREDB' )) require_once ( DOL_DOCUMENT_ROOT . " /lib/databases/ " . $conf -> db -> type . " .lib.php " );
2006-02-03 17:42:39 +01:00
2007-05-24 11:26:28 +02:00
/*
2007-12-30 19:47:45 +01:00
* Creation objet $langs ( must be before all other code )
2007-05-24 11:26:28 +02:00
*/
2009-01-15 23:49:06 +01:00
if ( ! defined ( 'NOREQUIRETRAN' ))
2007-09-09 13:16:33 +02:00
{
2008-03-31 17:17:39 +02:00
$langs = new Translate ( " " , $conf ); // A mettre apres lecture de la conf
2007-09-09 13:16:33 +02:00
}
2007-05-23 23:10:11 +02:00
2006-06-03 01:20:36 +02:00
/*
* Creation objet $db
*/
2009-01-15 23:49:06 +01:00
if ( ! defined ( 'NOREQUIREDB' ))
2007-09-09 13:16:33 +02:00
{
2008-03-10 23:38:43 +01:00
$db = new DoliDb ( $conf -> db -> type , $conf -> db -> host , $conf -> db -> user , $conf -> db -> pass , $conf -> db -> name , $conf -> db -> port );
2007-09-15 21:36:18 +02:00
if ( $db -> error )
2007-09-09 13:16:33 +02:00
{
2009-02-20 21:28:16 +01:00
dol_print_error ( $db , " host= " . $conf -> db -> host . " , port= " . $conf -> db -> port . " , user= " . $conf -> db -> user . " , databasename= " . $conf -> db -> name . " , " . $db -> error );
2009-01-15 23:49:06 +01:00
exit ;
2007-09-09 13:16:33 +02:00
}
2006-02-03 17:42:39 +01:00
}
2009-05-08 03:23:33 +02:00
// Now database connexion is known, so we can forget password
//$dolibarr_main_db_pass=''; // Comment this because this constant is used in a lot of pages
2009-08-30 03:39:40 +02:00
$conf -> db -> pass = '' ; // This is to avoid password to be shown in memory/swap dump
2006-02-03 17:42:39 +01:00
/*
2006-06-03 01:20:36 +02:00
* Creation objet $user
2006-02-03 17:42:39 +01:00
*/
2009-01-15 23:49:06 +01:00
if ( ! defined ( 'NOREQUIREUSER' ))
2007-09-09 13:16:33 +02:00
{
$user = new User ( $db );
}
2006-02-03 17:42:39 +01:00
/*
2009-05-08 03:23:33 +02:00
* Load object $conf
2007-10-07 16:49:36 +02:00
* After this , all parameters conf -> global -> CONSTANTS are loaded
2006-02-03 17:42:39 +01:00
*/
2009-01-15 23:49:06 +01:00
if ( ! defined ( 'NOREQUIREDB' ))
2007-09-09 13:16:33 +02:00
{
2009-09-01 17:47:29 +02:00
// By default conf->entity is 1, but we change this if we ask another value.
if ( session_id () && ! empty ( $_SESSION [ " dol_entity " ])) // Entity inside an opened session
2009-05-08 03:23:33 +02:00
{
$conf -> entity = $_SESSION [ " dol_entity " ];
}
2009-09-01 17:47:29 +02:00
elseif ( ! empty ( $_ENV [ " dol_entity " ])) // Entity inside a CLI script
2009-05-08 03:23:33 +02:00
{
$conf -> entity = $_ENV [ " dol_entity " ];
}
2009-09-01 17:47:29 +02:00
elseif ( isset ( $_POST [ " loginfunction " ]) && ! empty ( $_POST [ " entity " ])) // Just after a login page
2009-05-22 00:28:05 +02:00
{
2009-05-22 17:24:32 +02:00
$conf -> entity = $_POST [ " entity " ];
2009-05-22 00:28:05 +02:00
}
2009-05-24 02:19:06 +02:00
else
2009-05-23 19:44:36 +02:00
{
2010-09-26 11:53:42 +02:00
// Add real path in session name
$realpath = '' ;
if ( preg_match ( '/^([^.]+)\/htdocs\//i' , realpath ( $_SERVER [ " SCRIPT_FILENAME " ]), $regs )) $realpath = isset ( $regs [ 1 ]) ? $regs [ 1 ] : '' ;
2010-09-29 13:08:52 +02:00
2010-09-26 11:53:42 +02:00
$entityCookieName = 'DOLENTITYID_' . md5 ( $_SERVER [ " SERVER_NAME " ] . $_SERVER [ " DOCUMENT_ROOT " ] . $realpath );
2009-09-01 17:47:29 +02:00
if ( ! empty ( $_COOKIE [ $entityCookieName ]) && ! empty ( $conf -> file -> cookie_cryptkey )) // Just for view specific login page
2009-05-24 02:19:06 +02:00
{
2010-04-28 12:02:54 +02:00
include_once ( DOL_DOCUMENT_ROOT . " /core/class/cookie.class.php " );
2009-05-24 02:19:06 +02:00
$lastuser = '' ;
$lastentity = '' ;
$entityCookie = new DolCookie ( $conf -> file -> cookie_cryptkey );
$cookieValue = $entityCookie -> _getCookie ( $entityCookieName );
2009-10-20 15:14:44 +02:00
list ( $lastuser , $lastentity ) = explode ( '|' , $cookieValue );
2009-05-24 02:19:06 +02:00
$conf -> entity = $lastentity ;
}
2009-05-23 19:44:36 +02:00
}
2009-09-01 17:52:08 +02:00
//print "Will work with data into entity instance number '".$conf->entity."'";
2009-09-01 17:50:40 +02:00
// Here we read database (llx_const table) and define $conf->global->XXX var.
$conf -> setValues ( $db );
2009-08-30 03:39:40 +02:00
}
// If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
if ( ! empty ( $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ))
{
/* print '$_SERVER["GATEWAY_INTERFACE"]=' . $_SERVER [ " GATEWAY_INTERFACE " ] . '<br>' ;
2009-10-22 02:36:21 +02:00
print 'session_id()=' . session_id () . '<br>' ;
print '$_SESSION["dol_login"]=' . $_SESSION [ " dol_login " ] . '<br>' ;
print '$conf->global->MAIN_ONLY_LOGIN_ALLOWED=' . $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED . '<br>' ;
exit ; */
2009-08-30 03:39:40 +02:00
$ok = 0 ;
if (( ! session_id () || ! isset ( $_SESSION [ " dol_login " ])) && ! isset ( $_POST [ " username " ]) && ! empty ( $_SERVER [ " GATEWAY_INTERFACE " ])) $ok = 1 ; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
elseif ( isset ( $_POST [ " username " ]) && $_POST [ " username " ] == $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ) $ok = 1 ; // We let working pages that is a login submission (login submit, to allow login by admin)
elseif ( defined ( 'NOREQUIREDB' )) $ok = 1 ; // We let working pages that don't need database access (xxx.css.php)
elseif ( defined ( 'EVEN_IF_ONLY_LOGIN_ALLOWED' )) $ok = 1 ; // We let working pages that ask to work even if only login enabled (logout.php)
elseif ( session_id () && isset ( $_SESSION [ " dol_login " ]) && $_SESSION [ " dol_login " ] == $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ) $ok = 1 ; // We let working if user is allowed admin
if ( ! $ok )
{
if ( session_id () && isset ( $_SESSION [ " dol_login " ]) && $_SESSION [ " dol_login " ] != $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED )
{
print 'Sorry, your application is offline.' . " \n " ;
print 'You are logged with user "' . $_SESSION [ " dol_login " ] . '" and only administrator user "' . $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED . '" is allowed to connect for the moment.' . " \n " ;
$nexturl = DOL_URL_ROOT . '/user/logout.php' ;
print 'Please try later or <a href="' . $nexturl . '">click here to disconnect and change login user</a>...' . " \n " ;
}
else
{
print 'Sorry, your application is offline. Only administrator user "' . $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED . '" is allowed to connect for the moment.' . " \n " ;
$nexturl = DOL_URL_ROOT . '/' ;
print 'Please try later or <a href="' . $nexturl . '">click here to change login user</a>...' . " \n " ;
}
exit ;
}
2007-09-09 13:16:33 +02:00
}
2006-02-03 17:42:39 +01:00
/*
2009-08-29 20:08:46 +02:00
* Create object $mysoc ( A " Societe " object that contains properties of companies managed by Dolibarr .
2006-02-03 17:42:39 +01:00
*/
2009-05-08 03:23:33 +02:00
if ( ! defined ( 'NOREQUIREDB' ) && ! defined ( 'NOREQUIRESOC' ))
2006-06-16 02:33:04 +02:00
{
2010-04-29 16:54:12 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /societe/class/societe.class.php " );
2007-09-09 13:16:33 +02:00
$mysoc = new Societe ( $db );
2009-05-08 03:23:33 +02:00
2007-09-09 13:16:33 +02:00
$mysoc -> id = 0 ;
2010-04-06 18:12:00 +02:00
$mysoc -> nom = $conf -> global -> MAIN_INFO_SOCIETE_NOM ; // TODO obsolete
$mysoc -> name = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
2009-12-23 11:07:48 +01:00
$mysoc -> adresse = $conf -> global -> MAIN_INFO_SOCIETE_ADRESSE ; // TODO obsolete
$mysoc -> address = $conf -> global -> MAIN_INFO_SOCIETE_ADRESSE ;
2010-04-06 18:12:00 +02:00
$mysoc -> cp = $conf -> global -> MAIN_INFO_SOCIETE_CP ; // TODO obsolete
$mysoc -> zip = $conf -> global -> MAIN_INFO_SOCIETE_CP ;
$mysoc -> ville = $conf -> global -> MAIN_INFO_SOCIETE_VILLE ; // TODO obsolete
$mysoc -> town = $conf -> global -> MAIN_INFO_SOCIETE_VILLE ;
2010-06-18 00:19:37 +02:00
$mysoc -> departement_id = $conf -> global -> MAIN_INFO_SOCIETE_DEPARTEMENT ;
2010-07-28 00:07:50 +02:00
$mysoc -> note = empty ( $conf -> global -> MAIN_INFO_SOCIETE_NOTE ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_NOTE ;
2010-08-21 17:30:17 +02:00
// We define pays_id, pays_code and pays_label
$tmp = explode ( ':' , $conf -> global -> MAIN_INFO_SOCIETE_PAYS );
$pays_id = $tmp [ 0 ];
if ( ! empty ( $tmp [ 1 ])) // If $conf->global->MAIN_INFO_SOCIETE_PAYS is "id:code:label"
{
$pays_code = $tmp [ 1 ];
$pays_label = $tmp [ 2 ];
}
else // For backward compatibility
{
2010-09-15 00:14:55 +02:00
dol_syslog ( " Your country setup use an old syntax. Reedit it in setup area. " , LOG_WARNING );
2010-08-21 17:30:17 +02:00
include_once ( DOL_DOCUMENT_ROOT . '/lib/company.lib.php' );
2010-09-04 20:04:47 +02:00
$pays_code = getCountry ( $pays_id , 2 , $db ); // This need a SQL request, but it's the old feature
$pays_label = getCountry ( $pays_id , 0 , $db ); // This need a SQL request, but it's the old feature
2010-08-21 17:30:17 +02:00
}
$mysoc -> pays_id = $pays_id ;
$mysoc -> pays_code = $pays_code ;
$mysoc -> country = $pays_label ;
if ( is_object ( $langs )) $mysoc -> country = ( $langs -> trans ( 'Country' . $pays_code ) != 'Country' . $pays_code ) ? $langs -> trans ( 'Country' . $pays_code ) : $pays_label ;
$mysoc -> pays = $mysoc -> country ; // deprecated
2010-07-28 00:07:50 +02:00
$mysoc -> tel = empty ( $conf -> global -> MAIN_INFO_SOCIETE_TEL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_TEL ; // deprecated
$mysoc -> phone = empty ( $conf -> global -> MAIN_INFO_SOCIETE_TEL ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_TEL ;
$mysoc -> fax = empty ( $conf -> global -> MAIN_INFO_SOCIETE_FAX ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_FAX ;
$mysoc -> url = empty ( $conf -> global -> MAIN_INFO_SOCIETE_WEB ) ? '' : $conf -> global -> MAIN_INFO_SOCIETE_WEB ;
2007-09-09 13:16:33 +02:00
// Anciens id prof
2009-01-21 14:06:34 +01:00
$mysoc -> siren = empty ( $conf -> global -> MAIN_INFO_SIREN ) ? '' : $conf -> global -> MAIN_INFO_SIREN ;
$mysoc -> siret = empty ( $conf -> global -> MAIN_INFO_SIRET ) ? '' : $conf -> global -> MAIN_INFO_SIRET ;
$mysoc -> ape = empty ( $conf -> global -> MAIN_INFO_APE ) ? '' : $conf -> global -> MAIN_INFO_APE ;
$mysoc -> rcs = empty ( $conf -> global -> MAIN_INFO_RCS ) ? '' : $conf -> global -> MAIN_INFO_RCS ;
2009-09-15 18:05:58 +02:00
// Id prof generiques
2010-05-09 16:47:02 +02:00
$mysoc -> idprof1 = empty ( $conf -> global -> MAIN_INFO_SIREN ) ? '' : $conf -> global -> MAIN_INFO_SIREN ;
$mysoc -> idprof2 = empty ( $conf -> global -> MAIN_INFO_SIRET ) ? '' : $conf -> global -> MAIN_INFO_SIRET ;
$mysoc -> idprof3 = empty ( $conf -> global -> MAIN_INFO_APE ) ? '' : $conf -> global -> MAIN_INFO_APE ;
$mysoc -> idprof4 = empty ( $conf -> global -> MAIN_INFO_RCS ) ? '' : $conf -> global -> MAIN_INFO_RCS ;
2009-12-09 14:17:16 +01:00
$mysoc -> tva_intra = $conf -> global -> MAIN_INFO_TVAINTRA ; // VAT number, not necessarly INTRA.
2007-09-09 13:16:33 +02:00
$mysoc -> capital = $conf -> global -> MAIN_INFO_CAPITAL ;
$mysoc -> forme_juridique_code = $conf -> global -> MAIN_INFO_SOCIETE_FORME_JURIDIQUE ;
$mysoc -> email = $conf -> global -> MAIN_INFO_SOCIETE_MAIL ;
$mysoc -> logo = $conf -> global -> MAIN_INFO_SOCIETE_LOGO ;
$mysoc -> logo_small = $conf -> global -> MAIN_INFO_SOCIETE_LOGO_SMALL ;
$mysoc -> logo_mini = $conf -> global -> MAIN_INFO_SOCIETE_LOGO_MINI ;
2009-07-29 18:13:33 +02:00
// Define if company use vat or not (Do not use conf->global->FACTURE_TVAOPTION anymore)
2010-02-02 09:22:50 +01:00
$mysoc -> tva_assuj = (( isset ( $conf -> global -> FACTURE_TVAOPTION ) && $conf -> global -> FACTURE_TVAOPTION == 'franchise' ) ? 0 : 1 );
2010-01-23 23:01:34 +01:00
// Define if company use local taxes
2010-04-24 17:56:37 +02:00
$mysoc -> localtax1_assuj = (( isset ( $conf -> global -> FACTURE_LOCAL_TAX1_OPTION ) && $conf -> global -> FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' ) ? 1 : 0 );
$mysoc -> localtax2_assuj = (( isset ( $conf -> global -> FACTURE_LOCAL_TAX2_OPTION ) && $conf -> global -> FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' ) ? 1 : 0 );
2010-08-21 01:06:20 +02:00
2010-08-21 16:05:51 +02:00
// For some countries, we need to invert our address with customer address
2010-08-21 01:06:20 +02:00
if ( $mysoc -> pays_code == 'DE' && ! isset ( $conf -> global -> MAIN_INVERT_SENDER_RECIPIENT )) $conf -> global -> MAIN_INVERT_SENDER_RECIPIENT = 1 ;
2006-06-16 02:33:04 +02:00
}
2006-02-03 17:42:39 +01:00
2009-05-08 03:23:33 +02:00
/*
* Set default language ( must be after the setValues of $conf )
*/
if ( ! defined ( 'NOREQUIRETRAN' ))
{
$langs -> setDefaultLang ( $conf -> global -> MAIN_LANG_DEFAULT );
}
/*
* Pour utiliser d ' autres versions des librairies externes que les
2009-08-29 20:08:46 +02:00
* versions embarquees dans Dolibarr , definir les constantes adequates :
2009-05-08 03:23:33 +02:00
* Pour FPDF : FPDF_PATH
* Pour PHP_WriteExcel : PHP_WRITEEXCEL_PATH
* Pour MagpieRss : MAGPIERSS_PATH
* Pour PHPlot : PHPLOT_PATH
* Pour JPGraph : JPGRAPH_PATH
* Pour NuSOAP : NUSOAP_PATH
* Pour TCPDF : TCPDF_PATH
*/
// Les path racines
if ( ! defined ( 'FPDF_PATH' )) { define ( 'FPDF_PATH' , DOL_DOCUMENT_ROOT . '/includes/fpdf/fpdf/' ); }
if ( ! defined ( 'FPDFI_PATH' )) { define ( 'FPDFI_PATH' , DOL_DOCUMENT_ROOT . '/includes/fpdf/fpdfi/' ); }
if ( ! defined ( 'MAGPIERSS_PATH' )) { define ( 'MAGPIERSS_PATH' , DOL_DOCUMENT_ROOT . '/includes/magpierss/' ); }
if ( ! defined ( 'JPGRAPH_PATH' )) { define ( 'JPGRAPH_PATH' , DOL_DOCUMENT_ROOT . '/includes/jpgraph/' ); }
if ( ! defined ( 'NUSOAP_PATH' )) { define ( 'NUSOAP_PATH' , DOL_DOCUMENT_ROOT . '/includes/nusoap/lib/' ); }
if ( ! defined ( 'PHP_WRITEEXCEL_PATH' )) { define ( 'PHP_WRITEEXCEL_PATH' , DOL_DOCUMENT_ROOT . '/includes/php_writeexcel/' ); }
if ( ! defined ( 'PHPEXCELREADER' )) { define ( 'PHPEXCELREADER' , DOL_DOCUMENT_ROOT . '/includes/phpexcelreader/' ); }
// Les autres path
if ( ! defined ( 'MAGPIE_DIR' )) { define ( 'MAGPIE_DIR' , MAGPIERSS_PATH ); }
if ( ! defined ( 'MAGPIE_CACHE_DIR' )) { define ( 'MAGPIE_CACHE_DIR' , $conf -> externalrss -> dir_temp ); }
2008-01-10 23:21:18 +01:00
2009-05-08 03:23:33 +02:00
if ( ! defined ( 'MAIN_LABEL_MENTION_NPR' ) ) define ( 'MAIN_LABEL_MENTION_NPR' , 'NPR' );
2009-10-22 02:36:21 +02:00
2006-05-05 22:01:58 +02:00
?>