dolibarr 25.0.0-alpha
check.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
33include_once 'inc.php';
55'
56@phan-var-force string $lockfile
57@phan-var-force string $lockfile2
58';
59
60$err = 0;
61$allowinstall = 0;
62$allowupgrade = false;
63$checksok = 1;
64
65$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
66$langs->setDefaultLang($setuplang);
67
68$langs->loadLangs(array("install", "admin"));
69
70// Now we load forced/pre-set values from install.forced.php file.
71$useforcedwizard = false;
72$forcedfile = "./install.forced.php";
73if ($conffile == "/etc/dolibarr/conf.php") {
74 $forcedfile = "/etc/dolibarr/install.forced.php";
75}
76if (@file_exists($forcedfile)) {
77 $useforcedwizard = true;
78 include_once $forcedfile;
79}
80
81dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
82
83
84/*
85 * View
86 */
87
88pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
89
90
91print '<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/gear.svg" width="20" alt="Database"> ';
92print '<span class="inline-block valignmiddle">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
93
94// Check browser
95$useragent = $_SERVER['HTTP_USER_AGENT'] ?? '';
96if (!empty($useragent)) {
97 $tmp = getBrowserInfo($useragent);
98 $browserversion = $tmp['browserversion'];
99 $browsername = $tmp['browsername'];
100 if ($browsername == 'ie' && $browserversion < 7) {
101 print img_picto('', 'warning', 'class="pictofixedwidth warning"');
102 print $langs->trans("WarningBrowserTooOld")."<br>\n";
103 }
104}
105
106
107// Check PHP version min
108$arrayphpminversionerror = array(7, 1, 0);
109$arrayphpminversionwarning = array(7, 2, 0);
110if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
111 print img_picto('', 'warning', 'class="pictofixedwidth error"');
112 print $langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
113 $checksok = 0; // 0=error, 1=warning
114} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
115 print img_picto('', 'warning', 'class="pictofixedwidth warning"');
116 print $langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
117 $checksok = 1; // 0=error, 1=warning
118} else {
119 print img_picto('', 'tick', 'class="pictofixedwidth"');
120 print $langs->trans("PHPVersion")." ".versiontostring(versionphparray());
121}
122if (empty($force_install_nophpinfo) && (!file_exists($lockfile) && !file_exists($lockfile2))) { // Do not show sensible information in update process, only in install process.
123 print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">';
124 $conf->use_javascript_ajax = 1; // We suppose javascript is on for install process
125 print dolButtonToOpenUrlInDialogPopup('phpinfo', $langs->trans("MoreInformation"), $langs->trans("MoreInformation"), '/install/phpinfo.php', '', '');
126 print '</a>)';
127}
128print "<br>\n";
129
130// Check PHP version max
131$arrayphpmaxversionwarning = array(8, 5, 0);
132if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
133 print img_picto('', 'warning', 'class="pictofixedwidth error"');
134 print $langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
135 $checksok = 1; // 0=error, 1=warning
136 print "<br>\n";
137}
138
139
140// Check PHP support for $_GET and $_POST
141if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
142 print img_picto('', 'warning', 'class="pictofixedwidth warning"');
143 print $langs->trans("PHPSupportPOSTGETKo");
144 print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
145 print "<br>\n";
146 $checksok = 0;
147} else {
148 print img_picto('', 'tick', 'class="pictofixedwidth"');
149 print $langs->trans("PHPSupportPOSTGETOk")."<br>\n";
150}
151
152
153// Check if session_id is enabled
154if (!function_exists("session_id")) {
155 print img_picto('', 'warning', 'class="pictofixedwidth error"');
156 print $langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
157 $checksok = 0;
158} else {
159 print img_picto('', 'tick', 'class="pictofixedwidth"');
160 print $langs->trans("PHPSupportSessions")."<br>\n";
161}
162
163$extensionok = array();
164$extensionko = array();
165
166// Check for mbstring extension
167if (!extension_loaded("mbstring")) {
168 $extensionko[] = 'MBString';
169 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
170} else {
171 $extensionok[] = 'MBString';
172}
173
174// Check for json extension
175if (!extension_loaded("json")) {
176 $extensionko[] = 'JSON';
177 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
178} else {
179 $extensionok[] = 'JSON';
180}
181
182// Check if GD is supported (we need GD for image conversion)
183if (!function_exists("imagecreate")) {
184 $extensionko[] = 'GD';
185 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
186} else {
187 $extensionok[] = 'GD';
188}
189
190// Check if Curl is supported
191if (!function_exists("curl_init")) {
192 $extensionko[] = 'Curl';
193 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
194} else {
195 $extensionok[] = 'Curl';
196}
197
198// Check if PHP calendar extension is available
199if (!function_exists("easter_date")) {
200 $extensionko[] = 'Calendar';
201} else {
202 $extensionok[] = 'Calendar';
203}
204
205// Check if Xml is supported
206if (!function_exists("simplexml_load_string")) {
207 $extensionko[] = 'Xml';
208 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
209} else {
210 $extensionok[] = 'Xml';
211}
212
213// Check if Dom is supported. Dolibarr uses DOMDocument to sanitize html, so a page can not even be rendered without it.
214if (!extension_loaded("dom")) {
215 $langs->load("errors");
216 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Dom")."<br>\n";
217 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
218} else {
219 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Dom")."<br>\n";
220}
221
222// Check if UTF8 is supported
223if (!function_exists("utf8_encode")) {
224 $extensionko[] = 'UTF8';
225 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
226} else {
227 $extensionok[] = 'UTF8';
228}
229
230// Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
231if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
232 if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
233 $extensionko[] = 'Intl';
234 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
235 } else {
236 $extensionok[] = 'Intl';
237 }
238}
239
240// Check if Imap is supported
241if (PHP_VERSION_ID <= 80300) {
242 if (!function_exists("imap_open")) {
243 $extensionko[] = 'IMAP';
244 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
245 } else {
246 $extensionok[] = 'IMAP';
247 }
248}
249
250// Check if Zip is supported
251if (!class_exists('ZipArchive')) {
252 $extensionko[] = 'ZIP';
253 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
254} else {
255 $extensionok[] = 'ZIP';
256}
257
258if (!empty($extensionok)) {
259 //print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle pictofixedwidth"> ';
260 print img_picto('', 'tick', 'class="pictofixedwidth"');
261 print $langs->trans("PHPSupport", '<b>'.implode(', ', $extensionok).'</b>')."<br>\n";
262}
263if (!empty($extensionko)) {
264 //print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle pictofixedwidth"> ';
265 $langs->load('errors');
266 print img_picto('', 'warning', 'class="pictofixedwidth error"');
267 print $langs->trans("ErrorPHPDoesNotSupport", '<b>'.implode(', ', $extensionko).'</b>')."<br>\n";
268}
269
270
271// Check memory
272$memrequiredorig = '64M';
273$memrequired = 64 * 1024 * 1024;
274$memmaxorig = @ini_get("memory_limit");
275$memmax = @ini_get("memory_limit");
276if ($memmaxorig != '') {
277 $reg = array();
278 preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
279 if ($reg[2]) {
280 if (strtoupper($reg[2]) == 'G') {
281 $memmax = (int) $reg[1] * 1024 * 1024 * 1024;
282 }
283 if (strtoupper($reg[2]) == 'M') {
284 $memmax = (int) $reg[1] * 1024 * 1024;
285 }
286 if (strtoupper($reg[2]) == 'K') {
287 $memmax = (int) $reg[1] * 1024;
288 }
289 }
290 if ($memmax >= $memrequired || $memmax == -1) {
291 print img_picto('', 'tick', 'class="pictofixedwidth"');
292 print $langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
293 } else {
294 print img_picto('', 'warning', 'class="pictofixedwidth warning"');
295 print $langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
296 }
297}
298
299// If that config file is present and filled
300clearstatcache();
301if (is_readable($conffile) && filesize($conffile) > 8) {
302 dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
303 $confexists = 1;
304 include_once $conffile;
305
306 $databaseok = 1;
307 if ($databaseok) {
308 // Already installed for all parts (config and database). We can propose upgrade.
309 $allowupgrade = true;
310 } else {
311 $allowupgrade = false;
312 }
313} else {
314 // If not, we create it
315 dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
316 $confexists = 0;
317
318 // First we try by copying example
319 if (@copy($conffile.".example", $conffile)) {
320 // Success
321 dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
322 } else {
323 // If failed, we try to create an empty file
324 dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
325
326 $fp = @fopen($conffile, "w");
327 if ($fp) {
328 @fwrite($fp, '<?php');
329 @fwrite($fp, "\n");
330 fclose($fp);
331 } else {
332 dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
333 }
334 }
335
336 // First install: no upgrade necessary/required
337 $allowupgrade = false;
338}
339
340
341// File is missing and cannot be created
342if (!file_exists($conffile)) {
343 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle pictofixedwidth"> ';
344 print $langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
345 print '<br><br><div class="error">';
346 print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
347 print '</div><br><br>'."\n";
348
349 print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
350 $err++;
351} else {
352 if (dol_is_dir($conffile)) {
353 print img_picto('', 'warning', 'class="pictofixedwidth error"');
354 print $langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
355
356 $allowinstall = 0;
357 } elseif (!is_writable($conffile)) {
358 // File exists but cannot be modified
359 if ($confexists) {
360 print img_picto('', 'tick', 'class="pictofixedwidth"');
361 print $langs->trans("ConfFileExists", $conffiletoshow);
362 } else {
363 print img_picto('', 'tick', 'class="pictofixedwidth"');
364 print $langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
365 }
366 print "<br>";
367 print img_picto('', 'tick', 'class="pictofixedwidth warning"');
368 print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
369 print "<br>\n";
370
371 $allowinstall = 0;
372 } else {
373 // File exists and can be modified
374 if ($confexists) {
375 print img_picto('', 'tick', 'class="pictofixedwidth"');
376 print $langs->trans("ConfFileExists", $conffiletoshow);
377 } else {
378 print img_picto('', 'tick', 'class="pictofixedwidth"');
379 print $langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
380 }
381 print "<br>";
382 print img_picto('', 'tick', 'class="pictofixedwidth"');
383 print $langs->trans("ConfFileIsWritable", $conffiletoshow);
384 print "<br>\n";
385
386 $allowinstall = 1;
387 }
388 print "<br>\n";
389
390 // Requirements met/all ok: display the next step button
391 if ($checksok) {
392 $ok = false;
393 $db = null;
394 $validfoundconf = false;
395
396 // Try to create db connection
397 if (file_exists($conffile)) {
398 include_once $conffile;
399 if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
400 if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
401 print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n";
402 dol_syslog("A '".$conffiletoshow."' file exists with a dolibarr_main_document_root to ".$dolibarr_main_document_root." that seems wrong. Try to fix or remove the '".$conffiletoshow."' file.", LOG_WARNING);
403 } else {
404 $validfoundconf = true;
405
406 require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
407
408 // If password is encoded, we decode it
409 if (preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
410 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
411 if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
412 $dolibarr_main_db_encrypted_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); // We need to set this as it is used to know the password was initially encrypted
413 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
414 } elseif (preg_match('/dolcrypt:/i', $dolibarr_main_db_pass)) {
415 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
416 $dolibarr_main_db_pass = dolDecrypt($dolibarr_main_db_pass);
417 } else {
418 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
419 }
420 }
421
422 // $conf already created in inc.php
423 $conf->db->type = $dolibarr_main_db_type;
424 $conf->db->host = $dolibarr_main_db_host;
425 $conf->db->port = $dolibarr_main_db_port;
426 $conf->db->name = $dolibarr_main_db_name;
427 $conf->db->user = $dolibarr_main_db_user;
428 $conf->db->pass = $dolibarr_main_db_pass;
429
430 $db = getDoliDBInstance($conf->db->type, $conf->db->host, (string) $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
431 if ($db->connected && $db->database_selected) {
432 $ok = true;
433 }
434 }
435 }
436 }
437
438 $dolibarrlastupgradeversionarray = array();
439 // If database access is available, we set more variables
440 if ($db !== null && $ok) {
441 if (empty($dolibarr_main_db_encryption)) {
442 $dolibarr_main_db_encryption = 0;
443 }
444 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
445 if (empty($dolibarr_main_db_cryptkey)) {
446 $dolibarr_main_db_cryptkey = '';
447 }
448 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
449
450 $conf->setValues($db);
451 // Reset forced setup after the setValues
452 if (defined('SYSLOG_FILE')) {
453 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
454 }
455 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
456
457 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
458 // Version to install is DOL_VERSION
459 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')));
460 $dolibarrversiontoinstallarray = versiondolibarrarray();
461 } elseif ($validfoundconf) {
462 print 'Failed to connect with data found in the current conf.php file.<br>';
463 }
464
465 // Show title
466 if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) {
467 print $langs->trans("VersionLastUpgrade").' <b><span class="badge-text okinversed">'.getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')).'</span></b> &nbsp; - &nbsp; ';
468 print $langs->trans("VersionProgram").' <b><span class="badge-text okinversed">'.DOL_VERSION.'</span></b>';
469 //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
470 print '<br>';
471 print '<br>';
472 } else {
473 print "<br>\n";
474 }
475
476 print '<br>';
477 print '<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/gear.svg" width="20" alt="Database"> ';
478 print '<span class="soustitre valignmiddle">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
479
480 $foundrecommandedchoice = 0;
481
482 $available_choices = array();
483 $notavailable_choices = array();
484
485 if (empty($dolibarr_main_db_host)) { // This means install process was not run
486 $foundrecommandedchoice = 1; // To show only once
487 }
488
489 // Show line of first install choice
490 $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
491 $choice .= '<td class="nowrap center firstcolumn"><b>'.$langs->trans("FreshInstall").'</b>';
492 $choice .= '</td>';
493 $choice .= '<td class="listofchoicesdesc">';
494 if (empty($dolibarr_main_db_host)) { // This means install process was not run
495 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
496 $choice .= '<div class=">';
497 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
498 $choice .= '</div>';
499 $choice .= '<br><br>';
500 }
501
502 $choice .= '<span class="opacitymedium">'.$langs->trans("FreshInstallDesc").'</span>';
503
504 $choice .= '</td>';
505 $choice .= '<td class="center lastcolumn">';
506 if ($allowinstall) {
507 $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
508 } else {
509 $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
510 }
511 $choice .= '</td>'."\n";
512 $choice .= '</tr>'."\n";
513
514 $positionkey = ($foundrecommandedchoice ? 999 : 0);
515 if ($allowinstall) {
516 $available_choices[$positionkey] = $choice;
517 } else {
518 $notavailable_choices[$positionkey] = $choice;
519 }
520
521 // Show upgrade lines
522 $allowupgrade = true;
523 if (empty($dolibarr_main_db_host)) { // This means install process was not run
524 $allowupgrade = false;
525 }
526 if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
527 $allowupgrade = false;
528 }
529 if (GETPOST('allowupgrade')) {
530 $allowupgrade = true;
531 }
532
533 $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
534 dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
535
536 // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
537 $migrationscript = array();
538 $handle = opendir($dir);
539 if (is_resource($handle)) {
540 $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
541 while (($file = readdir($handle)) !== false) {
542 $reg = array();
543 if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
544 //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
545 if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
546 $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
547 }
548 }
549 }
550 $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
551 } else {
552 print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
553 }
554
555 $count = 0;
556 foreach ($migrationscript as $migarray) {
557 $count++;
558 $recommended_choice = false;
559 $version = DOL_VERSION;
560 $versionfrom = $migarray['from'];
561 $versionto = $migarray['to'];
562 $versionarray = preg_split('/[\.-]/', $version);
563 $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
564 $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
565 // Define string newversionxxx that are used for text to show
566 $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
567 $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
568 $newversionfrombis = '';
569 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
570 $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
571 }
572
573 if ($ok) {
574 if (is_array($dolibarrlastupgradeversionarray) && count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
575 // Now we check if this is the first qualified choice
576 if ($allowupgrade && empty($foundrecommandedchoice) &&
577 (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
578 ) {
579 $foundrecommandedchoice = 1; // To show only once
580 $recommended_choice = true;
581 }
582 } else {
583 // We cannot recommend a choice.
584 // A version of install may be known, but we need last upgrade.
585 }
586 }
587
588 $choice = '';
589
590 $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
591 $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
592 $choice .= '<td class="nowrap center firstcolumn"><span class="opacitymedium">'.$langs->trans("Upgrade").'</span><br><b>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
593 $choice .= '<td class="listofchoicesdesc">';
594
595 if ($recommended_choice) {
596 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
597 $choice .= '<div class="">';
598 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
599 if ($count < count($migarray)) { // There are other choices after
600 print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
601 }
602 $choice .= '</div><br><br>';
603 }
604
605 $choice .= '<span class="opacitymedium">';
606 $choice .= $langs->trans("UpgradeDesc");
607 $choice .= '</span>';
608
609 $choice .= '</td>';
610 $choice .= '<td class="center lastcolumn">';
611 if ($allowupgrade) {
612 $disabled = false;
613 if ($foundrecommandedchoice == 2) {
614 $disabled = true;
615 }
616 if ($foundrecommandedchoice == 1) {
617 $foundrecommandedchoice = 2;
618 }
619 if ($disabled) {
620 $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
621 } else {
622 $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'"';
623 if ($recommended_choice) {
624 $choice .= ' title="'.dol_string_nohtmltag($langs->trans("InstallChoiceSuggested")).'"';
625 } else {
626 $choice .= ' title="'.dol_string_nohtmltag($langs->trans("MigrationAlreadyDone")).'"';
627 }
628 $choice .= '>';
629 $choice .= $langs->trans("Start");
630 $choice .= '</a>';
631 }
632 } else {
633 $choice .= $langs->trans("NotAvailable");
634 }
635 $choice .= '</td>';
636 $choice .= '</tr>'."\n";
637
638 if ($allowupgrade && $recommended_choice) {
639 $available_choices[$count] = $choice;
640 } else {
641 $notavailable_choices[$count] = $choice;
642 }
643 }
644
645 // If there is no choice at all, we show all of them.
646 if (empty($available_choices)) {
647 $available_choices = $notavailable_choices;
648 $notavailable_choices = array();
649 }
650
651 // Array of install choices
652 krsort($available_choices, SORT_NATURAL);
653 print"\n";
654 print '<table class="centpercent listofchoices">';
655 foreach ($available_choices as $choice) {
656 print $choice;
657 }
658
659 print '</table>'."\n";
660
661 if (count($notavailable_choices)) {
662 print '<br><div id="AShowChoices" class="opacitymedium cursorpointer">';
663 print '> '.$langs->trans('ShowNotAvailableOptions').'...';
664 print '</div>';
665
666 print '<div id="navail_choices" style="display:none">';
667 print "<br>\n";
668 print '<table class="centpercent listofchoices">';
669 foreach ($notavailable_choices as $choice) {
670 print $choice;
671 }
672
673 print '</table>'."\n";
674 print '</div>';
675 }
676 }
677}
678
679print '<script type="text/javascript">
680
681$("div#AShowChoices").click(function() {
682
683 $("div#navail_choices").toggle();
684
685 if ($("div#navail_choices").css("display") == "none") {
686 $(this).text(\'> '.dol_escape_js($langs->transnoentitiesnoconv('ShowNotAvailableOptions')).'...\');
687 } else {
688 $(this).text(\'> '.dol_escape_js($langs->transnoentitiesnoconv('HideNotAvailableOptions')).'...\');
689 }
690
691});
692
693/*
694$(".runupgrade").click(function() {
695 return confirm(\''.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'\');
696});
697*/
698
699</script>';
700
701dolibarr_install_syslog("- check: end");
702pFooter(1); // Never display next button
versiontostring($versionarray)
Return a version in a string from a version into an array.
Definition admin.lib.php:40
versiondolibarrarray()
Return version Dolibarr.
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:79
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
$conffile
dol_is_dir($folder)
Test if filename is a directory.
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getBrowserInfo($user_agent)
Return information about user browser.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
Definition html.lib.php:437
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:553
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:711
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.