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