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