diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 03d1c41afbe..3f7cb019521 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -28,17 +28,22 @@ */ // Just to define version DOL_VERSION -if (!defined('DOL_INC_FOR_VERSION_ERROR')) define('DOL_INC_FOR_VERSION_ERROR', '1'); +if (!defined('DOL_INC_FOR_VERSION_ERROR')) { + define('DOL_INC_FOR_VERSION_ERROR', '1'); +} require_once '../filefunc.inc.php'; // Define DOL_DOCUMENT_ROOT and ADODB_PATH used for install/upgrade process -if (!defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '..'); -if (!defined('ADODB_PATH')) -{ +if (!defined('DOL_DOCUMENT_ROOT')) { + define('DOL_DOCUMENT_ROOT', '..'); +} +if (!defined('ADODB_PATH')) { $foundpath = DOL_DOCUMENT_ROOT.'/includes/adodbtime/'; - if (!is_dir($foundpath)) $foundpath = '/usr/share/php/adodb/'; + if (!is_dir($foundpath)) { + $foundpath = '/usr/share/php/adodb/'; + } define('ADODB_PATH', $foundpath); } @@ -49,15 +54,14 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once ADODB_PATH.'adodb-time.inc.php'; -$conf = new Conf(); +$conf = new Conf(); // Force $_REQUEST["logtohtml"] $_REQUEST["logtohtml"] = 1; // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative // et non path absolu. -if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) -{ +if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) { $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"]; } @@ -76,19 +80,21 @@ $conffiletoshow = "htdocs/conf/conf.php"; // Load conf file if it is already defined -if (!defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) // Test on filesize is to ensure that conf file is more that an empty template with just 8) { // Test on filesize is to ensure that conf file is more that an empty template with just $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) : ''; // Remove last / or \ on directories or url value - if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root); - if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root); - if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root); - if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt); - if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt); + if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) { + $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root); + } + if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) { + $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root); + } + if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) { + $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root); + } + if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) { + $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt); + } + if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) { + $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt); + } // Create conf object - if (!empty($dolibarr_main_document_root)) - { + if (!empty($dolibarr_main_document_root)) { $result = conf($dolibarr_main_document_root); } // Load database driver - if ($result) - { - if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) - { + if ($result) { + if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) { $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php'; - if (!$result) - { + if (!$result) { $includeconferror = 'ErrorBadValueForDolibarrMainDBType'; } } @@ -130,7 +142,9 @@ if (!defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; // Define prefix -if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) $dolibarr_main_db_prefix = 'llx_'; +if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) { + $dolibarr_main_db_prefix = 'llx_'; +} define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : '')); define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir @@ -138,42 +152,51 @@ define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_r define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http* $suburi = strstr($uri, '/'); // $suburi contains url without domain -if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now '' +if ($suburi == '/') { + $suburi = ''; // If $suburi is /, it is now '' +} define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...) -if (empty($conf->file->character_set_client)) $conf->file->character_set_client = "utf-8"; -if (empty($conf->db->character_set)) $conf->db->character_set = 'utf8'; -if (empty($conf->db->dolibarr_main_db_collation)) $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci'; -if (empty($conf->db->dolibarr_main_db_encryption)) $conf->db->dolibarr_main_db_encryption = 0; -if (empty($conf->db->dolibarr_main_db_cryptkey)) $conf->db->dolibarr_main_db_cryptkey = ''; -if (empty($conf->db->user)) $conf->db->user = ''; +if (empty($conf->file->character_set_client)) { + $conf->file->character_set_client = "utf-8"; +} +if (empty($conf->db->character_set)) { + $conf->db->character_set = 'utf8'; +} +if (empty($conf->db->dolibarr_main_db_collation)) { + $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci'; +} +if (empty($conf->db->dolibarr_main_db_encryption)) { + $conf->db->dolibarr_main_db_encryption = 0; +} +if (empty($conf->db->dolibarr_main_db_cryptkey)) { + $conf->db->dolibarr_main_db_cryptkey = ''; +} +if (empty($conf->db->user)) { + $conf->db->user = ''; +} // Define array of document root directories $conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT); -if (!empty($dolibarr_main_document_root_alt)) -{ +if (!empty($dolibarr_main_document_root_alt)) { // dolibarr_main_document_root_alt contains several directories $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt); - foreach ($values as $value) - { + foreach ($values as $value) { $conf->file->dol_document_root[] = $value; } } // Security check (old method, when directory is renamed /install.lock) -if (preg_match('/install\.lock/i', $_SERVER["SCRIPT_FILENAME"])) -{ - if (!is_object($langs)) - { +if (preg_match('/install\.lock/i', $_SERVER["SCRIPT_FILENAME"])) { + if (!is_object($langs)) { $langs = new Translate('..', $conf); $langs->setDefaultLang('auto'); } $langs->load("install"); print $langs->trans("YouTryInstallDisabledByDirLock"); - if (!empty($dolibarr_main_url_root)) - { + if (!empty($dolibarr_main_url_root)) { print 'Click on following link, '; print $langs->trans("ClickHereToGoToApp"); print ''; @@ -187,17 +210,14 @@ if (constant('DOL_DATA_ROOT') === null) { // Try to detect any lockfile in the default documents path $lockfile = '../../documents/install.lock'; } -if (@file_exists($lockfile)) -{ - if (!isset($langs) || !is_object($langs)) - { +if (@file_exists($lockfile)) { + if (!isset($langs) || !is_object($langs)) { $langs = new Translate('..', $conf); $langs->setDefaultLang('auto'); } $langs->load("install"); print $langs->trans("YouTryInstallDisabledByFileLock"); - if (!empty($dolibarr_main_url_root)) - { + if (!empty($dolibarr_main_url_root)) { print $langs->trans("ClickOnLinkOrRemoveManualy").''; print ''; print $langs->trans("ClickHereToGoToApp"); @@ -212,42 +232,55 @@ if (@file_exists($lockfile)) // Force usage of log file for install and upgrades $conf->syslog->enabled = 1; $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG'); -if (!defined('SYSLOG_HANDLERS')) define('SYSLOG_HANDLERS', '["mod_syslog_file"]'); -if (!defined('SYSLOG_FILE')) // To avoid warning on systems with constant already defined -{ - if (@is_writable('/tmp')) define('SYSLOG_FILE', '/tmp/dolibarr_install.log'); - elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log'); - elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log'); - elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp - elseif (@is_writable('../../')) define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others +if (!defined('SYSLOG_HANDLERS')) { + define('SYSLOG_HANDLERS', '["mod_syslog_file"]'); +} +if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined + if (@is_writable('/tmp')) { + define('SYSLOG_FILE', '/tmp/dolibarr_install.log'); + } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) { + define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log'); + } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) { + define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log'); + } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) { + define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp + } elseif (@is_writable('../../')) { + define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others + } //print 'SYSLOG_FILE='.SYSLOG_FILE;exit; } -if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); -if (!defined('SYSLOG_FILE_NO_ERROR')) define('SYSLOG_FILE_NO_ERROR', 1); +if (defined('SYSLOG_FILE')) { + $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); +} +if (!defined('SYSLOG_FILE_NO_ERROR')) { + define('SYSLOG_FILE_NO_ERROR', 1); +} // We init log handler for install $handlers = array('mod_syslog_file'); -foreach ($handlers as $handler) -{ +foreach ($handlers as $handler) { $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php'; - if (!file_exists($file)) - { + if (!file_exists($file)) { throw new Exception('Missing log handler file '.$handler.'.php'); } require_once $file; $loghandlerinstance = new $handler(); - if (!$loghandlerinstance instanceof LogHandlerInterface) - { + if (!$loghandlerinstance instanceof LogHandlerInterface) { throw new Exception('Log handler does not extend LogHandlerInterface'); } - if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler] = $loghandlerinstance; + if (empty($conf->loghandlers[$handler])) { + $conf->loghandlers[$handler] = $loghandlerinstance; + } } // Define object $langs $langs = new Translate('..', $conf); -if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); -else $langs->setDefaultLang('auto'); +if (GETPOST('lang', 'aZ09')) { + $langs->setDefaultLang(GETPOST('lang', 'aZ09')); +} else { + $langs->setDefaultLang('auto'); +} /** @@ -268,7 +301,9 @@ function conf($dolibarr_main_document_root) global $character_set_client; $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php'; - if (!$return) return -1; + if (!$return) { + return -1; + } $conf = new Conf(); $conf->db->type = trim($dolibarr_main_db_type); @@ -279,51 +314,73 @@ function conf($dolibarr_main_document_root) $conf->db->pass = trim($dolibarr_main_db_pass); // Mysql driver support has been removed in favor of mysqli - if ($conf->db->type == 'mysql') $conf->db->type = 'mysqli'; - if (empty($character_set_client)) $character_set_client = "UTF-8"; + if ($conf->db->type == 'mysql') { + $conf->db->type = 'mysqli'; + } + 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 == 'mysqli' ? 'utf8' : ''); + if (empty($dolibarr_main_db_character_set)) { + $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : ''); + } $conf->db->character_set = $dolibarr_main_db_character_set; - if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : ''); + if (empty($dolibarr_main_db_collation)) { + $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : ''); + } $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation; - if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0; + 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 = ''; + 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_HANDLERS')) define('SYSLOG_HANDLERS', '["mod_syslog_file"]'); - if (!defined('SYSLOG_FILE')) // To avoid warning on systems with constant already defined - { - if (@is_writable('/tmp')) define('SYSLOG_FILE', '/tmp/dolibarr_install.log'); - elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log'); - elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log'); - elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp - elseif (@is_writable('../../')) define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others + if (!defined('SYSLOG_HANDLERS')) { + define('SYSLOG_HANDLERS', '["mod_syslog_file"]'); + } + if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined + if (@is_writable('/tmp')) { + define('SYSLOG_FILE', '/tmp/dolibarr_install.log'); + } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) { + define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log'); + } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) { + define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log'); + } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) { + define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp + } elseif (@is_writable('../../')) { + define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others + } //print 'SYSLOG_FILE='.SYSLOG_FILE;exit; } - if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); - if (!defined('SYSLOG_FILE_NO_ERROR')) define('SYSLOG_FILE_NO_ERROR', 1); + if (defined('SYSLOG_FILE')) { + $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); + } + if (!defined('SYSLOG_FILE_NO_ERROR')) { + define('SYSLOG_FILE_NO_ERROR', 1); + } // We init log handler for install $handlers = array('mod_syslog_file'); - foreach ($handlers as $handler) - { + foreach ($handlers as $handler) { $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php'; - if (!file_exists($file)) - { + if (!file_exists($file)) { throw new Exception('Missing log handler file '.$handler.'.php'); } require_once $file; $loghandlerinstance = new $handler(); - if (!$loghandlerinstance instanceof LogHandlerInterface) - { + if (!$loghandlerinstance instanceof LogHandlerInterface) { throw new Exception('Log handler does not extend LogHandlerInterface'); } - if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler] = $loghandlerinstance; + if (empty($conf->loghandlers[$handler])) { + $conf->loghandlers[$handler] = $loghandlerinstance; + } } return 1; @@ -351,8 +408,7 @@ function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl $jquerytheme = 'base'; - if ($forcejqueryurl) - { + if ($forcejqueryurl) { $jQueryCustomPath = $forcejqueryurl; $jQueryUiCustomPath = $forcejqueryurl; } else { @@ -373,14 +429,23 @@ function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl print ''."\n"; print ''."\n"; - if ($jQueryUiCustomPath) print ''."\n"; // JQuery - else print ''."\n"; // JQuery + if ($jQueryUiCustomPath) { + print ''."\n"; // JQuery + } else { + print ''."\n"; // JQuery + } print ''."\n"; - if ($jQueryCustomPath) print ''."\n"; - else print ''."\n"; - if ($jQueryUiCustomPath) print ''."\n"; - else print ''."\n"; + if ($jQueryCustomPath) { + print ''."\n"; + } else { + print ''."\n"; + } + if ($jQueryUiCustomPath) { + print ''."\n"; + } else { + print ''."\n"; + } print ''.$langs->trans("DolibarrSetup").''."\n"; print ''."\n"; @@ -399,7 +464,9 @@ function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; @@ -427,11 +494,9 @@ function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleas print ''."\n"; print ''."\n"; - if (!$nonext || ($nonext == '2')) - { + if (!$nonext || ($nonext == '2')) { print ''; - if ($nonext == '2') - { + if ($nonext == '2') { print ''; print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"].'&ignoreerrors=1' : ''); print ''; @@ -439,25 +504,26 @@ function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleas } print 'trans("NextStep").' ->"'; - if ($jscheckfunction) print ' onClick="return '.$jscheckfunction.'();"'; + if ($jscheckfunction) { + print ' onClick="return '.$jscheckfunction.'();"'; + } print '>'; - if ($withpleasewait) print ''.$langs->trans("NextStepMightLastALongTime").''.$langs->trans("PleaseBePatient").''; + if ($withpleasewait) { + print ''.$langs->trans("NextStepMightLastALongTime").''.$langs->trans("PleaseBePatient").''; + } } - if ($setuplang) - { + if ($setuplang) { print ''; } print ''."\n"; // If there is some logs in buffer to show - if (isset($conf->logbuffer) && count($conf->logbuffer)) - { + if (isset($conf->logbuffer) && count($conf->logbuffer)) { print "\n"; print "