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