dolibarr 22.0.5
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
40// Define DOL_DOCUMENT_ROOT used for install/upgrade process
41if (!defined('DOL_DOCUMENT_ROOT')) {
42 define('DOL_DOCUMENT_ROOT', '..');
43}
44
45require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.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_db_prefix
54';
55
56$conf = new Conf();
57
58// Force $_REQUEST["logtohtml"]
59$_REQUEST["logtohtml"] = 1;
60
61// Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
62// et non path absolu.
63if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
64 $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
65}
66
67
68$includeconferror = '';
69
70
71// Define localization of conf file
72$conffile = "../conf/conf.php";
73$conffiletoshow = "htdocs/conf/conf.php";
74// For debian/redhat like systems
75//$conffile = "/etc/dolibarr/conf.php";
76//$conffiletoshow = "/etc/dolibarr/conf.php";
77
78$short_options = "c:h";
79$long_options = array(
80 "config:",
81 "help",
82);
83
97function install_usage($program, $header)
98{
99 echo $header."\n";
100 echo " php ".$program." [options] [script options]\n";
101 echo "\n";
102 echo "Script syntax when using step2.php:\n";
103 echo " php ".$program." [options] [action] [selectlang]\n";
104 echo "\n";
105 echo " action:\n";
106 echo " Specify the action to execute for the file among the following ones.\n";
107 echo " - set: Create tables, keys, functions and data for the instance.\n";
108 echo "\n";
109 echo " selectlang:\n";
110 echo " Setup the default lang to use, default to 'auto'.\n";
111 echo "\n";
112 echo "Script syntax when using upgrade.php:\n";
113 echo " php ".$program." [options] previous_version new_version [script options]\n";
114 echo "\n";
115 echo " dirmodule:\n";
116 echo " Specify dirmodule to provide a path for an external module\n";
117 echo " so the migration is done using a script from a module.\n";
118 echo "\n";
119 echo " ignoredbversion:\n";
120 echo " Allow to run migration even if database version does\n";
121 echo " not match start version of migration.\n";
122 echo "\n";
123 echo "Script syntax when using upgrade2.php:\n";
124 echo " php ".$program." [options] previous_version new_version [module list]\n";
125 echo "\n";
126 echo " MAIN_MODULE_NAME1,MAIN_MODULE_NAME2:\n";
127 echo " Specify a list of module-name to enable, in upper case, with MAIN_MODULE_ prefix, joined by comma.\n";
128 echo "\n";
129 echo "Options:\n";
130 echo " -c, --config <filename>:\n";
131 echo " Provide a different conf.php file to use.\n";
132 echo "\n";
133 echo " -h, --help:\n";
134 echo " Display this help message.\n";
135}
136
137if (php_sapi_name() === "cli" && (float) PHP_VERSION > 7.0) {
138 $rest_index = 0;
139 $opts = getopt($short_options, $long_options, $rest_index);
140
141 foreach ($opts as $opt => $arg) {
142 switch ($opt) {
143 case 'c':
144 case 'config':
145 $conffile = $arg;
146 $conffiletoshow = $arg;
147 break;
148 case 'h':
149 case 'help':
150 install_usage($argv[0], "Usage:");
151 exit(0);
152 }
153 }
154
155 // Parse the arguments to find the options.
156 $args_options = array_filter(
157 array_slice($argv, 0, $rest_index),
162 static function ($arg) {
163 return strlen($arg) >= 2 && $arg[0] == '-';
164 }
165 );
166 $parsed_options = array_map(
172 static function ($arg) {
173 if (strlen($arg) > 1) {
174 return "--" . $arg;
175 }
176 return "-" . $arg;
177 },
178 array_keys($opts)
179 );
180
181 // Find options (dash-prefixed) that were not parsed.
182 $unknown_options = array_diff($args_options, $parsed_options);
183
184 // In the following test, only dash-prefixed arguments will trigger an
185 // error, given that scripts options can allow a variable number of
186 // additional non-prefixed argument and we mostly want to check for
187 // typo right now.
188 if (count($unknown_options) > 0) {
189 echo "Unknown option: ".array_values($unknown_options)[0]."\n";
190 install_usage($argv[0], "Usage:");
191 exit(1);
192 }
193
194 // Tricky argument list hack, should be removed someday.
195 // Reset argv to remove the argument that were parsed. This is needed
196 // currently because some install code, like in upgrade.php, are using
197 // $argv[] directly with fixed index to fetch some arguments.
198 $argv = array_merge(array($argv[0]), array_slice($argv, $rest_index));
199 $argc = count($argv);
200}
201
202// Load conf file if it is already defined
203if (!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
204 $result = include_once $conffile; // Load conf file
205 if ($result) {
206 if (empty($dolibarr_main_db_type)) {
207 $dolibarr_main_db_type = 'mysqli'; // For backward compatibility
208 }
209
210 //Mysql driver support has been removed in favor of mysqli
211 if ($dolibarr_main_db_type == 'mysql') {
212 $dolibarr_main_db_type = 'mysqli';
213 }
214
215 if (!isset($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
216 $dolibarr_main_db_port = '3306'; // For backward compatibility
217 }
218
219 // Clean parameters
220 // isset() is true on an empty string, which would let DOL_DATA_ROOT
221 // resolve to '' and the lock file to /install.lock (rejected by a
222 // restrictive open_basedir). Use !empty() so an empty value falls
223 // back to the default relative documents path.
224 $dolibarr_main_data_root = !empty($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents';
227 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : '';
228 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) : '';
229
230 // Remove last / or \ on directories or url value
231 if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
232 $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
233 }
234 if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
235 $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
236 }
237 if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
238 $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
239 }
240 if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
241 $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
242 }
243 if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
244 $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
245 }
246
247 // Create conf object
248 if (!empty($dolibarr_main_document_root)) {
249 $result = conf($dolibarr_main_document_root);
250 }
251 // Load database driver
252 if ($result > 0) {
253 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
254 $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
255 if (!$result) {
256 $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
257 }
258 }
259 } else {
260 $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
261 }
262 } else {
263 $includeconferror = 'ErrorBadFormatForConfFile';
264 }
265}
266
267$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
268
269// Define prefix
270if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
271 $dolibarr_main_db_prefix = 'llx_';
272}
273define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
274
275define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir
276define('DOL_DATA_ROOT', (!empty($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents'));
277define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
278$uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
279$suburi = strstr($uri, '/'); // $suburi contains url without domain
280if ($suburi == '/') {
281 $suburi = ''; // If $suburi is /, it is now ''
282}
283define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
284
285
286if (empty($conf->file->character_set_client)) {
287 $conf->file->character_set_client = "utf-8";
288}
289if (empty($conf->db->character_set)) {
290 $conf->db->character_set = 'utf8';
291}
292if (empty($conf->db->dolibarr_main_db_collation)) {
293 $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
294}
295if (empty($conf->db->dolibarr_main_db_encryption)) {
296 $conf->db->dolibarr_main_db_encryption = 0;
297}
298if (empty($conf->db->dolibarr_main_db_cryptkey)) {
299 $conf->db->dolibarr_main_db_cryptkey = '';
300}
301if (empty($conf->db->user)) {
302 $conf->db->user = '';
303}
304
305// Define an array of document root directories
306$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
307if (!empty($dolibarr_main_document_root_alt)) {
308 // dolibarr_main_document_root_alt contains several directories
309 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
310 foreach ($values as $value) {
311 $conf->file->dol_document_root[] = $value;
312 }
313}
314
315
316// Check install.lock (for both install and upgrade)
317
318$lockfile = DOL_DATA_ROOT.'/install.lock'; // To lock all /install pages
319$lockfile2 = DOL_DOCUMENT_ROOT.'/install.lock'; // To lock all /install pages (recommended)
320$upgradeunlockfile = DOL_DATA_ROOT.'/upgrade.unlock'; // To unlock upgrade process
321$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.'/upgrade.unlock'; // To unlock upgrade process
322if (constant('DOL_DATA_ROOT') === null) {
323 // We don't have a configuration file yet
324 // Try to detect any lockfile in the default documents path
325 $lockfile = '../../documents/install.lock';
326 $upgradeunlockfile = '../../documents/upgrade.unlock';
327}
328$islocked = false;
329if (@file_exists($lockfile) || @file_exists($lockfile2)) {
330 if (!defined('ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
331 // If this is a dangerous install page (ALLOWED_IF_UPGRADE_UNLOCK_FOUND not defined) or
332 // if there is no upgrade unlock files, we lock the pages.
333 $islocked = true;
334 }
335}
336if ($islocked) { // Pages are locked
337 if (!isset($langs) || !is_object($langs)) {
338 $langs = new Translate('..', $conf);
339 $langs->setDefaultLang('auto');
340 }
341 $langs->load("install");
342
343 header("X-Content-Type-Options: nosniff");
344 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
345
346 if (GETPOST('action') != 'upgrade') {
347 print $langs->trans("YouTryInstallDisabledByFileLock").'<br>';
348 } else {
349 print $langs->trans("YouTryUpgradeDisabledByMissingFileUnLock").'<br>';
350 }
351 if (!empty($dolibarr_main_url_root)) {
352 if (GETPOST('action') != 'upgrade' && (!file_exists($conffile) || !isset($dolibarr_main_url_root))) {
353 print $langs->trans("ClickOnLinkOrRemoveManualy").'<br>';
354 } else {
355 print $langs->trans("ClickOnLinkOrCreateUnlockFileManualy").'<br>';
356 }
357 print '<a href="'.$dolibarr_main_url_root.'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
358 print $langs->trans("ClickHereToGoToApp");
359 print '</a>';
360 } else {
361 print 'If you always reach this page, you must remove the install.lock file manually.<br>';
362 }
363 exit;
364}
365
366
367// Force usage of log file for install and upgrades
368$conf->modules['syslog'] = 'syslog';
369$conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
370if (!defined('SYSLOG_HANDLERS')) {
371 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
372}
373if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
374 if (@is_writable('/tmp')) {
375 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
376 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
377 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
378 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
379 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
380 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
381 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
382 } elseif (@is_writable('../../')) {
383 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
384 }
385 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
386}
387if (defined('SYSLOG_FILE')) {
388 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
389}
390if (!defined('SYSLOG_FILE_NO_ERROR')) {
391 define('SYSLOG_FILE_NO_ERROR', 1);
392}
393// We init log handler for install
394$handlers = array('mod_syslog_file');
395foreach ($handlers as $handler) {
396 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
397 if (!file_exists($file)) {
398 throw new Exception('Missing log handler file '.$handler.'.php');
399 }
400
401 require_once $file;
402 $loghandlerinstance = new $handler();
403 if (!$loghandlerinstance instanceof LogHandler) {
404 throw new Exception('Log handler does not extend LogHandler');
405 }
406
407 if (empty($conf->loghandlers[$handler])) {
408 $conf->loghandlers[$handler] = $loghandlerinstance;
409 }
410}
411
412// Define object $langs
413$langs = new Translate('..', $conf);
414if (GETPOST('lang', 'aZ09')) {
415 $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
416} else {
417 $langs->setDefaultLang('auto');
418}
419
420
427function conf($dolibarr_main_document_root)
428{
429 global $conf;
430 global $dolibarr_main_db_type;
431 global $dolibarr_main_db_host;
432 global $dolibarr_main_db_port;
433 global $dolibarr_main_db_name;
434 global $dolibarr_main_db_user;
435 global $dolibarr_main_db_pass;
436 global $dolibarr_main_db_collation;
437 global $dolibarr_main_db_character_set;
438 global $character_set_client;
439 global $dolibarr_main_instance_unique_id;
440 global $dolibarr_main_cookie_cryptkey;
441
442 $return = @include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
443 if (!$return) {
444 return -1;
445 }
446
447 $conf = new Conf();
448 $conf->db->type = trim($dolibarr_main_db_type);
449 $conf->db->host = trim($dolibarr_main_db_host);
450 $conf->db->port = trim($dolibarr_main_db_port);
451 $conf->db->name = trim($dolibarr_main_db_name);
452 $conf->db->user = trim($dolibarr_main_db_user);
453 $conf->db->pass = (empty($dolibarr_main_db_pass) ? '' : trim($dolibarr_main_db_pass));
454
455 // Mysql driver support has been removed in favor of mysqli
456 if ($conf->db->type == 'mysql') {
457 $conf->db->type = 'mysqli';
458 }
459 if (empty($character_set_client)) {
460 $character_set_client = "UTF-8";
461 }
462 $conf->file->character_set_client = strtoupper($character_set_client);
463 // Unique id of instance
464 $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;
465 if (empty($dolibarr_main_db_character_set)) {
466 $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
467 }
468 $conf->db->character_set = $dolibarr_main_db_character_set;
469 if (empty($dolibarr_main_db_collation)) {
470 $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
471 }
472 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
473 if (empty($dolibarr_main_db_encryption)) {
474 $dolibarr_main_db_encryption = 0;
475 }
476 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
477 if (empty($dolibarr_main_db_cryptkey)) {
478 $dolibarr_main_db_cryptkey = '';
479 }
480 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
481
482 // Force usage of log file for install and upgrades
483 $conf->modules['syslog'] = 'syslog';
484 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
485 if (!defined('SYSLOG_HANDLERS')) {
486 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
487 }
488 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
489 if (@is_writable('/tmp')) {
490 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
491 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
492 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
493 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
494 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
495 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
496 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
497 } elseif (@is_writable('../../')) {
498 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
499 }
500 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
501 }
502 if (defined('SYSLOG_FILE')) {
503 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
504 }
505 if (!defined('SYSLOG_FILE_NO_ERROR')) {
506 define('SYSLOG_FILE_NO_ERROR', 1);
507 }
508 // We init log handler for install
509 $handlers = array('mod_syslog_file');
510 foreach ($handlers as $handler) {
511 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
512 if (!file_exists($file)) {
513 throw new Exception('Missing log handler file '.$handler.'.php');
514 }
515
516 require_once $file;
517 $loghandlerinstance = new $handler();
518 if (!$loghandlerinstance instanceof LogHandler) {
519 throw new Exception('Log handler does not extend LogHandler');
520 }
521
522 if (empty($conf->loghandlers[$handler])) {
523 $conf->loghandlers[$handler] = $loghandlerinstance;
524 }
525 }
526
527 return 1;
528}
529
530
542function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl = '', $csstable = 'main-inside')
543{
544 global $conf;
545 global $langs;
546 $langs->load("main");
547 $langs->load("admin");
548 $langs->load("install");
549
550 $jquerytheme = 'base';
551
552 if ($forcejqueryurl) {
553 $jQueryCustomPath = $forcejqueryurl;
554 $jQueryUiCustomPath = $forcejqueryurl;
555 } else {
556 $jQueryCustomPath = (defined('JS_JQUERY') && constant('JS_JQUERY')) ? JS_JQUERY : false;
557 $jQueryUiCustomPath = (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) ? JS_JQUERY_UI : false;
558 }
559
560 // We force the content charset
561 header("Content-type: text/html; charset=".$conf->file->character_set_client);
562 header("X-Content-Type-Options: nosniff");
563 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
564
565 print '<!DOCTYPE HTML>'."\n";
566 print '<html>'."\n";
567 print '<head>'."\n";
568 print '<meta charset="'.$conf->file->character_set_client.'">'."\n";
569 print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
570 print '<meta name="generator" content="Dolibarr installer">'."\n";
571 print '<link rel="stylesheet" type="text/css" href="default.css">'."\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="../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="../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="../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.
$dolibarr_main_url_root_alt
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:427
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:542
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:97
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
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79