29require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
30require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
31require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
42$err = error_reporting();
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"));
58if ($dolibarr_main_db_type ==
"mysqli") {
61if ($dolibarr_main_db_type ==
"pgsql") {
64if ($dolibarr_main_db_type ==
"mssql") {
67if ($dolibarr_main_db_type ==
"sqlite") {
70if ($dolibarr_main_db_type ==
"sqlite3") {
78$useforcedwizard =
false;
79$forcedfile =
"./install.forced.php";
80if ($conffile ==
"/etc/dolibarr/conf.php") {
81 $forcedfile =
"/etc/dolibarr/install.forced.php";
83if (@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';
108pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"CreateDatabaseObjects"),
"step4");
111if (!is_writable($conffile)) {
112 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
113 pFooter(1, $setuplang,
'jscheckparam');
117if ($action ==
"set") {
118 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
120 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
123 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
125 if ($db->connected) {
127 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
130 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
134 if ($db->database_selected) {
138 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
146 $version = $db->getVersion();
147 $versionarray = $db->getVersionArray();
148 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
149 print
'<td>'.$version.
'</td></tr>';
152 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
153 print
'<td>'.$db->database_name.
'</td></tr>';
161 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
162 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
163 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
164 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
168 if (property_exists($db,
'unescapeslashquot')) {
169 $db->unescapeslashquot =
true;
178 if ($ok && $createtables) {
180 $dir =
"mysql/tables/";
183 $handle = opendir($dir);
184 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
186 $tabledata = array();
187 if (is_resource($handle)) {
188 while (($file = readdir($handle)) !==
false) {
189 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
191 $tabledata[] = $file;
199 foreach ($tabledata as $file) {
200 $name = substr($file, 0,
dol_strlen($file) - 4);
202 $fp = fopen($dir.$file,
"r");
205 $buf = fgets($fp, 4096);
206 if (substr($buf, 0, 2) !=
'--') {
207 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
213 $buffer = trim($buffer);
214 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
215 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
219 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
220 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
224 if ($dolibarr_main_db_prefix !=
'llx_') {
225 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
232 $resql = $db->query($buffer, 0,
'dml');
237 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
238 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
241 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
242 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
244 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
249 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
251 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
260 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
264 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
276 if ($ok && $createkeys) {
278 $dir =
"mysql/tables/";
281 $handle = opendir($dir);
282 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
284 $tabledata = array();
285 if (is_resource($handle)) {
286 while (($file = readdir($handle)) !==
false) {
287 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
289 $tabledata[] = $file;
297 foreach ($tabledata as $file) {
298 $name = substr($file, 0,
dol_strlen($file) - 4);
301 $fp = fopen($dir.$file,
"r");
304 $buf = fgets($fp, 4096);
308 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
309 $versioncommande = explode(
'.', $reg[1]);
312 if (count($versioncommande) && count($versionarray)
315 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
320 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
321 $versioncommande = explode(
'.', $reg[1]);
324 if (count($versioncommande) && count($versionarray)
327 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
333 if (!preg_match(
'/^--/i', $buf)) {
340 $listesql = explode(
';', $buffer);
341 foreach ($listesql as $req) {
342 $buffer = trim($req);
345 if ($dolibarr_main_db_prefix !=
'llx_') {
346 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
353 $resql = $db->query($buffer, 0,
'dml');
358 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
359 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
360 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
361 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
362 preg_match(
'/duplicate key name/i', $db->error())) {
366 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
367 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
369 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
376 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
378 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
384 if ($tablefound && $error == 0) {
386 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
397 if ($ok && $createfunctions) {
400 $dir =
"mysql/functions/";
401 } elseif ($choix == 2) {
402 $dir =
"pgsql/functions/";
403 } elseif ($choix == 3) {
404 $dir =
"mssql/functions/";
405 } elseif ($choix == 4) {
406 $dir =
"sqlite3/functions/";
410 $file =
"functions.sql";
411 if (file_exists($dir.$file)) {
412 $fp = fopen($dir.$file,
"r");
413 dolibarr_install_syslog(
"step2: open function file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
417 $buf = fgets($fp, 4096);
418 if (substr($buf, 0, 2) !=
'--') {
427 $listesql = explode(
'§', $buffer);
428 foreach ($listesql as $buffer) {
429 $buffer = trim($buffer);
432 if ($dolibarr_main_db_prefix !=
'llx_') {
433 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
436 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
437 $resql = $db->query($buffer, 0,
'dml');
442 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
443 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
448 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
449 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
451 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
458 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
460 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
462 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
474 if ($ok && $createdata) {
476 $dir =
"mysql/data/";
479 $handle = opendir($dir);
480 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
482 $tabledata = array();
483 if (is_resource($handle)) {
484 while (($file = readdir($handle)) !==
false) {
485 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
486 if (preg_match(
'/^llx_accounting_account_/', $file)) {
491 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
493 $tabledata[] = $file;
502 foreach ($tabledata as $file) {
503 $name = substr($file, 0,
dol_strlen($file) - 4);
504 $fp = fopen($dir.$file,
"r");
505 dolibarr_install_syslog(
"step2: open data file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
507 $arrayofrequests = array();
514 $buffer = fgets($fp, 4096);
515 $buffer = trim($buffer);
517 if (substr($buffer, 0, 2) ==
'--') {
521 if ($linefound && ($linefound % $sizeofgroup) == 0) {
524 if (empty($arrayofrequests[$linegroup])) {
525 $arrayofrequests[$linegroup] = $buffer;
527 $arrayofrequests[$linegroup] .=
" ".$buffer;
541 foreach ($arrayofrequests as $buffer) {
543 if ($dolibarr_main_db_prefix !=
'llx_') {
544 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
548 $buffer = preg_replace(
'/__ENTITY__/i',
'1', $buffer);
551 $resql = $db->query($buffer, 1);
555 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
560 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
573 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
575 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
577 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
583 print
'Parameter action=set not defined';
588if (!$ok && isset($argv[1])) {
599$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);
601$hash_unique_id =
dol_hash(
'dolibarr'.$conf->file->instance_unique_id,
'sha256');
603$out =
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
604$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
606$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
607$out .=
'<script type="text/javascript">';
608$out .=
'jQuery(document).ready(function(){';
609$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
610$out .=
' jQuery("#dolibarrpingno").click(function() {';
611$out .=
' if (! $(this).is(\':checked\')) {';
612$out .=
' console.log("We uncheck anonymous ping");';
613$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
614$out .=
' } else {'.
"\n";
615$out .=
' console.log("We check anonymous ping");';
616$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
624pFooter($ok ? 0 : 1, $setuplang);
626if (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.