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