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