inc.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/install/inc.php
  24. * \ingroup core
  25. * \brief File that define environment for support pages
  26. */
  27. // Just to define version DOL_VERSION
  28. if (! defined('DOL_INC_FOR_VERSION_ERROR')) define('DOL_INC_FOR_VERSION_ERROR','1');
  29. require_once '../filefunc.inc.php';
  30. // Define DOL_DOCUMENT_ROOT and ADODB_PATH used for install/upgrade process
  31. if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '..');
  32. if (! defined('ADODB_PATH'))
  33. {
  34. $foundpath=DOL_DOCUMENT_ROOT .'/includes/adodbtime/';
  35. if (! is_dir($foundpath)) $foundpath='/usr/share/php/adodb/';
  36. define('ADODB_PATH', $foundpath);
  37. }
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  42. require_once ADODB_PATH.'adodb-time.inc.php';
  43. // Avoid warnings with strict mode E_STRICT
  44. $conf = new stdClass(); // instantiate $conf explicitely
  45. $conf->global = new stdClass();
  46. $conf->file = new stdClass();
  47. $conf->db = new stdClass();
  48. $conf->syslog = new stdClass();
  49. // Force $_REQUEST["logtohtml"]
  50. $_REQUEST["logtohtml"]=1;
  51. // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
  52. // et non path absolu.
  53. if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"])
  54. {
  55. $_SERVER["PHP_SELF"]=$_SERVER["DOCUMENT_URI"];
  56. }
  57. $includeconferror='';
  58. // Define vars
  59. $conffiletoshowshort = "conf.php";
  60. // Define localization of conf file
  61. $conffile = "../conf/conf.php";
  62. $conffiletoshow = "htdocs/conf/conf.php";
  63. // For debian/redhat like systems
  64. //$conffile = "/etc/dolibarr/conf.php";
  65. //$conffiletoshow = "/etc/dolibarr/conf.php";
  66. // Load conf file if it is already defined
  67. 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
  68. {
  69. $result=include_once $conffile; // Load conf file
  70. if ($result)
  71. {
  72. if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysqli'; // For backward compatibility
  73. //Mysql driver support has been removed in favor of mysqli
  74. if ($dolibarr_main_db_type == 'mysql') {
  75. $dolibarr_main_db_type = 'mysqli';
  76. }
  77. if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type=='mysqli')) $dolibarr_main_db_port='3306'; // For backward compatibility
  78. // Clean parameters
  79. $dolibarr_main_data_root =isset($dolibarr_main_data_root)?trim($dolibarr_main_data_root):DOL_DOCUMENT_ROOT . '/../documents';
  80. $dolibarr_main_url_root =isset($dolibarr_main_url_root)?trim($dolibarr_main_url_root):'';
  81. $dolibarr_main_url_root_alt =isset($dolibarr_main_url_root_alt)?trim($dolibarr_main_url_root_alt):'';
  82. $dolibarr_main_document_root =isset($dolibarr_main_document_root)?trim($dolibarr_main_document_root):'';
  83. $dolibarr_main_document_root_alt=isset($dolibarr_main_document_root_alt)?trim($dolibarr_main_document_root_alt):'';
  84. // Remove last / or \ on directories or url value
  85. if (! empty($dolibarr_main_document_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_document_root)) $dolibarr_main_document_root=preg_replace('/[\\/]+$/','',$dolibarr_main_document_root);
  86. if (! empty($dolibarr_main_url_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_url_root)) $dolibarr_main_url_root=preg_replace('/[\\/]+$/','',$dolibarr_main_url_root);
  87. if (! empty($dolibarr_main_data_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_data_root)) $dolibarr_main_data_root=preg_replace('/[\\/]+$/','',$dolibarr_main_data_root);
  88. if (! empty($dolibarr_main_document_root_alt) && ! preg_match('/^[\\/]+$/',$dolibarr_main_document_root_alt)) $dolibarr_main_document_root_alt=preg_replace('/[\\/]+$/','',$dolibarr_main_document_root_alt);
  89. if (! empty($dolibarr_main_url_root_alt) && ! preg_match('/^[\\/]+$/',$dolibarr_main_url_root_alt)) $dolibarr_main_url_root_alt=preg_replace('/[\\/]+$/','',$dolibarr_main_url_root_alt);
  90. // Create conf object
  91. if (! empty($dolibarr_main_document_root))
  92. {
  93. $result=conf($dolibarr_main_document_root);
  94. }
  95. // Load database driver
  96. if ($result)
  97. {
  98. if (! empty($dolibarr_main_document_root) && ! empty($dolibarr_main_db_type))
  99. {
  100. $result=include_once $dolibarr_main_document_root . "/core/db/".$dolibarr_main_db_type.'.class.php';
  101. if (! $result)
  102. {
  103. $includeconferror='ErrorBadValueForDolibarrMainDBType';
  104. }
  105. }
  106. }
  107. else
  108. {
  109. $includeconferror='ErrorBadValueForDolibarrMainDocumentRoot';
  110. }
  111. }
  112. else
  113. {
  114. $includeconferror='ErrorBadFormatForConfFile';
  115. }
  116. }
  117. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  118. // Define prefix
  119. if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
  120. define('MAIN_DB_PREFIX',(isset($dolibarr_main_db_prefix)?$dolibarr_main_db_prefix:''));
  121. define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
  122. define('DOL_DATA_ROOT',(isset($dolibarr_main_data_root)?$dolibarr_main_data_root:DOL_DOCUMENT_ROOT . '/../documents'));
  123. define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root)?$dolibarr_main_url_root:'')); // URL relative root
  124. $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
  125. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  126. if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
  127. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  128. if (empty($conf->file->character_set_client)) $conf->file->character_set_client="utf-8";
  129. if (empty($conf->db->character_set)) $conf->db->character_set='utf8';
  130. if (empty($conf->db->dolibarr_main_db_collation)) $conf->db->dolibarr_main_db_collation='utf8_unicode_ci';
  131. if (empty($conf->db->dolibarr_main_db_encryption)) $conf->db->dolibarr_main_db_encryption=0;
  132. if (empty($conf->db->dolibarr_main_db_cryptkey)) $conf->db->dolibarr_main_db_cryptkey='';
  133. if (empty($conf->db->user)) $conf->db->user='';
  134. // Define array of document root directories
  135. $conf->file->dol_document_root=array(DOL_DOCUMENT_ROOT);
  136. if (! empty($dolibarr_main_document_root_alt))
  137. {
  138. // dolibarr_main_document_root_alt contains several directories
  139. $values=preg_split('/[;,]/',$dolibarr_main_document_root_alt);
  140. foreach($values as $value)
  141. {
  142. $conf->file->dol_document_root[]=$value;
  143. }
  144. }
  145. // Security check (old method, when directory is renamed /install.lock)
  146. if (preg_match('/install\.lock/i',$_SERVER["SCRIPT_FILENAME"]))
  147. {
  148. if (! is_object($langs))
  149. {
  150. $langs = new Translate('..', $conf);
  151. $langs->setDefaultLang('auto');
  152. }
  153. $langs->load("install");
  154. print $langs->trans("YouTryInstallDisabledByDirLock");
  155. if (! empty($dolibarr_main_url_root))
  156. {
  157. print 'Click on following link, <a href="'.$dolibarr_main_url_root .'/admin/index.php?mainmenu=home&leftmenu=setup'.(isset($_POST["login"])?'&username='.urlencode($_POST["login"]):'').'">';
  158. print $langs->trans("ClickHereToGoToApp");
  159. print '</a>';
  160. }
  161. exit;
  162. }
  163. $lockfile = DOL_DATA_ROOT . '/install.lock';
  164. if (constant('DOL_DATA_ROOT') === null) {
  165. // We don't have a configuration file yet
  166. // Try to detect any lockfile in the default documents path
  167. $lockfile = '../../documents/install.lock';
  168. }
  169. if (@file_exists($lockfile))
  170. {
  171. if (! isset($langs) || ! is_object($langs))
  172. {
  173. $langs = new Translate('..', $conf);
  174. $langs->setDefaultLang('auto');
  175. }
  176. $langs->load("install");
  177. print $langs->trans("YouTryInstallDisabledByFileLock");
  178. if (! empty($dolibarr_main_url_root))
  179. {
  180. print $langs->trans("ClickOnLinkOrRemoveManualy").'<br>';
  181. print '<a href="'.$dolibarr_main_url_root .'/admin/index.php?mainmenu=home&leftmenu=setup'.(isset($_POST["login"])?'&username='.urlencode($_POST["login"]):'').'">';
  182. print $langs->trans("ClickHereToGoToApp");
  183. print '</a>';
  184. }
  185. else
  186. {
  187. print 'If you always reach this page, you must remove install.lock file manually.<br>';
  188. }
  189. exit;
  190. }
  191. // Force usage of log file for install and upgrades
  192. $conf->syslog->enabled=1;
  193. $conf->global->SYSLOG_LEVEL=constant('LOG_DEBUG');
  194. if (! defined('SYSLOG_HANDLERS')) define('SYSLOG_HANDLERS','["mod_syslog_file"]');
  195. if (! defined('SYSLOG_FILE')) // To avoid warning on systems with constant already defined
  196. {
  197. if (@is_writable('/tmp')) define('SYSLOG_FILE','/tmp/dolibarr_install.log');
  198. else if (! empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) define('SYSLOG_FILE',$_ENV["TMP"].'/dolibarr_install.log');
  199. else if (! empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) define('SYSLOG_FILE',$_ENV["TEMP"].'/dolibarr_install.log');
  200. else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) define('SYSLOG_FILE','../../../../dolibarr_install.log'); // For DoliWamp
  201. else if (@is_writable('../../')) define('SYSLOG_FILE','../../dolibarr_install.log'); // For others
  202. //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
  203. }
  204. if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE=constant('SYSLOG_FILE');
  205. if (! defined('SYSLOG_FILE_NO_ERROR')) define('SYSLOG_FILE_NO_ERROR',1);
  206. // We init log handler for install
  207. $handlers = array('mod_syslog_file');
  208. foreach ($handlers as $handler)
  209. {
  210. $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
  211. if (!file_exists($file))
  212. {
  213. throw new Exception('Missing log handler file '.$handler.'.php');
  214. }
  215. require_once $file;
  216. $loghandlerinstance = new $handler();
  217. if (!$loghandlerinstance instanceof LogHandlerInterface)
  218. {
  219. throw new Exception('Log handler does not extend LogHandlerInterface');
  220. }
  221. if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler]=$loghandlerinstance;
  222. }
  223. // Removed magic_quotes
  224. if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP 5.4
  225. {
  226. if (get_magic_quotes_gpc())
  227. {
  228. // Forcing parameter setting magic_quotes_gpc and cleaning parameters
  229. // (Otherwise he would have for each position, condition
  230. // Reading stripslashes variable according to state get_magic_quotes_gpc).
  231. // Off mode (recommended, you just do $db->escape when an insert / update.
  232. function stripslashes_deep($value)
  233. {
  234. return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
  235. }
  236. $_GET = array_map('stripslashes_deep', $_GET);
  237. $_POST = array_map('stripslashes_deep', $_POST);
  238. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  239. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  240. @set_magic_quotes_runtime(0);
  241. }
  242. }
  243. // Defini objet langs
  244. $langs = new Translate('..',$conf);
  245. if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
  246. else $langs->setDefaultLang('auto');
  247. $bc[false]=' class="bg1"';
  248. $bc[true]=' class="bg2"';
  249. /**
  250. * Load conf file (file must exists)
  251. *
  252. * @param string $dolibarr_main_document_root Root directory of Dolibarr bin files
  253. * @return int <0 if KO, >0 if OK
  254. */
  255. function conf($dolibarr_main_document_root)
  256. {
  257. global $conf;
  258. global $dolibarr_main_db_type;
  259. global $dolibarr_main_db_host;
  260. global $dolibarr_main_db_port;
  261. global $dolibarr_main_db_name;
  262. global $dolibarr_main_db_user;
  263. global $dolibarr_main_db_pass;
  264. global $character_set_client;
  265. $return=include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  266. if (! $return) return -1;
  267. $conf=new Conf();
  268. $conf->db->type = trim($dolibarr_main_db_type);
  269. $conf->db->host = trim($dolibarr_main_db_host);
  270. $conf->db->port = trim($dolibarr_main_db_port);
  271. $conf->db->name = trim($dolibarr_main_db_name);
  272. $conf->db->user = trim($dolibarr_main_db_user);
  273. $conf->db->pass = trim($dolibarr_main_db_pass);
  274. // Mysql driver support has been removed in favor of mysqli
  275. if ($conf->db->type == 'mysql') $conf->db->type = 'mysqli';
  276. if (empty($character_set_client)) $character_set_client="UTF-8";
  277. $conf->file->character_set_client=strtoupper($character_set_client);
  278. if (empty($dolibarr_main_db_character_set)) $dolibarr_main_db_character_set=($conf->db->type=='mysqli'?'utf8':'');
  279. $conf->db->character_set=$dolibarr_main_db_character_set;
  280. if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation=($conf->db->type=='mysqli'?'utf8_unicode_ci':'');
  281. $conf->db->dolibarr_main_db_collation=$dolibarr_main_db_collation;
  282. if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0;
  283. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  284. if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey='';
  285. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  286. // Force usage of log file for install and upgrades
  287. $conf->syslog->enabled=1;
  288. $conf->global->SYSLOG_LEVEL=constant('LOG_DEBUG');
  289. if (! defined('SYSLOG_HANDLERS')) define('SYSLOG_HANDLERS','["mod_syslog_file"]');
  290. if (! defined('SYSLOG_FILE')) // To avoid warning on systems with constant already defined
  291. {
  292. if (@is_writable('/tmp')) define('SYSLOG_FILE','/tmp/dolibarr_install.log');
  293. else if (! empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) define('SYSLOG_FILE',$_ENV["TMP"].'/dolibarr_install.log');
  294. else if (! empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) define('SYSLOG_FILE',$_ENV["TEMP"].'/dolibarr_install.log');
  295. else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) define('SYSLOG_FILE','../../../../dolibarr_install.log'); // For DoliWamp
  296. else if (@is_writable('../../')) define('SYSLOG_FILE','../../dolibarr_install.log'); // For others
  297. //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
  298. }
  299. if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE=constant('SYSLOG_FILE');
  300. if (! defined('SYSLOG_FILE_NO_ERROR')) define('SYSLOG_FILE_NO_ERROR',1);
  301. // We init log handler for install
  302. $handlers = array('mod_syslog_file');
  303. foreach ($handlers as $handler)
  304. {
  305. $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
  306. if (!file_exists($file))
  307. {
  308. throw new Exception('Missing log handler file '.$handler.'.php');
  309. }
  310. require_once $file;
  311. $loghandlerinstance = new $handler();
  312. if (!$loghandlerinstance instanceof LogHandlerInterface)
  313. {
  314. throw new Exception('Log handler does not extend LogHandlerInterface');
  315. }
  316. if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler]=$loghandlerinstance;
  317. }
  318. return 1;
  319. }
  320. /**
  321. * Show HTML header of install pages
  322. *
  323. * @param string $subtitle Title
  324. * @param string $next Next
  325. * @param string $action Action code ('set' or 'upgrade')
  326. * @param string $param Param
  327. * @param string $forcejqueryurl Set jquery relative URL (must end with / if defined)
  328. * @param string $csstable Css for table
  329. * @return void
  330. */
  331. function pHeader($subtitle,$next,$action='set',$param='',$forcejqueryurl='',$csstable='main-inside')
  332. {
  333. global $conf;
  334. global $langs;
  335. $langs->load("main");
  336. $langs->load("admin");
  337. $langs->load("install");
  338. $jquerytheme='base';
  339. if ($forcejqueryurl)
  340. {
  341. $jQueryCustomPath = $forcejqueryurl;
  342. $jQueryUiCustomPath = $forcejqueryurl;
  343. }
  344. else
  345. {
  346. $jQueryCustomPath = (defined('JS_JQUERY') && constant('JS_JQUERY')) ? JS_JQUERY : false;
  347. $jQueryUiCustomPath = (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) ? JS_JQUERY_UI : false;
  348. }
  349. // We force the content charset
  350. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  351. header("X-Content-Type-Options: nosniff");
  352. print '<!DOCTYPE HTML>'."\n";
  353. print '<html>'."\n";
  354. print '<head>'."\n";
  355. print '<meta charset="'.$conf->file->character_set_client.'">'."\n";
  356. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
  357. print '<meta name="generator" content="Dolibarr installer">'."\n";
  358. print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
  359. print '<!-- Includes CSS for JQuery -->'."\n";
  360. if ($jQueryUiCustomPath) print '<link rel="stylesheet" type="text/css" href="'.$jQueryUiCustomPath.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
  361. else print '<link rel="stylesheet" type="text/css" href="../includes/jquery/css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
  362. print '<!-- Includes JS for JQuery -->'."\n";
  363. if ($jQueryCustomPath) print '<script type="text/javascript" src="'.$jQueryCustomPath.'jquery.min.js"></script>'."\n";
  364. else print '<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>'."\n";
  365. if ($jQueryUiCustomPath) print '<script type="text/javascript" src="'.$jQueryUiCustomPath.'jquery-ui.min.js"></script>'."\n";
  366. else print '<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>'."\n";
  367. print '<title>'.$langs->trans("DolibarrSetup").'</title>'."\n";
  368. print '</head>'."\n";
  369. print '<body>'."\n";
  370. print '<div class="divlogoinstall" style="text-align:center">';
  371. print '<img class="imglogoinstall" src="../theme/dolibarr_logo.png" alt="Dolibarr logo"><br>';
  372. print DOL_VERSION;
  373. print '</div><br>';
  374. print '<span class="titre">'.$langs->trans("DolibarrSetup");
  375. if ($subtitle) {
  376. print ' - '.$subtitle;
  377. }
  378. print '</span>'."\n";
  379. print '<form name="forminstall" style="width: 100%" action="'.$next.'.php'.($param?'?'.$param:'').'" method="POST">'."\n";
  380. print '<input type="hidden" name="testpost" value="ok">'."\n";
  381. print '<input type="hidden" name="action" value="'.$action.'">'."\n";
  382. print '<table class="main" width="100%"><tr><td>'."\n";
  383. print '<table class="'.$csstable.'" width="100%"><tr><td>'."\n";
  384. }
  385. /**
  386. * Print HTML footer of install pages
  387. *
  388. * @param integer $nonext 1=No button "Next step", 2=Show button but disabled with a link to enable
  389. * @param string $setuplang Language code
  390. * @param string $jscheckfunction Add a javascript check function
  391. * @param integer $withpleasewait Add also please wait tags
  392. * @return void
  393. */
  394. function pFooter($nonext=0,$setuplang='',$jscheckfunction='', $withpleasewait=0)
  395. {
  396. global $conf,$langs;
  397. $langs->load("main");
  398. $langs->load("other");
  399. $langs->load("admin");
  400. print '</td></tr></table>'."\n";
  401. print '</td></tr></table>'."\n";
  402. if (! $nonext || ($nonext == '2'))
  403. {
  404. print '<div class="nextbutton" id="nextbutton">';
  405. if ($nonext == '2')
  406. {
  407. print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"])?$_SERVER["REQUEST_URI"].'&ignoreerrors=1':'').'<br><br>';
  408. }
  409. print '<input type="submit" '.($nonext == '2' ? 'disabled="disabled" ':'').'value="'.$langs->trans("NextStep").' ->"';
  410. if ($jscheckfunction) print ' onClick="return '.$jscheckfunction.'();"';
  411. print '></div>';
  412. if ($withpleasewait) print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>'.$langs->trans("NextStepMightLastALongTime").'<br><br><div class="blinkwait">'.$langs->trans("PleaseBePatient").'</div></div>';
  413. }
  414. if ($setuplang)
  415. {
  416. print '<input type="hidden" name="selectlang" value="'.$setuplang.'">';
  417. }
  418. print '</form>'."\n";
  419. // If there is some logs in buffer to show
  420. if (isset($conf->logbuffer) && count($conf->logbuffer))
  421. {
  422. print "\n";
  423. print "<!-- Start of log output\n";
  424. //print '<div class="hidden">'."\n";
  425. foreach($conf->logbuffer as $logline)
  426. {
  427. print $logline."<br>\n";
  428. }
  429. //print '</div>'."\n";
  430. print "End of log output -->\n";
  431. print "\n";
  432. }
  433. print '</body>'."\n";
  434. print '</html>'."\n";
  435. }
  436. /**
  437. * Log function for install pages
  438. *
  439. * @param string $message Message
  440. * @param int $level Level of log
  441. * @return void
  442. */
  443. function dolibarr_install_syslog($message, $level=LOG_DEBUG)
  444. {
  445. if (! defined('LOG_DEBUG')) define('LOG_DEBUG',6);
  446. dol_syslog($message,$level);
  447. }
  448. /**
  449. * Automatically detect Dolibarr's main document root
  450. *
  451. * @return string
  452. */
  453. function detect_dolibarr_main_document_root()
  454. {
  455. // If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
  456. // Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
  457. if ($_SERVER["SCRIPT_FILENAME"] == 'php' || preg_match('/[\\/]php$/i', $_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i', $_SERVER["SCRIPT_FILENAME"]))
  458. {
  459. $dolibarr_main_document_root = $_SERVER["DOCUMENT_ROOT"];
  460. if (!preg_match('/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
  461. $dolibarr_main_document_root .= "/dolibarr/htdocs";
  462. }
  463. } else {
  464. // We assume /install to be under /htdocs, so we get the parent directory of the current directory
  465. $dolibarr_main_document_root = dirname(dirname($_SERVER["SCRIPT_FILENAME"]));
  466. }
  467. return $dolibarr_main_document_root;
  468. }
  469. /**
  470. * Automatically detect Dolibarr's main data root
  471. *
  472. * @param string $dolibarr_main_document_root Current main document root
  473. * @return string
  474. */
  475. function detect_dolibarr_main_data_root($dolibarr_main_document_root)
  476. {
  477. $dolibarr_main_data_root = preg_replace("/\/htdocs$/", "", $dolibarr_main_document_root);
  478. $dolibarr_main_data_root .= "/documents";
  479. return $dolibarr_main_data_root;
  480. }
  481. /**
  482. * Automatically detect Dolibarr's main URL root
  483. *
  484. * @return string
  485. */
  486. function detect_dolibarr_main_url_root()
  487. {
  488. // If defined (Ie: Apache with Linux)
  489. if (isset($_SERVER["SCRIPT_URI"])) {
  490. $dolibarr_main_url_root = $_SERVER["SCRIPT_URI"];
  491. } // If defined (Ie: Apache with Caudium)
  492. elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
  493. $dolibarr_main_url_root = $_SERVER["SERVER_URL"] . $_SERVER["DOCUMENT_URI"];
  494. } // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
  495. else {
  496. $proto = ( (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') || $_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
  497. if (!empty($_SERVER["HTTP_HOST"])) {
  498. $serverport = $_SERVER["HTTP_HOST"];
  499. } else {
  500. $serverport = $_SERVER["SERVER_NAME"];
  501. }
  502. $dolibarr_main_url_root = $proto . "://" . $serverport . $_SERVER["SCRIPT_NAME"];
  503. }
  504. // Clean proposed URL
  505. // We assume /install to be under /htdocs, so we get the parent path of the current URL
  506. $dolibarr_main_url_root = dirname(dirname($dolibarr_main_url_root));
  507. return $dolibarr_main_url_root;
  508. }
  509. /**
  510. * Replaces automatic database login by actual value
  511. *
  512. * @param string $force_install_databaserootlogin Login
  513. * @return string
  514. */
  515. function parse_database_login($force_install_databaserootlogin)
  516. {
  517. return preg_replace('/__SUPERUSERLOGIN__/', 'root', $force_install_databaserootlogin);
  518. }
  519. /**
  520. * Replaces automatic database password by actual value
  521. *
  522. * @param string $force_install_databaserootpass Password
  523. * @return string
  524. */
  525. function parse_database_pass($force_install_databaserootpass)
  526. {
  527. return preg_replace('/__SUPERUSERPASSWORD__/', '', $force_install_databaserootpass);
  528. }