dolibarr 25.0.0-alpha
inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
4 * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2021 Charlene Benke <charlene@patas-monkey.com>
9 * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
10 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
11*
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Just to define version DOL_VERSION
33if (!defined('DOL_INC_FOR_VERSION_ERROR')) {
34 define('DOL_INC_FOR_VERSION_ERROR', '1');
35}
36require_once '../filefunc.inc.php';
37
38
39// Define DOL_DOCUMENT_ROOT used for install/upgrade process
40if (!defined('DOL_DOCUMENT_ROOT')) {
41 define('DOL_DOCUMENT_ROOT', '..');
42}
43
44require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
49
50'
51@phan-var-force ?string $dolibarr_main_url_root_alt
52@phan-var-force ?string $dolibarr_main_db_prefix
53';
54
55$realpathconf = realpath(DOL_DOCUMENT_ROOT.'/core/class/conf.class.php');
56
57$conf = new Conf();
58
59// Force $_REQUEST["logtohtml"]
60$_REQUEST["logtohtml"] = 1;
61
62// Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
63// et non path absolu.
64if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
65 $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
66}
67
68
69$includeconferror = '';
70
71
72// Define localization of conf file
73$conffile = "../conf/conf.php";
74$conffiletoshow = "htdocs/conf/conf.php";
75// For debian/redhat like systems
76//$conffile = "/etc/dolibarr/conf.php";
77//$conffiletoshow = "/etc/dolibarr/conf.php";
78
79$short_options = "c:h";
80$long_options = array(
81 "config:",
82 "help",
83);
84
98function install_usage($program, $header)
99{
100 echo $header."\n";
101 echo " php ".$program." [options] [script options]\n";
102 echo "\n";
103 echo "Script syntax when using step2.php:\n";
104 echo " php ".$program." [options] [action] [selectlang]\n";
105 echo "\n";
106 echo " action:\n";
107 echo " Specify the action to execute for the file among the following ones.\n";
108 echo " - set: Create tables, keys, functions and data for the instance.\n";
109 echo "\n";
110 echo " selectlang:\n";
111 echo " Setup the default lang to use, default to 'auto'.\n";
112 echo "\n";
113 echo "Script syntax when using upgrade.php:\n";
114 echo " php ".$program." [options] previous_version new_version [script options]\n";
115 echo "\n";
116 echo " dirmodule:\n";
117 echo " Specify dirmodule to provide a path for an external module\n";
118 echo " so the migration is done using a script from a module.\n";
119 echo "\n";
120 echo " ignoredbversion:\n";
121 echo " Allow to run migration even if database version does\n";
122 echo " not match start version of migration.\n";
123 echo "\n";
124 echo "Script syntax when using upgrade2.php:\n";
125 echo " php ".$program." [options] previous_version new_version [module list]\n";
126 echo "\n";
127 echo " MAIN_MODULE_NAME1,MAIN_MODULE_NAME2:\n";
128 echo " Specify a list of module-name to enable, in upper case, with MAIN_MODULE_ prefix, joined by comma.\n";
129 echo "\n";
130 echo "Options:\n";
131 echo " -c, --config <filename>:\n";
132 echo " Provide a different conf.php file to use.\n";
133 echo "\n";
134 echo " -h, --help:\n";
135 echo " Display this help message.\n";
136}
137
138if (php_sapi_name() === "cli" && (float) PHP_VERSION > 7.0) {
139 $rest_index = 0;
140 $opts = getopt($short_options, $long_options, $rest_index);
141
142 foreach ($opts as $opt => $arg) {
143 switch ($opt) {
144 case 'c':
145 case 'config':
146 $conffile = $arg;
147 $conffiletoshow = $arg;
148 break;
149 case 'h':
150 case 'help':
151 install_usage($argv[0], "Usage:");
152 exit(0);
153 }
154 }
155
156 // Parse the arguments to find the options.
157 $args_options = array_filter(
158 array_slice($argv, 0, $rest_index),
163 static function ($arg) {
164 return strlen($arg) >= 2 && $arg[0] == '-';
165 }
166 );
167 $parsed_options = array_map(
173 static function ($arg) {
174 if (strlen($arg) > 1) {
175 return "--" . $arg;
176 }
177 return "-" . $arg;
178 },
179 array_keys($opts)
180 );
181
182 // Find options (dash-prefixed) that were not parsed.
183 $unknown_options = array_diff($args_options, $parsed_options);
184
185 // In the following test, only dash-prefixed arguments will trigger an
186 // error, given that scripts options can allow a variable number of
187 // additional non-prefixed argument and we mostly want to check for
188 // typo right now.
189 if (count($unknown_options) > 0) {
190 echo "Unknown option: ".array_values($unknown_options)[0]."\n";
191 install_usage($argv[0], "Usage:");
192 exit(1);
193 }
194
195 // Tricky argument list hack, should be removed someday.
196 // Reset argv to remove the argument that were parsed. This is needed
197 // currently because some install code, like in upgrade.php, are using
198 // $argv[] directly with fixed index to fetch some arguments.
199 $argv = array_merge(array($argv[0]), array_slice($argv, $rest_index));
200 $argc = count($argv);
201}
202
203// Load conf file if it is already defined
204if (!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 <?php in first line
205 $result = include_once $conffile; // Load conf file
206 if ($result) {
207 if (empty($dolibarr_main_db_type)) {
208 $dolibarr_main_db_type = 'mysqli'; // For backward compatibility
209 }
210
211 //Mysql driver support has been removed in favor of mysqli
212 if ($dolibarr_main_db_type == 'mysql') {
213 $dolibarr_main_db_type = 'mysqli';
214 }
215
216 if (!isset($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
217 $dolibarr_main_db_port = '3306'; // For backward compatibility
218 }
219
220 // Clean parameters
221 // isset() is true on an empty string, which would let DOL_DATA_ROOT
222 // resolve to '' and the lock file to /install.lock (rejected by a
223 // restrictive open_basedir). Use !empty() so an empty value falls
224 // back to the default relative documents path.
225 $dolibarr_main_data_root = !empty($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents';
227 $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) : '';
228 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : '';
229 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) : '';
230
231 // Remove last / or \ on directories or url value
232 if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
233 $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
234 }
235 if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
236 $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
237 }
238 if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
239 $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
240 }
241 if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
242 $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
243 }
244 if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
245 $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
246 }
247
248 // Create conf object
249 if (!empty($dolibarr_main_document_root)) {
250 $result = conf($dolibarr_main_document_root, $realpathconf);
251 }
252 // Load database driver
253 if ($result > 0) {
254 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
255 $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
256 if (!$result) {
257 $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
258 }
259 }
260 } else {
261 $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
262 }
263 } else {
264 $includeconferror = 'ErrorBadFormatForConfFile';
265 }
266}
267
268$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
269
270// Define prefix
271if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
272 $dolibarr_main_db_prefix = 'llx_';
273}
274define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
275
276define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir
277define('DOL_DATA_ROOT', (!empty($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents'));
278define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
279$uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
280$suburi = strstr($uri, '/'); // $suburi contains url without domain
281if ($suburi == '/') {
282 $suburi = ''; // If $suburi is /, it is now ''
283}
284define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
285
286
287if (empty($conf->file->character_set_client)) {
288 $conf->file->character_set_client = "utf-8";
289}
290if (empty($conf->db->character_set)) {
291 $conf->db->character_set = 'utf8';
292}
293if (empty($conf->db->dolibarr_main_db_collation)) {
294 $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
295}
296if (empty($conf->db->dolibarr_main_db_encryption)) {
297 $conf->db->dolibarr_main_db_encryption = 0;
298}
299if (empty($conf->db->dolibarr_main_db_cryptkey)) {
300 $conf->db->dolibarr_main_db_cryptkey = '';
301}
302if (empty($conf->db->user)) {
303 $conf->db->user = '';
304}
305
306// Define an array of document root directories
307$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
308if (!empty($dolibarr_main_document_root_alt)) {
309 // dolibarr_main_document_root_alt contains several directories
310 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
311 foreach ($values as $value) {
312 $conf->file->dol_document_root[] = $value;
313 }
314}
315
316
317// Check install.lock (for both install and upgrade)
318
319$lockfile = DOL_DATA_ROOT.'/install.lock'; // To lock all /install pages
320$lockfile2 = DOL_DOCUMENT_ROOT.'/install.lock'; // To lock all /install pages (recommended)
321$upgradeunlockfile = DOL_DATA_ROOT.'/upgrade.unlock'; // To unlock upgrade process
322$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.'/upgrade.unlock'; // To unlock upgrade process
323if (constant('DOL_DATA_ROOT') === null) {
324 // We don't have a configuration file yet
325 // Try to detect any lockfile in the default documents path
326 $lockfile = '../../documents/install.lock';
327 $upgradeunlockfile = '../../documents/upgrade.unlock';
328}
329$islocked = false;
330if (@file_exists($lockfile) || @file_exists($lockfile2)) {
331 if (!defined('ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
332 // If this is a dangerous install page (ALLOWED_IF_UPGRADE_UNLOCK_FOUND not defined) or
333 // if there is no upgrade unlock files, we lock the pages.
334 $islocked = true;
335 }
336}
337if ($islocked) { // Pages are locked
338 if (!isset($langs) || !is_object($langs)) {
339 $langs = new Translate('..', $conf);
340 $langs->setDefaultLang('auto');
341 }
342 $langs->load("install");
343
344 header("X-Content-Type-Options: nosniff");
345 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
346
347 if (GETPOST('action') != 'upgrade') {
348 print $langs->trans("YouTryInstallDisabledByFileLock").'<br>';
349 } else {
350 print $langs->trans("YouTryUpgradeDisabledByMissingFileUnLock").'<br>';
351 }
352 if (!empty($dolibarr_main_url_root)) {
353 if (GETPOST('action') != 'upgrade' && (!file_exists($conffile) || !isset($dolibarr_main_url_root))) {
354 print $langs->trans("ClickOnLinkOrRemoveManualy").'<br>';
355 } else {
356 print $langs->trans("ClickOnLinkOrCreateUnlockFileManualy").'<br>';
357 }
358 print '<a href="'.$dolibarr_main_url_root.'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
359 print $langs->trans("ClickHereToGoToApp");
360 print '</a>';
361 } else {
362 print 'If you always reach this page, you must remove the install.lock file manually.<br>';
363 }
364 exit;
365}
366
367
368// Force usage of log file for install and upgrades
369$conf->modules['syslog'] = 'syslog';
370$conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
371if (!defined('SYSLOG_HANDLERS')) {
372 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
373}
374if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
375 if (@is_writable('/tmp')) {
376 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
377 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
378 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
379 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
380 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
381 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
382 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
383 } elseif (@is_writable('../../')) {
384 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
385 }
386 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
387}
388if (defined('SYSLOG_FILE')) {
389 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
390}
391if (!defined('SYSLOG_FILE_NO_ERROR')) {
392 define('SYSLOG_FILE_NO_ERROR', 1);
393}
394// We init log handler for install
395$handlers = array('mod_syslog_file');
396foreach ($handlers as $handler) {
397 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
398 if (!file_exists($file)) {
399 throw new Exception('Missing log handler file '.$handler.'.php');
400 }
401
402 require_once $file;
403 $loghandlerinstance = new $handler();
404 if (!$loghandlerinstance instanceof LogHandler) {
405 throw new Exception('Log handler does not extend LogHandler');
406 }
407
408 if (empty($conf->loghandlers[$handler])) {
409 $conf->loghandlers[$handler] = $loghandlerinstance;
410 }
411}
412
413// Define object $langs
414$langs = new Translate('..', $conf);
415if (GETPOST('lang', 'aZ09')) {
416 $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
417} else {
418 $langs->setDefaultLang('auto');
419}
420
421
429function conf($dolibarr_main_document_root, $realpathconf = null)
430{
431 global $conf;
432 global $dolibarr_main_db_type;
433 global $dolibarr_main_db_host;
434 global $dolibarr_main_db_port;
435 global $dolibarr_main_db_name;
436 global $dolibarr_main_db_user;
437 global $dolibarr_main_db_pass;
438 global $dolibarr_main_db_collation;
439 global $dolibarr_main_db_character_set;
440 global $character_set_client;
441 global $dolibarr_main_instance_unique_id;
442 global $dolibarr_main_cookie_cryptkey;
443
444 if ($realpathconf) {
445 if (realpath($dolibarr_main_document_root.'/core/class/conf.class.php') != $realpathconf) {
446 print 'Warning: You are running files from directory ('.preg_replace('/core\/class\/conf\.class\.php$/', '', $realpathconf).') that differs from the directory already defined into the existing conf.php file ($dolibarr_main_document_root = '.$dolibarr_main_document_root.').';
447 die(-1);
448 }
449 }
450
451 $return = @include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
452 if (!$return) {
453 return -1;
454 }
455
456 $conf = new Conf();
457 $conf->db->type = trim((string) $dolibarr_main_db_type);
458 $conf->db->host = trim((string) $dolibarr_main_db_host);
459 $conf->db->port = trim((string) $dolibarr_main_db_port);
460 $conf->db->name = trim((string) $dolibarr_main_db_name);
461 $conf->db->user = trim((string) $dolibarr_main_db_user);
462 $conf->db->pass = (empty($dolibarr_main_db_pass) ? '' : trim((string) $dolibarr_main_db_pass));
463
464 // Mysql driver support has been removed in favor of mysqli
465 if ($conf->db->type == 'mysql') {
466 $conf->db->type = 'mysqli';
467 }
468 if (empty($character_set_client)) {
469 $character_set_client = "UTF-8";
470 }
471 $conf->file->character_set_client = strtoupper($character_set_client);
472 // Unique id of instance
473 $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
474 if (empty($dolibarr_main_db_character_set)) {
475 $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
476 }
477 $conf->db->character_set = $dolibarr_main_db_character_set;
478 if (empty($dolibarr_main_db_collation)) {
479 $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
480 }
481 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
482 if (empty($dolibarr_main_db_encryption)) {
483 $dolibarr_main_db_encryption = 0;
484 }
485 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
486 if (empty($dolibarr_main_db_cryptkey)) {
487 $dolibarr_main_db_cryptkey = '';
488 }
489 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
490
491 // Force usage of log file for install and upgrades
492 $conf->modules['syslog'] = 'syslog';
493 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
494 if (!defined('SYSLOG_HANDLERS')) {
495 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
496 }
497 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
498 if (@is_writable('/tmp')) {
499 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
500 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
501 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
502 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
503 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
504 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
505 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
506 } elseif (@is_writable('../../')) {
507 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
508 }
509 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
510 }
511 if (defined('SYSLOG_FILE')) {
512 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
513 }
514 if (!defined('SYSLOG_FILE_NO_ERROR')) {
515 define('SYSLOG_FILE_NO_ERROR', 1);
516 }
517 // We init log handler for install
518 $handlers = array('mod_syslog_file');
519 foreach ($handlers as $handler) {
520 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
521 if (!file_exists($file)) {
522 throw new Exception('Missing log handler file '.$handler.'.php');
523 }
524
525 require_once $file;
526 $loghandlerinstance = new $handler();
527 if (!$loghandlerinstance instanceof LogHandler) {
528 throw new Exception('Log handler does not extend LogHandler');
529 }
530
531 if (empty($conf->loghandlers[$handler])) {
532 $conf->loghandlers[$handler] = $loghandlerinstance;
533 }
534 }
535
536 return 1;
537}
538
539
551function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl = '', $csstable = 'main-inside')
552{
553 global $conf;
554 global $langs;
555 $langs->load("main");
556 $langs->load("admin");
557 $langs->load("install");
558
559 $jquerytheme = 'base';
560
561 if ($forcejqueryurl) {
562 $jQueryCustomPath = $forcejqueryurl;
563 $jQueryUiCustomPath = $forcejqueryurl;
564 } else {
565 $jQueryCustomPath = (defined('JS_JQUERY') && constant('JS_JQUERY')) ? JS_JQUERY : false;
566 $jQueryUiCustomPath = (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) ? JS_JQUERY_UI : false;
567 }
568
569 // We force the content charset
570 header("Content-type: text/html; charset=".$conf->file->character_set_client);
571 header("X-Content-Type-Options: nosniff");
572 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
573
574 print '<!DOCTYPE HTML>'."\n";
575 print '<html>'."\n";
576 print '<head>'."\n";
577 print '<meta charset="'.$conf->file->character_set_client.'">'."\n";
578 print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
579 print '<meta name="generator" content="Dolibarr installer">'."\n";
580 print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
581 print '<link rel="stylesheet" type="text/css" href="../public/theme/common/fontawesome-5/css/all.min.css?layout=classic">'."\n";
582
583 print '<!-- Includes CSS for JQuery -->'."\n";
584 if ($jQueryUiCustomPath) {
585 print '<link rel="stylesheet" type="text/css" href="'.$jQueryUiCustomPath.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
586 } else {
587 print '<link rel="stylesheet" type="text/css" href="../public/includes/jquery/css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
588 }
589
590 print '<!-- Includes JS for JQuery -->'."\n";
591 if ($jQueryCustomPath) {
592 print '<script type="text/javascript" src="'.$jQueryCustomPath.'jquery.min.js"></script>'."\n";
593 } else {
594 print '<script type="text/javascript" src="../public/includes/jquery/js/jquery.min.js"></script>'."\n";
595 }
596 if ($jQueryUiCustomPath) {
597 print '<script type="text/javascript" src="'.$jQueryUiCustomPath.'jquery-ui.min.js"></script>'."\n";
598 } else {
599 print '<script type="text/javascript" src="../public/includes/jquery/js/jquery-ui.min.js"></script>'."\n";
600 }
601
602 print '<title>'.$langs->trans("DolibarrSetup").'</title>'."\n";
603 print '</head>'."\n";
604
605 print '<body>'."\n";
606
607 print '<div class="divlogoinstall" style="text-align:center">';
608 print '<img class="imglogoinstall" src="../theme/dolibarr_logo.svg" alt="Dolibarr logo" width="300px"><br>';
609 print '<span class="opacitymedium">'.DOL_VERSION.'</span>';
610 print '</div><br>';
611
612 print '<span class="titre">';
613 if ($subtitle) {
614 print $subtitle;
615 } else {
616 print $langs->trans("DolibarrSetup");
617 }
618 print '</span>'."\n";
619
620 print '<form name="forminstall" id="forminstall" class="centpercent" action="'.$next.'.php'.($param ? '?'.$param : '').'" method="POST"';
621 if ($next == 'step5') {
622 print ' autocomplete="off"';
623 }
624 print '>'."\n";
625 print '<input type="hidden" name="testpost" value="ok">'."\n";
626 print '<input type="hidden" name="action" value="'.$action.'">'."\n";
627
628 print '<div id="divinstall">';
629
630 print '<table class="main centpercent"><tr><td>'."\n";
631
632 print '<table class="'.$csstable.' centpercent"><tr><td>'."\n";
633}
634
645function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleasewait = 0, $morehtml = '')
646{
647 global $conf, $langs;
648
649 $langs->loadLangs(array("main", "other", "admin"));
650
651 print '</td></tr></table>'."\n";
652 print '</td></tr></table>'."\n";
653
654 print '<!-- pFooter -->'."\n";
655
656 print $morehtml;
657
658 print '</div>';
659
660 if (!$nonext || ($nonext == '2')) {
661 print '<div class="nextbutton" id="nextbutton">';
662 if ($nonext == '2') {
663 print '<span class="warning">';
664 print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"].'&ignoreerrors=1' : '');
665 print '</span>';
666 print '<br><br>';
667 }
668
669 print '<input type="submit" '.($nonext == '2' ? 'disabled="disabled" ' : '').'value="'.$langs->trans("NextStep").' ->"';
670 if ($jscheckfunction) {
671 print ' onClick="return '.$jscheckfunction.'();"';
672 }
673 print '>';
674 print '</div>';
675 if ($withpleasewait) {
676 print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>'.$langs->trans("NextStepMightLastALongTime").'<br><br><div class="blinkwait">'.$langs->trans("PleaseBePatient").'</div></div>';
677 }
678 }
679 if ($setuplang) {
680 print '<input type="hidden" name="selectlang" value="'.dol_escape_htmltag($setuplang).'">';
681 }
682
683 print '</form><br>'."\n";
684
685 // If there is some logs in buffer to show
686 if (isset($conf->logbuffer) && count($conf->logbuffer)) {
687 print "\n";
688 print "<!-- Start of log output\n";
689 //print '<div class="hidden">'."\n";
690 foreach ($conf->logbuffer as $logline) {
691 print $logline."<br>\n";
692 }
693 //print '</div>'."\n";
694 print "End of log output -->\n";
695 print "\n";
696 }
697
698 print '</body>'."\n";
699 print '</html>'."\n";
700}
701
709function dolibarr_install_syslog($message, $level = LOG_DEBUG)
710{
711 if (!defined('LOG_DEBUG')) {
712 define('LOG_DEBUG', 6);
713 }
714 dol_syslog($message, $level);
715}
716
723{
724 // If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
725 // Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
726 if ($_SERVER["SCRIPT_FILENAME"] == 'php' || preg_match('/[\\/]php$/i', $_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i', $_SERVER["SCRIPT_FILENAME"])) {
727 $dolibarr_main_document_root = $_SERVER["DOCUMENT_ROOT"];
728
729 if (!preg_match('/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
730 $dolibarr_main_document_root .= "/dolibarr/htdocs";
731 }
732 } else {
733 // We assume /install to be under /htdocs, so we get the parent directory of the current directory
734 $dolibarr_main_document_root = dirname(dirname($_SERVER["SCRIPT_FILENAME"]));
735 }
736
737 return $dolibarr_main_document_root;
738}
739
746function detect_dolibarr_main_data_root($dolibarr_main_document_root)
747{
748 $dolibarr_main_data_root = preg_replace("/\/[^\/]+$/", "/documents", $dolibarr_main_document_root);
749 return $dolibarr_main_data_root;
750}
751
758{
759 // If defined (Ie: Apache with Linux)
760 if (isset($_SERVER["SCRIPT_URI"])) {
761 $dolibarr_main_url_root = $_SERVER["SCRIPT_URI"];
762 } elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
763 // If defined (Ie: Apache with Caudium)
764 $dolibarr_main_url_root = $_SERVER["SERVER_URL"].$_SERVER["DOCUMENT_URI"];
765 } else {
766 // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
767 $proto = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? 'https' : 'http';
768 if (!empty($_SERVER["HTTP_HOST"])) {
769 $serverport = $_SERVER["HTTP_HOST"];
770 } elseif (!empty($_SERVER["SERVER_NAME"])) {
771 $serverport = $_SERVER["SERVER_NAME"];
772 } else {
773 $serverport = 'localhost';
774 }
775 $dolibarr_main_url_root = $proto."://".$serverport.$_SERVER["SCRIPT_NAME"];
776 }
777 // Clean proposed URL
778 // We assume /install to be under /htdocs, so we get the parent path of the current URL
780
782}
783
790function parse_database_login($force_install_databaserootlogin)
791{
792 return preg_replace('/__SUPERUSERLOGIN__/', 'root', $force_install_databaserootlogin);
793}
794
801function parse_database_pass($force_install_databaserootpass)
802{
803 return preg_replace('/__SUPERUSERPASSWORD__/', '', $force_install_databaserootpass);
804}
global $dolibarr_main_url_root
Class to stock current configuration.
Parent class for log handlers.
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
$conffile
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:551
detect_dolibarr_main_data_root($dolibarr_main_document_root)
Automatically detect Dolibarr's main data root.
Definition inc.php:746
install_usage($program, $header)
Print the usage when executing scripts from install/.
Definition inc.php:98
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:645
parse_database_login($force_install_databaserootlogin)
Replaces automatic database login by actual value.
Definition inc.php:790
parse_database_pass($force_install_databaserootpass)
Replaces automatic database password by actual value.
Definition inc.php:801
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition inc.php:429
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:709
detect_dolibarr_main_url_root()
Automatically detect Dolibarr's main URL root.
Definition inc.php:757
detect_dolibarr_main_document_root()
Automatically detect Dolibarr's main document root.
Definition inc.php:722