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