dolibarr 22.0.5
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-2025 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';
34
49$err = 0;
50$allowinstall = 0;
51$allowupgrade = false;
52$checksok = 1;
53
54$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
55$langs->setDefaultLang($setuplang);
56
57$langs->load("install");
58
59// Now we load forced/pre-set values from install.forced.php file.
60$useforcedwizard = false;
61$forcedfile = "./install.forced.php";
62if ($conffile == "/etc/dolibarr/conf.php") {
63 $forcedfile = "/etc/dolibarr/install.forced.php";
64}
65if (@file_exists($forcedfile)) {
66 $useforcedwizard = true;
67 include_once $forcedfile;
68}
69
70dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
71
72
73/*
74 * View
75 */
76
77pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
78
79
80//print "<br>\n";
81//print $langs->trans("InstallEasy")."<br><br>\n";
82
83print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
84print '<span class="inline-block valignmiddle">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
85
86// Check browser
87$useragent = $_SERVER['HTTP_USER_AGENT'];
88if (!empty($useragent)) {
89 $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
90 $browserversion = $tmp['browserversion'];
91 $browsername = $tmp['browsername'];
92 if ($browsername == 'ie' && $browserversion < 7) {
93 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
94 }
95}
96
97
98// Check PHP version min
99$arrayphpminversionerror = array(7, 0, 0);
100$arrayphpminversionwarning = array(7, 1, 0);
101if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
102 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
103 $checksok = 0; // 0=error, 1=warning
104} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
105 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
106 $checksok = 1; // 0=error, 1=warning
107} else {
108 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
109}
110if (empty($force_install_nophpinfo)) {
111 print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
112}
113print "<br>\n";
114
115// Check PHP version max
116$arrayphpmaxversionwarning = array(8, 4, 0);
117if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
118 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
119 $checksok = 1; // 0=error, 1=warning
120 print "<br>\n";
121}
122
123
124// Check PHP support for $_GET and $_POST
125if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
126 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETKo");
127 print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
128 print "<br>\n";
129 $checksok = 0;
130} else {
131 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupportPOSTGETOk")."<br>\n";
132}
133
134
135// Check if session_id is enabled
136if (!function_exists("session_id")) {
137 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
138 $checksok = 0;
139} else {
140 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupportSessions")."<br>\n";
141}
142
143
144// Check for mbstring extension
145if (!extension_loaded("mbstring")) {
146 $langs->load("errors");
147 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "MBString")."<br>\n";
148 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
149} else {
150 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "MBString")."<br>\n";
151}
152
153// Check for json extension
154if (!extension_loaded("json")) {
155 $langs->load("errors");
156 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "JSON")."<br>\n";
157 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
158} else {
159 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "JSON")."<br>\n";
160}
161
162// Check if GD is supported (we need GD for image conversion)
163if (!function_exists("imagecreate")) {
164 $langs->load("errors");
165 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "GD")."<br>\n";
166 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
167} else {
168 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "GD")."<br>\n";
169}
170
171// Check if Curl is supported
172if (!function_exists("curl_init")) {
173 $langs->load("errors");
174 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<br>\n";
175 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
176} else {
177 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Curl")."<br>\n";
178}
179
180// Check if PHP calendar extension is available
181if (!function_exists("easter_date")) {
182 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
183} else {
184 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
185}
186
187// Check if Xml is supported
188if (!function_exists("simplexml_load_string")) {
189 $langs->load("errors");
190 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
191 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
192} else {
193 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
194}
195
196// Check if UTF8 is supported
197if (!function_exists("utf8_encode")) {
198 $langs->load("errors");
199 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
200 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
201} else {
202 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
203}
204
205// Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
206if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
207 if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
208 $langs->load("errors");
209 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
210 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
211 } else {
212 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
213 }
214}
215
216// Check if Imap is supported
217if (PHP_VERSION_ID <= 80300) {
218 if (!function_exists("imap_open")) {
219 $langs->load("errors");
220 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
221 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
222 } else {
223 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
224 }
225}
226
227// Check if Zip is supported
228if (!class_exists('ZipArchive')) {
229 $langs->load("errors");
230 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
231 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
232} else {
233 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
234}
235
236// Check memory
237$memrequiredorig = '64M';
238$memrequired = 64 * 1024 * 1024;
239$memmaxorig = @ini_get("memory_limit");
240$memmax = @ini_get("memory_limit");
241if ($memmaxorig != '') {
242 $reg = array();
243 preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
244 if ($reg[2]) {
245 if (strtoupper($reg[2]) == 'G') {
246 $memmax = (int) $reg[1] * 1024 * 1024 * 1024;
247 }
248 if (strtoupper($reg[2]) == 'M') {
249 $memmax = (int) $reg[1] * 1024 * 1024;
250 }
251 if (strtoupper($reg[2]) == 'K') {
252 $memmax = (int) $reg[1] * 1024;
253 }
254 }
255 if ($memmax >= $memrequired || $memmax == -1) {
256 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
257 } else {
258 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle paddingright"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
259 }
260}
261
262
263// If that config file is present and filled
264clearstatcache();
265if (is_readable($conffile) && filesize($conffile) > 8) {
266 dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
267 $confexists = 1;
268 include_once $conffile;
269
270 $databaseok = 1;
271 if ($databaseok) {
272 // Already installed for all parts (config and database). We can propose upgrade.
273 $allowupgrade = true;
274 } else {
275 $allowupgrade = false;
276 }
277} else {
278 // If not, we create it
279 dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
280 $confexists = 0;
281
282 // First we try by copying example
283 if (@copy($conffile.".example", $conffile)) {
284 // Success
285 dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
286 } else {
287 // If failed, we try to create an empty file
288 dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
289
290 $fp = @fopen($conffile, "w");
291 if ($fp) {
292 @fwrite($fp, '<?php');
293 @fwrite($fp, "\n");
294 fclose($fp);
295 } else {
296 dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
297 }
298 }
299
300 // First install: no upgrade necessary/required
301 $allowupgrade = false;
302}
303
304
305
306// File is missing and cannot be created
307if (!file_exists($conffile)) {
308 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle paddingright"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
309 print '<br><br><div class="error">';
310 print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
311 print '</div><br><br>'."\n";
312
313 print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
314 $err++;
315} else {
316 if (dol_is_dir($conffile)) {
317 print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
318
319 $allowinstall = 0;
320 } elseif (!is_writable($conffile)) {
321 // File exists but cannot be modified
322 if ($confexists) {
323 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileExists", $conffiletoshow);
324 } else {
325 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
326 }
327 print "<br>";
328 print '<img src="../theme/eldy/img/tick.png" alt="Warning" class="valignmiddle paddingright"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
329 print "<br>\n";
330
331 $allowinstall = 0;
332 } else {
333 // File exists and can be modified
334 if ($confexists) {
335 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileExists", $conffiletoshow);
336 } else {
337 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
338 }
339 print "<br>";
340 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
341 print "<br>\n";
342
343 $allowinstall = 1;
344 }
345 print "<br>\n";
346
347 // Requirements met/all ok: display the next step button
348 if ($checksok) {
349 $ok = false;
350
351 // Try to create db connection
352 if (file_exists($conffile)) {
353 include_once $conffile;
354 if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
355 if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
356 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";
357 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);
358 } else {
359 require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
360
361 // If password is encoded, we decode it
362 if (preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
363 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
364 if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
365 $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
366 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
367 } elseif (preg_match('/dolcrypt:/i', $dolibarr_main_db_pass)) {
368 $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
369 $dolibarr_main_db_pass = dolDecrypt($dolibarr_main_db_pass);
370 } else {
371 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
372 }
373 }
374
375 // $conf already created in inc.php
376 $conf->db->type = $dolibarr_main_db_type;
377 $conf->db->host = $dolibarr_main_db_host;
378 $conf->db->port = $dolibarr_main_db_port;
379 $conf->db->name = $dolibarr_main_db_name;
380 $conf->db->user = $dolibarr_main_db_user;
381 $conf->db->pass = $dolibarr_main_db_pass;
382
383 $db = getDoliDBInstance($conf->db->type, $conf->db->host, (string) $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
384 if ($db->connected && $db->database_selected) {
385 $ok = true;
386 }
387 }
388 }
389 }
390
391 $dolibarrlastupgradeversionarray = array();
392 // If database access is available, we set more variables
393 if ($ok) {
394 if (empty($dolibarr_main_db_encryption)) {
395 $dolibarr_main_db_encryption = 0;
396 }
397 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
398 if (empty($dolibarr_main_db_cryptkey)) {
399 $dolibarr_main_db_cryptkey = '';
400 }
401 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
402
403 $conf->setValues($db);
404 // Reset forced setup after the setValues
405 if (defined('SYSLOG_FILE')) {
406 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
407 }
408 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
409
410 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
411 // Version to install is DOL_VERSION
412 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')));
413 $dolibarrversiontoinstallarray = versiondolibarrarray();
414 }
415
416 // Show title
417 if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) {
418 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')).'</span></b> - ';
419 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
420 //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
421 print '<br>';
422 print '<br>';
423 } else {
424 print "<br>\n";
425 }
426
427 //print $langs->trans("InstallEasy")." ";
428 print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
429
430 $foundrecommandedchoice = 0;
431
432 $available_choices = array();
433 $notavailable_choices = array();
434
435 if (empty($dolibarr_main_db_host)) { // This means install process was not run
436 $foundrecommandedchoice = 1; // To show only once
437 }
438
439 // Show line of first install choice
440 $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
441 $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
442 $choice .= '</td>';
443 $choice .= '<td class="listofchoicesdesc">';
444 $choice .= $langs->trans("FreshInstallDesc");
445 if (empty($dolibarr_main_db_host)) { // This means install process was not run
446 $choice .= '<br>';
447 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
448 $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
449 // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle paddingright"> ';
450 }
451
452 $choice .= '</td>';
453 $choice .= '<td class="center">';
454 if ($allowinstall) {
455 $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
456 } else {
457 $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
458 }
459 $choice .= '</td>'."\n";
460 $choice .= '</tr>'."\n";
461
462 $positionkey = ($foundrecommandedchoice ? 999 : 0);
463 if ($allowinstall) {
464 $available_choices[$positionkey] = $choice;
465 } else {
466 $notavailable_choices[$positionkey] = $choice;
467 }
468
469 // Show upgrade lines
470 $allowupgrade = true;
471 if (empty($dolibarr_main_db_host)) { // This means install process was not run
472 $allowupgrade = false;
473 }
474 if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
475 $allowupgrade = false;
476 }
477 if (GETPOST('allowupgrade')) {
478 $allowupgrade = true;
479 }
480
481 $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
482 dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
483
484 // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
485 $migrationscript = array();
486 $handle = opendir($dir);
487 if (is_resource($handle)) {
488 $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
489 while (($file = readdir($handle)) !== false) {
490 $reg = array();
491 if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
492 //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
493 if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
494 $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
495 }
496 }
497 }
498 $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
499 } else {
500 print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
501 }
502
503 $count = 0;
504 foreach ($migrationscript as $migarray) {
505 $choice = '';
506
507 $count++;
508 $recommended_choice = false;
509 $version = DOL_VERSION;
510 $versionfrom = $migarray['from'];
511 $versionto = $migarray['to'];
512 $versionarray = preg_split('/[\.-]/', $version);
513 $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
514 $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
515 // Define string newversionxxx that are used for text to show
516 $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
517 $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
518 $newversionfrombis = '';
519 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
520 $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
521 }
522
523 if ($ok) {
524 if (is_array($dolibarrlastupgradeversionarray) && count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
525 // Now we check if this is the first qualified choice
526 if ($allowupgrade && empty($foundrecommandedchoice) &&
527 (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
528 ) {
529 $foundrecommandedchoice = 1; // To show only once
530 $recommended_choice = true;
531 }
532 } else {
533 // We cannot recommend a choice.
534 // A version of install may be known, but we need last upgrade.
535 }
536 }
537
538 $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
539 $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
540 $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
541 $choice .= '<td class="listofchoicesdesc">';
542 $choice .= $langs->trans("UpgradeDesc");
543
544 if ($recommended_choice) {
545 $choice .= '<br>';
546 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
547 $choice .= '<div class="center">';
548 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
549 if ($count < count($migarray)) { // There are other choices after
550 print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
551 }
552 $choice .= '</div>';
553 }
554
555 $choice .= '</td>';
556 $choice .= '<td class="center">';
557 if ($allowupgrade) {
558 $disabled = false;
559 if ($foundrecommandedchoice == 2) {
560 $disabled = true;
561 }
562 if ($foundrecommandedchoice == 1) {
563 $foundrecommandedchoice = 2;
564 }
565 if ($disabled) {
566 $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
567 } else {
568 $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
569 }
570 } else {
571 $choice .= $langs->trans("NotAvailable");
572 }
573 $choice .= '</td>';
574 $choice .= '</tr>'."\n";
575
576 if ($allowupgrade) {
577 $available_choices[$count] = $choice;
578 } else {
579 $notavailable_choices[$count] = $choice;
580 }
581 }
582
583 // If there is no choice at all, we show all of them.
584 if (empty($available_choices)) {
585 $available_choices = $notavailable_choices;
586 $notavailable_choices = array();
587 }
588
589 // Array of install choices
590 krsort($available_choices, SORT_NATURAL);
591 print"\n";
592 print '<table width="100%" class="listofchoices">';
593 foreach ($available_choices as $choice) {
594 print $choice;
595 }
596
597 print '</table>'."\n";
598
599 if (count($notavailable_choices)) {
600 print '<br><div id="AShowChoices" style="opacity: 0.5">';
601 print '> '.$langs->trans('ShowNotAvailableOptions').'...';
602 print '</div>';
603
604 print '<div id="navail_choices" style="display:none">';
605 print "<br>\n";
606 print '<table width="100%" class="listofchoices">';
607 foreach ($notavailable_choices as $choice) {
608 print $choice;
609 }
610
611 print '</table>'."\n";
612 print '</div>';
613 }
614 }
615}
616
617print '<script type="text/javascript">
618
619$("div#AShowChoices").click(function() {
620
621 $("div#navail_choices").toggle();
622
623 if ($("div#navail_choices").css("display") == "none") {
624 $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
625 } else {
626 $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
627 }
628
629});
630
631/*
632$(".runupgrade").click(function() {
633 return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
634});
635*/
636
637</script>';
638
639dolibarr_install_syslog("- check: end");
640pFooter(1); // Never display next button
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition admin.lib.php:39
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:71
dol_is_dir($folder)
Test if filename is a directory.
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...
getBrowserInfo($user_agent)
Return information about user browser.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.
Definition inc.php:538
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:631
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:695
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.