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';
101pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"CreateDatabaseObjects"),
"step4");
104if (!is_writable($conffile)) {
105 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
106 pFooter(1, $setuplang,
'jscheckparam');
110if ($action ==
"set") {
111 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
113 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
116 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
118 if ($db->connected) {
120 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
123 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
127 if ($db->database_selected) {
131 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
139 $version = $db->getVersion();
140 $versionarray = $db->getVersionArray();
141 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
142 print
'<td>'.$version.
'</td></tr>';
145 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
146 print
'<td>'.$db->database_name.
'</td></tr>';
154 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
155 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
156 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
157 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
161 if (property_exists($db,
'unescapeslashquot')) {
162 $db->unescapeslashquot =
true;
171 if ($ok && $createtables) {
173 $dir =
"mysql/tables/";
176 $handle = opendir($dir);
177 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
179 $tabledata = array();
180 if (is_resource($handle)) {
181 while (($file = readdir($handle)) !==
false) {
182 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
184 $tabledata[] = $file;
192 foreach ($tabledata as $file) {
193 $name = substr($file, 0,
dol_strlen($file) - 4);
195 $fp = fopen($dir.$file,
"r");
198 $buf = fgets($fp, 4096);
199 if (substr($buf, 0, 2) !=
'--') {
200 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
206 $buffer = trim($buffer);
207 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
208 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
212 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
213 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
217 if ($dolibarr_main_db_prefix !=
'llx_') {
218 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
225 $resql = $db->query($buffer, 0,
'dml');
230 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
231 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
234 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
235 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
237 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
242 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
244 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
253 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
257 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
269 if ($ok && $createkeys) {
271 $dir =
"mysql/tables/";
274 $handle = opendir($dir);
275 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
277 $tabledata = array();
278 if (is_resource($handle)) {
279 while (($file = readdir($handle)) !==
false) {
280 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
282 $tabledata[] = $file;
290 foreach ($tabledata as $file) {
291 $name = substr($file, 0,
dol_strlen($file) - 4);
294 $fp = fopen($dir.$file,
"r");
297 $buf = fgets($fp, 4096);
301 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
302 $versioncommande = explode(
'.', $reg[1]);
305 if (count($versioncommande) && count($versionarray)
308 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
313 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
314 $versioncommande = explode(
'.', $reg[1]);
317 if (count($versioncommande) && count($versionarray)
320 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
326 if (!preg_match(
'/^--/i', $buf)) {
333 $listesql = explode(
';', $buffer);
334 foreach ($listesql as $req) {
335 $buffer = trim($req);
338 if ($dolibarr_main_db_prefix !=
'llx_') {
339 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
346 $resql = $db->query($buffer, 0,
'dml');
351 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
352 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
353 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
354 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
355 preg_match(
'/duplicate key name/i', $db->error())) {
359 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
360 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
362 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
369 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
371 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
377 if ($tablefound && $error == 0) {
379 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
390 if ($ok && $createfunctions) {
393 $dir =
"mysql/functions/";
394 } elseif ($choix == 2) {
395 $dir =
"pgsql/functions/";
396 } elseif ($choix == 3) {
397 $dir =
"mssql/functions/";
398 } elseif ($choix == 4) {
399 $dir =
"sqlite3/functions/";
403 $file =
"functions.sql";
404 if (file_exists($dir.$file)) {
405 $fp = fopen($dir.$file,
"r");
406 dolibarr_install_syslog(
"step2: open function file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
410 $buf = fgets($fp, 4096);
411 if (substr($buf, 0, 2) !=
'--') {
420 $listesql = explode(
'§', $buffer);
421 foreach ($listesql as $buffer) {
422 $buffer = trim($buffer);
425 if ($dolibarr_main_db_prefix !=
'llx_') {
426 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
429 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
430 $resql = $db->query($buffer, 0,
'dml');
435 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
436 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
441 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
442 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
444 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
451 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
453 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
455 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
467 if ($ok && $createdata) {
469 $dir =
"mysql/data/";
472 $handle = opendir($dir);
473 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
475 $tabledata = array();
476 if (is_resource($handle)) {
477 while (($file = readdir($handle)) !==
false) {
478 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
479 if (preg_match(
'/^llx_accounting_account_/', $file)) {
484 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
486 $tabledata[] = $file;
495 foreach ($tabledata as $file) {
496 $name = substr($file, 0,
dol_strlen($file) - 4);
497 $fp = fopen($dir.$file,
"r");
498 dolibarr_install_syslog(
"step2: open data file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
500 $arrayofrequests = array();
507 $buffer = fgets($fp, 4096);
508 $buffer = trim($buffer);
510 if (substr($buffer, 0, 2) ==
'--') {
514 if ($linefound && ($linefound % $sizeofgroup) == 0) {
517 if (empty($arrayofrequests[$linegroup])) {
518 $arrayofrequests[$linegroup] = $buffer;
520 $arrayofrequests[$linegroup] .=
" ".$buffer;
534 foreach ($arrayofrequests as $buffer) {
536 if ($dolibarr_main_db_prefix !=
'llx_') {
537 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
541 $buffer = preg_replace(
'/__ENTITY__/i',
'1', $buffer);
544 $resql = $db->query($buffer, 1);
548 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
553 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
566 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
568 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
570 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
576 print
'Parameter action=set not defined';
581if (!$ok && isset($argv[1])) {
592$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);
594$hash_unique_id =
dol_hash(
'dolibarr'.$conf->file->instance_unique_id,
'sha256');
596$out =
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
597$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
599$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
600$out .=
'<script type="text/javascript">';
601$out .=
'jQuery(document).ready(function(){';
602$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
603$out .=
' jQuery("#dolibarrpingno").click(function() {';
604$out .=
' if (! $(this).is(\':checked\')) {';
605$out .=
' console.log("We uncheck anonymous ping");';
606$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
607$out .=
' } else {'.
"\n";
608$out .=
' console.log("We check anonymous ping");';
609$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
617pFooter($ok ? 0 : 1, $setuplang);
619if (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.