28require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
29require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
40$err = error_reporting();
46$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
47$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
48$langs->setDefaultLang($setuplang);
50$langs->loadLangs(array(
"admin",
"install"));
56if ($dolibarr_main_db_type ==
"mysqli") {
59if ($dolibarr_main_db_type ==
"pgsql") {
62if ($dolibarr_main_db_type ==
"mssql") {
65if ($dolibarr_main_db_type ==
"sqlite") {
68if ($dolibarr_main_db_type ==
"sqlite3") {
76$useforcedwizard =
false;
77$forcedfile =
"./install.forced.php";
78if ($conffile ==
"/etc/dolibarr/conf.php") {
79 $forcedfile =
"/etc/dolibarr/install.forced.php";
81if (@file_exists($forcedfile)) {
82 $useforcedwizard =
true;
83 include_once $forcedfile;
85 if (!empty($argv[1]) && $argv[1] ==
"set") {
97pHeader($langs->trans(
"CreateDatabaseObjects"),
"step4");
100if (!is_writable($conffile)) {
101 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
102 pFooter(1, $setuplang,
'jscheckparam');
106if ($action ==
"set") {
107 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
109 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
112 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
114 if ($db->connected) {
116 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
119 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 if ($db->database_selected) {
127 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
135 $version = $db->getVersion();
136 $versionarray = $db->getVersionArray();
137 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
138 print
'<td>'.$version.
'</td></tr>';
141 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
142 print
'<td>'.$db->database_name.
'</td></tr>';
150 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
151 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
152 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
153 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
157 $db->unescapeslashquot =
true;
166 if ($ok && $createtables) {
168 $dir =
"mysql/tables/";
171 $handle = opendir($dir);
174 $tabledata = array();
175 if (is_resource($handle)) {
176 while (($file = readdir($handle)) !==
false) {
177 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
179 $tabledata[] = $file;
187 foreach ($tabledata as $file) {
188 $name = substr($file, 0,
dol_strlen($file) - 4);
190 $fp = fopen($dir.$file,
"r");
193 $buf = fgets($fp, 4096);
194 if (substr($buf, 0, 2) <>
'--') {
195 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
201 $buffer = trim($buffer);
202 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
203 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
207 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
208 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
212 if ($dolibarr_main_db_prefix !=
'llx_') {
213 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
220 $resql = $db->query($buffer, 0,
'dml');
225 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
226 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
229 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
230 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
232 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
237 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
239 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
248 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
252 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
264 if ($ok && $createkeys) {
266 $dir =
"mysql/tables/";
269 $handle = opendir($dir);
272 $tabledata = array();
273 if (is_resource($handle)) {
274 while (($file = readdir($handle)) !==
false) {
275 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
277 $tabledata[] = $file;
285 foreach ($tabledata as $file) {
286 $name = substr($file, 0,
dol_strlen($file) - 4);
289 $fp = fopen($dir.$file,
"r");
292 $buf = fgets($fp, 4096);
296 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
297 $versioncommande = explode(
'.', $reg[1]);
300 if (count($versioncommande) && count($versionarray)
303 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
308 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
309 $versioncommande = explode(
'.', $reg[1]);
312 if (count($versioncommande) && count($versionarray)
315 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
321 if (!preg_match(
'/^--/i', $buf)) {
328 $listesql = explode(
';', $buffer);
329 foreach ($listesql as $req) {
330 $buffer = trim($req);
333 if ($dolibarr_main_db_prefix !=
'llx_') {
334 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
341 $resql = $db->query($buffer, 0,
'dml');
346 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
347 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
348 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
349 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
350 preg_match(
'/duplicate key name/i', $db->error())) {
354 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
355 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
357 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
364 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
366 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
372 if ($tablefound && $error == 0) {
374 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
385 if ($ok && $createfunctions) {
388 $dir =
"mysql/functions/";
389 } elseif ($choix == 2) {
390 $dir =
"pgsql/functions/";
391 } elseif ($choix == 3) {
392 $dir =
"mssql/functions/";
393 } elseif ($choix == 4) {
394 $dir =
"sqlite3/functions/";
398 $file =
"functions.sql";
399 if (file_exists($dir.$file)) {
400 $fp = fopen($dir.$file,
"r");
405 $buf = fgets($fp, 4096);
406 if (substr($buf, 0, 2) <>
'--') {
415 $listesql = explode(
'§', $buffer);
416 foreach ($listesql as $buffer) {
417 $buffer = trim($buffer);
420 if ($dolibarr_main_db_prefix !=
'llx_') {
421 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
424 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
425 $resql = $db->query($buffer, 0,
'dml');
430 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
431 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
436 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
437 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
439 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
446 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
448 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
450 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
462 if ($ok && $createdata) {
464 $dir =
"mysql/data/";
467 $handle = opendir($dir);
470 $tabledata = array();
471 if (is_resource($handle)) {
472 while (($file = readdir($handle)) !==
false) {
473 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
474 if (preg_match(
'/^llx_accounting_account_/', $file)) {
479 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
481 $tabledata[] = $file;
490 foreach ($tabledata as $file) {
491 $name = substr($file, 0,
dol_strlen($file) - 4);
492 $fp = fopen($dir.$file,
"r");
495 $arrayofrequests = array();
502 $buffer = fgets($fp, 4096);
503 $buffer = trim($buffer);
505 if (substr($buffer, 0, 2) ==
'--') {
509 if ($linefound && ($linefound % $sizeofgroup) == 0) {
512 if (empty($arrayofrequests[$linegroup])) {
513 $arrayofrequests[$linegroup] = $buffer;
515 $arrayofrequests[$linegroup] .=
" ".$buffer;
529 foreach ($arrayofrequests as $buffer) {
531 if ($dolibarr_main_db_prefix !=
'llx_') {
532 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
536 $resql = $db->query($buffer, 1);
540 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
545 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
558 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
560 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
562 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
568 print
'Parameter action=set not defined';
573if (!$ok && isset($argv[1])) {
584$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);
586$hash_unique_id = md5(
'dolibarr'.$conf->file->instance_unique_id);
588$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"').
'> ';
589$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
591$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
592$out .=
'<script type="text/javascript">';
593$out .=
'jQuery(document).ready(function(){';
594$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
595$out .=
' jQuery("#dolibarrpingno").click(function() {';
596$out .=
' if (! $(this).is(\':checked\')) {';
597$out .=
' console.log("We uncheck anonymous ping");';
598$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
599$out .=
' } else {'.
"\n";
600$out .=
' console.log("We check anonymous ping");';
601$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
609pFooter($ok ? 0 : 1, $setuplang);
611if (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.