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';
42 $err = error_reporting();
45 @set_time_limit(1800);
46 error_reporting($err);
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);
52 $langs->loadLangs(array(
"admin",
"install"));
58 if ($dolibarr_main_db_type ==
"mysqli") {
61 if ($dolibarr_main_db_type ==
"pgsql") {
64 if ($dolibarr_main_db_type ==
"mssql") {
67 if ($dolibarr_main_db_type ==
"sqlite") {
70 if ($dolibarr_main_db_type ==
"sqlite3") {
78 $useforcedwizard =
false;
79 $forcedfile =
"./install.forced.php";
80 if ($conffile ==
"/etc/dolibarr/conf.php") {
81 $forcedfile =
"/etc/dolibarr/install.forced.php";
83 if (@file_exists($forcedfile)) {
84 $useforcedwizard =
true;
85 include_once $forcedfile;
87 if (!empty($argv[1]) && $argv[1] ==
"set") {
94 '@phan-var-force string $dolibarr_main_db_prefix';
100 pHeader($langs->trans(
"CreateDatabaseObjects"),
"step4");
103 if (!is_writable($conffile)) {
104 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
105 pFooter(1, $setuplang,
'jscheckparam');
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>';
112 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
115 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
117 if ($db->connected) {
119 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
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>';
126 if ($db->database_selected) {
130 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
138 $version = $db->getVersion();
139 $versionarray = $db->getVersionArray();
140 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
141 print
'<td>'.$version.
'</td></tr>';
144 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
145 print
'<td>'.$db->database_name.
'</td></tr>';
160 if (property_exists($db,
'unescapeslashquot')) {
161 $db->unescapeslashquot =
true;
170 if ($ok && $createtables) {
172 $dir =
"mysql/tables/";
175 $handle = opendir($dir);
176 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
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)) {
183 $tabledata[] = $file;
191 foreach ($tabledata as $file) {
192 $name = substr($file, 0,
dol_strlen($file) - 4);
194 $fp = fopen($dir.$file,
"r");
197 $buf = fgets($fp, 4096);
198 if (substr($buf, 0, 2) !=
'--') {
199 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
205 $buffer = trim($buffer);
206 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
207 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
211 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
212 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
216 if ($dolibarr_main_db_prefix !=
'llx_') {
217 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
224 $resql = $db->query($buffer, 0,
'dml');
229 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
230 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
233 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
234 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
236 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
241 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
243 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
252 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
256 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
268 if ($ok && $createkeys) {
270 $dir =
"mysql/tables/";
273 $handle = opendir($dir);
274 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
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)) {
281 $tabledata[] = $file;
289 foreach ($tabledata as $file) {
290 $name = substr($file, 0,
dol_strlen($file) - 4);
293 $fp = fopen($dir.$file,
"r");
296 $buf = fgets($fp, 4096);
300 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
301 $versioncommande = explode(
'.', $reg[1]);
304 if (count($versioncommande) && count($versionarray)
307 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
312 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
313 $versioncommande = explode(
'.', $reg[1]);
316 if (count($versioncommande) && count($versionarray)
319 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
325 if (!preg_match(
'/^--/i', $buf)) {
332 $listesql = explode(
';', $buffer);
333 foreach ($listesql as $req) {
334 $buffer = trim($req);
337 if ($dolibarr_main_db_prefix !=
'llx_') {
338 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
345 $resql = $db->query($buffer, 0,
'dml');
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())) {
358 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
359 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
361 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
368 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
370 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
376 if ($tablefound && $error == 0) {
378 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
389 if ($ok && $createfunctions) {
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/";
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));
409 $buf = fgets($fp, 4096);
410 if (substr($buf, 0, 2) !=
'--') {
419 $listesql = explode(
'§', $buffer);
420 foreach ($listesql as $buffer) {
421 $buffer = trim($buffer);
424 if ($dolibarr_main_db_prefix !=
'llx_') {
425 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
428 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
429 $resql = $db->query($buffer, 0,
'dml');
434 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
435 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
440 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
441 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
443 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
450 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
452 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
454 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
466 if ($ok && $createdata) {
468 $dir =
"mysql/data/";
471 $handle = opendir($dir);
472 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
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)) {
483 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
485 $tabledata[] = $file;
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));
499 $arrayofrequests = array();
506 $buffer = fgets($fp, 4096);
507 $buffer = trim($buffer);
509 if (substr($buffer, 0, 2) ==
'--') {
513 if ($linefound && ($linefound % $sizeofgroup) == 0) {
516 if (empty($arrayofrequests[$linegroup])) {
517 $arrayofrequests[$linegroup] = $buffer;
519 $arrayofrequests[$linegroup] .=
" ".$buffer;
533 foreach ($arrayofrequests as $buffer) {
535 if ($dolibarr_main_db_prefix !=
'llx_') {
536 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
540 $resql = $db->query($buffer, 1);
544 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
549 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
562 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
564 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
566 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
572 print
'Parameter action=set not defined';
577 if (!$ok && isset($argv[1])) {
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);
590 $hash_unique_id =
dol_hash(
'dolibarr'.$conf->file->instance_unique_id,
'sha256');
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>';
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";
613 pFooter($ok ? 0 : 1, $setuplang);
615 if (isset($db) && is_object($db)) {
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
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.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.