step2.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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, $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 = isset($_GET['createtables']) ?GETPOST('createtables') : 1;
  121. $createkeys = isset($_GET['createkeys']) ?GETPOST('createkeys') : 1;
  122. $createfunctions = isset($_GET['createfunctions']) ?GETPOST('createfunction') : 1;
  123. $createdata = isset($_GET['createdata']) ?GETPOST('createdata') : 1;
  124. // To say sql requests are escaped for mysql so we need to unescape them
  125. $db->unescapeslashquot = true;
  126. /**************************************************************************************
  127. *
  128. * Load files tables/*.sql (not the *.key.sql). Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  129. * To do before the files *.key.sql
  130. *
  131. ***************************************************************************************/
  132. if ($ok && $createtables) {
  133. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  134. $dir = "mysql/tables/";
  135. $ok = 0;
  136. $handle = opendir($dir);
  137. dolibarr_install_syslog("step2: open tables directory ".$dir." handle=".$handle);
  138. $tablefound = 0;
  139. $tabledata = array();
  140. if (is_resource($handle)) {
  141. while (($file = readdir($handle)) !== false) {
  142. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  143. $tablefound++;
  144. $tabledata[] = $file;
  145. }
  146. }
  147. closedir($handle);
  148. }
  149. // Sort list of sql files on alphabetical order (load order is important)
  150. sort($tabledata);
  151. foreach ($tabledata as $file) {
  152. $name = substr($file, 0, dol_strlen($file) - 4);
  153. $buffer = '';
  154. $fp = fopen($dir.$file, "r");
  155. if ($fp) {
  156. while (!feof($fp)) {
  157. $buf = fgets($fp, 4096);
  158. if (substr($buf, 0, 2) <> '--') {
  159. $buf = preg_replace('/--(.+)*/', '', $buf);
  160. $buffer .= $buf;
  161. }
  162. }
  163. fclose($fp);
  164. $buffer = trim($buffer);
  165. if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb
  166. $buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer);
  167. } else {
  168. // Keyword ENGINE is MySQL-specific, so scrub it for
  169. // other database types (mssql, pgsql)
  170. $buffer = preg_replace('/type=innodb/i', '', $buffer);
  171. $buffer = preg_replace('/ENGINE=innodb/i', '', $buffer);
  172. }
  173. // Replace the prefix tables
  174. if ($dolibarr_main_db_prefix != 'llx_') {
  175. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  176. }
  177. //print "<tr><td>Creation of table $name/td>";
  178. $requestnb++;
  179. dolibarr_install_syslog("step2: request: ".$buffer);
  180. $resql = $db->query($buffer, 0, 'dml');
  181. if ($resql) {
  182. // print "<td>OK request ==== $buffer</td></tr>";
  183. $db->free($resql);
  184. } else {
  185. if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' ||
  186. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
  187. //print "<td>already existing</td></tr>";
  188. } else {
  189. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  190. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer.' <br>Executed query : '.$db->lastquery;
  191. print "\n</td>";
  192. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  193. $error++;
  194. }
  195. }
  196. } else {
  197. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  198. print "</td>";
  199. print '<td><span class="error">'.$langs->trans("Error").' Failed to open file '.$dir.$file.'</span></td></tr>';
  200. $error++;
  201. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  202. }
  203. }
  204. if ($tablefound) {
  205. if ($error == 0) {
  206. print '<tr><td>';
  207. print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  208. $ok = 1;
  209. }
  210. } else {
  211. print '<tr><td>'.$langs->trans("ErrorFailedToFindSomeFiles", $dir).'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  212. dolibarr_install_syslog("step2: failed to find files to create database in directory ".$dir, LOG_ERR);
  213. }
  214. }
  215. /***************************************************************************************
  216. *
  217. * Load files tables/*.key.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  218. * To do after the files *.sql
  219. *
  220. ***************************************************************************************/
  221. if ($ok && $createkeys) {
  222. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  223. $dir = "mysql/tables/";
  224. $okkeys = 0;
  225. $handle = opendir($dir);
  226. dolibarr_install_syslog("step2: open keys directory ".$dir." handle=".$handle);
  227. $tablefound = 0;
  228. $tabledata = array();
  229. if (is_resource($handle)) {
  230. while (($file = readdir($handle)) !== false) {
  231. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  232. $tablefound++;
  233. $tabledata[] = $file;
  234. }
  235. }
  236. closedir($handle);
  237. }
  238. // Sort list of sql files on alphabetical order (load order is important)
  239. sort($tabledata);
  240. foreach ($tabledata as $file) {
  241. $name = substr($file, 0, dol_strlen($file) - 4);
  242. //print "<tr><td>Creation of table $name</td>";
  243. $buffer = '';
  244. $fp = fopen($dir.$file, "r");
  245. if ($fp) {
  246. while (!feof($fp)) {
  247. $buf = fgets($fp, 4096);
  248. // Special case of lines allowed for some version only
  249. // MySQL
  250. if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) {
  251. $versioncommande = explode('.', $reg[1]);
  252. //var_dump($versioncommande);
  253. //var_dump($versionarray);
  254. if (count($versioncommande) && count($versionarray)
  255. && versioncompare($versioncommande, $versionarray) <= 0) {
  256. // Version qualified, delete SQL comments
  257. $buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf);
  258. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  259. }
  260. }
  261. // PGSQL
  262. if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
  263. $versioncommande = explode('.', $reg[1]);
  264. //var_dump($versioncommande);
  265. //var_dump($versionarray);
  266. if (count($versioncommande) && count($versionarray)
  267. && versioncompare($versioncommande, $versionarray) <= 0) {
  268. // Version qualified, delete SQL comments
  269. $buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf);
  270. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  271. }
  272. }
  273. // Add line if no comment
  274. if (!preg_match('/^--/i', $buf)) {
  275. $buffer .= $buf;
  276. }
  277. }
  278. fclose($fp);
  279. // If several requests, we loop on each
  280. $listesql = explode(';', $buffer);
  281. foreach ($listesql as $req) {
  282. $buffer = trim($req);
  283. if ($buffer) {
  284. // Replace the prefix tables
  285. if ($dolibarr_main_db_prefix != 'llx_') {
  286. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  287. }
  288. //print "<tr><td>Creation of keys and table index $name: '$buffer'</td>";
  289. $requestnb++;
  290. dolibarr_install_syslog("step2: request: ".$buffer);
  291. $resql = $db->query($buffer, 0, 'dml');
  292. if ($resql) {
  293. //print "<td>OK request ==== $buffer</td></tr>";
  294. $db->free($resql);
  295. } else {
  296. if ($db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
  297. $db->errno() == 'DB_ERROR_CANNOT_CREATE' ||
  298. $db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
  299. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
  300. preg_match('/duplicate key name/i', $db->error())) {
  301. //print "<td>Deja existante</td></tr>";
  302. $key_exists = 1;
  303. } else {
  304. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  305. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$db->lastqueryerror();
  306. print "\n</td>";
  307. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  308. $error++;
  309. }
  310. }
  311. }
  312. }
  313. } else {
  314. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  315. print "</td>";
  316. print '<td><span class="error">'.$langs->trans("Error")." Failed to open file ".$dir.$file."</span></td></tr>";
  317. $error++;
  318. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  319. }
  320. }
  321. if ($tablefound && $error == 0) {
  322. print '<tr><td>';
  323. print $langs->trans("OtherKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  324. $okkeys = 1;
  325. }
  326. }
  327. /***************************************************************************************
  328. *
  329. * Load the file 'functions.sql'
  330. *
  331. ***************************************************************************************/
  332. if ($ok && $createfunctions) {
  333. // For this file, we use a directory according to database type
  334. if ($choix == 1) {
  335. $dir = "mysql/functions/";
  336. } elseif ($choix == 2) {
  337. $dir = "pgsql/functions/";
  338. } elseif ($choix == 3) {
  339. $dir = "mssql/functions/";
  340. } elseif ($choix == 4) {
  341. $dir = "sqlite3/functions/";
  342. }
  343. // Creation of data
  344. $file = "functions.sql";
  345. if (file_exists($dir.$file)) {
  346. $fp = fopen($dir.$file, "r");
  347. dolibarr_install_syslog("step2: open function file ".$dir.$file." handle=".$fp);
  348. if ($fp) {
  349. $buffer = '';
  350. while (!feof($fp)) {
  351. $buf = fgets($fp, 4096);
  352. if (substr($buf, 0, 2) <> '--') {
  353. $buffer .= $buf."§";
  354. }
  355. }
  356. fclose($fp);
  357. }
  358. //$buffer=preg_replace('/;\';/',";'§",$buffer);
  359. // If several requests, we loop on each of them
  360. $listesql = explode('§', $buffer);
  361. foreach ($listesql as $buffer) {
  362. $buffer = trim($buffer);
  363. if ($buffer) {
  364. // Replace the prefix in table names
  365. if ($dolibarr_main_db_prefix != 'llx_') {
  366. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  367. }
  368. dolibarr_install_syslog("step2: request: ".$buffer);
  369. print "<!-- Insert line : ".$buffer."<br>-->\n";
  370. $resql = $db->query($buffer, 0, 'dml');
  371. if ($resql) {
  372. $ok = 1;
  373. $db->free($resql);
  374. } else {
  375. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
  376. || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
  377. //print "Insert line : ".$buffer."<br>\n";
  378. } else {
  379. $ok = 0;
  380. print "<tr><td>".$langs->trans("FunctionsCreation");
  381. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer;
  382. print "\n</td>";
  383. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  384. $error++;
  385. }
  386. }
  387. }
  388. }
  389. print "<tr><td>".$langs->trans("FunctionsCreation")."</td>";
  390. if ($ok) {
  391. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  392. } else {
  393. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  394. $ok = 1;
  395. }
  396. }
  397. }
  398. /***************************************************************************************
  399. *
  400. * Load files data/*.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  401. *
  402. ***************************************************************************************/
  403. if ($ok && $createdata) {
  404. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  405. $dir = "mysql/data/";
  406. // Insert data
  407. $handle = opendir($dir);
  408. dolibarr_install_syslog("step2: open directory data ".$dir." handle=".$handle);
  409. $tablefound = 0;
  410. $tabledata = array();
  411. if (is_resource($handle)) {
  412. while (($file = readdir($handle)) !== false) {
  413. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\-/', $file)) {
  414. if (preg_match('/^llx_accounting_account_/', $file)) {
  415. continue; // We discard data file of chart of account. This will be loaded when a chart is selected.
  416. }
  417. //print 'x'.$file.'-'.$createdata.'<br>';
  418. if (is_numeric($createdata) || preg_match('/'.preg_quote($createdata).'/i', $file)) {
  419. $tablefound++;
  420. $tabledata[] = $file;
  421. }
  422. }
  423. }
  424. closedir($handle);
  425. }
  426. // Sort list of data files on alphabetical order (load order is important)
  427. sort($tabledata);
  428. foreach ($tabledata as $file) {
  429. $name = substr($file, 0, dol_strlen($file) - 4);
  430. $fp = fopen($dir.$file, "r");
  431. dolibarr_install_syslog("step2: open data file ".$dir.$file." handle=".$fp);
  432. if ($fp) {
  433. $arrayofrequests = array();
  434. $linefound = 0;
  435. $linegroup = 0;
  436. $sizeofgroup = 1; // Grouping request to have 1 query for several requests does not works with mysql, so we use 1.
  437. // Load all requests
  438. while (!feof($fp)) {
  439. $buffer = fgets($fp, 4096);
  440. $buffer = trim($buffer);
  441. if ($buffer) {
  442. if (substr($buffer, 0, 2) == '--') {
  443. continue;
  444. }
  445. if ($linefound && ($linefound % $sizeofgroup) == 0) {
  446. $linegroup++;
  447. }
  448. if (empty($arrayofrequests[$linegroup])) {
  449. $arrayofrequests[$linegroup] = $buffer;
  450. } else {
  451. $arrayofrequests[$linegroup] .= " ".$buffer;
  452. }
  453. $linefound++;
  454. }
  455. }
  456. fclose($fp);
  457. dolibarr_install_syslog("step2: found ".$linefound." records, defined ".count($arrayofrequests)." group(s).");
  458. $okallfile = 1;
  459. $db->begin();
  460. // We loop on each requests of file
  461. foreach ($arrayofrequests as $buffer) {
  462. // Replace the tables prefixes
  463. if ($dolibarr_main_db_prefix != 'llx_') {
  464. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  465. }
  466. //dolibarr_install_syslog("step2: request: " . $buffer);
  467. $resql = $db->query($buffer, 1);
  468. if ($resql) {
  469. //$db->free($resql); // Not required as request we launch here does not return memory needs.
  470. } else {
  471. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  472. //print "<tr><td>Insertion ligne : $buffer</td><td>";
  473. } else {
  474. $ok = 0;
  475. $okallfile = 0;
  476. print '<span class="error">'.$langs->trans("ErrorSQL")." : ".$db->lasterrno()." - ".$db->lastqueryerror()." - ".$db->lasterror()."</span><br>";
  477. }
  478. }
  479. }
  480. if ($okallfile) {
  481. $db->commit();
  482. } else {
  483. $db->rollback();
  484. }
  485. }
  486. }
  487. print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>";
  488. if ($ok) {
  489. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  490. } else {
  491. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  492. $ok = 1; // Data loading are not blocking errors
  493. }
  494. }
  495. print '</table>';
  496. } else {
  497. print 'Parameter action=set not defined';
  498. }
  499. $ret = 0;
  500. if (!$ok && isset($argv[1])) {
  501. $ret = 1;
  502. }
  503. dolibarr_install_syslog("Exit ".$ret);
  504. dolibarr_install_syslog("- step2: end");
  505. // Force here a value we need after because master.inc.php is not loaded into step2.
  506. // This code must be similar with the one into main.inc.php
  507. $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
  508. $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id);
  509. $out = '<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((!empty($conf->global->MAIN_FIRST_PING_OK_ID) && $conf->global->MAIN_FIRST_PING_OK_ID == 'disabled') ? '' : ' value="checked" checked="true"').'> ';
  510. $out .= '<label for="dolibarrpingno">'.$langs->trans("MakeAnonymousPing").'</label>';
  511. $out .= '<!-- Add js script to manage the uncheck of option to not send the ping -->';
  512. $out .= '<script type="text/javascript">';
  513. $out .= 'jQuery(document).ready(function(){';
  514. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  515. $out .= ' jQuery("#dolibarrpingno").click(function() {';
  516. $out .= ' if (! $(this).is(\':checked\')) {';
  517. $out .= ' console.log("We uncheck anonymous ping");';
  518. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=1; path=/"'."\n";
  519. $out .= ' } else {'."\n";
  520. $out .= ' console.log("We check anonymous ping");';
  521. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  522. $out .= ' }'."\n";
  523. $out .= ' });';
  524. $out .= '});';
  525. $out .= '</script>';
  526. print $out;
  527. pFooter($ok ? 0 : 1, $setuplang);
  528. if (isset($db) && is_object($db)) {
  529. $db->close();
  530. }
  531. // Return code if ran from command line
  532. if ($ret) {
  533. exit($ret);
  534. }