2012-06-20 22:23:43 +02: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 >
2012-02-06 00:07:48 +01:00
* Copyright ( C ) 2004 - 2012 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 >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
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 >
2011-06-15 19:35:26 +02:00
* Copyright ( C ) 2011 Philippe Grand < philippe . grand @ atoo - net . com >
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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-02-03 17:42:39 +01:00
* ( 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
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2006-02-03 17:42:39 +01:00
*/
/**
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 )
2011-07-30 12:23:24 +02:00
* This script reads the conf file , init $lang , $db and and empty $user
2008-11-28 00:24:50 +01:00
*/
2006-02-03 17:42:39 +01:00
2012-08-22 23:11:24 +02:00
require_once 'filefunc.inc.php' ; // May have been already require by main.inc.php. But may not by scripts.
2006-02-03 17:42:39 +01:00
2008-03-17 03:53:48 +01:00
2013-03-09 18:55:57 +01:00
2009-10-22 02:36:21 +02:00
/*
* Create $conf object
*/
2012-08-22 23:11:24 +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 ();
2012-12-19 13:06:45 +01:00
// Set properties specific to database
2011-11-04 09:09:53 +01:00
$conf -> db -> host = $dolibarr_main_db_host ;
$conf -> db -> port = $dolibarr_main_db_port ;
$conf -> db -> name = $dolibarr_main_db_name ;
$conf -> db -> user = $dolibarr_main_db_user ;
$conf -> db -> pass = $dolibarr_main_db_pass ;
$conf -> db -> type = $dolibarr_main_db_type ;
$conf -> db -> prefix = $dolibarr_main_db_prefix ;
$conf -> db -> character_set = $dolibarr_main_db_character_set ;
$conf -> db -> dolibarr_main_db_collation = $dolibarr_main_db_collation ;
$conf -> db -> dolibarr_main_db_encryption = $dolibarr_main_db_encryption ;
$conf -> db -> dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey ;
2013-01-10 08:27:12 +01:00
if ( defined ( 'TEST_DB_FORCE_TYPE' )) $conf -> db -> type = constant ( 'TEST_DB_FORCE_TYPE' ); // Force db type (for test purpose, by PHP unit for example)
2012-12-19 13:06:45 +01:00
// Set properties specific to conf file
2011-11-04 09:09:53 +01:00
$conf -> file -> main_limit_users = $dolibarr_main_limit_users ;
$conf -> file -> mailing_limit_sendbyweb = $dolibarr_mailing_limit_sendbyweb ;
2012-12-19 13:06:45 +01:00
$conf -> file -> main_authentication = empty ( $dolibarr_main_authentication ) ? '' : $dolibarr_main_authentication ; // Identification mode
$conf -> file -> main_force_https = empty ( $dolibarr_main_force_https ) ? '' : $dolibarr_main_force_https ; // Force https
$conf -> file -> strict_mode = empty ( $dolibarr_strict_mode ) ? '' : $dolibarr_strict_mode ; // Force php strict mode (for debug)
$conf -> file -> cookie_cryptkey = empty ( $dolibarr_main_cookie_cryptkey ) ? '' : $dolibarr_main_cookie_cryptkey ; // Cookie cryptkey
2013-07-07 03:26:51 +02:00
$conf -> file -> dol_document_root = array ( 'main' => ( string ) DOL_DOCUMENT_ROOT ); // Define array of document root directories ('/home/htdocs')
$conf -> file -> dol_url_root = array ( 'main' => ( string ) DOL_URL_ROOT ); // Define array of url root path ('' or '/dolibarr')
2009-01-15 23:49:06 +01:00
if ( ! empty ( $dolibarr_main_document_root_alt ))
2008-12-07 20:19:32 +01:00
{
2012-12-19 13:06:45 +01:00
// dolibarr_main_document_root_alt can contains several directories
2009-10-20 15:14:44 +02:00
$values = preg_split ( '/[;,]/' , $dolibarr_main_document_root_alt );
2013-07-07 03:26:51 +02:00
$i = 0 ;
foreach ( $values as $value ) $conf -> file -> dol_document_root [ 'alt' . ( $i ++ )] = ( string ) $value ;
$values = preg_split ( '/[;,]/' , $dolibarr_main_url_root_alt );
$i = 0 ;
foreach ( $values as $value ) $conf -> file -> dol_url_root [ 'alt' . ( $i ++ )] = ( string ) $value ;
2008-12-07 20:19:32 +01:00
}
2012-12-19 13:06:45 +01:00
// Set properties specific to multicompany
2013-03-30 14:27:13 +01:00
// TODO Multicompany Remove this. Useless. Var should be read when required.
2012-12-19 13:06:45 +01:00
$conf -> multicompany -> transverse_mode = empty ( $multicompany_transverse_mode ) ? '' : $multicompany_transverse_mode ; // Force Multi-Company transverse mode
$conf -> multicompany -> force_entity = empty ( $multicompany_force_entity ) ? '' : ( int ) $multicompany_force_entity ; // Force entity in login page
2011-11-04 09:09:53 +01:00
2007-12-30 19:47:45 +01:00
// Chargement des includes principaux de librairies communes
2012-08-22 23:11:24 +02:00
if ( ! defined ( 'NOREQUIREUSER' )) require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ; // Need 500ko memory
if ( ! defined ( 'NOREQUIRETRAN' )) require_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php' ;
if ( ! defined ( 'NOREQUIRESOC' )) require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2006-02-03 17:42:39 +01:00
2012-12-19 13:06:45 +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
{
2011-12-04 22:25:49 +01: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
/*
2012-01-11 10:38:29 +01:00
* Object $db
2006-06-03 01:20:36 +02:00
*/
2009-01-15 23:49:06 +01:00
if ( ! defined ( 'NOREQUIREDB' ))
2007-09-09 13:16:33 +02:00
{
2011-09-28 16:26:49 +02:00
$db = getDoliDBInstance ( $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
}
2011-12-04 22:25:49 +01:00
2009-05-08 03:23:33 +02:00
// Now database connexion is known, so we can forget password
2011-12-04 22:25:49 +01:00
//unset($dolibarr_main_db_pass); // We comment this because this constant is used in a lot of pages
unset ( $conf -> db -> pass ); // This is to avoid password to be shown in memory/swap dump
2006-02-03 17:42:39 +01:00
/*
2012-01-11 10:38:29 +01:00
* Object $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.
2011-12-05 00:35:50 +01:00
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 " ];
}
2012-01-11 10:38:29 +01:00
else if ( ! empty ( $_ENV [ " dol_entity " ])) // Entity inside a CLI script
2009-05-08 03:23:33 +02:00
{
$conf -> entity = $_ENV [ " dol_entity " ];
}
2012-01-11 10:38:29 +01:00
else if ( isset ( $_POST [ " loginfunction " ]) && GETPOST ( " entity " )) // Just after a login page
2009-05-22 00:28:05 +02:00
{
2011-12-05 00:35:50 +01:00
$conf -> entity = GETPOST ( " entity " , 'int' );
2009-05-22 00:28:05 +02:00
}
2012-05-04 13:18:29 +02:00
else if ( defined ( 'DOLENTITY' ) && is_int ( DOLENTITY )) // For public page with MultiCompany module
{
$conf -> entity = DOLENTITY ;
}
2013-04-25 15:49:27 +02:00
else if ( ! empty ( $_COOKIE [ 'DOLENTITY' ])) // For other application with MultiCompany module
{
$conf -> entity = $_COOKIE [ 'DOLENTITY' ];
}
2012-09-05 19:17:55 +02:00
else if ( ! empty ( $conf -> multicompany -> force_entity ) && is_int ( $conf -> multicompany -> force_entity )) // To force entity in login page
{
$conf -> entity = $conf -> multicompany -> force_entity ;
}
2011-12-28 17:30:30 +01: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
}
2010-12-27 15:54:27 +01:00
// Overwrite database value
if ( ! empty ( $conf -> file -> mailing_limit_sendbyweb ))
{
$conf -> global -> MAILING_LIMIT_SENDBYWEB = $conf -> file -> mailing_limit_sendbyweb ;
}
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 ))
{
$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
2013-01-25 19:12:54 +01:00
// Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
2009-05-08 03:23:33 +02:00
if ( ! defined ( 'NOREQUIREDB' ) && ! defined ( 'NOREQUIRESOC' ))
2006-06-16 02:33:04 +02:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2010-10-21 15:34:31 +02:00
2012-10-04 18:52:32 +02:00
$mysoc = new Societe ( $db );
2013-03-09 18:55:57 +01:00
$mysoc -> setMysoc ( $conf );
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
2011-12-29 18:07:41 +01:00
if ( $mysoc -> country_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
2013-02-25 10:17:38 +01:00
// Set default language (must be after the setValues setting global $conf->global->MAIN_LANG_DEFAULT. Page main.inc.php will overwrite langs->defaultlang with user value later)
2009-05-08 03:23:33 +02:00
if ( ! defined ( 'NOREQUIRETRAN' ))
{
2013-02-25 10:17:38 +01:00
$langcode = ( GETPOST ( 'lang' ) ? GETPOST ( 'lang' , 'alpha' , 1 ) : ( empty ( $conf -> global -> MAIN_LANG_DEFAULT ) ? 'auto' : $conf -> global -> MAIN_LANG_DEFAULT ));
$langs -> setDefaultLang ( $langcode );
2009-05-08 03:23:33 +02:00
}
2013-01-25 19:12:54 +01:00
// Create the global $hookmanager object
2013-01-26 10:38:11 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
$hookmanager = new HookManager ( $db );
2013-01-25 19:12:54 +01:00
2011-08-11 21:12:37 +02:00
if ( ! defined ( 'MAIN_LABEL_MENTION_NPR' ) ) define ( 'MAIN_LABEL_MENTION_NPR' , 'NPR' );
2011-10-27 01:06:43 +02:00
// We force feature to help debug
2012-11-17 19:55:19 +01:00
//$conf->global->MAIN_JS_ON_PAYMENT=0;
2011-10-27 01:06:43 +02:00
2012-12-19 13:06:45 +01:00
// We force FPDF
if ( ! empty ( $dolibarr_pdf_force_fpdf )) $conf -> global -> MAIN_USE_FPDF = $dolibarr_pdf_force_fpdf ;
2006-05-05 22:01:58 +02:00
?>