Example #1
0
/**
 * Load conf file (file must exists)
 *
 * @param	string		$dolibarr_main_document_root		Root directory of Dolibarr bin files
 * @return	int												<0 if KO, >0 if OK
 */
function conf($dolibarr_main_document_root) {
	global $conf, $couch;
	global $dolibarr_main_db_type;
	global $dolibarr_main_db_host;
	global $dolibarr_main_db_port;
	global $dolibarr_main_db_name;
	global $dolibarr_main_db_user;
	global $dolibarr_main_db_pass;
	global $character_set_client;

	global $dolibarr_main_couchdb_host;
	global $dolibarr_main_couchdb_port;
	global $dolibarr_main_couchdb_name;

	$return = include_once($dolibarr_main_document_root . "/core/class/conf.class.php");
	if (!$return)
		return -1;

	$conf = new Conf();
	$conf->db->type = trim($dolibarr_main_db_type);
	$conf->db->host = trim($dolibarr_main_db_host);
	$conf->db->port = trim($dolibarr_main_db_port);
	$conf->db->name = trim($dolibarr_main_db_name);
	$conf->db->user = trim($dolibarr_main_db_user);
	$conf->db->pass = trim($dolibarr_main_db_pass);

	// CouchDB
	$conf->Couchdb->host = trim($dolibarr_main_couchdb_host);
	$conf->Couchdb->port = trim($dolibarr_main_couchdb_port);
	$conf->Couchdb->name = trim($dolibarr_main_couchdb_name);
	
	$couch = new couchClient($conf->Couchdb->host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name);
	$couch->setSessionCookie("AuthSession=" . $_COOKIE['AuthSession']);

	$conf->useDatabase();

	if (empty($character_set_client))
		$character_set_client = "UTF-8";
	$conf->file->character_set_client = strtoupper($character_set_client);
	if (empty($dolibarr_main_db_character_set))
		$dolibarr_main_db_character_set = ($conf->db->type == 'mysql' ? 'latin1' : '');  // Old installation
	$conf->db->character_set = $dolibarr_main_db_character_set;
	if (empty($dolibarr_main_db_collation))
		$dolibarr_main_db_collation = ($conf->db->type == 'mysql' ? 'latin1_swedish_ci' : '');  // Old installation
	$conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
	if (empty($dolibarr_main_db_encryption))
		$dolibarr_main_db_encryption = 0;
	$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
	if (empty($dolibarr_main_db_cryptkey))
		$dolibarr_main_db_cryptkey = '';
	$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;

	// Force usage of log file for install and upgrades
	$conf->syslog->enabled = 1;
	$conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
	if (!defined('SYSLOG_FILE_ON'))
		define('SYSLOG_FILE_ON', 1);
	if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
		if (@is_writable('/tmp'))
			define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
		else if (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"]))
			define('SYSLOG_FILE', $_ENV["TMP"] . '/dolibarr_install.log');
		else if (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"]))
			define('SYSLOG_FILE', $_ENV["TEMP"] . '/dolibarr_install.log');
		else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat'))
			define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
		else if (@is_writable('../../'))
			define('SYSLOG_FILE', '../../dolibarr_install.log');	// For others
			
//print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
	}
	if (!defined('SYSLOG_FILE_NO_ERROR'))
		define('SYSLOG_FILE_NO_ERROR', 1);

	return 1;
}