step2.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Cedric GROSS <c.gross@kreiz-it.fr>
  5. * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/install/step2.php
  22. * \ingroup install
  23. * \brief Create tables, primary keys, foreign keys, indexes and functions into database and then load reference data
  24. */
  25. include 'inc.php';
  26. require_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  27. require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
  28. global $langs;
  29. $step = 2;
  30. $ok = 0;
  31. // This page can be long. We increase the time allowed. / Cette page peut etre longue. On augmente le delai autorise.
  32. // Only works if you are not in safe_mode. / Ne fonctionne que si on est pas en safe_mode.
  33. $err = error_reporting();
  34. error_reporting(0); // Disable all errors
  35. //error_reporting(E_ALL);
  36. @set_time_limit(1800); // Need 1800 on some very slow OS like Windows 7/64
  37. error_reporting($err);
  38. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]);
  39. $setuplang = GETPOST('selectlang', 'aZ09', 3) ?GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]);
  40. $langs->setDefaultLang($setuplang);
  41. $langs->loadLangs(array("admin", "install"));
  42. // Choice of DBMS
  43. $choix = 0;
  44. if ($dolibarr_main_db_type == "mysqli") {
  45. $choix = 1;
  46. }
  47. if ($dolibarr_main_db_type == "pgsql") {
  48. $choix = 2;
  49. }
  50. if ($dolibarr_main_db_type == "mssql") {
  51. $choix = 3;
  52. }
  53. if ($dolibarr_main_db_type == "sqlite") {
  54. $choix = 4;
  55. }
  56. if ($dolibarr_main_db_type == "sqlite3") {
  57. $choix = 5;
  58. }
  59. //if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into step2.php page');
  60. // Now we load forced values from install.forced.php file.
  61. $useforcedwizard = false;
  62. $forcedfile = "./install.forced.php";
  63. if ($conffile == "/etc/dolibarr/conf.php") {
  64. $forcedfile = "/etc/dolibarr/install.forced.php";
  65. }
  66. if (@file_exists($forcedfile)) {
  67. $useforcedwizard = true;
  68. include_once $forcedfile;
  69. // test for travis
  70. if (!empty($argv[1]) && $argv[1] == "set") {
  71. $action = "set";
  72. }
  73. }
  74. dolibarr_install_syslog("--- step2: entering step2.php page");
  75. /*
  76. * View
  77. */
  78. pHeader($langs->trans("CreateDatabaseObjects"), "step4");
  79. // Test if we can run a first install process
  80. if (!is_writable($conffile)) {
  81. print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  82. pFooter(1, $setuplang, 'jscheckparam');
  83. exit;
  84. }
  85. if ($action == "set") {
  86. print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans("Database").'</h3>';
  87. print '<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
  88. $error = 0;
  89. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
  90. if ($db->connected) {
  91. print "<tr><td>";
  92. print $langs->trans("ServerConnection")." : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  93. $ok = 1;
  94. } else {
  95. print "<tr><td>Failed to connect to server : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  96. }
  97. if ($ok) {
  98. if ($db->database_selected) {
  99. dolibarr_install_syslog("step2: successful connection to database: ".$conf->db->name);
  100. } else {
  101. dolibarr_install_syslog("step2: failed connection to database :".$conf->db->name, LOG_ERR);
  102. print "<tr><td>Failed to select database ".$conf->db->name.'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  103. $ok = 0;
  104. }
  105. }
  106. // Display version / Affiche version
  107. if ($ok) {
  108. $version = $db->getVersion();
  109. $versionarray = $db->getVersionArray();
  110. print '<tr><td>'.$langs->trans("DatabaseVersion").'</td>';
  111. print '<td>'.$version.'</td></tr>';
  112. //print '<td class="right">'.join('.',$versionarray).'</td></tr>';
  113. print '<tr><td>'.$langs->trans("DatabaseName").'</td>';
  114. print '<td>'.$db->database_name.'</td></tr>';
  115. //print '<td class="right">'.join('.',$versionarray).'</td></tr>';
  116. }
  117. $requestnb = 0;
  118. // To disable some code, so you can call step2 with url like
  119. // http://localhost/dolibarrnew/install/step2.php?action=set&token='.newToken().'&createtables=0&createkeys=0&createfunctions=0&createdata=llx_20_c_departements
  120. $createtables = GETPOSTISSET('createtables') ? GETPOST('createtables') : 1;
  121. $createkeys = GETPOSTISSET('createkeys') ? GETPOST('createkeys') : 1;
  122. $createfunctions = GETPOSTISSET('createfunctions') ? GETPOST('createfunction') : 1;
  123. $createdata = GETPOSTISSET('createdata') ? GETPOST('createdata') : 1;
  124. // To say that SQL we pass to query are already escaped for mysql, so we need to unescape them
  125. if (property_exists($db, 'unescapeslashquot')) {
  126. $db->unescapeslashquot = true;
  127. }
  128. /**************************************************************************************
  129. *
  130. * Load files tables/*.sql (not the *.key.sql). Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  131. * To do before the files *.key.sql
  132. *
  133. ***************************************************************************************/
  134. if ($ok && $createtables) {
  135. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  136. $dir = "mysql/tables/";
  137. $ok = 0;
  138. $handle = opendir($dir);
  139. dolibarr_install_syslog("step2: open tables directory ".$dir." handle=".$handle);
  140. $tablefound = 0;
  141. $tabledata = array();
  142. if (is_resource($handle)) {
  143. while (($file = readdir($handle)) !== false) {
  144. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  145. $tablefound++;
  146. $tabledata[] = $file;
  147. }
  148. }
  149. closedir($handle);
  150. }
  151. // Sort list of sql files on alphabetical order (load order is important)
  152. sort($tabledata);
  153. foreach ($tabledata as $file) {
  154. $name = substr($file, 0, dol_strlen($file) - 4);
  155. $buffer = '';
  156. $fp = fopen($dir.$file, "r");
  157. if ($fp) {
  158. while (!feof($fp)) {
  159. $buf = fgets($fp, 4096);
  160. if (substr($buf, 0, 2) <> '--') {
  161. $buf = preg_replace('/--(.+)*/', '', $buf);
  162. $buffer .= $buf;
  163. }
  164. }
  165. fclose($fp);
  166. $buffer = trim($buffer);
  167. if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb
  168. $buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer);
  169. } else {
  170. // Keyword ENGINE is MySQL-specific, so scrub it for
  171. // other database types (mssql, pgsql)
  172. $buffer = preg_replace('/type=innodb/i', '', $buffer);
  173. $buffer = preg_replace('/ENGINE=innodb/i', '', $buffer);
  174. }
  175. // Replace the prefix tables
  176. if ($dolibarr_main_db_prefix != 'llx_') {
  177. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  178. }
  179. //print "<tr><td>Creation of table $name/td>";
  180. $requestnb++;
  181. dolibarr_install_syslog("step2: request: ".$buffer);
  182. $resql = $db->query($buffer, 0, 'dml');
  183. if ($resql) {
  184. // print "<td>OK request ==== $buffer</td></tr>";
  185. $db->free($resql);
  186. } else {
  187. if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' ||
  188. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
  189. //print "<td>already existing</td></tr>";
  190. } else {
  191. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  192. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer.' <br>Executed query : '.$db->lastquery;
  193. print "\n</td>";
  194. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  195. $error++;
  196. }
  197. }
  198. } else {
  199. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  200. print "</td>";
  201. print '<td><span class="error">'.$langs->trans("Error").' Failed to open file '.$dir.$file.'</span></td></tr>';
  202. $error++;
  203. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  204. }
  205. }
  206. if ($tablefound) {
  207. if ($error == 0) {
  208. print '<tr><td>';
  209. print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  210. $ok = 1;
  211. }
  212. } else {
  213. print '<tr><td>'.$langs->trans("ErrorFailedToFindSomeFiles", $dir).'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  214. dolibarr_install_syslog("step2: failed to find files to create database in directory ".$dir, LOG_ERR);
  215. }
  216. }
  217. /***************************************************************************************
  218. *
  219. * Load files tables/*.key.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  220. * To do after the files *.sql
  221. *
  222. ***************************************************************************************/
  223. if ($ok && $createkeys) {
  224. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  225. $dir = "mysql/tables/";
  226. $okkeys = 0;
  227. $handle = opendir($dir);
  228. dolibarr_install_syslog("step2: open keys directory ".$dir." handle=".$handle);
  229. $tablefound = 0;
  230. $tabledata = array();
  231. if (is_resource($handle)) {
  232. while (($file = readdir($handle)) !== false) {
  233. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  234. $tablefound++;
  235. $tabledata[] = $file;
  236. }
  237. }
  238. closedir($handle);
  239. }
  240. // Sort list of sql files on alphabetical order (load order is important)
  241. sort($tabledata);
  242. foreach ($tabledata as $file) {
  243. $name = substr($file, 0, dol_strlen($file) - 4);
  244. //print "<tr><td>Creation of table $name</td>";
  245. $buffer = '';
  246. $fp = fopen($dir.$file, "r");
  247. if ($fp) {
  248. while (!feof($fp)) {
  249. $buf = fgets($fp, 4096);
  250. // Special case of lines allowed for some version only
  251. // MySQL
  252. if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) {
  253. $versioncommande = explode('.', $reg[1]);
  254. //var_dump($versioncommande);
  255. //var_dump($versionarray);
  256. if (count($versioncommande) && count($versionarray)
  257. && versioncompare($versioncommande, $versionarray) <= 0) {
  258. // Version qualified, delete SQL comments
  259. $buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf);
  260. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  261. }
  262. }
  263. // PGSQL
  264. if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
  265. $versioncommande = explode('.', $reg[1]);
  266. //var_dump($versioncommande);
  267. //var_dump($versionarray);
  268. if (count($versioncommande) && count($versionarray)
  269. && versioncompare($versioncommande, $versionarray) <= 0) {
  270. // Version qualified, delete SQL comments
  271. $buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf);
  272. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  273. }
  274. }
  275. // Add line if no comment
  276. if (!preg_match('/^--/i', $buf)) {
  277. $buffer .= $buf;
  278. }
  279. }
  280. fclose($fp);
  281. // If several requests, we loop on each
  282. $listesql = explode(';', $buffer);
  283. foreach ($listesql as $req) {
  284. $buffer = trim($req);
  285. if ($buffer) {
  286. // Replace the prefix tables
  287. if ($dolibarr_main_db_prefix != 'llx_') {
  288. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  289. }
  290. //print "<tr><td>Creation of keys and table index $name: '$buffer'</td>";
  291. $requestnb++;
  292. dolibarr_install_syslog("step2: request: ".$buffer);
  293. $resql = $db->query($buffer, 0, 'dml');
  294. if ($resql) {
  295. //print "<td>OK request ==== $buffer</td></tr>";
  296. $db->free($resql);
  297. } else {
  298. if ($db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
  299. $db->errno() == 'DB_ERROR_CANNOT_CREATE' ||
  300. $db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
  301. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
  302. preg_match('/duplicate key name/i', $db->error())) {
  303. //print "<td>Deja existante</td></tr>";
  304. $key_exists = 1;
  305. } else {
  306. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  307. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$db->lastqueryerror();
  308. print "\n</td>";
  309. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  310. $error++;
  311. }
  312. }
  313. }
  314. }
  315. } else {
  316. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  317. print "</td>";
  318. print '<td><span class="error">'.$langs->trans("Error")." Failed to open file ".$dir.$file."</span></td></tr>";
  319. $error++;
  320. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  321. }
  322. }
  323. if ($tablefound && $error == 0) {
  324. print '<tr><td>';
  325. print $langs->trans("OtherKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  326. $okkeys = 1;
  327. }
  328. }
  329. /***************************************************************************************
  330. *
  331. * Load the file 'functions.sql'
  332. *
  333. ***************************************************************************************/
  334. if ($ok && $createfunctions) {
  335. // For this file, we use a directory according to database type
  336. if ($choix == 1) {
  337. $dir = "mysql/functions/";
  338. } elseif ($choix == 2) {
  339. $dir = "pgsql/functions/";
  340. } elseif ($choix == 3) {
  341. $dir = "mssql/functions/";
  342. } elseif ($choix == 4) {
  343. $dir = "sqlite3/functions/";
  344. }
  345. // Creation of data
  346. $file = "functions.sql";
  347. if (file_exists($dir.$file)) {
  348. $fp = fopen($dir.$file, "r");
  349. dolibarr_install_syslog("step2: open function file ".$dir.$file." handle=".$fp);
  350. if ($fp) {
  351. $buffer = '';
  352. while (!feof($fp)) {
  353. $buf = fgets($fp, 4096);
  354. if (substr($buf, 0, 2) <> '--') {
  355. $buffer .= $buf."§";
  356. }
  357. }
  358. fclose($fp);
  359. }
  360. //$buffer=preg_replace('/;\';/',";'§",$buffer);
  361. // If several requests, we loop on each of them
  362. $listesql = explode('§', $buffer);
  363. foreach ($listesql as $buffer) {
  364. $buffer = trim($buffer);
  365. if ($buffer) {
  366. // Replace the prefix in table names
  367. if ($dolibarr_main_db_prefix != 'llx_') {
  368. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  369. }
  370. dolibarr_install_syslog("step2: request: ".$buffer);
  371. print "<!-- Insert line : ".$buffer."<br>-->\n";
  372. $resql = $db->query($buffer, 0, 'dml');
  373. if ($resql) {
  374. $ok = 1;
  375. $db->free($resql);
  376. } else {
  377. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
  378. || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
  379. //print "Insert line : ".$buffer."<br>\n";
  380. } else {
  381. $ok = 0;
  382. print "<tr><td>".$langs->trans("FunctionsCreation");
  383. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer;
  384. print "\n</td>";
  385. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  386. $error++;
  387. }
  388. }
  389. }
  390. }
  391. print "<tr><td>".$langs->trans("FunctionsCreation")."</td>";
  392. if ($ok) {
  393. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  394. } else {
  395. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  396. $ok = 1;
  397. }
  398. }
  399. }
  400. /***************************************************************************************
  401. *
  402. * Load files data/*.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  403. *
  404. ***************************************************************************************/
  405. if ($ok && $createdata) {
  406. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  407. $dir = "mysql/data/";
  408. // Insert data
  409. $handle = opendir($dir);
  410. dolibarr_install_syslog("step2: open directory data ".$dir." handle=".$handle);
  411. $tablefound = 0;
  412. $tabledata = array();
  413. if (is_resource($handle)) {
  414. while (($file = readdir($handle)) !== false) {
  415. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\-/', $file)) {
  416. if (preg_match('/^llx_accounting_account_/', $file)) {
  417. continue; // We discard data file of chart of account. This will be loaded when a chart is selected.
  418. }
  419. //print 'x'.$file.'-'.$createdata.'<br>';
  420. if (is_numeric($createdata) || preg_match('/'.preg_quote($createdata).'/i', $file)) {
  421. $tablefound++;
  422. $tabledata[] = $file;
  423. }
  424. }
  425. }
  426. closedir($handle);
  427. }
  428. // Sort list of data files on alphabetical order (load order is important)
  429. sort($tabledata);
  430. foreach ($tabledata as $file) {
  431. $name = substr($file, 0, dol_strlen($file) - 4);
  432. $fp = fopen($dir.$file, "r");
  433. dolibarr_install_syslog("step2: open data file ".$dir.$file." handle=".$fp);
  434. if ($fp) {
  435. $arrayofrequests = array();
  436. $linefound = 0;
  437. $linegroup = 0;
  438. $sizeofgroup = 1; // Grouping request to have 1 query for several requests does not works with mysql, so we use 1.
  439. // Load all requests
  440. while (!feof($fp)) {
  441. $buffer = fgets($fp, 4096);
  442. $buffer = trim($buffer);
  443. if ($buffer) {
  444. if (substr($buffer, 0, 2) == '--') {
  445. continue;
  446. }
  447. if ($linefound && ($linefound % $sizeofgroup) == 0) {
  448. $linegroup++;
  449. }
  450. if (empty($arrayofrequests[$linegroup])) {
  451. $arrayofrequests[$linegroup] = $buffer;
  452. } else {
  453. $arrayofrequests[$linegroup] .= " ".$buffer;
  454. }
  455. $linefound++;
  456. }
  457. }
  458. fclose($fp);
  459. dolibarr_install_syslog("step2: found ".$linefound." records, defined ".count($arrayofrequests)." group(s).");
  460. $okallfile = 1;
  461. $db->begin();
  462. // We loop on each requests of file
  463. foreach ($arrayofrequests as $buffer) {
  464. // Replace the tables prefixes
  465. if ($dolibarr_main_db_prefix != 'llx_') {
  466. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  467. }
  468. //dolibarr_install_syslog("step2: request: " . $buffer);
  469. $resql = $db->query($buffer, 1);
  470. if ($resql) {
  471. //$db->free($resql); // Not required as request we launch here does not return memory needs.
  472. } else {
  473. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  474. //print "<tr><td>Insertion ligne : $buffer</td><td>";
  475. } else {
  476. $ok = 0;
  477. $okallfile = 0;
  478. print '<span class="error">'.$langs->trans("ErrorSQL")." : ".$db->lasterrno()." - ".$db->lastqueryerror()." - ".$db->lasterror()."</span><br>";
  479. }
  480. }
  481. }
  482. if ($okallfile) {
  483. $db->commit();
  484. } else {
  485. $db->rollback();
  486. }
  487. }
  488. }
  489. print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>";
  490. if ($ok) {
  491. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  492. } else {
  493. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  494. $ok = 1; // Data loading are not blocking errors
  495. }
  496. }
  497. print '</table>';
  498. } else {
  499. print 'Parameter action=set not defined';
  500. }
  501. $ret = 0;
  502. if (!$ok && isset($argv[1])) {
  503. $ret = 1;
  504. }
  505. dolibarr_install_syslog("Exit ".$ret);
  506. dolibarr_install_syslog("- step2: end");
  507. // Force here a value we need after because master.inc.php is not loaded into step2.
  508. // This code must be similar with the one into main.inc.php
  509. $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); // Unique id of instance
  510. $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id);
  511. $out = '<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString('MAIN_FIRST_PING_OK_ID') == 'disabled') ? '' : ' value="checked" checked="true"').'> ';
  512. $out .= '<label for="dolibarrpingno">'.$langs->trans("MakeAnonymousPing").'</label>';
  513. $out .= '<!-- Add js script to manage the uncheck of option to not send the ping -->';
  514. $out .= '<script type="text/javascript">';
  515. $out .= 'jQuery(document).ready(function(){';
  516. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  517. $out .= ' jQuery("#dolibarrpingno").click(function() {';
  518. $out .= ' if (! $(this).is(\':checked\')) {';
  519. $out .= ' console.log("We uncheck anonymous ping");';
  520. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=1; path=/"'."\n";
  521. $out .= ' } else {'."\n";
  522. $out .= ' console.log("We check anonymous ping");';
  523. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  524. $out .= ' }'."\n";
  525. $out .= ' });';
  526. $out .= '});';
  527. $out .= '</script>';
  528. print $out;
  529. pFooter($ok ? 0 : 1, $setuplang);
  530. if (isset($db) && is_object($db)) {
  531. $db->close();
  532. }
  533. // Return code if ran from command line
  534. if ($ret) {
  535. exit($ret);
  536. }