28 require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
29 require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
39 $err = error_reporting();
42 @set_time_limit(1800);
43 error_reporting($err);
45 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
46 $setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
47 $langs->setDefaultLang($setuplang);
49 $langs->loadLangs(array(
"admin",
"install"));
52 if ($dolibarr_main_db_type ==
"mysqli") $choix = 1;
53 if ($dolibarr_main_db_type ==
"pgsql") $choix = 2;
54 if ($dolibarr_main_db_type ==
"mssql") $choix = 3;
55 if ($dolibarr_main_db_type ==
"sqlite") $choix = 4;
56 if ($dolibarr_main_db_type ==
"sqlite3") $choix = 5;
61 $useforcedwizard =
false;
62 $forcedfile =
"./install.forced.php";
63 if ($conffile ==
"/etc/dolibarr/conf.php") $forcedfile =
"/etc/dolibarr/install.forced.php";
64 if (@file_exists($forcedfile)) {
65 $useforcedwizard =
true;
66 include_once $forcedfile;
68 if (!empty($argv[1]) && $argv[1] ==
"set") $action =
"set";
78 pHeader($langs->trans(
"CreateDatabaseObjects"),
"step4");
81 if (!is_writable($conffile))
83 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
84 pFooter(1, $setuplang,
'jscheckparam');
90 print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
92 print '<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
95 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
100 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
103 print "<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
108 if ($db->database_selected)
113 print "<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
122 $version = $db->getVersion();
123 $versionarray = $db->getVersionArray();
124 print '<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
125 print '<td>'.$version.
'</td></tr>';
128 print '<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
129 print '<td>'.$db->database_name.
'</td></tr>';
137 $createtables = isset($_GET[
'createtables']) ?
GETPOST(
'createtables') : 1;
138 $createkeys = isset($_GET[
'createkeys']) ?
GETPOST(
'createkeys') : 1;
139 $createfunctions = isset($_GET[
'createfunctions']) ?
GETPOST(
'createfunction') : 1;
140 $createdata = isset($_GET[
'createdata']) ?
GETPOST(
'createdata') : 1;
144 $db->unescapeslashquot =
true;
153 if ($ok && $createtables)
156 $dir =
"mysql/tables/";
159 $handle = opendir($dir);
162 $tabledata = array();
163 if (is_resource($handle))
165 while (($file = readdir($handle)) !==
false)
167 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file))
170 $tabledata[] = $file;
178 foreach ($tabledata as $file)
180 $name = substr($file, 0,
dol_strlen($file) - 4);
182 $fp = fopen($dir.$file,
"r");
187 $buf = fgets($fp, 4096);
188 if (substr($buf, 0, 2) <>
'--')
190 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
196 $buffer = trim($buffer);
197 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli')
199 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
203 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
204 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
208 if ($dolibarr_main_db_prefix !=
'llx_')
210 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
217 $resql = $db->query($buffer, 0,
'dml');
223 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
224 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS')
228 print "<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
229 print "<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
231 print '<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
236 print "<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
238 print '<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
249 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
253 print '<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
265 if ($ok && $createkeys)
268 $dir =
"mysql/tables/";
271 $handle = opendir($dir);
274 $tabledata = array();
275 if (is_resource($handle))
277 while (($file = readdir($handle)) !==
false)
279 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file))
282 $tabledata[] = $file;
290 foreach ($tabledata as $file)
292 $name = substr($file, 0,
dol_strlen($file) - 4);
295 $fp = fopen($dir.$file,
"r");
300 $buf = fgets($fp, 4096);
303 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg))
305 $versioncommande = explode(
'.', $reg[1]);
308 if (count($versioncommande) && count($versionarray)
312 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
316 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg))
318 $versioncommande = explode(
'.', $reg[1]);
321 if (count($versioncommande) && count($versionarray)
325 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
331 if (!preg_match(
'/^--/i', $buf)) $buffer .= $buf;
336 $listesql = explode(
';', $buffer);
337 foreach ($listesql as $req)
339 $buffer = trim($req);
343 if ($dolibarr_main_db_prefix !=
'llx_')
345 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
352 $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()))
367 print "<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
368 print "<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
370 print '<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
377 print "<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
379 print '<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
385 if ($tablefound && $error == 0)
388 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
399 if ($ok && $createfunctions)
402 if ($choix == 1) $dir =
"mysql/functions/";
403 elseif ($choix == 2) $dir = "pgsql/functions/";
404 elseif ($choix == 3) $dir = "mssql/functions/";
405 elseif ($choix == 4) { $dir =
"sqlite3/functions/"; }
408 $file =
"functions.sql";
409 if (file_exists($dir.$file))
411 $fp = fopen($dir.$file,
"r");
418 $buf = fgets($fp, 4096);
419 if (substr($buf, 0, 2) <>
'--')
429 $listesql = explode(
'§', $buffer);
430 foreach ($listesql as $buffer)
432 $buffer = trim($buffer);
436 if ($dolibarr_main_db_prefix !=
'llx_')
438 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
441 print "<!-- Insert line : ".$buffer.
"<br>-->\n";
442 $resql = $db->query($buffer, 0,
'dml');
448 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
449 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS')
455 print "<tr><td>".$langs->trans(
"FunctionsCreation");
456 print "<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
458 print '<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
465 print "<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
468 print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
470 print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
482 if ($ok && $createdata)
485 $dir =
"mysql/data/";
488 $handle = opendir($dir);
491 $tabledata = array();
492 if (is_resource($handle))
494 while (($file = readdir($handle)) !==
false)
496 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file))
498 if (preg_match(
'/^llx_accounting_account_/', $file))
continue;
501 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file))
504 $tabledata[] = $file;
513 foreach ($tabledata as $file)
515 $name = substr($file, 0,
dol_strlen($file) - 4);
516 $fp = fopen($dir.$file,
"r");
520 $arrayofrequests = array();
528 $buffer = fgets($fp, 4096);
529 $buffer = trim($buffer);
532 if (substr($buffer, 0, 2) ==
'--')
continue;
534 if ($linefound && ($linefound % $sizeofgroup) == 0)
538 if (empty($arrayofrequests[$linegroup])) $arrayofrequests[$linegroup] = $buffer;
539 else $arrayofrequests[$linegroup] .=
" ".$buffer;
552 foreach ($arrayofrequests as $buffer)
555 if ($dolibarr_main_db_prefix !=
'llx_')
557 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
561 $resql = $db->query($buffer, 1);
566 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
572 print '<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
577 if ($okallfile) $db->commit();
578 else $db->rollback();
582 print "<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
585 print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
587 print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
593 print 'Parameter action=set not defined';
598 if (!$ok && isset($argv[1])) $ret = 1;
604 $out =
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno" value="checked" checked="true"> ';
605 $out .= $langs->trans(
"MakeAnonymousPing");
607 $out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
608 $out .=
'<script type="text/javascript">';
609 $out .=
'jQuery(document).ready(function(){';
610 $out .=
' document.cookie = "DOLINSTALLNOPING_'.md5($dolibarr_main_instance_unique_id).
'=0; path=/"'.
"\n";
611 $out .=
' jQuery("#dolibarrpingno").click(function() {';
612 $out .=
' if (! $(this).is(\':checked\')) {';
613 $out .=
' console.log("We uncheck anonymous ping");';
614 $out .=
' document.cookie = "DOLINSTALLNOPING_'.md5($dolibarr_main_instance_unique_id).
'=1; path=/"'.
"\n";
622 pFooter($ok ? 0 : 1, $setuplang);
624 if (isset($db) && is_object($db)) $db->close();
627 if ($ret) exit($ret);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
pHeader($subtitle, $next, $action= 'set', $param= '', $forcejqueryurl= '', $csstable= 'main-inside')
Show HTML header of install pages.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
pFooter($nonext=0, $setuplang= '', $jscheckfunction= '', $withpleasewait=0)
Print HTML footer of install pages.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.