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