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