28require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
29require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
30require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
41$err = error_reporting();
47$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
48$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
49$langs->setDefaultLang($setuplang);
51$langs->loadLangs(array(
"admin",
"install"));
57if ($dolibarr_main_db_type ==
"mysqli") {
60if ($dolibarr_main_db_type ==
"pgsql") {
63if ($dolibarr_main_db_type ==
"mssql") {
66if ($dolibarr_main_db_type ==
"sqlite") {
69if ($dolibarr_main_db_type ==
"sqlite3") {
77$useforcedwizard =
false;
78$forcedfile =
"./install.forced.php";
79if ($conffile ==
"/etc/dolibarr/conf.php") {
80 $forcedfile =
"/etc/dolibarr/install.forced.php";
82if (@file_exists($forcedfile)) {
83 $useforcedwizard =
true;
84 include_once $forcedfile;
86 if (!empty($argv[1]) && $argv[1] ==
"set") {
98pHeader($langs->trans(
"CreateDatabaseObjects"),
"step4");
101if (!is_writable($conffile)) {
102 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
103 pFooter(1, $setuplang,
'jscheckparam');
107if ($action ==
"set") {
108 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
110 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
113 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
115 if ($db->connected) {
117 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
120 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
124 if ($db->database_selected) {
128 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
136 $version = $db->getVersion();
137 $versionarray = $db->getVersionArray();
138 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
139 print
'<td>'.$version.
'</td></tr>';
142 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
143 print
'<td>'.$db->database_name.
'</td></tr>';
151 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
152 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
153 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
154 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
158 if (property_exists($db,
'unescapeslashquot')) {
159 $db->unescapeslashquot =
true;
168 if ($ok && $createtables) {
170 $dir =
"mysql/tables/";
173 $handle = opendir($dir);
176 $tabledata = array();
177 if (is_resource($handle)) {
178 while (($file = readdir($handle)) !==
false) {
179 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
181 $tabledata[] = $file;
189 foreach ($tabledata as $file) {
190 $name = substr($file, 0,
dol_strlen($file) - 4);
192 $fp = fopen($dir.$file,
"r");
195 $buf = fgets($fp, 4096);
196 if (substr($buf, 0, 2) !=
'--') {
197 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
203 $buffer = trim($buffer);
204 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
205 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
209 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
210 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
214 if ($dolibarr_main_db_prefix !=
'llx_') {
215 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
222 $resql = $db->query($buffer, 0,
'dml');
227 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
228 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
231 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
232 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
234 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
239 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
241 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
250 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
254 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
266 if ($ok && $createkeys) {
268 $dir =
"mysql/tables/";
271 $handle = opendir($dir);
274 $tabledata = array();
275 if (is_resource($handle)) {
276 while (($file = readdir($handle)) !==
false) {
277 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
279 $tabledata[] = $file;
287 foreach ($tabledata as $file) {
288 $name = substr($file, 0,
dol_strlen($file) - 4);
291 $fp = fopen($dir.$file,
"r");
294 $buf = fgets($fp, 4096);
298 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
299 $versioncommande = explode(
'.', $reg[1]);
302 if (count($versioncommande) && count($versionarray)
305 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
310 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
311 $versioncommande = explode(
'.', $reg[1]);
314 if (count($versioncommande) && count($versionarray)
317 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
323 if (!preg_match(
'/^--/i', $buf)) {
330 $listesql = explode(
';', $buffer);
331 foreach ($listesql as $req) {
332 $buffer = trim($req);
335 if ($dolibarr_main_db_prefix !=
'llx_') {
336 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
343 $resql = $db->query($buffer, 0,
'dml');
348 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
349 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
350 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
351 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
352 preg_match(
'/duplicate key name/i', $db->error())) {
356 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
357 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
359 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
366 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
368 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
374 if ($tablefound && $error == 0) {
376 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
387 if ($ok && $createfunctions) {
390 $dir =
"mysql/functions/";
391 } elseif ($choix == 2) {
392 $dir =
"pgsql/functions/";
393 } elseif ($choix == 3) {
394 $dir =
"mssql/functions/";
395 } elseif ($choix == 4) {
396 $dir =
"sqlite3/functions/";
400 $file =
"functions.sql";
401 if (file_exists($dir.$file)) {
402 $fp = fopen($dir.$file,
"r");
407 $buf = fgets($fp, 4096);
408 if (substr($buf, 0, 2) !=
'--') {
417 $listesql = explode(
'§', $buffer);
418 foreach ($listesql as $buffer) {
419 $buffer = trim($buffer);
422 if ($dolibarr_main_db_prefix !=
'llx_') {
423 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
426 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
427 $resql = $db->query($buffer, 0,
'dml');
432 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
433 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
438 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
439 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
441 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
448 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
450 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
452 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
464 if ($ok && $createdata) {
466 $dir =
"mysql/data/";
469 $handle = opendir($dir);
472 $tabledata = array();
473 if (is_resource($handle)) {
474 while (($file = readdir($handle)) !==
false) {
475 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
476 if (preg_match(
'/^llx_accounting_account_/', $file)) {
481 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
483 $tabledata[] = $file;
492 foreach ($tabledata as $file) {
493 $name = substr($file, 0,
dol_strlen($file) - 4);
494 $fp = fopen($dir.$file,
"r");
497 $arrayofrequests = array();
504 $buffer = fgets($fp, 4096);
505 $buffer = trim($buffer);
507 if (substr($buffer, 0, 2) ==
'--') {
511 if ($linefound && ($linefound % $sizeofgroup) == 0) {
514 if (empty($arrayofrequests[$linegroup])) {
515 $arrayofrequests[$linegroup] = $buffer;
517 $arrayofrequests[$linegroup] .=
" ".$buffer;
531 foreach ($arrayofrequests as $buffer) {
533 if ($dolibarr_main_db_prefix !=
'llx_') {
534 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
538 $resql = $db->query($buffer, 1);
542 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
547 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
560 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
562 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
564 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
570 print
'Parameter action=set not defined';
575if (!$ok && isset($argv[1])) {
586$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);
588$hash_unique_id =
dol_hash(
'dolibarr'.$conf->file->instance_unique_id,
'sha256');
590$out =
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
591$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
593$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
594$out .=
'<script type="text/javascript">';
595$out .=
'jQuery(document).ready(function(){';
596$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
597$out .=
' jQuery("#dolibarrpingno").click(function() {';
598$out .=
' if (! $(this).is(\':checked\')) {';
599$out .=
' console.log("We uncheck anonymous ping");';
600$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
601$out .=
' } else {'.
"\n";
602$out .=
' console.log("We check anonymous ping");';
603$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
611pFooter($ok ? 0 : 1, $setuplang);
613if (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.
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.