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