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