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 $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents';
223 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : '';
224 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) : '';
225
226 // Remove last / or \ on directories or url value
227 if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
228 $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
229 }
230 if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
231 $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
232 }
233 if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
234 $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
235 }
236 if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
237 $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
238 }
239 if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
240 $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
241 }
242
243 // Create conf object
244 if (!empty($dolibarr_main_document_root)) {
245 $result = conf($dolibarr_main_document_root);
246 }
247 // Load database driver
248 if ($result > 0) {
249 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
250 $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
251 if (!$result) {
252 $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
253 }
254 }
255 } else {
256 $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
257 }
258 } else {
259 $includeconferror = 'ErrorBadFormatForConfFile';
260 }
261}
262
263$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
264
265// Define prefix
266if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
267 $dolibarr_main_db_prefix = 'llx_';
268}
269define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
270
271define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir
272define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents'));
273define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
274$uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
275$suburi = strstr($uri, '/'); // $suburi contains url without domain
276if ($suburi == '/') {
277 $suburi = ''; // If $suburi is /, it is now ''
278}
279define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
280
281
282if (empty($conf->file->character_set_client)) {
283 $conf->file->character_set_client = "utf-8";
284}
285if (empty($conf->db->character_set)) {
286 $conf->db->character_set = 'utf8';
287}
288if (empty($conf->db->dolibarr_main_db_collation)) {
289 $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
290}
291if (empty($conf->db->dolibarr_main_db_encryption)) {
292 $conf->db->dolibarr_main_db_encryption = 0;
293}
294if (empty($conf->db->dolibarr_main_db_cryptkey)) {
295 $conf->db->dolibarr_main_db_cryptkey = '';
296}
297if (empty($conf->db->user)) {
298 $conf->db->user = '';
299}
300
301// Define an array of document root directories
302$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
303if (!empty($dolibarr_main_document_root_alt)) {
304 // dolibarr_main_document_root_alt contains several directories
305 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
306 foreach ($values as $value) {
307 $conf->file->dol_document_root[] = $value;
308 }
309}
310
311
312// Check install.lock (for both install and upgrade)
313
314$lockfile = DOL_DATA_ROOT.'/install.lock'; // To lock all /install pages
315$lockfile2 = DOL_DOCUMENT_ROOT.'/install.lock'; // To lock all /install pages (recommended)
316$upgradeunlockfile = DOL_DATA_ROOT.'/upgrade.unlock'; // To unlock upgrade process
317$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.'/upgrade.unlock'; // To unlock upgrade process
318if (constant('DOL_DATA_ROOT') === null) {
319 // We don't have a configuration file yet
320 // Try to detect any lockfile in the default documents path
321 $lockfile = '../../documents/install.lock';
322 $upgradeunlockfile = '../../documents/upgrade.unlock';
323}
324$islocked = false;
325if (@file_exists($lockfile) || @file_exists($lockfile2)) {
326 if (!defined('ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
327 // If this is a dangerous install page (ALLOWED_IF_UPGRADE_UNLOCK_FOUND not defined) or
328 // if there is no upgrade unlock files, we lock the pages.
329 $islocked = true;
330 }
331}
332if ($islocked) { // Pages are locked
333 if (!isset($langs) || !is_object($langs)) {
334 $langs = new Translate('..', $conf);
335 $langs->setDefaultLang('auto');
336 }
337 $langs->load("install");
338
339 header("X-Content-Type-Options: nosniff");
340 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
341
342 if (GETPOST('action') != 'upgrade') {
343 print $langs->trans("YouTryInstallDisabledByFileLock").'<br>';
344 } else {
345 print $langs->trans("YouTryUpgradeDisabledByMissingFileUnLock").'<br>';
346 }
347 if (!empty($dolibarr_main_url_root)) {
348 if (GETPOST('action') != 'upgrade' && (!file_exists($conffile) || !isset($dolibarr_main_url_root))) {
349 print $langs->trans("ClickOnLinkOrRemoveManualy").'<br>';
350 } else {
351 print $langs->trans("ClickOnLinkOrCreateUnlockFileManualy").'<br>';
352 }
353 print '<a href="'.$dolibarr_main_url_root.'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
354 print $langs->trans("ClickHereToGoToApp");
355 print '</a>';
356 } else {
357 print 'If you always reach this page, you must remove the install.lock file manually.<br>';
358 }
359 exit;
360}
361
362
363// Force usage of log file for install and upgrades
364$conf->modules['syslog'] = 'syslog';
365$conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
366if (!defined('SYSLOG_HANDLERS')) {
367 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
368}
369if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
370 if (@is_writable('/tmp')) {
371 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
372 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
373 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
374 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
375 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
376 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
377 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
378 } elseif (@is_writable('../../')) {
379 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
380 }
381 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
382}
383if (defined('SYSLOG_FILE')) {
384 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
385}
386if (!defined('SYSLOG_FILE_NO_ERROR')) {
387 define('SYSLOG_FILE_NO_ERROR', 1);
388}
389// We init log handler for install
390$handlers = array('mod_syslog_file');
391foreach ($handlers as $handler) {
392 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
393 if (!file_exists($file)) {
394 throw new Exception('Missing log handler file '.$handler.'.php');
395 }
396
397 require_once $file;
398 $loghandlerinstance = new $handler();
399 if (!$loghandlerinstance instanceof LogHandler) {
400 throw new Exception('Log handler does not extend LogHandler');
401 }
402
403 if (empty($conf->loghandlers[$handler])) {
404 $conf->loghandlers[$handler] = $loghandlerinstance;
405 }
406}
407
408// Define object $langs
409$langs = new Translate('..', $conf);
410if (GETPOST('lang', 'aZ09')) {
411 $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
412} else {
413 $langs->setDefaultLang('auto');
414}
415
416
423function conf($dolibarr_main_document_root)
424{
425 global $conf;
426 global $dolibarr_main_db_type;
427 global $dolibarr_main_db_host;
428 global $dolibarr_main_db_port;
429 global $dolibarr_main_db_name;
430 global $dolibarr_main_db_user;
431 global $dolibarr_main_db_pass;
432 global $dolibarr_main_db_collation;
433 global $dolibarr_main_db_character_set;
434 global $character_set_client;
435 global $dolibarr_main_instance_unique_id;
436 global $dolibarr_main_cookie_cryptkey;
437
438 $return = @include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
439 if (!$return) {
440 return -1;
441 }
442
443 $conf = new Conf();
444 $conf->db->type = trim($dolibarr_main_db_type);
445 $conf->db->host = trim($dolibarr_main_db_host);
446 $conf->db->port = trim($dolibarr_main_db_port);
447 $conf->db->name = trim($dolibarr_main_db_name);
448 $conf->db->user = trim($dolibarr_main_db_user);
449 $conf->db->pass = (empty($dolibarr_main_db_pass) ? '' : trim($dolibarr_main_db_pass));
450
451 // Mysql driver support has been removed in favor of mysqli
452 if ($conf->db->type == 'mysql') {
453 $conf->db->type = 'mysqli';
454 }
455 if (empty($character_set_client)) {
456 $character_set_client = "UTF-8";
457 }
458 $conf->file->character_set_client = strtoupper($character_set_client);
459 // Unique id of instance
460 $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;
461 if (empty($dolibarr_main_db_character_set)) {
462 $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
463 }
464 $conf->db->character_set = $dolibarr_main_db_character_set;
465 if (empty($dolibarr_main_db_collation)) {
466 $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
467 }
468 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
469 if (empty($dolibarr_main_db_encryption)) {
470 $dolibarr_main_db_encryption = 0;
471 }
472 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
473 if (empty($dolibarr_main_db_cryptkey)) {
474 $dolibarr_main_db_cryptkey = '';
475 }
476 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
477
478 // Force usage of log file for install and upgrades
479 $conf->modules['syslog'] = 'syslog';
480 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
481 if (!defined('SYSLOG_HANDLERS')) {
482 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
483 }
484 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
485 if (@is_writable('/tmp')) {
486 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
487 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
488 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
489 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
490 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
491 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
492 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
493 } elseif (@is_writable('../../')) {
494 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
495 }
496 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
497 }
498 if (defined('SYSLOG_FILE')) {
499 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
500 }
501 if (!defined('SYSLOG_FILE_NO_ERROR')) {
502 define('SYSLOG_FILE_NO_ERROR', 1);
503 }
504 // We init log handler for install
505 $handlers = array('mod_syslog_file');
506 foreach ($handlers as $handler) {
507 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
508 if (!file_exists($file)) {
509 throw new Exception('Missing log handler file '.$handler.'.php');
510 }
511
512 require_once $file;
513 $loghandlerinstance = new $handler();
514 if (!$loghandlerinstance instanceof LogHandler) {
515 throw new Exception('Log handler does not extend LogHandler');
516 }
517
518 if (empty($conf->loghandlers[$handler])) {
519 $conf->loghandlers[$handler] = $loghandlerinstance;
520 }
521 }
522
523 return 1;
524}
525
526
538function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl = '', $csstable = 'main-inside')
539{
540 global $conf;
541 global $langs;
542 $langs->load("main");
543 $langs->load("admin");
544 $langs->load("install");
545
546 $jquerytheme = 'base';
547
548 if ($forcejqueryurl) {
549 $jQueryCustomPath = $forcejqueryurl;
550 $jQueryUiCustomPath = $forcejqueryurl;
551 } else {
552 $jQueryCustomPath = (defined('JS_JQUERY') && constant('JS_JQUERY')) ? JS_JQUERY : false;
553 $jQueryUiCustomPath = (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) ? JS_JQUERY_UI : false;
554 }
555
556 // We force the content charset
557 header("Content-type: text/html; charset=".$conf->file->character_set_client);
558 header("X-Content-Type-Options: nosniff");
559 header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
560
561 print '<!DOCTYPE HTML>'."\n";
562 print '<html>'."\n";
563 print '<head>'."\n";
564 print '<meta charset="'.$conf->file->character_set_client.'">'."\n";
565 print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
566 print '<meta name="generator" content="Dolibarr installer">'."\n";
567 print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
568
569 print '<!-- Includes CSS for JQuery -->'."\n";
570 if ($jQueryUiCustomPath) {
571 print '<link rel="stylesheet" type="text/css" href="'.$jQueryUiCustomPath.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
572 } else {
573 print '<link rel="stylesheet" type="text/css" href="../includes/jquery/css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
574 }
575
576 print '<!-- Includes JS for JQuery -->'."\n";
577 if ($jQueryCustomPath) {
578 print '<script type="text/javascript" src="'.$jQueryCustomPath.'jquery.min.js"></script>'."\n";
579 } else {
580 print '<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>'."\n";
581 }
582 if ($jQueryUiCustomPath) {
583 print '<script type="text/javascript" src="'.$jQueryUiCustomPath.'jquery-ui.min.js"></script>'."\n";
584 } else {
585 print '<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>'."\n";
586 }
587
588 print '<title>'.$langs->trans("DolibarrSetup").'</title>'."\n";
589 print '</head>'."\n";
590
591 print '<body>'."\n";
592
593 print '<div class="divlogoinstall" style="text-align:center">';
594 print '<img class="imglogoinstall" src="../theme/dolibarr_logo.svg" alt="Dolibarr logo" width="300px"><br>';
595 print '<span class="opacitymedium">'.DOL_VERSION.'</span>';
596 print '</div><br>';
597
598 print '<span class="titre">';
599 if ($subtitle) {
600 print $subtitle;
601 } else {
602 print $langs->trans("DolibarrSetup");
603 }
604 print '</span>'."\n";
605
606 print '<form name="forminstall" id="forminstall" class="centpercent" action="'.$next.'.php'.($param ? '?'.$param : '').'" method="POST"';
607 if ($next == 'step5') {
608 print ' autocomplete="off"';
609 }
610 print '>'."\n";
611 print '<input type="hidden" name="testpost" value="ok">'."\n";
612 print '<input type="hidden" name="action" value="'.$action.'">'."\n";
613
614 print '<div id="divinstall">';
615
616 print '<table class="main centpercent"><tr><td>'."\n";
617
618 print '<table class="'.$csstable.' centpercent"><tr><td>'."\n";
619}
620
631function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleasewait = 0, $morehtml = '')
632{
633 global $conf, $langs;
634
635 $langs->loadLangs(array("main", "other", "admin"));
636
637 print '</td></tr></table>'."\n";
638 print '</td></tr></table>'."\n";
639
640 print '<!-- pFooter -->'."\n";
641
642 print $morehtml;
643
644 print '</div>';
645
646 if (!$nonext || ($nonext == '2')) {
647 print '<div class="nextbutton" id="nextbutton">';
648 if ($nonext == '2') {
649 print '<span class="warning">';
650 print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"].'&ignoreerrors=1' : '');
651 print '</span>';
652 print '<br><br>';
653 }
654
655 print '<input type="submit" '.($nonext == '2' ? 'disabled="disabled" ' : '').'value="'.$langs->trans("NextStep").' ->"';
656 if ($jscheckfunction) {
657 print ' onClick="return '.$jscheckfunction.'();"';
658 }
659 print '>';
660 print '</div>';
661 if ($withpleasewait) {
662 print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>'.$langs->trans("NextStepMightLastALongTime").'<br><br><div class="blinkwait">'.$langs->trans("PleaseBePatient").'</div></div>';
663 }
664 }
665 if ($setuplang) {
666 print '<input type="hidden" name="selectlang" value="'.dol_escape_htmltag($setuplang).'">';
667 }
668
669 print '</form><br>'."\n";
670
671 // If there is some logs in buffer to show
672 if (isset($conf->logbuffer) && count($conf->logbuffer)) {
673 print "\n";
674 print "<!-- Start of log output\n";
675 //print '<div class="hidden">'."\n";
676 foreach ($conf->logbuffer as $logline) {
677 print $logline."<br>\n";
678 }
679 //print '</div>'."\n";
680 print "End of log output -->\n";
681 print "\n";
682 }
683
684 print '</body>'."\n";
685 print '</html>'."\n";
686}
687
695function dolibarr_install_syslog($message, $level = LOG_DEBUG)
696{
697 if (!defined('LOG_DEBUG')) {
698 define('LOG_DEBUG', 6);
699 }
700 dol_syslog($message, $level);
701}
702
709{
710 // If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
711 // Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
712 if ($_SERVER["SCRIPT_FILENAME"] == 'php' || preg_match('/[\\/]php$/i', $_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i', $_SERVER["SCRIPT_FILENAME"])) {
713 $dolibarr_main_document_root = $_SERVER["DOCUMENT_ROOT"];
714
715 if (!preg_match('/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
716 $dolibarr_main_document_root .= "/dolibarr/htdocs";
717 }
718 } else {
719 // We assume /install to be under /htdocs, so we get the parent directory of the current directory
720 $dolibarr_main_document_root = dirname(dirname($_SERVER["SCRIPT_FILENAME"]));
721 }
722
723 return $dolibarr_main_document_root;
724}
725
732function detect_dolibarr_main_data_root($dolibarr_main_document_root)
733{
734 $dolibarr_main_data_root = preg_replace("/\/[^\/]+$/", "/documents", $dolibarr_main_document_root);
735 return $dolibarr_main_data_root;
736}
737
744{
745 // If defined (Ie: Apache with Linux)
746 if (isset($_SERVER["SCRIPT_URI"])) {
747 $dolibarr_main_url_root = $_SERVER["SCRIPT_URI"];
748 } elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
749 // If defined (Ie: Apache with Caudium)
750 $dolibarr_main_url_root = $_SERVER["SERVER_URL"].$_SERVER["DOCUMENT_URI"];
751 } else {
752 // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
753 $proto = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? 'https' : 'http';
754 if (!empty($_SERVER["HTTP_HOST"])) {
755 $serverport = $_SERVER["HTTP_HOST"];
756 } elseif (!empty($_SERVER["SERVER_NAME"])) {
757 $serverport = $_SERVER["SERVER_NAME"];
758 } else {
759 $serverport = 'localhost';
760 }
761 $dolibarr_main_url_root = $proto."://".$serverport.$_SERVER["SCRIPT_NAME"];
762 }
763 // Clean proposed URL
764 // We assume /install to be under /htdocs, so we get the parent path of the current URL
766
768}
769
776function parse_database_login($force_install_databaserootlogin)
777{
778 return preg_replace('/__SUPERUSERLOGIN__/', 'root', $force_install_databaserootlogin);
779}
780
787function parse_database_pass($force_install_databaserootpass)
788{
789 return preg_replace('/__SUPERUSERPASSWORD__/', '', $force_install_databaserootpass);
790}
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:423
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:538
detect_dolibarr_main_data_root($dolibarr_main_document_root)
Automatically detect Dolibarr's main data root.
Definition inc.php:732
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:631
parse_database_login($force_install_databaserootlogin)
Replaces automatic database login by actual value.
Definition inc.php:776
parse_database_pass($force_install_databaserootpass)
Replaces automatic database password by actual value.
Definition inc.php:787
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:695
detect_dolibarr_main_url_root()
Automatically detect Dolibarr's main URL root.
Definition inc.php:743
detect_dolibarr_main_document_root()
Automatically detect Dolibarr's main document root.
Definition inc.php:708
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79