step1.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. <?php
  2. /* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2015-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 <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/install/step1.php
  24. * \ingroup install
  25. * \brief Build conf file on disk
  26. */
  27. define('DONOTLOADCONF', 1); // To avoid loading conf by file inc.php
  28. include 'inc.php';
  29. global $langs;
  30. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]);
  31. $setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]);
  32. $langs->setDefaultLang($setuplang);
  33. $langs->loadLangs(array("admin", "install", "errors"));
  34. // Dolibarr pages directory
  35. $main_dir = GETPOST('main_dir') ? GETPOST('main_dir') : (empty($argv[3]) ? '' : $argv[3]);
  36. // Directory for generated documents (invoices, orders, ecm, etc...)
  37. $main_data_dir = GETPOST('main_data_dir') ? GETPOST('main_data_dir') : (empty($argv[4]) ? ($main_dir.'/documents') : $argv[4]);
  38. // Dolibarr root URL
  39. $main_url = GETPOST('main_url') ? GETPOST('main_url') : (empty($argv[5]) ? '' : $argv[5]);
  40. // Database login information
  41. $userroot = GETPOST('db_user_root', 'alpha') ? GETPOST('db_user_root', 'alpha') : (empty($argv[6]) ? '' : $argv[6]);
  42. $passroot = GETPOST('db_pass_root', 'none') ? GETPOST('db_pass_root', 'none') : (empty($argv[7]) ? '' : $argv[7]);
  43. // Database server
  44. $db_type = GETPOST('db_type', 'aZ09') ? GETPOST('db_type', 'aZ09') : (empty($argv[8]) ? '' : $argv[8]);
  45. $db_host = GETPOST('db_host', 'alpha') ? GETPOST('db_host', 'alpha') : (empty($argv[9]) ? '' : $argv[9]);
  46. $db_name = GETPOST('db_name', 'aZ09') ? GETPOST('db_name', 'aZ09') : (empty($argv[10]) ? '' : $argv[10]);
  47. $db_user = GETPOST('db_user', 'alpha') ? GETPOST('db_user', 'alpha') : (empty($argv[11]) ? '' : $argv[11]);
  48. $db_pass = GETPOST('db_pass', 'none') ? GETPOST('db_pass', 'none') : (empty($argv[12]) ? '' : $argv[12]);
  49. $db_port = GETPOST('db_port', 'int') ? GETPOST('db_port', 'int') : (empty($argv[13]) ? '' : $argv[13]);
  50. $db_prefix = GETPOST('db_prefix', 'aZ09') ? GETPOST('db_prefix', 'aZ09') : (empty($argv[14]) ? '' : $argv[14]);
  51. $db_create_database = GETPOST('db_create_database', 'alpha') ? GETPOST('db_create_database', 'alpha') : (empty($argv[15]) ? '' : $argv[15]);
  52. $db_create_user = GETPOST('db_create_user', 'alpha') ? GETPOST('db_create_user', 'alpha') : (empty($argv[16]) ? '' : $argv[16]);
  53. // Force https
  54. $main_force_https = ((GETPOST("main_force_https", 'alpha') && (GETPOST("main_force_https", 'alpha') == "on" || GETPOST("main_force_https", 'alpha') == 1)) ? '1' : '0');
  55. // Use alternative directory
  56. $main_use_alt_dir = ((GETPOST("main_use_alt_dir", 'alpha') == '' || (GETPOST("main_use_alt_dir", 'alpha') == "on" || GETPOST("main_use_alt_dir", 'alpha') == 1)) ? '' : '//');
  57. // Alternative root directory name
  58. $main_alt_dir_name = ((GETPOST("main_alt_dir_name", 'alpha') && GETPOST("main_alt_dir_name", 'alpha') != '') ? GETPOST("main_alt_dir_name", 'alpha') : 'custom');
  59. $dolibarr_main_distrib = 'standard';
  60. session_start(); // To be able to keep info into session (used for not losing password during navigation. The password must not transit through parameters)
  61. // Save a flag to tell to restore input value if we go back
  62. $_SESSION['dol_save_pass'] = $db_pass;
  63. //$_SESSION['dol_save_passroot']=$passroot;
  64. // Now we load forced values from install.forced.php file.
  65. $useforcedwizard = false;
  66. $forcedfile = "./install.forced.php";
  67. if ($conffile == "/etc/dolibarr/conf.php") {
  68. $forcedfile = "/etc/dolibarr/install.forced.php";
  69. }
  70. if (@file_exists($forcedfile)) {
  71. $useforcedwizard = true;
  72. include_once $forcedfile;
  73. // If forced install is enabled, replace the post values. These are empty because form fields are disabled.
  74. if ($force_install_noedit) {
  75. $main_dir = detect_dolibarr_main_document_root();
  76. if (!empty($argv[3])) {
  77. $main_dir = $argv[3]; // override when executing the script in command line
  78. }
  79. if (!empty($force_install_main_data_root)) {
  80. $main_data_dir = $force_install_main_data_root;
  81. } else {
  82. $main_data_dir = detect_dolibarr_main_data_root($main_dir);
  83. }
  84. if (!empty($argv[4])) {
  85. $main_data_dir = $argv[4]; // override when executing the script in command line
  86. }
  87. $main_url = detect_dolibarr_main_url_root();
  88. if (!empty($argv[5])) {
  89. $main_url = $argv[5]; // override when executing the script in command line
  90. }
  91. if (!empty($force_install_databaserootlogin)) {
  92. $userroot = parse_database_login($force_install_databaserootlogin);
  93. }
  94. if (!empty($argv[6])) {
  95. $userroot = $argv[6]; // override when executing the script in command line
  96. }
  97. if (!empty($force_install_databaserootpass)) {
  98. $passroot = parse_database_pass($force_install_databaserootpass);
  99. }
  100. if (!empty($argv[7])) {
  101. $passroot = $argv[7]; // override when executing the script in command line
  102. }
  103. }
  104. if ($force_install_noedit == 2) {
  105. if (!empty($force_install_type)) {
  106. $db_type = $force_install_type;
  107. }
  108. if (!empty($force_install_dbserver)) {
  109. $db_host = $force_install_dbserver;
  110. }
  111. if (!empty($force_install_database)) {
  112. $db_name = $force_install_database;
  113. }
  114. if (!empty($force_install_databaselogin)) {
  115. $db_user = $force_install_databaselogin;
  116. }
  117. if (!empty($force_install_databasepass)) {
  118. $db_pass = $force_install_databasepass;
  119. }
  120. if (!empty($force_install_port)) {
  121. $db_port = $force_install_port;
  122. }
  123. if (!empty($force_install_prefix)) {
  124. $db_prefix = $force_install_prefix;
  125. }
  126. if (!empty($force_install_createdatabase)) {
  127. $db_create_database = $force_install_createdatabase;
  128. }
  129. if (!empty($force_install_createuser)) {
  130. $db_create_user = $force_install_createuser;
  131. }
  132. if (!empty($force_install_mainforcehttps)) {
  133. $main_force_https = $force_install_mainforcehttps;
  134. }
  135. }
  136. if (!empty($force_install_distrib)) {
  137. $dolibarr_main_distrib = $force_install_distrib;
  138. }
  139. }
  140. $error = 0;
  141. /*
  142. * View
  143. */
  144. dolibarr_install_syslog("--- step1: entering step1.php page");
  145. pHeader($langs->trans("ConfigurationFile"), "step2");
  146. // Test if we can run a first install process
  147. if (!is_writable($conffile)) {
  148. print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  149. pFooter(1, $setuplang, 'jscheckparam');
  150. exit;
  151. }
  152. // Check parameters
  153. $is_sqlite = false;
  154. if (empty($db_type)) {
  155. print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseType")).'</div>';
  156. $error++;
  157. } else {
  158. $is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3');
  159. }
  160. if (empty($db_host) && !$is_sqlite) {
  161. print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Server")).'</div>';
  162. $error++;
  163. }
  164. if (empty($db_name)) {
  165. print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseName")).'</div>';
  166. $error++;
  167. }
  168. if (empty($db_user) && !$is_sqlite) {
  169. print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Login")).'</div>';
  170. $error++;
  171. }
  172. if (!empty($db_port) && !is_numeric($db_port)) {
  173. print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_port, $langs->transnoentities("Port")).'</div>';
  174. $error++;
  175. }
  176. if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix)) {
  177. print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_prefix, $langs->transnoentities("DatabasePrefix")).'</div>';
  178. $error++;
  179. }
  180. // Remove last / into dans main_dir
  181. if (substr($main_dir, dol_strlen($main_dir) - 1) == "/") {
  182. $main_dir = substr($main_dir, 0, dol_strlen($main_dir) - 1);
  183. }
  184. // Remove last / into dans main_url
  185. if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/") {
  186. $main_url = substr($main_url, 0, dol_strlen($main_url) - 1);
  187. }
  188. if (!dol_is_dir($main_dir.'/core/db/')) {
  189. print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $main_dir, $langs->transnoentitiesnoconv("WebPagesDirectory")).'</div>';
  190. print '<br>';
  191. //print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  192. print $langs->trans("ErrorGoBackAndCorrectParameters");
  193. $error++;
  194. }
  195. // Test database connection
  196. if (!$error) {
  197. $result = @include_once $main_dir."/core/db/".$db_type.'.class.php';
  198. if ($result) {
  199. // If we require database or user creation we need to connect as root, so we need root login credentials
  200. if (!empty($db_create_database) && !$userroot) {
  201. print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $db_name).'</div>';
  202. print '<br>';
  203. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  204. print $langs->trans("ErrorGoBackAndCorrectParameters");
  205. $error++;
  206. }
  207. if (!empty($db_create_user) && !$userroot) {
  208. print '<div class="error">'.$langs->trans("YouAskLoginCreationSoDolibarrNeedToConnect", $db_user).'</div>';
  209. print '<br>';
  210. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  211. print $langs->trans("ErrorGoBackAndCorrectParameters");
  212. $error++;
  213. }
  214. // If we need root access
  215. if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
  216. $databasefortest = $db_name;
  217. if (!empty($db_create_database)) {
  218. if ($db_type == 'mysql' || $db_type == 'mysqli') {
  219. $databasefortest = 'mysql';
  220. } elseif ($db_type == 'pgsql') {
  221. $databasefortest = 'postgres';
  222. } else {
  223. $databasefortest = 'master';
  224. }
  225. }
  226. $db = getDoliDBInstance($db_type, $db_host, $userroot, $passroot, $databasefortest, (int) $db_port);
  227. dol_syslog("databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected, LOG_DEBUG);
  228. //print "databasefortest=".$databasefortest." connected=".$db->connected." database_selected=".$db->database_selected;
  229. if (empty($db_create_database) && $db->connected && !$db->database_selected) {
  230. print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound", $db_name).'</div>';
  231. print '<br>';
  232. if (!$db->connected) {
  233. print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
  234. }
  235. print $langs->trans("ErrorGoBackAndCorrectParameters");
  236. $error++;
  237. } elseif ($db->error && !(!empty($db_create_database) && $db->connected)) {
  238. // Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
  239. if ($db->error == "No such file or directory") {
  240. print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
  241. } else {
  242. print '<div class="error">'.$db->error.'</div>';
  243. }
  244. if (!$db->connected) {
  245. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  246. }
  247. //print '<a href="#" onClick="javascript: history.back();">';
  248. print $langs->trans("ErrorGoBackAndCorrectParameters");
  249. //print '</a>';
  250. $error++;
  251. }
  252. }
  253. // If we need simple access
  254. if (!$error && (empty($db_create_database) && empty($db_create_user))) {
  255. $db = getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, (int) $db_port);
  256. if ($db->error) {
  257. print '<div class="error">'.$db->error.'</div>';
  258. if (!$db->connected) {
  259. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  260. }
  261. //print '<a href="#" onClick="javascript: history.back();">';
  262. print $langs->trans("ErrorGoBackAndCorrectParameters");
  263. //print '</a>';
  264. $error++;
  265. }
  266. }
  267. } else {
  268. print "<br>\nFailed to include_once(\"".$main_dir."/core/db/".$db_type.".class.php\")<br>\n";
  269. print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter", $langs->transnoentities("WebPagesDirectory")).'</div>';
  270. //print '<a href="#" onClick="javascript: history.back();">';
  271. print $langs->trans("ErrorGoBackAndCorrectParameters");
  272. //print '</a>';
  273. $error++;
  274. }
  275. } else {
  276. if (isset($db)) {
  277. print $db->lasterror();
  278. }
  279. if (isset($db) && !$db->connected) {
  280. print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  281. }
  282. print $langs->trans("ErrorGoBackAndCorrectParameters");
  283. $error++;
  284. }
  285. if (!$error && $db->connected) {
  286. if (!empty($db_create_database)) {
  287. $result = $db->select_db($db_name);
  288. if ($result) {
  289. print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
  290. print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate").'<br><br>';
  291. print $langs->trans("ErrorGoBackAndCorrectParameters");
  292. $error++;
  293. }
  294. }
  295. }
  296. // Define $defaultCharacterSet and $defaultDBSortingCollation
  297. if (!$error && $db->connected) {
  298. if (!empty($db_create_database)) { // If we create database, we force default value
  299. // Default values come from the database handler
  300. $defaultCharacterSet = $db->forcecharset;
  301. $defaultDBSortingCollation = $db->forcecollate;
  302. } else { // If already created, we take current value
  303. $defaultCharacterSet = $db->getDefaultCharacterSetDatabase();
  304. $defaultDBSortingCollation = $db->getDefaultCollationDatabase();
  305. }
  306. // It seems some PHP driver mysqli does not support utf8mb3
  307. if ($defaultCharacterSet == 'utf8mb3' || $defaultDBSortingCollation == 'utf8mb3_unicode_ci') {
  308. $defaultCharacterSet = 'utf8';
  309. $defaultDBSortingCollation = 'utf8_unicode_ci';
  310. }
  311. // Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
  312. // TODO Remove this when utf8mb4 is supported
  313. if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci') {
  314. $defaultCharacterSet = 'utf8';
  315. $defaultDBSortingCollation = 'utf8_unicode_ci';
  316. }
  317. print '<input type="hidden" name="dolibarr_main_db_character_set" value="'.$defaultCharacterSet.'">';
  318. print '<input type="hidden" name="dolibarr_main_db_collation" value="'.$defaultDBSortingCollation.'">';
  319. $db_character_set = $defaultCharacterSet;
  320. $db_collation = $defaultDBSortingCollation;
  321. dolibarr_install_syslog("step1: db_character_set=".$db_character_set." db_collation=".$db_collation);
  322. }
  323. // Create config file
  324. if (!$error && $db->connected && $action == "set") {
  325. umask(0);
  326. if (is_array($_POST)) {
  327. foreach ($_POST as $key => $value) {
  328. if (!preg_match('/^db_pass/i', $key)) {
  329. dolibarr_install_syslog("step1: choice for ".$key." = ".$value);
  330. }
  331. }
  332. }
  333. // Show title of step
  334. print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Configuration"> '.$langs->trans("ConfigurationFile").'</h3>';
  335. print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
  336. // Check parameter main_dir
  337. if (!$error) {
  338. if (!is_dir($main_dir)) {
  339. dolibarr_install_syslog("step1: directory '".$main_dir."' is unavailable or can't be accessed");
  340. print "<tr><td>";
  341. print $langs->trans("ErrorDirDoesNotExists", $main_dir).'<br>';
  342. print $langs->trans("ErrorWrongValueForParameter", $langs->transnoentitiesnoconv("WebPagesDirectory")).'<br>';
  343. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  344. print '</td><td>';
  345. print $langs->trans("Error");
  346. print "</td></tr>";
  347. $error++;
  348. }
  349. }
  350. if (!$error) {
  351. dolibarr_install_syslog("step1: directory '".$main_dir."' exists");
  352. }
  353. // Create subdirectory main_data_dir
  354. if (!$error) {
  355. // Create directory for documents
  356. if (!is_dir($main_data_dir)) {
  357. dol_mkdir($main_data_dir);
  358. }
  359. if (!is_dir($main_data_dir)) {
  360. print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
  361. print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
  362. print '</td><td>';
  363. print '<span class="error">'.$langs->trans("Error").'</span>';
  364. print "</td></tr>";
  365. print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
  366. $error++;
  367. } else {
  368. // Create .htaccess file in document directory
  369. $pathhtaccess = $main_data_dir.'/.htaccess';
  370. if (!file_exists($pathhtaccess)) {
  371. dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '".$main_data_dir."'");
  372. $handlehtaccess = @fopen($pathhtaccess, 'w');
  373. if ($handlehtaccess) {
  374. fwrite($handlehtaccess, 'Order allow,deny'."\n");
  375. fwrite($handlehtaccess, 'Deny from all'."\n");
  376. fclose($handlehtaccess);
  377. dolibarr_install_syslog("step1: .htaccess file created");
  378. }
  379. }
  380. // Documents are stored above the web pages root to prevent being downloaded without authentification
  381. $dir = array();
  382. $dir[] = $main_data_dir."/mycompany";
  383. $dir[] = $main_data_dir."/medias";
  384. $dir[] = $main_data_dir."/users";
  385. $dir[] = $main_data_dir."/facture";
  386. $dir[] = $main_data_dir."/propale";
  387. $dir[] = $main_data_dir."/ficheinter";
  388. $dir[] = $main_data_dir."/produit";
  389. $dir[] = $main_data_dir."/doctemplates";
  390. // Loop on each directory of dir [] to create them if they do not exist
  391. $num = count($dir);
  392. for ($i = 0; $i < $num; $i++) {
  393. if (is_dir($dir[$i])) {
  394. dolibarr_install_syslog("step1: directory '".$dir[$i]."' exists");
  395. } else {
  396. if (dol_mkdir($dir[$i]) < 0) {
  397. print "<tr><td>";
  398. print "Failed to create directory: ".$dir[$i];
  399. print '</td><td>';
  400. print $langs->trans("Error");
  401. print "</td></tr>";
  402. $error++;
  403. } else {
  404. dolibarr_install_syslog("step1: directory '".$dir[$i]."' created");
  405. }
  406. }
  407. }
  408. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  409. // Copy directory medias
  410. $srcroot = $main_dir.'/install/medias';
  411. $destroot = $main_data_dir.'/medias';
  412. dolCopyDir($srcroot, $destroot, 0, 0);
  413. if ($error) {
  414. print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
  415. print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
  416. print '</td><td>';
  417. print '<span class="error">'.$langs->trans("Error").'</span>';
  418. print "</td></tr>";
  419. print '<tr><td colspan="2"><br>'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</td></tr>';
  420. } else {
  421. //ODT templates
  422. $srcroot = $main_dir.'/install/doctemplates';
  423. $destroot = $main_data_dir.'/doctemplates';
  424. $docs = array(
  425. 'contracts' => 'contract',
  426. 'invoices' => 'invoice',
  427. 'orders' => 'order',
  428. 'products' => 'product',
  429. 'projects' => 'project',
  430. 'proposals' => 'proposal',
  431. 'shipments' => 'shipment',
  432. 'supplier_proposals' => 'supplier_proposal',
  433. 'tasks' => 'task_summary',
  434. 'thirdparties' => 'thirdparty',
  435. 'usergroups' => 'usergroups',
  436. 'users' => 'user',
  437. );
  438. foreach ($docs as $cursordir => $cursorfile) {
  439. $src = $srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
  440. $dirodt = $destroot.'/'.$cursordir;
  441. $dest = $dirodt.'/template_'.$cursorfile.'.odt';
  442. dol_mkdir($dirodt);
  443. $result = dol_copy($src, $dest, 0, 0);
  444. if ($result < 0) {
  445. print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile', $src, $dest).'</td></tr>';
  446. }
  447. }
  448. }
  449. }
  450. }
  451. // Table prefix
  452. $main_db_prefix = (!empty($db_prefix) ? $db_prefix : 'llx_');
  453. // Write conf file on disk
  454. if (!$error) {
  455. // Save old conf file on disk
  456. if (file_exists("$conffile")) {
  457. // We must ignore errors as an existing old file may already exist and not be replaceable or
  458. // the installer (like for ubuntu) may not have permission to create another file than conf.php.
  459. // Also no other process must be able to read file or we expose the new file, so content with password.
  460. @dol_copy($conffile, $conffile.'.old', '0400');
  461. }
  462. $error += write_conf_file($conffile);
  463. }
  464. // Create database and admin user database
  465. if (!$error) {
  466. // We reload configuration file
  467. conf($dolibarr_main_document_root);
  468. print '<tr><td>';
  469. print $langs->trans("ConfFileReload");
  470. print '</td>';
  471. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  472. // Create database user if requested
  473. if (isset($db_create_user) && ($db_create_user == "1" || $db_create_user == "on")) {
  474. dolibarr_install_syslog("step1: create database user: ".$dolibarr_main_db_user);
  475. //print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
  476. $databasefortest = $conf->db->name;
  477. if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') {
  478. $databasefortest = 'mysql';
  479. } elseif ($conf->db->type == 'pgsql') {
  480. $databasefortest = 'postgres';
  481. } elseif ($conf->db->type == 'mssql') {
  482. $databasefortest = 'master';
  483. }
  484. // Check database connection
  485. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, $databasefortest, (int) $conf->db->port);
  486. if ($db->error) {
  487. print '<div class="error">'.$db->error.'</div>';
  488. $error++;
  489. }
  490. if (!$error) {
  491. if ($db->connected) {
  492. $resultbis = 1;
  493. if (empty($dolibarr_main_db_pass)) {
  494. dolibarr_install_syslog("step1: failed to create user, password is empty", LOG_ERR);
  495. print '<tr><td>';
  496. print $langs->trans("UserCreation").' : ';
  497. print $dolibarr_main_db_user;
  498. print '</td>';
  499. print '<td>'.$langs->trans("Error").": A password for database user is mandatory.</td></tr>";
  500. } else {
  501. // Create user
  502. $result = $db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
  503. // Create user bis
  504. if ($databasefortest == 'mysql') {
  505. if (!in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local'))) {
  506. $resultbis = $db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
  507. }
  508. }
  509. if ($result > 0 && $resultbis > 0) {
  510. print '<tr><td>';
  511. print $langs->trans("UserCreation").' : ';
  512. print $dolibarr_main_db_user;
  513. print '</td>';
  514. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  515. } else {
  516. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
  517. || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
  518. || $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS') {
  519. dolibarr_install_syslog("step1: user already exists");
  520. print '<tr><td>';
  521. print $langs->trans("UserCreation").' : ';
  522. print $dolibarr_main_db_user;
  523. print '</td>';
  524. print '<td>'.$langs->trans("LoginAlreadyExists").'</td></tr>';
  525. } else {
  526. dolibarr_install_syslog("step1: failed to create user", LOG_ERR);
  527. print '<tr><td>';
  528. print $langs->trans("UserCreation").' : ';
  529. print $dolibarr_main_db_user;
  530. print '</td>';
  531. print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error().($db->error ? '. '.$db->error : '')."</td></tr>";
  532. }
  533. }
  534. }
  535. $db->close();
  536. } else {
  537. print '<tr><td>';
  538. print $langs->trans("UserCreation").' : ';
  539. print $dolibarr_main_db_user;
  540. print '</td>';
  541. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
  542. print '</tr>';
  543. // warning message due to connection failure
  544. print '<tr><td colspan="2"><br>';
  545. print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
  546. print '<br>';
  547. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  548. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  549. print '</td></tr>';
  550. $error++;
  551. }
  552. }
  553. } // end of user account creation
  554. // If database creation was asked, we create it
  555. if (!$error && (isset($db_create_database) && ($db_create_database == "1" || $db_create_database == "on"))) {
  556. dolibarr_install_syslog("step1: create database: ".$dolibarr_main_db_name." ".$dolibarr_main_db_character_set." ".$dolibarr_main_db_collation." ".$dolibarr_main_db_user);
  557. $newdb = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, '', (int) $conf->db->port);
  558. //print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
  559. if ($newdb->connected) {
  560. $result = $newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
  561. if ($result) {
  562. print '<tr><td>';
  563. print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
  564. print $dolibarr_main_db_name;
  565. print '</td>';
  566. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  567. $newdb->select_db($dolibarr_main_db_name);
  568. $check1 = $newdb->getDefaultCharacterSetDatabase();
  569. $check2 = $newdb->getDefaultCollationDatabase();
  570. dolibarr_install_syslog('step1: new database is using charset='.$check1.' collation='.$check2);
  571. // If values differs, we save conf file again
  572. //if ($check1 != $dolibarr_main_db_character_set) dolibarr_install_syslog('step1: value for character_set is not the one asked for database creation', LOG_WARNING);
  573. //if ($check2 != $dolibarr_main_db_collation) dolibarr_install_syslog('step1: value for collation is not the one asked for database creation', LOG_WARNING);
  574. } else {
  575. // warning message
  576. print '<tr><td colspan="2"><br>';
  577. print $langs->trans("ErrorFailedToCreateDatabase", $dolibarr_main_db_name).'<br>';
  578. print $newdb->lasterror().'<br>';
  579. print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate");
  580. print '<br>';
  581. print '</td></tr>';
  582. dolibarr_install_syslog('step1: failed to create database '.$dolibarr_main_db_name.' '.$newdb->lasterrno().' '.$newdb->lasterror(), LOG_ERR);
  583. $error++;
  584. }
  585. $newdb->close();
  586. } else {
  587. print '<tr><td>';
  588. print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
  589. print $dolibarr_main_db_name;
  590. print '</td>';
  591. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td>';
  592. print '</tr>';
  593. // warning message
  594. print '<tr><td colspan="2"><br>';
  595. print $langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $dolibarr_main_db_user, $dolibarr_main_db_host, $userroot);
  596. print '<br>';
  597. print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
  598. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  599. print '</td></tr>';
  600. $error++;
  601. }
  602. } // end of create database
  603. // We test access with dolibarr database user (not admin)
  604. if (!$error) {
  605. dolibarr_install_syslog("step1: connection type=".$conf->db->type." on host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name);
  606. //print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
  607. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
  608. if ($db->connected) {
  609. dolibarr_install_syslog("step1: connection to server by user ".$conf->db->user." ok");
  610. print "<tr><td>";
  611. print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
  612. print $dolibarr_main_db_host;
  613. print "</td><td>";
  614. print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
  615. print "</td></tr>";
  616. // server access ok, basic access ok
  617. if ($db->database_selected) {
  618. dolibarr_install_syslog("step1: connection to database ".$conf->db->name." by user ".$conf->db->user." ok");
  619. print "<tr><td>";
  620. print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
  621. print $dolibarr_main_db_name;
  622. print "</td><td>";
  623. print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
  624. print "</td></tr>";
  625. $error = 0;
  626. } else {
  627. dolibarr_install_syslog("step1: connection to database ".$conf->db->name." by user ".$conf->db->user." failed", LOG_ERR);
  628. print "<tr><td>";
  629. print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
  630. print $dolibarr_main_db_name;
  631. print '</td><td>';
  632. print '<img src="../theme/eldy/img/error.png" alt="Error">';
  633. print "</td></tr>";
  634. // warning message
  635. print '<tr><td colspan="2"><br>';
  636. print $langs->trans('CheckThatDatabasenameIsCorrect', $dolibarr_main_db_name).'<br>';
  637. print $langs->trans('IfAlreadyExistsCheckOption').'<br>';
  638. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  639. print '</td></tr>';
  640. $error++;
  641. }
  642. } else {
  643. dolibarr_install_syslog("step1: connection to server by user ".$conf->db->user." failed", LOG_ERR);
  644. print "<tr><td>";
  645. print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
  646. print $dolibarr_main_db_host;
  647. print '</td><td>';
  648. print '<img src="../theme/eldy/img/error.png" alt="Error">';
  649. print "</td></tr>";
  650. // warning message
  651. print '<tr><td colspan="2"><br>';
  652. print $langs->trans("ErrorConnection", $conf->db->host, $conf->db->name, $conf->db->user);
  653. print $langs->trans('IfLoginDoesNotExistsCheckCreateUser').'<br>';
  654. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  655. print '</td></tr>';
  656. $error++;
  657. }
  658. }
  659. }
  660. print '</table>';
  661. }
  662. ?>
  663. <script type="text/javascript">
  664. function jsinfo()
  665. {
  666. ok=true;
  667. //alert('<?php echo dol_escape_js($langs->transnoentities("NextStepMightLastALongTime")); ?>');
  668. document.getElementById('nextbutton').style.visibility="hidden";
  669. document.getElementById('pleasewait').style.visibility="visible";
  670. return ok;
  671. }
  672. </script>
  673. <?php
  674. $ret = 0;
  675. if ($error && isset($argv[1])) {
  676. $ret = 1;
  677. }
  678. dolibarr_install_syslog("Exit ".$ret);
  679. dolibarr_install_syslog("--- step1: end");
  680. pFooter($error ? 1 : 0, $setuplang, 'jsinfo', 1);
  681. // Return code if ran from command line
  682. if ($ret) {
  683. exit($ret);
  684. }
  685. /**
  686. * Create main file. No particular permissions are set by installer.
  687. *
  688. * @param string $mainfile Full path name of main file to generate/update
  689. * @param string $main_dir Full path name to main.inc.php file
  690. * @return void
  691. */
  692. function write_main_file($mainfile, $main_dir)
  693. {
  694. $fp = @fopen("$mainfile", "w");
  695. if ($fp) {
  696. clearstatcache();
  697. fputs($fp, '<?php'."\n");
  698. fputs($fp, "// Wrapper to include main into htdocs\n");
  699. fputs($fp, "include_once '".$main_dir."/main.inc.php';\n");
  700. fclose($fp);
  701. }
  702. }
  703. /**
  704. * Create master file. No particular permissions are set by installer.
  705. *
  706. * @param string $masterfile Full path name of master file to generate/update
  707. * @param string $main_dir Full path name to master.inc.php file
  708. * @return void
  709. */
  710. function write_master_file($masterfile, $main_dir)
  711. {
  712. $fp = @fopen("$masterfile", "w");
  713. if ($fp) {
  714. clearstatcache();
  715. fputs($fp, '<?php'."\n");
  716. fputs($fp, "// Wrapper to include master into htdocs\n");
  717. fputs($fp, "include_once '".$main_dir."/master.inc.php';\n");
  718. fclose($fp);
  719. }
  720. }
  721. /**
  722. * Save configuration file. No particular permissions are set by installer.
  723. *
  724. * @param string $conffile Path to conf file to generate/update
  725. * @return integer
  726. */
  727. function write_conf_file($conffile)
  728. {
  729. global $conf, $langs;
  730. global $main_url, $main_dir, $main_data_dir, $main_force_https, $main_use_alt_dir, $main_alt_dir_name, $main_db_prefix;
  731. global $dolibarr_main_url_root, $dolibarr_main_document_root, $dolibarr_main_data_root, $dolibarr_main_db_host;
  732. global $dolibarr_main_db_port, $dolibarr_main_db_name, $dolibarr_main_db_user, $dolibarr_main_db_pass;
  733. global $dolibarr_main_db_type, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_authentication;
  734. global $dolibarr_main_distrib;
  735. global $db_host, $db_port, $db_name, $db_user, $db_pass, $db_type, $db_character_set, $db_collation;
  736. global $conffile, $conffiletoshow, $conffiletoshowshort;
  737. global $force_dolibarr_lib_NUSOAP_PATH;
  738. global $force_dolibarr_lib_TCPDF_PATH, $force_dolibarr_lib_FPDI_PATH;
  739. global $force_dolibarr_lib_GEOIP_PATH;
  740. global $force_dolibarr_lib_ODTPHP_PATH, $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP;
  741. global $force_dolibarr_js_CKEDITOR, $force_dolibarr_js_JQUERY, $force_dolibarr_js_JQUERY_UI;
  742. global $force_dolibarr_font_DOL_DEFAULT_TTF, $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD;
  743. $error = 0;
  744. $key = md5(uniqid(mt_rand(), true)); // Generate random hash
  745. $fp = fopen("$conffile", "w");
  746. if ($fp) {
  747. clearstatcache();
  748. fputs($fp, '<?php'."\n");
  749. fputs($fp, '//'."\n");
  750. fputs($fp, '// File generated by Dolibarr installer '.DOL_VERSION.' on '.dol_print_date(dol_now(), '')."\n");
  751. fputs($fp, '//'."\n");
  752. fputs($fp, '// Take a look at conf.php.example file for an example of '.$conffiletoshowshort.' file'."\n");
  753. fputs($fp, '// and explanations for all possibles parameters.'."\n");
  754. fputs($fp, '//'."\n");
  755. fputs($fp, '$dolibarr_main_url_root=\''.str_replace("'", "\'", trim($main_url)).'\';');
  756. fputs($fp, "\n");
  757. fputs($fp, '$dolibarr_main_document_root=\''.str_replace("'", "\'", trim($main_dir)).'\';');
  758. fputs($fp, "\n");
  759. fputs($fp, $main_use_alt_dir.'$dolibarr_main_url_root_alt=\''.str_replace("'", "\'", trim("/".$main_alt_dir_name)).'\';');
  760. fputs($fp, "\n");
  761. fputs($fp, $main_use_alt_dir.'$dolibarr_main_document_root_alt=\''.str_replace("'", "\'", trim($main_dir."/".$main_alt_dir_name)).'\';');
  762. fputs($fp, "\n");
  763. fputs($fp, '$dolibarr_main_data_root=\''.str_replace("'", "\'", trim($main_data_dir)).'\';');
  764. fputs($fp, "\n");
  765. fputs($fp, '$dolibarr_main_db_host=\''.str_replace("'", "\'", trim($db_host)).'\';');
  766. fputs($fp, "\n");
  767. fputs($fp, '$dolibarr_main_db_port=\''.str_replace("'", "\'", trim($db_port)).'\';');
  768. fputs($fp, "\n");
  769. fputs($fp, '$dolibarr_main_db_name=\''.str_replace("'", "\'", trim($db_name)).'\';');
  770. fputs($fp, "\n");
  771. fputs($fp, '$dolibarr_main_db_prefix=\''.str_replace("'", "\'", trim($main_db_prefix)).'\';');
  772. fputs($fp, "\n");
  773. fputs($fp, '$dolibarr_main_db_user=\''.str_replace("'", "\'", trim($db_user)).'\';');
  774. fputs($fp, "\n");
  775. fputs($fp, '$dolibarr_main_db_pass=\''.str_replace("'", "\'", trim($db_pass)).'\';');
  776. fputs($fp, "\n");
  777. fputs($fp, '$dolibarr_main_db_type=\''.str_replace("'", "\'", trim($db_type)).'\';');
  778. fputs($fp, "\n");
  779. fputs($fp, '$dolibarr_main_db_character_set=\''.str_replace("'", "\'", trim($db_character_set)).'\';');
  780. fputs($fp, "\n");
  781. fputs($fp, '$dolibarr_main_db_collation=\''.str_replace("'", "\'", trim($db_collation)).'\';');
  782. fputs($fp, "\n");
  783. // Authentication
  784. fputs($fp, '// Authentication settings');
  785. fputs($fp, "\n");
  786. fputs($fp, '$dolibarr_main_authentication=\'dolibarr\';');
  787. fputs($fp, "\n\n");
  788. fputs($fp, '//$dolibarr_main_demo=\'autologin,autopass\';');
  789. fputs($fp, "\n");
  790. fputs($fp, '// Security settings');
  791. fputs($fp, "\n");
  792. fputs($fp, '$dolibarr_main_prod=\'0\';');
  793. fputs($fp, "\n");
  794. fputs($fp, '$dolibarr_main_force_https=\''.$main_force_https.'\';');
  795. fputs($fp, "\n");
  796. fputs($fp, '$dolibarr_main_restrict_os_commands=\'mariadb-dump, mariadb, mysqldump, mysql, pg_dump, pgrestore, clamdscan, clamscan.exe\';');
  797. fputs($fp, "\n");
  798. fputs($fp, '$dolibarr_nocsrfcheck=\'0\';');
  799. fputs($fp, "\n");
  800. fputs($fp, '$dolibarr_main_instance_unique_id=\''.$key.'\';');
  801. fputs($fp, "\n");
  802. fputs($fp, '$dolibarr_mailing_limit_sendbyweb=\'0\';');
  803. fputs($fp, "\n");
  804. fputs($fp, '$dolibarr_mailing_limit_sendbycli=\'0\';');
  805. fputs($fp, "\n");
  806. // Write params to overwrites default lib path
  807. fputs($fp, "\n");
  808. if (empty($force_dolibarr_lib_FPDF_PATH)) {
  809. fputs($fp, '//');
  810. $force_dolibarr_lib_FPDF_PATH = '';
  811. }
  812. fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
  813. fputs($fp, "\n");
  814. if (empty($force_dolibarr_lib_TCPDF_PATH)) {
  815. fputs($fp, '//');
  816. $force_dolibarr_lib_TCPDF_PATH = '';
  817. }
  818. fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
  819. fputs($fp, "\n");
  820. if (empty($force_dolibarr_lib_FPDI_PATH)) {
  821. fputs($fp, '//');
  822. $force_dolibarr_lib_FPDI_PATH = '';
  823. }
  824. fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
  825. fputs($fp, "\n");
  826. if (empty($force_dolibarr_lib_TCPDI_PATH)) {
  827. fputs($fp, '//');
  828. $force_dolibarr_lib_TCPDI_PATH = '';
  829. }
  830. fputs($fp, '$dolibarr_lib_TCPDI_PATH=\''.$force_dolibarr_lib_TCPDI_PATH.'\';');
  831. fputs($fp, "\n");
  832. if (empty($force_dolibarr_lib_GEOIP_PATH)) {
  833. fputs($fp, '//');
  834. $force_dolibarr_lib_GEOIP_PATH = '';
  835. }
  836. fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
  837. fputs($fp, "\n");
  838. if (empty($force_dolibarr_lib_NUSOAP_PATH)) {
  839. fputs($fp, '//');
  840. $force_dolibarr_lib_NUSOAP_PATH = '';
  841. }
  842. fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
  843. fputs($fp, "\n");
  844. if (empty($force_dolibarr_lib_ODTPHP_PATH)) {
  845. fputs($fp, '//');
  846. $force_dolibarr_lib_ODTPHP_PATH = '';
  847. }
  848. fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
  849. fputs($fp, "\n");
  850. if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) {
  851. fputs($fp, '//');
  852. $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = '';
  853. }
  854. fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
  855. fputs($fp, "\n");
  856. if (empty($force_dolibarr_js_CKEDITOR)) {
  857. fputs($fp, '//');
  858. $force_dolibarr_js_CKEDITOR = '';
  859. }
  860. fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
  861. fputs($fp, "\n");
  862. if (empty($force_dolibarr_js_JQUERY)) {
  863. fputs($fp, '//');
  864. $force_dolibarr_js_JQUERY = '';
  865. }
  866. fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
  867. fputs($fp, "\n");
  868. if (empty($force_dolibarr_js_JQUERY_UI)) {
  869. fputs($fp, '//');
  870. $force_dolibarr_js_JQUERY_UI = '';
  871. }
  872. fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
  873. fputs($fp, "\n");
  874. // Write params to overwrites default font path
  875. fputs($fp, "\n");
  876. if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) {
  877. fputs($fp, '//');
  878. $force_dolibarr_font_DOL_DEFAULT_TTF = '';
  879. }
  880. fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
  881. fputs($fp, "\n");
  882. if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) {
  883. fputs($fp, '//');
  884. $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = '';
  885. }
  886. fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
  887. fputs($fp, "\n");
  888. // Other
  889. fputs($fp, '$dolibarr_main_distrib=\''.str_replace("'", "\'", trim($dolibarr_main_distrib)).'\';');
  890. fputs($fp, "\n");
  891. fclose($fp);
  892. if (file_exists("$conffile")) {
  893. include $conffile; // force config reload, do not put include_once
  894. conf($dolibarr_main_document_root);
  895. print "<tr><td>";
  896. print $langs->trans("SaveConfigurationFile");
  897. print ' <strong>'.$conffile.'</strong>';
  898. print "</td><td>";
  899. print '<img src="../theme/eldy/img/tick.png" alt="Ok">';
  900. print "</td></tr>";
  901. } else {
  902. $error++;
  903. }
  904. }
  905. return $error;
  906. }